Skip to content

Commit

Permalink
[FIX] l10n_br_account_payment_brcobranca: fix fare value field
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianoMafraJunior authored and antoniospneto committed Mar 26, 2024
1 parent adf2758 commit 9d74da9
Show file tree
Hide file tree
Showing 8 changed files with 664 additions and 96 deletions.
11 changes: 10 additions & 1 deletion l10n_br_account_payment_brcobranca/demo/account_journal_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,14 @@
/>
<field name="return_auto_reconcile">True</field>
</record>

<!--Diario Banco do Brasil -->
<record id="l10n_br_account_payment_order.bb_journal" model="account.journal">
<field name="used_for_import">True</field>
<field name="import_type">cnab400</field>
<field
name="bank_account_id"
ref="l10n_br_account_payment_order.main_company_bank_test"
/>
<field name="return_auto_reconcile">True</field>
</record>
</odoo>
22 changes: 10 additions & 12 deletions l10n_br_account_payment_brcobranca/models/account_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ class AccountJournal(models.Model):
help="Enable automatic payment return reconciliation.",
default=False,
)
floating_days = fields.Integer(
help=(
"Specifies the number of 'floating days' - the time period between when a "
"payment is initiated and when the funds become available in the recipient's "
"account. During these days, the funds are being processed by the banking "
"system and are not yet accessible to the recipient. Please enter the typical "
"number of days it takes for transactions with your bank to be fully processed "
"and cleared."
),
)

def multi_move_import(self, file_stream, ftype="csv"):
"""Create multiple bank statements from values given by the parser for
Expand Down Expand Up @@ -178,18 +188,6 @@ def _get_moves(self, parser, result_row_list):
)

move_vals = self.prepare_move_vals(result_row, parser)

# O campo referente a Data de Credito no account.move é o date que
# no account.move.line existe um related desse campo a forma de
# obter e preencher ele por enquanto e feito da forma abaixo,
# verificar se possível melhorar isso.
data_credito = ""
for row in result_row:
if row.get("type") == "liquidado":
data_credito = row.get("date")
break
move_vals["date"] = data_credito

move = move_obj.create(move_vals)
moves |= move
try:
Expand Down
115 changes: 63 additions & 52 deletions l10n_br_account_payment_brcobranca/parser/cnab_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,15 @@ def process_return_file(self, data):
# obj_account_move_line.company_id.partner_id.name,
# 'tipo_moeda': evento.credito_moeda_tipo,
}

# Caso de Pagamento deve criar os Lançamentos de Diário
merged_row_list = []
log_event_payment = {}
valor_tarifa = self.cnab_str_to_float(linha_cnab.get("valor_tarifa", 0.0))
if cod_ocorrencia in cnab_liq_move_code:
row_list, log_event_payment = self._get_accounting_entries(
linha_cnab, account_move_line, payment_lines
linha_cnab, account_move_line, payment_lines, valor_tarifa
)
result_row_list.append(row_list)
merged_row_list.extend(row_list)
cnab_return_log_event.update(log_event_payment)
else:
# Nos codigos de retorno cadastrados no Data do modulo
Expand All @@ -375,12 +377,19 @@ def process_return_file(self, data):
# exceções ?
# Caso exista será preciso criar o campo no payment.mode
# para informa-lo como nos outros casos.
if cod_ocorrencia == "02":
account_move_line.cnab_state = "accepted"
elif cod_ocorrencia == "03":
# TODO - algo a mais a ser feito ?
account_move_line.cnab_state = "not_accepted"

ocorrencia_to_state = {
"02": "accepted",
"03": "not_accepted",
}
account_move_line.cnab_state = ocorrencia_to_state.get(cod_ocorrencia)
if valor_tarifa:
row_list = self._create_tariff_entries(
account_move_line, payment_lines, valor_tarifa
)
merged_row_list.extend(row_list)
cnab_return_log_event.update({"tariff_charge": valor_tarifa})
if merged_row_list:
result_row_list.append(merged_row_list)
# Inclui o LOG do Evento CNAB
self.cnab_return_events.append(cnab_return_log_event)

Expand All @@ -403,12 +412,44 @@ def _get_description_occurrence(self, payment_method_cnab, cod_ocorrencia):

return descricao_ocorrencia

def _get_accounting_entries(self, linha_cnab, account_move_line, payment_lines):
def _create_tariff_entries(self, account_move_line, payment_lines, valor_tarifa):
row_list = []
row_list.append(
{
"name": "Tarifas bancárias (boleto) "
+ account_move_line.document_number,
"debit": 0.0,
"credit": valor_tarifa,
"account_id": self.journal.default_account_id.id,
"type": "tarifa",
"partner_id": account_move_line.company_id.partner_id.id,
"payment_line_ids": payment_lines.ids,
"cnab_returned_ref": account_move_line.document_number,
}
)
tariff_charge_account = (
account_move_line.payment_mode_id.tariff_charge_account_id
)
row_list.append(
{
"name": "Tarifas bancárias (boleto) "
+ account_move_line.document_number,
"debit": valor_tarifa,
"credit": 0.0,
"type": "tarifa",
"account_id": tariff_charge_account.id,
"payment_line_ids": payment_lines.ids,
"cnab_returned_ref": account_move_line.document_number,
}
)
return row_list

def _get_accounting_entries(
self, linha_cnab, account_move_line, payment_lines, valor_tarifa
):
row_list = []
bank_name_brcobranca = dict_brcobranca_bank[self.bank.code_bc]
valor_recebido = (
valor_desconto
) = valor_juros_mora = valor_abatimento = valor_tarifa = 0.0
valor_recebido = valor_desconto = valor_juros_mora = valor_abatimento = 0.0

if linha_cnab["valor_recebido"]:
# Campo Valor Recebido vem com o Valor da Tarifa:
Expand Down Expand Up @@ -498,43 +539,6 @@ def _get_accounting_entries(self, linha_cnab, account_move_line, payment_lines):
}
)

# Valor Tarifa
if linha_cnab.get("valor_tarifa"):
valor_tarifa = self.cnab_str_to_float(linha_cnab["valor_tarifa"])

if valor_tarifa > 0.0:
# Usado para Conciliar a Fatura
row_list.append(
{
"name": "Tarifas bancárias (boleto) "
+ account_move_line.document_number,
"debit": 0.0,
"credit": valor_tarifa,
"account_id": self.journal.default_account_id.id,
"type": "tarifa",
"partner_id": account_move_line.company_id.partner_id.id,
"payment_line_ids": payment_lines.ids,
"cnab_returned_ref": account_move_line.document_number,
}
)

# Avoid error in pre commit
tariff_charge_account = (
account_move_line.payment_mode_id.tariff_charge_account_id
)
row_list.append(
{
"name": "Tarifas bancárias (boleto) "
+ account_move_line.document_number,
"debit": valor_tarifa,
"credit": 0.0,
"type": "tarifa",
"account_id": tariff_charge_account.id,
"payment_line_ids": payment_lines.ids,
"cnab_returned_ref": account_move_line.document_number,
}
)

# Valor Abatimento
if linha_cnab.get("valor_abatimento"):
valor_abatimento = self.cnab_str_to_float(linha_cnab["valor_abatimento"])
Expand Down Expand Up @@ -595,15 +599,13 @@ def _get_accounting_entries(self, linha_cnab, account_move_line, payment_lines):
"cnab_returned_ref": account_move_line.own_number,
}
)

# CNAB LOG
log_event_payment = {
"real_payment_date": data_credito.strftime("%Y-%m-%d"),
"payment_value": valor_recebido,
"discount_value": valor_desconto,
"interest_fee_value": valor_juros_mora,
"rebate_value": valor_abatimento,
"tariff_charge": valor_tarifa,
}

return row_list, log_event_payment
Expand All @@ -620,6 +622,14 @@ def get_move_vals(self):
of statement.
:return: dict of vals that represent additional infos for the statement
"""
for row in self.cnab_return_events:
if "real_payment_date" in row and row["real_payment_date"]:
self.move_date = row["real_payment_date"]
break
elif "occurrence_date" in row:
self.move_date = row["occurrence_date"] + datetime.timedelta(
days=self.journal.floating_days
)
return {
# O campo name precisa ser como abaixo ou não ser enviado
# se não gera erro no metodo _check_unique_sequence_number,
Expand All @@ -632,6 +642,7 @@ def get_move_vals(self):
+ " - Conta "
+ self.journal.bank_account_id.acc_number,
"is_cnab": True,
"date": self.move_date if self.move_date else datetime.date.today(),
}

def get_move_line_vals(self, line, *args, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
08500000 2972316080001691010040040000 0010150123600000000003735 SUA EMPRESA LTDA COOPERATIVA DE CREDITO DO VALE 10912202103080600000608700000
08500001T01 043 20972316080001691010040040000 0123600000000003735 SUA EMPRESA LTDA 000001752411202323112023
0850000300023T 2300101500000107131230000000489 00000000029577040711202300000000015285908500101503/01 902043782798000183PONTO FIRMADO TESTE SUA EMPRESA FANTASMA LTDA 0000000000000000000001700000
0850000300024U 230000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002311202300000000 000000000000000 00000000000000000000000
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
08500000 2972316080001691010040040000 0010150123600000000003735 SUA EMPRESA LTDA COOPERATIVA DE CREDITO DO VALE 10912202103080600000608700000
08500001T01 043 20972316080001691010040040000 0123600000000003735 SUA EMPRESA LTDA 000001752411202323112023
0850000300023T 2300101500000107131230000000489 00000000029577040711202300000000015285908500101503/01 902043782798000183PONTO TESTE SUA EMPRESA FANTASMA LTDA 0000000000000000000000000000
0850000300024U 230000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002311202300000000 000000000000000 00000000000000000000000
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
02RETORNO01COBRANCA 15298000060533000000EMPRESA TESTE 001BANCO DO BRASIL0602240001657 000002944910772557 2417143 000001
70000000000000000152980000605332417879 2417143000000001570000900AI 01900000000000 1702060224000001/01 150224000000004000800131747010000000000234000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000090010000000000000 0000000000000000000000000000000000000000000000001050000002
9201001 000000050000000039160800000177 000001810000004907912500000000 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000003
Loading

0 comments on commit 9d74da9

Please sign in to comment.