Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][FIX] l10n_br_account_payment_order: trigger CNAB info load on payment_mode_id change #3213

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions l10n_br_account_payment_order/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions l10n_br_account_payment_order/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions l10n_br_account_payment_order/tests/test_payment_order_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions l10n_br_account_payment_order/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import account_payment_line_create
from . import account_move_line_change
from . import account_move_payment_mode
24 changes: 24 additions & 0 deletions l10n_br_account_payment_order/wizards/account_move_payment_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2024 - TODAY, Kaynnan Lemes <[email protected]>
# 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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 - TODAY, Kaynnan Lemes <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>

<record id="account_move_payment_mode_cnab_change_wizard_form" model="ir.ui.view">
<field name="name">account.move.payment.mode.cnab.change.form</field>
<field name="model">account.move.payment.mode.cnab.change</field>
<field name="arch" type="xml">
<form string="Set Payment Mode CNAB">
<group>
<field name="payment_mode_id" />
</group>
<footer>
<button
name="set_payment_mode"
string="Confirm"
class="btn-primary"
type="object"
/>
<button string="Cancel" class="btn-default" special="cancel" />
</footer>
</form>
</field>
</record>

<record model="ir.actions.act_window" id="wizard_set_payment_mode_cnab_act_multi">
<field name="name">Set Payment Mode CNAB</field>
<field name="res_model">account.move.payment.mode.cnab.change</field>
<field name="view_mode">form</field>
<field name="binding_model_id" ref="model_account_move" />
<field name="target">new</field>
</record>

</odoo>
Loading