Skip to content

Commit

Permalink
[IMP] pos_payment_change : simplify code of test, and make it compati…
Browse files Browse the repository at this point in the history
…ble with pos_check_accounting_settings_company module
  • Loading branch information
legalsylvain committed Jul 2, 2024
1 parent ce44854 commit 6b112e4
Showing 1 changed file with 15 additions and 29 deletions.
44 changes: 15 additions & 29 deletions pos_payment_change/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,21 @@ def setUp(self):
"pos.payment.change.wizard.new.line"
]
self.product = self.env.ref("product.product_product_3")
self.pos_config = self.env.ref("point_of_sale.pos_config_main").copy()

def _initialize_journals_open_session(self):
account_id = self.env.company.account_default_pos_receivable_account_id
self.bank_payment_method = self.PosPaymentMethod.create(
{
"name": "Bank",
"receivable_account_id": account_id.id,
self.pos_config = self.env.ref("point_of_sale.pos_config_main").copy(
default={
"payment_method_ids": self.env.ref(
"point_of_sale.pos_config_main"
).payment_method_ids.ids
}
)
self.cash_payment_method = self.PosPaymentMethod.create(
{
"name": "Cash",
"is_cash_count": True,
"receivable_account_id": account_id.id,
"journal_id": self.env["account.journal"]
.search(
[("type", "=", "cash"), ("company_id", "=", self.env.company.id)],
limit=1,
)
.id,
}
self.cash_payment_method = self.pos_config.payment_method_ids.filtered(
lambda x: x.journal_id.type == "cash"
)
self.bank_payment_method = self.pos_config.payment_method_ids.filtered(
lambda x: x.journal_id.type == "bank" and not x.split_transactions
)

# create new session and open it
self.pos_config.payment_method_ids = [
self.bank_payment_method.id,
self.cash_payment_method.id,
]
def _open_session(self):
self.pos_config.open_ui()
self.session = self.pos_config.current_session_id

Expand Down Expand Up @@ -120,7 +106,7 @@ def _change_payment(
def test_01_payment_change_policy_update(self):
self.pos_config.payment_change_policy = "update"

self._initialize_journals_open_session()
self._open_session()
# Make a sale with 35 in cash journal and 65 in check
order = self._sale(self.cash_payment_method, 35, self.bank_payment_method, 65)

Expand Down Expand Up @@ -165,7 +151,7 @@ def test_01_payment_change_policy_update(self):
def test_02_payment_change_policy_refund(self):
self.pos_config.payment_change_policy = "refund"

self._initialize_journals_open_session()
self._open_session()
# Make a sale with 35 in cash journal and 65 in check
order = self._sale(self.cash_payment_method, 35, self.bank_payment_method, 65)

Expand All @@ -185,7 +171,7 @@ def test_02_payment_change_policy_refund(self):
def test_03_payment_change_closed_orders(self):
self.pos_config.payment_change_policy = "update"

self._initialize_journals_open_session()
self._open_session()
# Make a sale with 35 in cash journal and 65 in check
order = self._sale(self.cash_payment_method, 35, self.bank_payment_method, 65)

Expand All @@ -198,7 +184,7 @@ def test_03_payment_change_closed_orders(self):

def test_04_payment_change_security(self):
self.pos_config.payment_change_policy = "refund"
self._initialize_journals_open_session()
self._open_session()
order = self._sale(self.cash_payment_method, 35, self.bank_payment_method, 65)

# the demo user should be able to do this
Expand Down

0 comments on commit 6b112e4

Please sign in to comment.