Skip to content

Commit

Permalink
[REF] l10n_br_account_payment_brcobranca: Unified CNAB Codes in only …
Browse files Browse the repository at this point in the history
…one object and separated CNAB Configuration from Payment Mode.
  • Loading branch information
mbcosta committed Aug 9, 2024
1 parent 09690d2 commit 83f01b0
Show file tree
Hide file tree
Showing 14 changed files with 315 additions and 185 deletions.
4 changes: 2 additions & 2 deletions l10n_br_account_payment_brcobranca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "L10n Br Account Payment BRCobranca",
"version": "14.0.5.2.4",
"name": "Brazilian Payment Order BRCobranca",
"version": "14.0.6.0.0",
"license": "AGPL-3",
"author": "Akretion, " "Odoo Community Association (OCA)",
"maintainers": ["rvalyi", "mbcosta"],
Expand Down
56 changes: 28 additions & 28 deletions l10n_br_account_payment_brcobranca/demo/account_payment_mode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,112 +3,112 @@

<!-- Bradesco CNAB 400 -->
<record
id="l10n_br_account_payment_order.payment_mode_cobranca_bradesco400"
model="account.payment.mode"
id="l10n_br_account_payment_order.cnab_config_bradesco_400"
model="l10n_br_cnab.config"
>
<field name="cnab_processor">brcobranca</field>
</record>

<!-- Modo de Pagamento cobrança Bradesco 240 -->
<record
id="l10n_br_account_payment_order.payment_mode_cobranca_bradesco240"
model="account.payment.mode"
id="l10n_br_account_payment_order.cnab_config_bradesco_240"
model="l10n_br_cnab.config"
>
<field name="cnab_processor">brcobranca</field>
</record>

<!-- Payment Mode Cobrança Unicred 400 -->
<record
id="l10n_br_account_payment_order.payment_mode_cobranca_unicred400"
model="account.payment.mode"
id="l10n_br_account_payment_order.cnab_config_unicred_400"
model="l10n_br_cnab.config"
>
<field name="cnab_processor">brcobranca</field>
</record>

<!-- Payment Mode Cobrança Unicred 240 -->
<record
id="l10n_br_account_payment_order.payment_mode_cobranca_unicred240"
model="account.payment.mode"
id="l10n_br_account_payment_order.cnab_config_unicred_240"
model="l10n_br_cnab.config"
>
<field name="cnab_processor">brcobranca</field>
</record>

<!-- Payment Mode Cobrança AILOS 240 -->
<record
id="l10n_br_account_payment_order.payment_mode_cobranca_ailos240"
model="account.payment.mode"
id="l10n_br_account_payment_order.cnab_config_ailos_240"
model="l10n_br_cnab.config"
>
<field name="cnab_processor">brcobranca</field>
</record>

<!-- Modo de Pagamento cobrança Itau 240 -->
<record
id="l10n_br_account_payment_order.payment_mode_cobranca_itau240"
model="account.payment.mode"
id="l10n_br_account_payment_order.cnab_config_itau_240"
model="l10n_br_cnab.config"
>
<field name="cnab_processor">brcobranca</field>
</record>

<!-- Modo de Pagamento cobrança Itau 400 -->
<record
id="l10n_br_account_payment_order.payment_mode_cobranca_itau400"
model="account.payment.mode"
id="l10n_br_account_payment_order.cnab_config_itau_400"
model="l10n_br_cnab.config"
>
<field name="cnab_processor">brcobranca</field>
</record>

<!-- Modo de Pagamento cobrança Caixa Economica Federal 240 -->
<record
id="l10n_br_account_payment_order.payment_mode_cobranca_cef240"
model="account.payment.mode"
id="l10n_br_account_payment_order.cnab_config_cef_240"
model="l10n_br_cnab.config"
>
<field name="cnab_processor">brcobranca</field>
</record>

<!-- Modo de Pagamento cobrança Caixa Economica Federal 400 -->
<record
id="l10n_br_account_payment_order.payment_mode_cobranca_cef400"
model="account.payment.mode"
id="l10n_br_account_payment_order.cnab_config_cef_400"
model="l10n_br_cnab.config"
>
<field name="cnab_processor">brcobranca</field>
</record>

<!-- Modo de Pagamento Cobrança SICRED 240 -->
<record
id="l10n_br_account_payment_order.payment_mode_cobranca_sicredi240"
model="account.payment.mode"
id="l10n_br_account_payment_order.cnab_config_sicredi_240"
model="l10n_br_cnab.config"
>
<field name="cnab_processor">brcobranca</field>
</record>

<!-- Payment Mode Cobrança Banco do Brasil 400 -->
<record
id="l10n_br_account_payment_order.payment_mode_cobranca_bb400"
model="account.payment.mode"
id="l10n_br_account_payment_order.cnab_config_bb_400"
model="l10n_br_cnab.config"
>
<field name="cnab_processor">brcobranca</field>
</record>

<!-- Payment Mode Cobrança Banco do Brasil 240 -->
<record
id="l10n_br_account_payment_order.payment_mode_cobranca_bb240"
model="account.payment.mode"
id="l10n_br_account_payment_order.cnab_config_bb_240"
model="l10n_br_cnab.config"
>
<field name="cnab_processor">brcobranca</field>
</record>

<!-- Bradesco 400 -->
<record
id="l10n_br_account_payment_order.payment_mode_cobranca_santander_400"
model="account.payment.mode"
id="l10n_br_account_payment_order.cnab_config_santander_400"
model="l10n_br_cnab.config"
>
<field name="cnab_processor">brcobranca</field>
</record>

<!-- Bradesco 240 -->
<record
id="l10n_br_account_payment_order.payment_mode_cobranca_santander_240"
model="account.payment.mode"
id="l10n_br_account_payment_order.cnab_config_santander_240"
model="l10n_br_cnab.config"
>
<field name="cnab_processor">brcobranca</field>
</record>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2024-Today - Akretion (<http://www.akretion.com>).
# @author Magno Costa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


def update_cnab_config(env):
"""Atualiza a Configurção do CNAB"""
env.cr.execute(
"""
SELECT id FROM account_payment_mode WHERE payment_method_id IN
(SELECT id FROM account_payment_method WHERE code IN ('240', '400', '500')
AND payment_type = 'inbound');
"""
)
for row in env.cr.fetchall():
payment_mode = env["account.payment.mode"].browse(row[0])
cnab_config = env["l10n_br_cnab.config"].search(
[
("bank_id", "=", payment_mode.fixed_journal_id.bank_id.id),
("payment_method_id", "=", payment_mode.payment_method_id.id),
]
)
cnab_config.cnab_processor = payment_mode.cnab_processor


@openupgrade.migrate()
def migrate(env, version):
if not version:
return
update_cnab_config(env)
1 change: 1 addition & 0 deletions l10n_br_account_payment_brcobranca/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from . import account_payment_line
from . import account_journal
from . import account_payment_mode
from . import l10n_br_cnab_config
2 changes: 1 addition & 1 deletion l10n_br_account_payment_brcobranca/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AccountMove(models.Model):
_inherit = "account.move"

def generate_boleto_pdf(self):
if self.payment_mode_id.cnab_processor != "brcobranca":
if self.payment_mode_id.cnab_config_id.cnab_processor != "brcobranca":
return super().generate_boleto_pdf()

file_pdf = self.file_boleto_pdf_id
Expand Down
34 changes: 15 additions & 19 deletions l10n_br_account_payment_brcobranca/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def send_payment(self):
bank_name_brcobranca = get_brcobranca_bank(
bank_account_id, move_line.payment_mode_id.payment_method_code
)
cnab_config = move_line.payment_mode_id.cnab_config_id

boleto_cnab_api_data = {
"bank": bank_name_brcobranca[0],
Expand All @@ -64,8 +65,8 @@ def send_payment(self):
"sacado_documento": move_line.partner_id.cnpj_cpf,
"agencia": bank_account_id.bra_number,
"conta_corrente": bank_account_id.acc_number,
"convenio": move_line.payment_mode_id.cnab_company_bank_code,
"carteira": str(move_line.payment_mode_id.boleto_wallet),
"convenio": cnab_config.cnab_company_bank_code,
"carteira": str(cnab_config.boleto_wallet),
"nosso_numero": int(
"".join(i for i in move_line.own_number if i.isdigit())
),
Expand All @@ -74,10 +75,10 @@ def send_payment(self):
"data_documento": move_line.move_id.invoice_date.strftime("%Y/%m/%d"),
"especie": move_line.currency_id.symbol,
"especie_documento": get_boleto_especie_short_name(
move_line.payment_mode_id.boleto_species
cnab_config.boleto_species
),
"moeda": DICT_BRCOBRANCA_CURRENCY["R$"],
"aceite": move_line.payment_mode_id.boleto_accept,
"aceite": cnab_config.boleto_accept,
"sacado_endereco": (move_line.partner_id.street_name or "")
+ " "
+ (move_line.partner_id.street_number or "")
Expand All @@ -92,22 +93,19 @@ def send_payment(self):
"data_processamento": move_line.move_id.invoice_date.strftime(
"%Y/%m/%d"
),
"instrucao1": move_line.payment_mode_id.instructions or "",
"instrucao1": cnab_config.instructions or "",
}

# Instrução de Juros
if move_line.payment_mode_id.boleto_interest_perc > 0.0:
if cnab_config.boleto_interest_perc > 0.0:
valor_juros = move_line.currency_id.round(
move_line.debit
* ((move_line.payment_mode_id.boleto_interest_perc / 100) / 30),
move_line.debit * ((cnab_config.boleto_interest_perc / 100) / 30),
)
instrucao_juros = (
"APÓS VENCIMENTO COBRAR PERCENTUAL"
+ " DE %s %% AO MÊS ( R$ %s AO DIA )"
% (
(
"%.2f" % move_line.payment_mode_id.boleto_interest_perc
).replace(".", ","),
("%.2f" % cnab_config.boleto_interest_perc).replace(".", ","),
("%.2f" % valor_juros).replace(".", ","),
)
)
Expand All @@ -118,17 +116,15 @@ def send_payment(self):
)

# Instrução Multa
if move_line.payment_mode_id.boleto_fee_perc > 0.0:
if cnab_config.boleto_fee_perc > 0.0:
valor_multa = move_line.currency_id.round(
move_line.debit * (move_line.payment_mode_id.boleto_fee_perc / 100),
move_line.debit * (cnab_config.boleto_fee_perc / 100),
)
instrucao_multa = (
"APÓS VENCIMENTO COBRAR MULTA"
+ " DE %s %% ( R$ %s )"
% (
("%.2f" % move_line.payment_mode_id.boleto_fee_perc).replace(
".", ","
),
("%.2f" % cnab_config.boleto_fee_perc).replace(".", ","),
("%.2f" % valor_multa).replace(".", ","),
)
)
Expand Down Expand Up @@ -174,8 +170,8 @@ def send_payment(self):
if bank_account_id.bank_id.code_bc in ("748", "756"):
boleto_cnab_api_data.update(
{
"byte_idt": move_line.payment_mode_id.boleto_byte_idt,
"posto": move_line.payment_mode_id.boleto_post,
"byte_idt": cnab_config.boleto_byte_idt,
"posto": cnab_config.boleto_post,
}
)
# Campo usado no Unicred
Expand All @@ -194,7 +190,7 @@ def send_payment(self):
# no boleto é usado o convenio
boleto_cnab_api_data.update(
{
"convenio": move_line.payment_mode_id.convention_code,
"convenio": cnab_config.convention_code,
}
)

Expand Down
Loading

0 comments on commit 83f01b0

Please sign in to comment.