diff --git a/l10n_br_account_payment_order/__manifest__.py b/l10n_br_account_payment_order/__manifest__.py index 634bfadc332c..7b4a8f3f0b45 100644 --- a/l10n_br_account_payment_order/__manifest__.py +++ b/l10n_br_account_payment_order/__manifest__.py @@ -39,6 +39,7 @@ # Wizards "wizards/account_payment_line_create_view.xml", "wizards/account_move_line_change.xml", + "wizards/account_move_payment_mode.xml", # Views "views/account_journal.xml", "views/account_payment_order.xml", diff --git a/l10n_br_account_payment_order/security/ir.model.access.csv b/l10n_br_account_payment_order/security/ir.model.access.csv index 134583be1d17..72571af88f26 100644 --- a/l10n_br_account_payment_order/security/ir.model.access.csv +++ b/l10n_br_account_payment_order/security/ir.model.access.csv @@ -18,3 +18,4 @@ access_l10n_br_cnab_payment_fields_manager,l10n_br_cnab.payment.fields manager,m access_account_move_line_cnab_change_user,access_account_move_line_cnab_change_user,model_account_move_line_cnab_change,group_cnab_user,1,1,1,1 access_l10n_br_cnab_boleto_wallet_code_manager,access_l10n_br_cnab_boleto_wallet_code manager,model_l10n_br_cnab_boleto_wallet_code,group_cnab_manager,1,1,1,1 access_l10n_br_cnab_boleto_wallet_code_user,access_l10n_br_cnab_boleto_wallet_code user,model_l10n_br_cnab_boleto_wallet_code,group_cnab_user,1,0,0,0 +access_account_move_payment_mode_cnab_change_user,access_account_move_payment_mode_cnab_change,model_account_move_payment_mode_cnab_change,base.group_user,1,1,1,1 diff --git a/l10n_br_account_payment_order/tests/test_payment_order_change.py b/l10n_br_account_payment_order/tests/test_payment_order_change.py index e48edc318cfa..5a1d3ed0eac0 100644 --- a/l10n_br_account_payment_order/tests/test_payment_order_change.py +++ b/l10n_br_account_payment_order/tests/test_payment_order_change.py @@ -18,6 +18,7 @@ def setUpClass(cls): cls.invoice_auto = cls.env.ref( "l10n_br_account_payment_order." "demo_invoice_automatic_test" ) + cls.wizard_payment_mode_cnab = cls.env["account.move.payment.mode.cnab.change"] if cls.invoice_auto.state == "draft": cls.invoice_auto.action_post() @@ -318,3 +319,20 @@ def test_change_suspend_cancel_discount(self): "mov_instruction_code_id" ).ids ), "Payment Order with wrong mov_instruction_code_id" + + def test_payment_mode_cnab_change(self): + invoice = self.env.ref( + "l10n_br_account_payment_order.demo_invoice_payment_order_manual" + ) + self.assertEqual(invoice.state, "posted") + payment_mode_id = self.env.ref( + "l10n_br_account_payment_order.payment_mode_cobranca_santander_400" + ) + with Form( + self.wizard_payment_mode_cnab.with_context(active_id=invoice.id) + ) as f: + f.payment_mode_id = payment_mode_id + wizard = f.save() + wizard.set_payment_mode() + + self.assertEqual(invoice.payment_mode_id, payment_mode_id) diff --git a/l10n_br_account_payment_order/wizards/__init__.py b/l10n_br_account_payment_order/wizards/__init__.py index c685fabf345a..0878b9ae86b6 100644 --- a/l10n_br_account_payment_order/wizards/__init__.py +++ b/l10n_br_account_payment_order/wizards/__init__.py @@ -1,2 +1,3 @@ from . import account_payment_line_create from . import account_move_line_change +from . import account_move_payment_mode diff --git a/l10n_br_account_payment_order/wizards/account_move_payment_mode.py b/l10n_br_account_payment_order/wizards/account_move_payment_mode.py new file mode 100644 index 000000000000..61446df8d4d6 --- /dev/null +++ b/l10n_br_account_payment_order/wizards/account_move_payment_mode.py @@ -0,0 +1,24 @@ +# Copyright 2024 - TODAY, Kaynnan Lemes +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + +from ..constants import BR_CODES_PAYMENT_ORDER + + +class AccountMovePaymentModeWizard(models.TransientModel): + _name = "account.move.payment.mode.cnab.change" + _description = "Account Move Payment Mode CNAB Wizard" + + payment_mode_id = fields.Many2one( + "account.payment.mode", + required=True, + domain=lambda self: [("payment_method_code", "in", BR_CODES_PAYMENT_ORDER)], + ) + + def set_payment_mode(self): + move_id = self.env.context.get("active_id") + move = self.env["account.move"].browse(move_id) + if move.state == "posted": + move.payment_mode_id = self.payment_mode_id + move.load_cnab_info() diff --git a/l10n_br_account_payment_order/wizards/account_move_payment_mode.xml b/l10n_br_account_payment_order/wizards/account_move_payment_mode.xml new file mode 100644 index 000000000000..4186e4263173 --- /dev/null +++ b/l10n_br_account_payment_order/wizards/account_move_payment_mode.xml @@ -0,0 +1,35 @@ + + + + + + account.move.payment.mode.cnab.change.form + account.move.payment.mode.cnab.change + +
+ + + +
+
+
+
+
+ + + Set Payment Mode CNAB + account.move.payment.mode.cnab.change + form + + new + + +