Skip to content

Commit

Permalink
Implementando ação de envio de email com boletos
Browse files Browse the repository at this point in the history
  • Loading branch information
danimaribeiro committed Sep 5, 2017
1 parent 94e5046 commit 99659d8
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 8 deletions.
2 changes: 2 additions & 0 deletions br_boleto/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
'data': [
'security/ir.model.access.csv',
'views/account_config_settings.xml',
'views/account_invoice.xml',
'views/account_move_line.xml',
'views/res_partner_bank.xml',
Expand All @@ -36,6 +37,7 @@
'sequence/payment_order_sequence.xml',
'sequence/numero_documento_sequence.xml',
'wizard/br_boleto_wizard.xml',
'wizard/send_boleto_email.xml',
],
'installable': True,
'application': True,
Expand Down
2 changes: 2 additions & 0 deletions br_boleto/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
from . import payment_order
from . import payment_mode
from . import account_journal
from . import res_company
from . import account_config_settings
21 changes: 21 additions & 0 deletions br_boleto/models/account_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# © 2017 Danimar Ribeiro <danimaribeiro@gmail.com>, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models


class AccountConfigSettings(models.TransientModel):
_inherit = 'account.config.settings'

boleto_email_tmpl = fields.Many2one(
'mail.template', string="Template de Email para Envio de Boleto",
domain=[('model_id.model', '=', 'account.invoice')])

def get_default_boleto_email_tmpl(self, fields):
return {'boleto_email_tmpl':
self.env.user.company_id.boleto_email_tmpl.id}

@api.multi
def set_default_boleto_email_tmpl(self):
self.env.user.company_id.boleto_email_tmpl = self.boleto_email_tmpl
36 changes: 36 additions & 0 deletions br_boleto/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,49 @@
# © 2016 Alessandro Fernandes Martini, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import base64
from odoo import api, models
from odoo.exceptions import UserError


class AccountInvoice(models.Model):
_inherit = 'account.invoice'

@api.multi
def send_email_boleto_queue(self):
mail = self.env.user.company_id.boleto_email_tmpl
if not mail:
raise UserError('Modelo de email padrão não configurado')

attachment_obj = self.env['ir.attachment']
for item in self:

atts = []
self = self.with_context({
'origin_model': 'account.invoice',
'active_ids': [item.id],
})
boleto, fmt = self.env['ir.actions.report.xml'].render_report(
[item.id], 'br_boleto.report.print', {'report_type': u'pdf'})

if boleto:
name = "boleto-%s-%s.pdf" % (
item.number, item.partner_id.commercial_partner_id.name)
boleto_id = attachment_obj.create(dict(
name=name,
datas_fname=name,
datas=base64.b64encode(boleto),
mimetype='application/pdf',
res_model='account.invoice',
res_id=item.id,
))
atts.append(boleto_id.id)

values = {
"attachment_ids": atts + mail.attachment_ids.ids
}
mail.send_mail(item.id, email_values=values)

@api.multi
def invoice_validate(self):
res = super(AccountInvoice, self).invoice_validate()
Expand Down
12 changes: 12 additions & 0 deletions br_boleto/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# © 2017 Danimar Ribeiro <danimaribeiro@gmail.com>, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ResCompany(models.Model):
_inherit = 'res.company'

boleto_email_tmpl = fields.Many2one(
'mail.template', string="Template de Email para Boleto")
15 changes: 15 additions & 0 deletions br_boleto/views/account_config_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="account_config_settings_email_boleto" model="ir.ui.view">
<field name="name">account_config_settings.emai.boletol</field>
<field name="model">account.config.settings</field>
<field name="inherit_id" ref="account.view_account_config_settings"/>
<field name="arch" type="xml">
<group name="followup" position="after" >
<group string="Email Boleto" name="boleto_mail">
<field name="boleto_email_tmpl" />
</group>
</group>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions br_boleto/wizard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import br_boleto_wizard
from . import send_boleto_email
8 changes: 0 additions & 8 deletions br_boleto/wizard/br_boleto_wizard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,4 @@
</field>
</record>

<act_window id="br_boleto_action"
name="Alterar / Reimprimir Boleto"
src_model="account.invoice"
res_model="br.boleto.wizard"
view_mode="form"
target="new"
key2="client_action_multi"/>

</odoo>
17 changes: 17 additions & 0 deletions br_boleto/wizard/send_boleto_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# © 2017 Danimar Ribeiro, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class BoletoSendEmail(models.TransientModel):
_name = 'boleto.send.email'

@api.multi
def send_boletos_by_email(self):
context = dict(self._context or {})
active_ids = context.get('active_ids', []) or []
invoices = self.env['account.invoice'].browse(active_ids)
invoices.send_email_boleto_queue()
return {'type': 'ir.actions.act_window_close'}
27 changes: 27 additions & 0 deletions br_boleto/wizard/send_boleto_email.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<record model="ir.ui.view" id="view_br_boleto_send_email_wizard">
<field name="name">view_br_boleto.send.email.form</field>
<field name="model">boleto.send.email</field>
<field name="arch" type="xml">
<form string="Enviar emails">
<footer>
<button name="send_boletos_by_email" type="object" string="Enviar e-mails" class="oe_highlight"/>
or
<button special="cancel" string="Cancelar"/>
</footer>
</form>
</field>
</record>


<act_window id="br_boleto_action"
name="Enviar boletos via e-mail"
src_model="account.invoice"
res_model="boleto.send.email"
view_mode="form"
target="new"
key2="client_action_multi"/>

</odoo>

0 comments on commit 99659d8

Please sign in to comment.