From 6d78f2f2eb882b1a5424642ae41f154024ea7e9f Mon Sep 17 00:00:00 2001 From: Danimar Ribeiro Date: Wed, 21 Nov 2018 20:25:41 -0200 Subject: [PATCH] =?UTF-8?q?[IMP]=20Bloqueia=20cancelamento=20de=20faturas?= =?UTF-8?q?=20com=20boletos=20emitidos=20Evita=20boletos=20orf=C3=A3os?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- br_account_payment/models/payment_order.py | 2 +- br_boleto/models/account_move_line.py | 21 +++++++++++++++++++++ br_payment_cnab/models/account_move.py | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/br_account_payment/models/payment_order.py b/br_account_payment/models/payment_order.py index 4a4e19933..6a8e3f26a 100644 --- a/br_account_payment/models/payment_order.py +++ b/br_account_payment/models/payment_order.py @@ -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' diff --git a/br_boleto/models/account_move_line.py b/br_boleto/models/account_move_line.py index 246d827cb..fca18224d 100644 --- a/br_boleto/models/account_move_line.py +++ b/br_boleto/models/account_move_line.py @@ -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'): diff --git a/br_payment_cnab/models/account_move.py b/br_payment_cnab/models/account_move.py index 550cbe056..84a131ee1 100644 --- a/br_payment_cnab/models/account_move.py +++ b/br_payment_cnab/models/account_move.py @@ -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!\