Skip to content

Commit

Permalink
[IMP] Case payment outside CNAB if Payment Order in Draft just delete…
Browse files Browse the repository at this point in the history
… Payment Line.
  • Loading branch information
mbcosta committed Mar 29, 2021
1 parent f05c1c1 commit e3d02e4
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions l10n_br_account_payment_order/models/l10n_br_cnab_change_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,28 +265,59 @@ def _create_cnab_not_payment(self, payorder, new_payorder, reason):
# Registra as Alterações na Fatura
self._msg_cnab_payment_order_at_invoice(new_payorder, payorder, reason)

def remove_payment_line(self, reason, payment_situation):
"""
Remove a Linha de Pagamento
:param reason:
:param payment_situation:
:return:
"""
self.payment_line_ids.unlink()
# Ordem de Pagto ainda não confirmada
# será apagada a linha
self.payment_situation = payment_situation
# TODO criar um state removed ?
self.cnab_state = 'done'
self.message_post(body=_(reason))

def create_cnab_write_off(self, reason, payment_situation):
"""
CNAB - Instrução de Baixar de Título.
"""

# Caso a Ordem ainda em Draft as linhas serão somente apagadas
cnab_already_start = self._cnab_already_start()
payment_lines_removed = False
if not cnab_already_start:
# So tem uma linha nesse caso
if self.payment_line_ids[0].order_id.state == 'draft':
reason = 'Removed Payline that would be sent to Bank' \
' by CNAB because amount payment was made' \
' before sending.'
payment_situation = 'baixa_liquidacao'
self.remove_payment_line(reason, payment_situation)
payment_lines_removed = True

if not self.invoice_id.payment_mode_id.cnab_write_off_code_id:
self._msg_error_cnab_missing(
self.payment_mode_id.name, 'Write Off Code')

# Checar se existe uma Instrução de CNAB ainda a ser enviada
self._check_cnab_instruction_to_be_send()
if not payment_lines_removed:
# Checar se existe uma Instrução de CNAB ainda a ser enviada
self._check_cnab_instruction_to_be_send()

payorder, new_payorder = self._get_payment_order(self.invoice_id)
payorder, new_payorder = self._get_payment_order(self.invoice_id)

self.mov_instruction_code_id = \
self.payment_mode_id.cnab_write_off_code_id
self.payment_situation = payment_situation
self.mov_instruction_code_id = \
self.payment_mode_id.cnab_write_off_code_id
self.payment_situation = payment_situation

self.create_payment_line_from_move_line(payorder)
self.cnab_state = 'added_paid'
self.create_payment_line_from_move_line(payorder)
self.cnab_state = 'added_paid'

# Registra as Alterações na Fatura
self._msg_cnab_payment_order_at_invoice(new_payorder, payorder, reason)
# Registra as Alterações na Fatura
self._msg_cnab_payment_order_at_invoice(
new_payorder, payorder, reason)

def create_cnab_change_tittle_value(self):
"""
Expand Down

0 comments on commit e3d02e4

Please sign in to comment.