Skip to content

Commit

Permalink
Merge da600f3 into 9255e82
Browse files Browse the repository at this point in the history
  • Loading branch information
danimaribeiro committed Nov 21, 2018
2 parents 9255e82 + da600f3 commit faa322c
Show file tree
Hide file tree
Showing 5 changed files with 55 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 - lines) > 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
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
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)
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 faa322c

Please sign in to comment.