diff --git a/l10n_it_withholding_tax/models/withholding_tax.py b/l10n_it_withholding_tax/models/withholding_tax.py index eae7d9b93253..bcd8a88ca5e1 100644 --- a/l10n_it_withholding_tax/models/withholding_tax.py +++ b/l10n_it_withholding_tax/models/withholding_tax.py @@ -437,7 +437,11 @@ def generate_account_move(self): move_lines.append((0, 0, ml_vals)) move_vals["line_ids"] = move_lines - move = self.env["account.move"].create(move_vals) + move = ( + self.env["account.move"] + .with_context(default_move_type="entry") + .create(move_vals) + ) move.action_post() # Save move in the wt move diff --git a/l10n_it_withholding_tax/tests/test_withholding_tax.py b/l10n_it_withholding_tax/tests/test_withholding_tax.py index da8594c7db8c..7386339d38b5 100644 --- a/l10n_it_withholding_tax/tests/test_withholding_tax.py +++ b/l10n_it_withholding_tax/tests/test_withholding_tax.py @@ -40,6 +40,10 @@ def setUp(self): {"name": "Bank", "type": "bank", "code": "BNK67"} ) + # Payment Register + self.payment_register_model = self.env["account.payment.register"] + self.register_view_id = "account.view_account_payment_register_form" + # Payments vals_payment = { "name": "", @@ -139,19 +143,15 @@ def test_withholding_tax(self): "active_model": "account.move", "active_ids": [self.invoice.id], } - register_payments = ( - self.env["account.payment.register"] - .with_context(ctx) - .create( - { - "payment_date": time.strftime("%Y") + "-07-15", - "amount": 800, - "journal_id": self.journal_bank.id, - "payment_method_id": self.env.ref( - "account.account_payment_method_manual_out" - ).id, - } - ) + register_payments = self.payment_register_model.with_context(ctx).create( + { + "payment_date": time.strftime("%Y") + "-07-15", + "amount": 800, + "journal_id": self.journal_bank.id, + "payment_method_id": self.env.ref( + "account.account_payment_method_manual_out" + ).id, + } ) register_payments.action_create_payments() @@ -183,19 +183,15 @@ def test_partial_payment(self): "active_id": self.invoice.id, "default_reconciled_invoice_ids": [(4, self.invoice.id, None)], } - register_payments = ( - self.env["account.payment.register"] - .with_context(ctx) - .create( - { - "payment_date": time.strftime("%Y") + "-07-15", - "amount": 600, - "journal_id": self.journal_bank.id, - "payment_method_id": self.env.ref( - "account.account_payment_method_manual_out" - ).id, - } - ) + register_payments = self.payment_register_model.with_context(ctx).create( + { + "payment_date": time.strftime("%Y") + "-07-15", + "amount": 600, + "journal_id": self.journal_bank.id, + "payment_method_id": self.env.ref( + "account.account_payment_method_manual_out" + ).id, + } ) register_payments.action_create_payments() @@ -283,3 +279,19 @@ def test_duplicating_wt(self): new_tax = self.wt1040.copy() self.assertEqual(new_tax.code, "1040 (copy)") self.assertEqual(new_tax.name, "Code 1040") + + def test_create_payments(self): + """Test create payment when Register Payment wizard is open from Bill tree view""" + ctx = { + "active_ids": [self.invoice.id], + "active_model": "account.move", + } + f = Form( + self.payment_register_model.with_context(ctx), view=self.register_view_id + ) + payment_register = f.save() + # passing default_move_type="in_invoice" in the context in order + # to simulate opening of payment_register from Bills tree view + payment_register.with_context( + default_move_type="in_invoice" + ).action_create_payments()