Skip to content

Commit

Permalink
[IMP] l10n_br_account_payment_order: wizard trigger CNAB info load af…
Browse files Browse the repository at this point in the history
…ter posted
  • Loading branch information
kaynnan committed Jul 28, 2024
1 parent 1b26aea commit 2bda539
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 0 deletions.
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
15 changes: 15 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,17 @@ 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):
self.assertEqual(self.invoice_auto.state, "posted")
payment_mode_id = self.env.ref(
"l10n_br_account_payment_order.main_payment_mode_boleto"
)
with Form(
self.wizard_payment_mode_cnab.with_context(active_id=self.invoice_auto.id)
) as f:
f.payment_mode_id = payment_mode_id
wizard = f.save()
wizard.set_payment_mode()

self.assertEqual(self.invoice_auto.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>

0 comments on commit 2bda539

Please sign in to comment.