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][REF+IMP] l10n_br_account_payment_order, l10n_br_account_payment_brcobranca: Adaptando o código para atender o Santander 240 e 400 #2925

Merged
Merged
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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exclude: |
^l10n_br_mdfe_spec/models/v3_0/| # (don't reformat generated code)
^spec_driven_model/tests/| # (tests include generated code)
^l10n_br_nfse_ginfes/tests/nfse/| # (skip reformat in test data)
^l10n_br_account_payment_brcobranca/tests/data/| # (don't reformat test data)
# Files and folders generated by bots, to avoid loops
^setup/|/static/description/index\.html$|
# We don't want to mess with tool-generated files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"001": BankRecord("banco_brasil", retorno=["400"], remessa=["240", "400"]),
"004": BankRecord("banco_nordeste", retorno=["400"], remessa=["400"]),
"021": BankRecord("banestes", retorno=[], remessa=[]),
"033": BankRecord("santander", retorno=["240"], remessa=["400"]),
"033": BankRecord("santander", retorno=["400", "240"], remessa=["400", "240"]),
"041": BankRecord("banrisul", retorno=["400"], remessa=["400"]),
"070": BankRecord("banco_brasilia", retorno=[], remessa=["400"]),
"085": BankRecord("ailos", retorno=["240"], remessa=["240"]),
Expand Down
16 changes: 16 additions & 0 deletions l10n_br_account_payment_brcobranca/demo/account_payment_mode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,20 @@
<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"
>
<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"
>
<field name="cnab_processor">brcobranca</field>
</record>

</odoo>
30 changes: 20 additions & 10 deletions l10n_br_account_payment_brcobranca/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class AccountMoveLine(models.Model):
# brcobranca/boleto/itau_spec.rb

def send_payment(self):
# super(AccountMoveLine, self).send_payment()
# Desnecessario chamar o super aqui o metodo
# que esta chamando já verifica isso.

wrapped_boleto_list = []

for move_line in self:
Expand Down Expand Up @@ -58,7 +60,7 @@ 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.code_convetion,
"convenio": move_line.payment_mode_id.cnab_company_bank_code,
"carteira": str(move_line.payment_mode_id.boleto_wallet),
"nosso_numero": int(
"".join(i for i in move_line.own_number if i.isdigit())
Expand Down Expand Up @@ -86,14 +88,6 @@ def send_payment(self):
"instrucao1": move_line.payment_mode_id.instructions or "",
}

# No Santander a carteira impressa no boleto é diferente da remessa.
if bank_account_id.bank_id.code_bc in ("033"):
boleto_cnab_api_data.update(
{
"carteira": str(move_line.payment_mode_id.boleto_wallet2),
}
)

# Instrução de Juros
if move_line.payment_mode_id.boleto_interest_perc > 0.0:
valor_juros = move_line.currency_id.round(
Expand Down Expand Up @@ -158,6 +152,10 @@ def send_payment(self):
)

bank_account = move_line.payment_mode_id.fixed_journal_id.bank_account_id
# Abaixo Campos Especificos de cada caso

# 021 - BANCO DO ESTADO DO ESPIRITO SANTO
# 004 - BANCO INTER
if bank_account_id.bank_id.code_bc in ("021", "004"):
boleto_cnab_api_data.update(
{
Expand All @@ -181,6 +179,18 @@ def send_payment(self):
}
)

# Campo Santander
if bank_account_id.bank_id.code_bc == "033":
# Caso Santander possui:
# Codigo de Transmissao tamanho 20 no 400 no 240 e 15
# Codigo do Convenio tamanho 7
# no boleto é usado o convenio
boleto_cnab_api_data.update(
{
"convenio": move_line.payment_mode_id.convention_code,
}
)

wrapped_boleto_list.append(boleto_cnab_api_data)

return wrapped_boleto_list
45 changes: 45 additions & 0 deletions l10n_br_account_payment_brcobranca/models/account_payment_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,51 @@
payment_mode_id.boleto_protest_code or "00"
)

# Caso Santander 400 precisa enviar o Nosso Numero com DV isso não acontece no
# 240, por enquanto é o único caso mapeado.
# Houve um PR https://github.com/kivanio/brcobranca/pull/236 na lib buscando
# resolver isso e foi apontando a contradição em ter para esse mesmo banco no
# caso do 400 a necessidade de informar o DV mas não precisar no 240,
# mas o mantedor da biblioteca não aceito a alteração.
# A melhor solução talvez seja ver a possibilidade de incluir ou fazer algo
# semelhante ao git-aggregator https://github.com/acsone/git-aggregator
# na API e com isso incluir um commit de outro repositorio que faça essa
# simples alteração porém mantendo a API ligada diretamente ao repo pricipal
# do BRcobranca, já que não existe o interesse em manter um Fork e um simples
# commit resolve o problema, por enquanto o calculo esta sendo feito aqui, se
# necessário ou isso for útil para outros casos pode ser visto de migrar esse
# calculo do modulo11 para um lugar genereico e facilitar seu uso exemplo
# l10n_br_account_payment_order/tools.py
def modulo11(self, num, base=9, r=0):
soma = 0
fator = 2
for c in reversed(num):
soma += int(c) * fator
if fator == base:
fator = 1

Check warning on line 98 in l10n_br_account_payment_brcobranca/models/account_payment_line.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_payment_brcobranca/models/account_payment_line.py#L98

Added line #L98 was not covered by tests
fator += 1
if r == 0:
soma = soma * 10
digito = soma % 11
if digito == 10:
digito = 0

Check warning on line 104 in l10n_br_account_payment_brcobranca/models/account_payment_line.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_payment_brcobranca/models/account_payment_line.py#L104

Added line #L104 was not covered by tests
return digito
if r == 1:
resto = soma % 11
return resto

Check warning on line 108 in l10n_br_account_payment_brcobranca/models/account_payment_line.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_payment_brcobranca/models/account_payment_line.py#L107-L108

Added lines #L107 - L108 were not covered by tests

def _prepare_bank_line_santander(self, payment_mode_id, linhas_pagamentos):
if payment_mode_id.payment_method_code == "400":
nosso_numero = linhas_pagamentos["nosso_numero"]
# O campo deve ter tamanho 7 caso a Sequencia não esteja configurada
# corretamente é tratado aqui, talvez deva ser feito na validação
if len(nosso_numero) > 7:
start_point = len(nosso_numero) - 7
nosso_numero = nosso_numero[start_point : len(nosso_numero)]

Check warning on line 117 in l10n_br_account_payment_brcobranca/models/account_payment_line.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_payment_brcobranca/models/account_payment_line.py#L116-L117

Added lines #L116 - L117 were not covered by tests

dv = self.modulo11(nosso_numero, 9, 0)
linhas_pagamentos["nosso_numero"] = str(nosso_numero) + str(dv)

def prepare_bank_payment_line(self, bank_name_brcobranca):
payment_mode_id = self.order_id.payment_mode_id
linhas_pagamentos = self._prepare_boleto_line_vals()
Expand Down
38 changes: 21 additions & 17 deletions l10n_br_account_payment_brcobranca/models/account_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,49 @@
class PaymentOrder(models.Model):
_inherit = "account.payment.order"

def _prepare_remessa_banco_brasil_400(self, remessa_values):
def _prepare_remessa_banco_brasil(self, remessa_values, cnab_type):
remessa_values.update(
{
"convenio": int(self.payment_mode_id.code_convetion),
"convenio": int(self.payment_mode_id.cnab_company_bank_code),
"variacao_carteira": self.payment_mode_id.boleto_variation.zfill(3),
"convenio_lider": self.payment_mode_id.code_convenio_lider.zfill(7),
"convenio_lider": self.payment_mode_id.convention_code.zfill(7),
"carteira": str(self.payment_mode_id.boleto_wallet).zfill(2),
}
)

def _prepare_remessa_santander_400(self, remessa_values):
def _prepare_remessa_santander(self, remessa_values, cnab_type):
remessa_values.update(
{
"codigo_carteira": str(self.payment_mode_id.boleto_wallet),
"codigo_transmissao": self.payment_mode_id.transmission_code,
"codigo_carteira": self.payment_mode_id.boleto_wallet_code_id.code,
"codigo_transmissao": self.payment_mode_id.cnab_company_bank_code,
"conta_corrente": misc.punctuation_rm(
self.journal_id.bank_account_id.acc_number
),
}
)

def _prepare_remessa_caixa_240(self, remessa_values):
def _prepare_remessa_caixa(self, remessa_values, cnab_type):
remessa_values.update(
{
"convenio": int(self.payment_mode_id.code_convetion),
"convenio": int(self.payment_mode_id.cnab_company_bank_code),
"digito_agencia": self.journal_id.bank_account_id.bra_number_dig,
}
)

def _prepare_remessa_ailos_240(self, remessa_values):
def _prepare_remessa_ailos(self, remessa_values, cnab_type):
remessa_values.update(
{
"convenio": int(self.payment_mode_id.code_convetion),
"convenio": int(self.payment_mode_id.cnab_company_bank_code),
"digito_agencia": self.journal_id.bank_account_id.bra_number_dig,
}
)

def _prepare_remessa_unicred_400(self, remessa_values):
remessa_values["codigo_beneficiario"] = int(self.payment_mode_id.code_convetion)
def _prepare_remessa_unicred(self, remessa_values, cnab_type):
remessa_values["codigo_beneficiario"] = int(
self.payment_mode_id.cnab_company_bank_code
)

def _prepare_remessa_sicredi_240(self, remessa_values):
def _prepare_remessa_sicredi(self, remessa_values, cnab_type):
bank_account_id = self.journal_id.bank_account_id
remessa_values.update(
{
Expand All @@ -78,8 +80,10 @@ def _prepare_remessa_sicredi_240(self, remessa_values):
}
)

def _prepare_remessa_bradesco_400(self, remessa_values):
remessa_values["codigo_empresa"] = int(self.payment_mode_id.code_convetion)
def _prepare_remessa_bradesco(self, remessa_values, cnab_type):
remessa_values["codigo_empresa"] = int(
self.payment_mode_id.cnab_company_bank_code
)

def get_file_name(self, cnab_type):
context_today = fields.Date.context_today(self)
Expand Down Expand Up @@ -159,10 +163,10 @@ def generate_payment_file(self):

try:
bank_method = getattr(
self, "_prepare_remessa_{}_{}".format(bank_brcobranca.name, cnab_type)
self, "_prepare_remessa_{}".format(bank_brcobranca.name)
)
if bank_method:
bank_method(remessa_values)
bank_method(remessa_values, cnab_type)
except Exception:
pass

Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
03300000 2097231608000169123456789012345 SUA EMPRESA LTDA BANCO SANTANDER 126022024 000001040
03300011R01 030 2097231608000169 123456789012345 SUA EMPRESA LTDA 000000012602202400000000
0330001300001P 010707200000133310000013331 0000000000019512 TESTE SANTANDER2602202400000000003000000000 02N26022024300000000000000000000000026022024000000000000300000000000000000000000000000000TESTE SANTANDER CNAB24001000300000
0330001300002Q 012011034414000158AKRETION LTDA AVENIDA PAULISTA 807 CENTRO 01311915SAO PAULO SP0000000000000000 000000000000
0330001300003R 01000000000000000000000000000000000000000000000000000000000000000000000000
0330001300004P 010707200000133310000013331 0000000000027512 TESTE SANTANDER3103202400000000007000000000 02N26022024300000000000000000000000031032024000000000000700000000000000000000000000000000TESTE SANTANDER CNAB24002000300000
0330001300005Q 012011034414000158AKRETION LTDA AVENIDA PAULISTA 807 CENTRO 01311915SAO PAULO SP0000000000000000 000000000000
0330001300006R 01000000000000000000000000000000000000000000000000000000000000000000000000
03300015 000008
03399999 000001000010
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
01REMESSA01COBRANCA 12345678901234567890SUA EMPRESA LTDA 033SANTANDER 2602240000000000000000 058000001
1029723160800016912345678901234567890TESTE SANTANDER CNAB400/0100000019000000 00000000000000000000 000000501TESTE SANTANDER CNAB400/0126022400000000300000330000001N260224000000000000000002602240000000000300000000000000000000000000000211034414000158AKRETION LTDA AVENIDA PAULISTA 807 CENTRO 01311915SAO PAULO SP 00 000002
1029723160800016912345678901234567890TESTE SANTANDER CNAB400/0200000027000000 00000000000000000000 000000501TESTE SANTANDER CNAB400/0231032400000000700000330000001N260224000000000000000003103240000000000700000000000000000000000000000211034414000158AKRETION LTDA AVENIDA PAULISTA 807 CENTRO 01311915SAO PAULO SP 00 000003
9000004000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004
22 changes: 22 additions & 0 deletions l10n_br_account_payment_brcobranca/tests/test_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,28 @@ def test_banco_ailos_cnab_240(self):
"teste_remessa_ailos240.REM",
)

def test_banco_santander_cnab_400(self):
"""Teste Boleto e Remessa Banco Santander - CNAB 400"""
invoice_santander_cnab_400 = self.env.ref(
"l10n_br_account_payment_order.demo_invoice_payment_order_santander_cnab400"
)
self._run_boleto_remessa(
invoice_santander_cnab_400,
"boleto_teste_santander400.pdf",
"teste_remessa_santander400.REM",
)

def test_banco_santander_cnab_240(self):
"""Teste Boleto e Remessa Banco Santander - CNAB 240"""
invoice_santander_cnab_240 = self.env.ref(
"l10n_br_account_payment_order.demo_invoice_payment_order_santander_cnab240"
)
self._run_boleto_remessa(
invoice_santander_cnab_240,
"boleto_teste_santander240.pdf",
"teste_remessa_santander240.REM",
)

def test_bank_cnab_not_implement_brcobranca(self):
"""Test Bank CNAB not implemented in BRCobranca."""
invoice = self.env.ref(
Expand Down
6 changes: 5 additions & 1 deletion l10n_br_account_payment_order/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "Brazilian Payment Order",
"version": "14.0.3.5.0",
"version": "14.0.4.0.0",
"license": "AGPL-3",
"author": "KMEE, Akretion, Odoo Community Association (OCA)",
"maintainers": ["mbcosta"],
Expand Down Expand Up @@ -33,6 +33,9 @@
"data/cnab_codes/banco_unicred_cnab_240_400.xml",
"data/cnab_codes/banco_ailos_cnab_240.xml",
"data/cnab_codes/banco_santander_cnab_240_400.xml",
# Boleto Wallet Code
"data/cnab_codes/banco_santander_boleto_wallet_code.xml",
"data/cnab_codes/banco_bradesco_boleto_wallet_code.xml",
# Wizards
"wizards/account_payment_line_create_view.xml",
"wizards/account_move_line_change.xml",
Expand All @@ -47,6 +50,7 @@
"views/account_payment_views.xml",
"views/l10n_br_cnab_mov_instruction_code_view.xml",
"views/account_move_view.xml",
"views/l10n_br_cnab_boleto_wallet_code_view.xml",
],
"demo": [
"demo/account_payment_method.xml",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">

<!-- Tipo de Cobrança ou Código da Carteira -->
<!-- Bradesco 240
https://banco.bradesco/assets/pessoajuridica/pdf/4008-523-0687-layout-multipag.pdf
-->
<record
id="bradesco_240_boleto_wallet_code_1"
model="l10n_br_cnab.boleto.wallet.code"
>
<field name="name">Cobrança Simples</field>
<field name="code">1</field>
<field name="bank_ids" eval="[(6,0,[ref('l10n_br_base.res_bank_237')])]" />
<field
name="payment_method_ids"
eval="[(6,0,[ref('payment_mode_type_cnab240')])]"
/>
</record>

<record
id="bradesco_240_boleto_wallet_code_2"
model="l10n_br_cnab.boleto.wallet.code"
>
<field name="name">Cobrança Vinculada</field>
<field name="code">2</field>
<field name="bank_ids" eval="[(6,0,[ref('l10n_br_base.res_bank_237')])]" />
<field
name="payment_method_ids"
eval="[(6,0,[ref('payment_mode_type_cnab240')])]"
/>
</record>

<record
id="bradesco_240_boleto_wallet_code_3"
model="l10n_br_cnab.boleto.wallet.code"
>
<field name="name">Cobrança Caucionada</field>
<field name="code">3</field>
<field name="bank_ids" eval="[(6,0,[ref('l10n_br_base.res_bank_237')])]" />
<field
name="payment_method_ids"
eval="[(6,0,[ref('payment_mode_type_cnab240')])]"
/>
</record>

<record
id="bradesco_240_boleto_wallet_code_4"
model="l10n_br_cnab.boleto.wallet.code"
>
<field name="name">Cobrança Descontada</field>
<field name="code">4</field>
<field name="bank_ids" eval="[(6,0,[ref('l10n_br_base.res_bank_237')])]" />
<field
name="payment_method_ids"
eval="[(6,0,[ref('payment_mode_type_cnab240')])]"
/>
</record>

<record
id="bradesco_240_boleto_wallet_code_5"
model="l10n_br_cnab.boleto.wallet.code"
>
<field name="name">Cobrança Vendor</field>
<field name="code">5</field>
<field name="bank_ids" eval="[(6,0,[ref('l10n_br_base.res_bank_237')])]" />
<field
name="payment_method_ids"
eval="[(6,0,[ref('payment_mode_type_cnab240')])]"
/>
</record>

</odoo>
Loading
Loading