Skip to content

Commit

Permalink
[REF] eng_cnab_filename: adapt new cnab config
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniospneto committed Feb 3, 2025
1 parent b7b3d5b commit 3c14d20
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion eng_cnab_filename/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Engenere",
"maintainers": ["antoniospneto"],
"website": "https://engenere.one",
"version": "14.0.1.0.0",
"version": "14.0.2.0.0",
"depends": ["l10n_br_account_payment_order"],
"data": [
"views/account_payment_mode.xml",
Expand Down
30 changes: 30 additions & 0 deletions eng_cnab_filename/migrations/14.0.2.0.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2024 - Engenere (<https://engenere.one>).
# @author Antônio S. Pereira Neto <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
# Verifique se o campo antigo existe no banco de dados
if openupgrade.column_exists(
env.cr, "account_payment_mode", "filename_sequence_id"
):
# Atualizar o arquivo cnab_config_id com filename_sequence_id
env.cr.execute(
"""
UPDATE l10n_br_cnab_config cc
SET filename_sequence_id = (
SELECT filename_sequence_id
FROM account_payment_mode apm
WHERE apm.cnab_config_id = cc.id
)
WHERE EXISTS (
SELECT 1
FROM account_payment_mode apm
WHERE apm.cnab_config_id = cc.id
AND apm.filename_sequence_id IS NOT NULL
)
"""
)
2 changes: 1 addition & 1 deletion eng_cnab_filename/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from . import account_payment_order
from . import account_payment_mode
from . import cnab_config
2 changes: 1 addition & 1 deletion eng_cnab_filename/models/account_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def get_file_name(self, cnab_type):
"""
Sobrescreve a lógica para a criação do nome a partir do sequenciador.
"""
sequence = self.payment_mode_id.filename_sequence_id
sequence = self.payment_mode_id.cnab_config_id.filename_sequence_id
if sequence:
filename = f"{sequence.next_by_id()}.REM"
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class AccountPaymentMode(models.Model):
_inherit = "account.payment.mode"
_inherit = "l10n_br_cnab.config"

filename_sequence_id = fields.Many2one(
comodel_name="ir.sequence",
Expand Down
8 changes: 4 additions & 4 deletions eng_cnab_filename/views/account_payment_mode.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="eng_cnab_filename_payment_mode_form" model="ir.ui.view">
<field name="name">eng_cnab_filename.payment_mode.form</field>
<field name="model">account.payment.mode</field>
<record id="cnab_config_form_view_filename_extension" model="ir.ui.view">
<field name="name">cnab.config.form.view.filename.extension</field>
<field name="model">l10n_br_cnab.config</field>
<field name="priority">99</field>
<field
name="inherit_id"
ref="l10n_br_account_payment_order.l10n_br_account_payment_mode_form"
ref="l10n_br_account_payment_order.l10n_br_cnab_config_form_view"
/>
<field name="arch" type="xml">
<field name="cnab_sequence_id" position="after">
Expand Down

0 comments on commit 3c14d20

Please sign in to comment.