diff options
| author | Rémi Rahir <rar@odoo.com> | 2018-08-03 12:21:28 +0200 |
|---|---|---|
| committer | Rémi Rahir <rar@odoo.com> | 2018-08-10 18:41:00 +0200 |
| commit | 53cdd68e7cc9e1494a9a99dcd2fff0cc835eab50 (patch) | |
| tree | 34b9c7837603a3e929b52271381a3a6e5bd17018 /addons/account | |
| parent | a07902ffa81443d242167bd8291f1902b43beb2e (diff) | |
[IMP] account,snailmail: support batch calls
- reworked the multi.compose.message model to manage
several documents simultaneously
- Added a letter model for asynchronous processing
- usability improvement of the modal
Diffstat (limited to 'addons/account')
| -rw-r--r-- | addons/account/__manifest__.py | 2 | ||||
| -rw-r--r-- | addons/account/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/account/models/account_invoice.py | 9 | ||||
| -rw-r--r-- | addons/account/models/company.py | 3 | ||||
| -rw-r--r-- | addons/account/models/res_company.py | 11 | ||||
| -rw-r--r-- | addons/account/models/res_config_settings.py | 2 | ||||
| -rw-r--r-- | addons/account/views/res_config_settings_views.xml | 21 | ||||
| -rw-r--r-- | addons/account/wizard/__init__.py | 2 | ||||
| -rw-r--r-- | addons/account/wizard/account_invoice_send.py | 64 | ||||
| -rw-r--r-- | addons/account/wizard/account_invoice_send_views.xml | 93 | ||||
| -rw-r--r-- | addons/account/wizard/multi_compose_message.py | 79 | ||||
| -rw-r--r-- | addons/account/wizard/multi_compose_message_views.xml | 66 |
12 files changed, 189 insertions, 164 deletions
diff --git a/addons/account/__manifest__.py b/addons/account/__manifest__.py index c99baf6f130..e79c388f6f3 100644 --- a/addons/account/__manifest__.py +++ b/addons/account/__manifest__.py @@ -72,11 +72,11 @@ You could use this simplified accounting in case you work with an (external) acc 'views/res_users_views.xml', 'data/service_cron_reverse.xml', 'views/account_fiscal_year_view.xml', - 'wizard/multi_compose_message_views.xml', 'views/account_incoterms_view.xml', 'data/account_incoterms_data.xml', 'views/res_company_view.xml', 'views/digest_views.xml', + 'wizard/account_invoice_send_views.xml', ], 'demo': [ 'demo/account_demo.xml', diff --git a/addons/account/models/__init__.py b/addons/account/models/__init__.py index 144bc6bc2ba..50b2b4adcf0 100644 --- a/addons/account/models/__init__.py +++ b/addons/account/models/__init__.py @@ -16,6 +16,5 @@ from . import res_config_settings from . import account_cash_rounding from . import reconciliation_widget from . import res_users -from . import res_company from . import account_incoterms from . import digest diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 785159896fd..56f1e9c910e 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -574,8 +574,7 @@ class AccountInvoice(models.Model): """ Print the invoice and mark it as sent, so that we can see more easily the next step of the workflow """ - self.ensure_one() - self.sent = True + self.write({'sent': True}) if self.user_has_groups('account.group_account_invoice'): return self.env.ref('account.account_invoices').report_action(self) else: @@ -588,7 +587,7 @@ class AccountInvoice(models.Model): """ self.ensure_one() template = self.env.ref('account.email_template_edi_invoice', False) - compose_form = self.env.ref('account.multi_compose_message_wizard_form', False) + compose_form = self.env.ref('account.account_invoice_send_wizard_form', False) ctx = dict( default_model='account.invoice', default_res_id=self.id, @@ -600,11 +599,11 @@ class AccountInvoice(models.Model): force_email=True ) return { - 'name': _('Compose Email'), + 'name': _('Send Invoice'), 'type': 'ir.actions.act_window', 'view_type': 'form', 'view_mode': 'form', - 'res_model': 'multi.compose.message', + 'res_model': 'account.invoice.send', 'views': [(compose_form.id, 'form')], 'view_id': compose_form.id, 'target': 'new', diff --git a/addons/account/models/company.py b/addons/account/models/company.py index 9929b942aa9..c9a898d626f 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -71,6 +71,9 @@ Best Regards,''')) qr_code_payment_journal_id = fields.Many2one('account.journal', string='SEPA QR Code Bank Journal account') qr_code_valid = fields.Boolean(string='Has all required arguments', related="qr_code_payment_journal_id.bank_account_id.qr_code_valid") + invoice_is_email = fields.Boolean('Email by default', default=True) + invoice_is_print = fields.Boolean('Print by default', default=True) + #Fields of the setup step for opening move account_opening_move_id = fields.Many2one(string='Opening Journal Entry', comodel_name='account.move', help="The journal entry containing the initial balance of all this company's accounts.") account_opening_journal_id = fields.Many2one(string='Opening Journal', comodel_name='account.journal', related='account_opening_move_id.journal_id', help="Journal where the opening entry of this company's accounting has been posted.") diff --git a/addons/account/models/res_company.py b/addons/account/models/res_company.py deleted file mode 100644 index 522bd956fc3..00000000000 --- a/addons/account/models/res_company.py +++ /dev/null @@ -1,11 +0,0 @@ -# -*- 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/models/res_config_settings.py b/addons/account/models/res_config_settings.py index 739507e5dc1..438393ca020 100644 --- a/addons/account/models/res_config_settings.py +++ b/addons/account/models/res_config_settings.py @@ -86,6 +86,8 @@ class ResConfigSettings(models.TransientModel): qr_code = fields.Boolean(string='Display SEPA QR code', related='company_id.qr_code') qr_code_payment_journal_id = fields.Many2one('account.journal', related='company_id.qr_code_payment_journal_id', string="Payment Journal", domain="['&',('type', '=', 'bank'), ('currency_id.name','=','EUR')]") qr_code_valid = fields.Boolean(string='Has all required arguments', related="qr_code_payment_journal_id.bank_account_id.qr_code_valid") + invoice_is_print = fields.Boolean(string='Print', related='company_id.invoice_is_print') + invoice_is_email = fields.Boolean(string='Send Email', related='company_id.invoice_is_email') @api.multi def set_values(self): diff --git a/addons/account/views/res_config_settings_views.xml b/addons/account/views/res_config_settings_views.xml index daf25279f83..6158e088d3f 100644 --- a/addons/account/views/res_config_settings_views.xml +++ b/addons/account/views/res_config_settings_views.xml @@ -450,6 +450,27 @@ </div> </div> </div> + <h2>Default Sending Options</h2> + <div class="row mt16 o_settings_container" id="send_default"> + <div class="col-12 col-lg-6 o_setting_box"> + <div class="o_setting_left_pane"> + <field name="invoice_is_print"/> + </div> + <div class="o_setting_right_pane"> + <label for="invoice_is_print"/> + <span class="fa fa-lg fa-building-o" title="Values set here are company-specific."/> + </div> + </div> + <div class="col-12 col-lg-6 o_setting_box"> + <div class="o_setting_left_pane"> + <field name="invoice_is_email"/> + </div> + <div class="o_setting_right_pane"> + <label for="invoice_is_email"/> + <span class="fa fa-lg fa-building-o" title="Values set here are company-specific."/> + </div> + </div> + </div> <h2>Invoices</h2> <div class="row mt16 o_settings_container" id="invoicing_settings"> <div class="col-12 col-lg-6 o_setting_box"> diff --git a/addons/account/wizard/__init__.py b/addons/account/wizard/__init__.py index b7374520988..d8440f9e57c 100644 --- a/addons/account/wizard/__init__.py +++ b/addons/account/wizard/__init__.py @@ -21,4 +21,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 +from . import account_invoice_send diff --git a/addons/account/wizard/account_invoice_send.py b/addons/account/wizard/account_invoice_send.py new file mode 100644 index 00000000000..2bb3c6b8750 --- /dev/null +++ b/addons/account/wizard/account_invoice_send.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models +from odoo.exceptions import UserError + + +class AccountInvoiceSend(models.TransientModel): + _name = 'account.invoice.send' + _inherits = {'mail.compose.message':'composer_id'} + + is_email = fields.Boolean('Email', default=lambda self: self.env.user.company_id.invoice_is_email) + is_print = fields.Boolean('Print', default=lambda self: self.env.user.company_id.invoice_is_print) + printed = fields.Boolean('Is Printed', default=False) + invoice_ids = fields.Many2many('account.invoice', 'account_invoice_account_invoice_send_rel', string='Invoices') + composer_id = fields.Many2one('mail.compose.message', string='Composer', required=True, ondelete='cascade') + template_id = fields.Many2one( + 'mail.template', 'Use template', index=True, + domain="[('model', '=', 'account.invoice')]" + ) + + @api.model + def default_get(self, fields): + res = super(AccountInvoiceSend, self).default_get(fields) + res_ids = self._context.get('active_ids') + composer = self.env['mail.compose.message'].create({ + 'composition_mode': 'comment' if len(res_ids) == 1 else 'mass_mail', + }) + res.update({ + 'invoice_ids': res_ids, + 'composer_id': composer.id, + }) + return res + + @api.multi + @api.onchange('invoice_ids') + def _compute_composition_mode(self): + for wizard in self: + wizard.composition_mode = 'comment' if len(wizard.invoice_ids) == 1 else 'mass_mail' + + @api.onchange('template_id') + def onchange_template_id(self): + if self.composer_id: + self.composer_id.template_id = self.template_id.id + self.composer_id.onchange_template_id_wrapper() + + @api.multi + def _send_email(self): + if self.is_email: + self.composer_id.send_mail() + + @api.multi + def _print_document(self): + """ to override for each type of models that will use this composer.""" + self.ensure_one() + return self.invoice_ids.invoice_print() + + @api.multi + def send_and_print_action(self): + self.ensure_one() + self._send_email() + if self.is_print: + return self._print_document() + return {'type': 'ir.actions.act_window_close'} diff --git a/addons/account/wizard/account_invoice_send_views.xml b/addons/account/wizard/account_invoice_send_views.xml new file mode 100644 index 00000000000..c48e7b4dc02 --- /dev/null +++ b/addons/account/wizard/account_invoice_send_views.xml @@ -0,0 +1,93 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <data> + + <record model="ir.ui.view" id="account_invoice_send_wizard_form"> + <field name="name">account.invoice.send.form</field> + <field name="model">account.invoice.send</field> + <field name="groups_id" eval="[(4,ref('base.group_user'))]"/> + <field name="arch" type="xml"> + <form string="Invoice send & Print"> + <!-- truly invisible fields for control and options --> + <field name="composition_mode" invisible="1"/> + <field name="composer_id" invisible="1"/> + <field name="printed" invisible="1"/> + <field name="invoice_ids" invisible="1"/> + <div name="option_print"> + <field name="is_print" /> + <b><label for="is_print"/></b> + <div name="info_form" attrs="{'invisible': ['|', ('is_print', '=', False), ('composition_mode', '=', 'mass_mail')]}" class="text-center text-muted d-inline-block"> + Preview as a PDF + </div> + </div> + <div name="option_email"> + <field name="is_email" /> + <b><label for="is_email"/></b> + </div> + <div name="mail_form" attrs="{'invisible': [('is_email', '=', False)]}"> + <!-- visible wizard --> + <div attrs="{'invisible': [('composition_mode', '=', 'mass_mail')]}"> + <group> + <label for="partner_ids" string="Recipients" groups="base.group_user"/> + <div groups="base.group_user"> + <span attrs="{'invisible': [('composition_mode', '!=', 'mass_mail')]}"> + <strong>Email mass mailing</strong> on + <span>the selected records</span> + </span> + <span>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}" attrs="{'invisible': [('composition_mode', '=', 'mass_mail')]}"/> + </div> + <field name="subject" placeholder="Subject..." attrs="{'required': [('is_email', '=', True), ('composition_mode', '=', 'comment')]}"/> + </group> + <field name="body" style="border:none;" options="{'style-inline': true}"/> + </div> + <group> + <group attrs="{'invisible': [('composition_mode', '=', 'mass_mail')]}"> + <field name="attachment_ids" widget="many2many_binary" string="Attach a file" nolabel="1" colspan="2" attrs="{'invisible': [('composition_mode', '=', 'mass_mail')]}"/> + </group> + <group> + <field name="template_id" options="{'no_create': True, 'no_edit': True}" + context="{'default_model': 'account.invoice'}"/> + </group> + </group> + </div> + + <footer> + <button string="Send & Print" + attrs="{'invisible': ['|', '|', ('printed', '=', True), '|', ('is_email', '=', False), ('is_print', '=', False)]}" + name="send_and_print_action" type="object" class="send_and_print btn-primary o_mail_send"/> + <button string="Send" + attrs="{'invisible': ['|', ('is_print', '=', True), ('is_email', '=', False)]}" + name="send_and_print_action" type="object" class="send btn-primary o_mail_send"/> + <button string="Print" + attrs="{'invisible': ['|', '|', ('printed', '=', True), ('is_print', '=', False), ('is_email', '=', True)]}" + name="send_and_print_action" type="object" class="print btn-primary o_mail_send"/> + <button string="Done" attrs="{'invisible': [('printed', '=', False)]}" special="cancel" class="btn-primary"/> + <button string="Cancel" class="btn-secondary" special="cancel" /> + <button icon="fa-lg fa-save" type="object" name="save_as_template" string="Save as new template" + attrs="{'invisible': ['|', '|', '|', ('composition_mode', '=', 'mass_mail'), ('printed', '=', True), ('is_email', '=', False)]}" + class="pull-right btn-secondary" help="Save as a new template" /> + </footer> + </form> + </field> + </record> + + <act_window + name="Send" + id="invoice_send" + multi="True" + key2="client_action_multi" + res_model="account.invoice.send" + src_model="account.invoice" + view_mode="form" + target="new" + view_type="form" + context="{ + 'default_template_id': ref('account.email_template_edi_invoice'), + 'default_is_print': False}" + groups="account.group_account_invoice"/> + + </data> + +</odoo> diff --git a/addons/account/wizard/multi_compose_message.py b/addons/account/wizard/multi_compose_message.py deleted file mode 100644 index cdbae7610f2..00000000000 --- a/addons/account/wizard/multi_compose_message.py +++ /dev/null @@ -1,79 +0,0 @@ -# -*- 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 deleted file mode 100644 index bed5b6939e8..00000000000 --- a/addons/account/wizard/multi_compose_message_views.xml +++ /dev/null @@ -1,66 +0,0 @@ -<?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 & 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 & 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-secondary" 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="float-right btn-secondary" help="Save as a new template" /> - </footer> - </form> - </field> - </record> - - </data> - -</odoo> |
