Skip to content

Commit

Permalink
add validator to generate boletos
Browse files Browse the repository at this point in the history
  • Loading branch information
yk2kus committed May 20, 2016
1 parent 18506a1 commit 46d4dfb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 34 deletions.
81 changes: 49 additions & 32 deletions l10n_br_account_payment_boleto/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from datetime import date
from ..boleto.document import Boleto
from ..boleto.document import BoletoException
from openerp.exceptions import Warning

_logger = logging.getLogger(__name__)

Expand All @@ -36,42 +37,58 @@ class AccountMoveLine(models.Model):
u'Data da criação do pagamento', readonly=True)
boleto_own_number = fields.Char(
u'Nosso Número', readonly=True)


#validate config to generate boletos
@api.multi
def validate_boleto_config(self):
for move_line in self:
if move_line.payment_mode_id.type_payment != '00':
raise Warning(u"Payment mode Tipo SPED must be 00 - Duplicata")
if not move_line.payment_mode_id.internal_sequence_id:
raise Warning(u"Please set sequence in payment mode")
if move_line.company_id.own_number_type != '2':
raise Warning(u"Tipo de nosso número Sequéncial uniquo por modo de pagamento")
if not move_line.payment_mode_id.boleto_type:
raise Warning(u'Configure o tipo de boleto no modo de '
u'pagamento')
if not move_line.payment_mode_id.boleto_convenio:
raise Warning(u"Codigo convênio not set in payment method")
if not move_line.payment_mode_id.boleto_carteira:
raise Warning(u"Carteira not set in payment method")
return True


@api.multi
def send_payment(self):
boleto_list = []

self.validate_boleto_config()
for move_line in self:
try:

if move_line.payment_mode_id.type_payment == '00':
number_type = move_line.company_id.own_number_type
if not move_line.boleto_own_number:
if number_type == '0':
nosso_numero = self.env['ir.sequence'].next_by_id(
move_line.company_id.own_number_sequence.id)
elif number_type == '1':
nosso_numero = \
move_line.transaction_ref.replace('/', '')
else:
nosso_numero = self.env['ir.sequence'].next_by_id(
move_line.payment_mode_id.
internal_sequence_id.id)
if move_line.payment_mode_id.type_payment == '00':
number_type = move_line.company_id.own_number_type
if not move_line.boleto_own_number:
if number_type == '0':
nosso_numero = self.env['ir.sequence'].next_by_id(
move_line.company_id.own_number_sequence.id)
elif number_type == '1':
nosso_numero = \
move_line.transaction_ref.replace('/', '')
else:
nosso_numero = move_line.boleto_own_number

boleto = Boleto.getBoleto(move_line, nosso_numero)
if boleto:
move_line.date_payment_created = date.today()
move_line.transaction_ref = \
boleto.boleto.format_nosso_numero()
move_line.boleto_own_number = nosso_numero
nosso_numero = self.env['ir.sequence'].next_by_id(
move_line.payment_mode_id.
internal_sequence_id.id)
else:
nosso_numero = move_line.boleto_own_number
try:
int(nosso_numero)
except:
raise Warning(u"Nosso numero must be integer please check prefix and suffix in payment method sequence")
boleto = Boleto.getBoleto(move_line, nosso_numero)
if boleto:
move_line.date_payment_created = date.today()
move_line.transaction_ref = \
boleto.boleto.format_nosso_numero()
move_line.boleto_own_number = nosso_numero


boleto_list.append(boleto.boleto)
except BoletoException as be:
_logger.error(be.message or be.value, exc_info=True)
continue
except Exception as e:
_logger.error(e.message or e.value, exc_info=True)
continue
boleto_list.append(boleto.boleto)
return boleto_list
2 changes: 2 additions & 0 deletions l10n_br_account_payment_boleto/reports/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def create(self, cr, uid, ids, datas, context=False):
for account_invoice in ai_obj.browse(cr, uid, active_ids):
for move_line in account_invoice.move_line_receivable_id:
ids_move_lines.append(move_line.id)
if not len(ids_move_lines):
raise Warning("No receivable or payable move lines found. Please set Gera Financeiro to True in Journal")
elif active_model == 'account.move.line':
ids_move_lines = active_ids
else:
Expand Down
2 changes: 1 addition & 1 deletion l10n_br_account_payment_mode/models/payment_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PaymentMode(models.Model):
type_payment = fields.Selection(
[('00', u'00 - Duplicata'),
('99', u'99 - Outros')],
string='Tipo SPED', required=True, default='99')
string='Tipo SPED', required=True, default='00')

type_purchase_payment = fields.Selection(
[('01', u'01 - Crédito em conta-corrente ou poupança Bradesco'),
Expand Down
3 changes: 2 additions & 1 deletion l10n_br_account_payment_mode/views/payment_mode_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
<field name="type" position="after">
<field name="payment_order_type"/>
<field name="internal_sequence_id"/>
<field name="type_payment"/>
</field>
<xpath expr="//form/group[@string='Note']" position="before">
<group string="Configurações" name='l10n-br-config' col="4">
<notebook colspan="4">
<page string="Cobrança" attrs="{'invisible': [('sale_ok', '!=', True)]}">
<group>
<field name="type_sale_payment"/>
<field name="type_sale_payment" invisible="1"/>
<field name="instrucoes"/>
<field name="invoice_print"/>
</group>
Expand Down

0 comments on commit 46d4dfb

Please sign in to comment.