Skip to content

Commit

Permalink
[IMP] Reemissão de boleto já enviado apenas após cancelamento manual
Browse files Browse the repository at this point in the history
Em caso de boletos cancelados ou rejeitados é criado uma nova linha de cobrança
  • Loading branch information
danimaribeiro committed Nov 21, 2018
1 parent 9255e82 commit ff56cf3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
7 changes: 5 additions & 2 deletions br_account_payment/models/payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ def _compute_state(self):
for item in self:
lines = item.line_ids.filtered(lambda x: x.state != 'cancelled')
if all(line.state in ('draft', 'approved') for line in lines):
item.state = 'draft'
elif all(line.state == 'paid' for line in lines):
if len(item.line_ids) > 0:
item.state = 'done'
else:
item.state = 'draft'
elif all(line.state in ('paid', 'rejected') for line in lines):
item.state = 'done'
elif any(line.state == 'rejected' for line in lines):
item.state = 'attention'
Expand Down
6 changes: 5 additions & 1 deletion br_boleto/models/payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def generate_payment_order_line(self, move_line):
move = self.env['payment.order.line'].search(
[('src_bank_account_id', '=',
payment_mode.journal_id.bank_account_id.id),
('move_line_id', '=', move_line.id)])
('move_line_id', '=', move_line.id),
('state', 'not in', ('cancelled', 'rejected'))])
if not move:
return self.env['payment.order.line'].create({
'move_line_id': move_line.id,
Expand Down Expand Up @@ -64,6 +65,9 @@ def action_register_boleto(self, move_lines):
return self

def generate_boleto_list(self):
if self.filtered(lambda x: x.state in ('cancelled', 'rejected')):
raise UserError(
'Boletos cancelados ou rejeitados não permitem a impressão')
boleto_list = []
for line in self:
boleto = Boleto.getBoleto(line, line.nosso_numero)
Expand Down
27 changes: 23 additions & 4 deletions br_boleto/wizard/br_boleto_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# © 2016 Alessandro Fernandes Martini, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from datetime import date
from odoo import api, fields, models
from odoo.exceptions import UserError


class BrBoletoWizard(models.TransientModel):
Expand All @@ -14,10 +16,27 @@ class BrBoletoWizard(models.TransientModel):

@api.multi
def imprimir_boleto(self):
line_id = self.move_line_id.l10n_br_order_line_id
if self.date_change:
self.move_line_id.date_maturity = self.date_change
self.move_line_id.boleto_emitido = False
if line_id.state == 'draft':
self.move_line_id.date_maturity = self.date_change
line_id.write({
'emission_date': date.today(),
'date_maturity': self.date_change,
})
elif line_id.state != 'cancelled':
raise UserError(
'O boleto está na situação %s, cancele o item de \
cobrança antes de reemitir outro boleto' %
dict(line_id._fields['state'].selection).get(
line_id.state))

return self.env.ref(
'br_boleto.action_boleto_account_move_line').report_action(
if not line_id or line_id.state in ('rejected', 'cancelled'):
if self.date_change:
self.move_line_id.date_maturity = self.date_change
line_id = self.env['payment.order.line'].action_register_boleto(
self.move_line_id)

return self.env.ref(
'br_boleto.action_boleto_payment_order_line').report_action(
line_id)

0 comments on commit ff56cf3

Please sign in to comment.