Skip to content

Commit

Permalink
Merge PR #3537 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by rvalyi
  • Loading branch information
OCA-git-bot committed Jan 13, 2025
2 parents 32b58d0 + 589accb commit a64f78a
Show file tree
Hide file tree
Showing 62 changed files with 4,156 additions and 3,407 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ jobs:
POSTGRES_DB: odoo
ports:
- 5432:5432
boleto_cnab_api:
image: ghcr.io/akretion/boleto_cnab_api:latest
ports:
- 9292:9292
env:
BRCOBRANCA_API_URL: http://boleto_cnab_api:9292
steps:
- uses: actions/checkout@v3
with:
Expand Down
347 changes: 183 additions & 164 deletions l10n_br_account_payment_brcobranca/README.rst

Large diffs are not rendered by default.

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 @@ -4,8 +4,8 @@

{
"name": "Boletos e CNAB de cobrança",
"summary": "receivable Boletos and CNAB using the brcobranca lib",
"version": "16.0.2.0.0",
"summary": "receivable Boletos and CNAB using the BRCobranca lib",
"version": "16.0.3.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 Configuraçã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)
2 changes: 1 addition & 1 deletion l10n_br_account_payment_brcobranca/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from . import account_payment_order
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: 16 additions & 18 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,19 +93,16 @@ 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),
)
percentual_formatado = (
f"{move_line.payment_mode_id.boleto_interest_perc:.2f}".replace(
".", ","
)
f"{cnab_config.boleto_interest_perc:.2f}".replace(".", ",")
)
juros_formatado = f"{valor_juros:.2f}".replace(".", ",")
instrucao_juros = (
Expand All @@ -118,12 +116,12 @@ 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),
)
percentual_formatado = (
f"{move_line.payment_mode_id.boleto_fee_perc:.2f}".replace(".", ",")
percentual_formatado = f"{cnab_config.boleto_fee_perc:.2f}".replace(
".", ","
)
multa_formatado = f"{valor_multa:.2f}".replace(".", ",")
instrucao_multa = (
Expand Down Expand Up @@ -173,8 +171,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 @@ -193,7 +191,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 a64f78a

Please sign in to comment.