Skip to content

Commit

Permalink
[IMP] Bloqueia cancelamento de faturas com boletos emitidos
Browse files Browse the repository at this point in the history
Evita boletos orfãos
  • Loading branch information
danimaribeiro committed Nov 21, 2018
1 parent ff56cf3 commit 6d78f2f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion br_account_payment/models/payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ 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):
if len(item.line_ids) > 0:
if len(item.line_ids - lines) > 0:
item.state = 'done'
else:
item.state = 'draft'
Expand Down
21 changes: 21 additions & 0 deletions br_boleto/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ class AccountMoveLine(models.Model):
boleto_emitido = fields.Boolean(string=u"Emitido")
nosso_numero = fields.Char(string=u"Nosso Número", size=30)

@api.multi
def unlink(self):
for item in self:
line_ids = self.env['payment.order.line'].search(
[('move_line_id', '=', item.id),
('state', '=', 'draft')])
line_ids.sudo().unlink()
return super(AccountMoveLine, self).unlink()

@api.multi
def _update_check(self):
for item in self:
total = self.env['payment.order.line'].search_count(
[('move_line_id', '=', item.id),
('type', '=', 'receivable'),
('state', 'not in', ('draft', 'cancelled', 'rejected'))])
if total > 0:
raise UserError('Existem boletos emitidos para esta fatura!\
Cancele estes boletos primeiro')
return super(AccountMoveLine, self)._update_check()

@api.multi
def action_print_boleto(self):
if self.move_id.state in ('draft', 'cancel'):
Expand Down
1 change: 1 addition & 0 deletions br_payment_cnab/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def _update_check(self):
for item in self:
total = self.env['payment.order.line'].search_count(
[('move_line_id', '=', item.id),
('type', '=', 'payable'),
('state', 'not in', ('draft', 'cancelled', 'rejected'))])
if total > 0:
raise UserError('Existe uma ordem de pagamento relacionada!\
Expand Down

0 comments on commit 6d78f2f

Please sign in to comment.