summaryrefslogtreecommitdiff
path: root/addons/account
diff options
context:
space:
mode:
authorRémi Rahir <rar@odoo.com>2018-04-23 16:04:43 +0200
committerRémi Rahir <rar@odoo.com>2018-07-19 15:54:00 +0200
commit4cb91942751130f003a5c2a8dce545a7cd877bee (patch)
treea13bd21c5056a2bb4c00420096899ce416d3299c /addons/account
parent01efffc472760d717953e6659ad84323094cea8e (diff)
[ADD] snailmail: new iap module to send letters by post
Diffstat (limited to 'addons/account')
-rw-r--r--addons/account/__manifest__.py1
-rw-r--r--addons/account/models/__init__.py1
-rw-r--r--addons/account/models/account_invoice.py4
-rw-r--r--addons/account/models/res_company.py11
-rw-r--r--addons/account/views/account_invoice_view.xml6
-rw-r--r--addons/account/wizard/__init__.py1
-rw-r--r--addons/account/wizard/multi_compose_message.py79
-rw-r--r--addons/account/wizard/multi_compose_message_views.xml66
8 files changed, 163 insertions, 6 deletions
diff --git a/addons/account/__manifest__.py b/addons/account/__manifest__.py
index 9b98ed5ff11..9654e47f01e 100644
--- a/addons/account/__manifest__.py
+++ b/addons/account/__manifest__.py
@@ -68,6 +68,7 @@ Core mechanisms for the accounting modules. To display the menuitems, install th
'views/res_users_views.xml',
'data/service_cron_reverse.xml',
'views/account_fiscal_year_view.xml',
+ 'wizard/multi_compose_message_views.xml',
],
'demo': [
'demo/account_demo.xml',
diff --git a/addons/account/models/__init__.py b/addons/account/models/__init__.py
index 95d9fcbf996..3865c09ee2d 100644
--- a/addons/account/models/__init__.py
+++ b/addons/account/models/__init__.py
@@ -16,3 +16,4 @@ from . import res_config_settings
from . import account_cash_rounding
from . import reconciliation_widget
from . import res_users
+from . import res_company
diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py
index 9b8afa4791c..980a6e92adc 100644
--- a/addons/account/models/account_invoice.py
+++ b/addons/account/models/account_invoice.py
@@ -593,7 +593,7 @@ class AccountInvoice(models.Model):
"""
self.ensure_one()
template = self.env.ref('account.email_template_edi_invoice', False)
- compose_form = self.env.ref('mail.email_compose_message_wizard_form', False)
+ compose_form = self.env.ref('account.multi_compose_message_wizard_form', False)
ctx = dict(
default_model='account.invoice',
default_res_id=self.id,
@@ -609,7 +609,7 @@ class AccountInvoice(models.Model):
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
- 'res_model': 'mail.compose.message',
+ 'res_model': 'multi.compose.message',
'views': [(compose_form.id, 'form')],
'view_id': compose_form.id,
'target': 'new',
diff --git a/addons/account/models/res_company.py b/addons/account/models/res_company.py
new file mode 100644
index 00000000000..522bd956fc3
--- /dev/null
+++ b/addons/account/models/res_company.py
@@ -0,0 +1,11 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import fields, models
+
+
+class ResCompany(models.Model):
+ _inherit = 'res.company'
+
+ is_email = fields.Boolean('Email by default', default=True)
+ is_print = fields.Boolean('Print by default', default=True)
diff --git a/addons/account/views/account_invoice_view.xml b/addons/account/views/account_invoice_view.xml
index 16c42777562..147e0d56ac7 100644
--- a/addons/account/views/account_invoice_view.xml
+++ b/addons/account/views/account_invoice_view.xml
@@ -387,10 +387,8 @@
<field name="arch" type="xml">
<form string="Invoice" class="o_invoice_form">
<header>
- <button name="action_invoice_sent" type="object" string="Send by Email" attrs="{'invisible':['|',('sent','=',True), ('state', 'not in', ('open','paid'))]}" class="oe_highlight o_invoice_send" groups="base.group_user"/>
- <button name="invoice_print" string="Print Invoice" type="object" attrs="{'invisible':['|',('sent','=',True), ('state', 'not in', ('open','paid'))]}" class="oe_highlight" groups="base.group_user"/>
- <button name="action_invoice_sent" type="object" string="Send by Email" attrs="{'invisible':['|',('sent','=',False), ('state', 'not in', ('open','paid'))]}" groups="base.group_user"/>
- <button name="invoice_print" string="Print Invoice" type="object" attrs="{'invisible':['|',('sent','=',False), ('state', 'not in', ('open','paid'))]}" groups="base.group_user"/>
+ <button name="action_invoice_sent" string="Send &amp; Print" type="object" attrs="{'invisible':['|',('sent','=',True), ('state', 'not in', ('open','paid'))]}" class="oe_highlight" groups="base.group_user"/>
+ <button name="action_invoice_sent" string="Send &amp; Print" type="object" attrs="{'invisible':['|',('sent','=',False), ('state', 'not in', ('open','paid'))]}" groups="base.group_user"/>
<button name="%(action_account_invoice_payment)d" id="account_invoice_payment_btn" type="action"
attrs="{'invisible': [('state', '!=', 'open')]}"
string="Register Payment" groups="account.group_account_invoice" class="oe_highlight"/>
diff --git a/addons/account/wizard/__init__.py b/addons/account/wizard/__init__.py
index 1529b392790..583ed252aeb 100644
--- a/addons/account/wizard/__init__.py
+++ b/addons/account/wizard/__init__.py
@@ -22,3 +22,4 @@ from . import account_report_aged_partner_balance
from . import setup_wizards
from . import wizard_tax_adjustments
from . import account_report_tax
+from . import multi_compose_message
diff --git a/addons/account/wizard/multi_compose_message.py b/addons/account/wizard/multi_compose_message.py
new file mode 100644
index 00000000000..cdbae7610f2
--- /dev/null
+++ b/addons/account/wizard/multi_compose_message.py
@@ -0,0 +1,79 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, fields, models
+
+
+class MultiComposer(models.TransientModel):
+
+ _name = 'multi.compose.message'
+ _inherit = 'mail.compose.message'
+
+ company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True,
+ default=lambda self: self.env.user.company_id.id)
+ is_email = fields.Boolean('Email', default=lambda self: self.env.user.company_id.is_email)
+ is_print = fields.Boolean('Print', default=lambda self: self.env.user.company_id.is_print)
+ printed = fields.Boolean('Is Printed', default=False)
+ partner_ids = fields.Many2many(
+ 'res.partner', 'account_compose_message_res_partner_rel',
+ 'wizard_id', 'partner_id', 'Additional Contacts')
+ attachment_ids = fields.Many2many(
+ 'ir.attachment', 'account_compose_message_ir_attachments_rel',
+ 'wizard_id', 'attachment_id', 'Attachments')
+ print_attachment_id = fields.Many2one('ir.attachment', string='Print Attachment')
+
+ @api.multi
+ def _update_company(self):
+ for rec in self:
+ values = {}
+ for field in ['is_print', 'is_email']:
+ if rec.company_id[field] != rec[field]:
+ values.update({field: rec[field]})
+ if values:
+ rec.company_id.write(values)
+
+ @api.multi
+ def write(self, vals):
+ res = super(MultiComposer, self).write(vals)
+ self._update_company()
+ return res
+
+ @api.multi
+ @api.onchange('template_id')
+ def onchange_template_id_wrapper(self):
+ self.ensure_one()
+ super(MultiComposer,self).onchange_template_id_wrapper()
+ self.print_attachment_id = self.attachment_ids[:1]
+
+ def _send_email(self):
+ if self.is_email:
+ self.send_mail()
+
+ @api.multi
+ def _print_document(self):
+ """ to override for each type of models that will use this composer."""
+ self.ensure_one()
+ action = {
+ 'type': 'ir.actions.act_url',
+ 'url': '/web/content/%s?download=true' % (self.print_attachment_id.id),
+ 'target': 'new',
+ }
+ self.printed = True
+ return action
+
+ @api.multi
+ def send_and_print_action(self):
+ self.ensure_one()
+ self._send_email()
+ return self._print_document()
+
+ @api.multi
+ def send_action(self):
+ for wizard in self:
+ wizard._send_email()
+ return {'type': 'ir.actions.act_window_close'}
+
+ @api.multi
+ def print_action(self):
+ self.ensure_one()
+ return self._print_document()
diff --git a/addons/account/wizard/multi_compose_message_views.xml b/addons/account/wizard/multi_compose_message_views.xml
new file mode 100644
index 00000000000..7a294573863
--- /dev/null
+++ b/addons/account/wizard/multi_compose_message_views.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <data>
+ <record model="ir.ui.view" id="multi_compose_message_wizard_form">
+ <field name="name">multi.compose.message.form</field>
+ <field name="model">multi.compose.message</field>
+ <field name="groups_id" eval="[(4,ref('base.group_user'))]"/>
+ <field name="arch" type="xml">
+ <form string="Compose Email &amp; Print">
+ <field name="print_attachment_id" invisible="1"/>
+ <div name="option_print" class="col-md-12 mb16">
+ <field name="is_print" widget="boolean_toggle"/>
+ <b><label for="is_print"/></b>
+ </div>
+ <div class="col-md-12 mb16" style="border-bottom: 1px solid #e5e5e5;"></div>
+ <div name="option_email" class="col-md-12 mb16">
+ <field name="is_email" widget="boolean_toggle"/>
+ <b><label for="is_email"/></b>
+ </div>
+ <div name="mail_form" attrs="{'invisible': [('is_email', '=', False)]}">
+ <group>
+ <!-- truly invisible fields for control and options -->
+ <field name="printed" invisible="1"/>
+ <field name="model" invisible="1"/>
+ <field name="res_id" invisible="1"/>
+ <field name="is_log" invisible="1"/>
+ <field name="company_id" invisible="1"/>
+ <!-- visible wizard -->
+ <label for="partner_ids" string="Recipients" groups="base.group_user"/>
+ <div groups="base.group_user">
+ <span attrs="{'invisible':['|', ('model', '=', False)]}">Followers of the document and</span>
+ <field name="partner_ids" widget="many2many_tags_email" placeholder="Add contacts to notify..."
+ context="{'force_email':True, 'show_email':True}"/>
+ </div>
+ <field name="subject" placeholder="Subject..." required="True"/>
+ </group>
+ <field name="body" options="{'style-inline': true}"/>
+ <group col="4">
+ <field name="attachment_ids" widget="many2many_binary" string="Attach a file" nolabel="1" colspan="2"/>
+ <field name="template_id" options="{'no_create': True}"
+ context="{'default_model': model, 'default_body_html': body, 'default_subject': subject}"/>
+ </group>
+ </div>
+ <footer>
+ <button string="Send &amp; Print"
+ attrs="{'invisible': ['|', '|', ('is_log', '=', True), ('printed', '=', True), '|', ('is_email', '=', False), ('is_print', '=', False)]}"
+ name="send_and_print_action" type="object" class="btn-primary o_mail_send"/>
+ <button string="Send"
+ attrs="{'invisible': ['|', ('is_print', '=', True), ('is_email', '=', False)]}"
+ name="send_action" type="object" class="btn-primary o_mail_send"/>
+ <button string="Print"
+ attrs="{'invisible': ['|', '|', '|', ('is_log', '=', True), ('printed', '=', True), ('is_print', '=', False), ('is_email', '=', True)]}"
+ name="print_action" type="object" class="btn-primary o_mail_send"/>
+ <button string="Done" attrs="{'invisible': [('printed', '=', False)]}" special="cancel" class="btn-primary"/>
+ <button string="Cancel" class="btn-default" special="cancel" />
+ <button icon="fa-lg fa-save" type="object" name="save_as_template" string="Save as new template"
+ attrs="{'invisible': ['|', '|', '|', ('is_log', '=', True), ('printed', '=', True), ('is_email', '=', False)]}"
+ class="pull-right btn-default" help="Save as a new template" />
+ </footer>
+ </form>
+ </field>
+ </record>
+
+ </data>
+
+</odoo>