From ff56cf362499c1c47be379e15f7756c757309362 Mon Sep 17 00:00:00 2001 From: Danimar Ribeiro Date: Wed, 21 Nov 2018 20:09:51 -0200 Subject: [PATCH] =?UTF-8?q?[IMP]=20Reemiss=C3=A3o=20de=20boleto=20j=C3=A1?= =?UTF-8?q?=20enviado=20apenas=20ap=C3=B3s=20cancelamento=20manual=20Em=20?= =?UTF-8?q?caso=20de=20boletos=20cancelados=20ou=20rejeitados=20=C3=A9=20c?= =?UTF-8?q?riado=20uma=20nova=20linha=20de=20cobran=C3=A7a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- br_account_payment/models/payment_order.py | 7 ++++-- br_boleto/models/payment_order.py | 6 ++++- br_boleto/wizard/br_boleto_wizard.py | 27 ++++++++++++++++++---- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/br_account_payment/models/payment_order.py b/br_account_payment/models/payment_order.py index c2506bd57..4a4e19933 100644 --- a/br_account_payment/models/payment_order.py +++ b/br_account_payment/models/payment_order.py @@ -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' diff --git a/br_boleto/models/payment_order.py b/br_boleto/models/payment_order.py index bcb79b0df..a0830e086 100644 --- a/br_boleto/models/payment_order.py +++ b/br_boleto/models/payment_order.py @@ -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, @@ -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) diff --git a/br_boleto/wizard/br_boleto_wizard.py b/br_boleto/wizard/br_boleto_wizard.py index 3a53d03fa..82f5682ff 100644 --- a/br_boleto/wizard/br_boleto_wizard.py +++ b/br_boleto/wizard/br_boleto_wizard.py @@ -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): @@ -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)