From 7fe9d58b0d890d714d690a5e17bd3ef31bcc47ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 28 Oct 2015 18:10:09 +0100 Subject: [PATCH] [IMP] invoice, sale, purchase: template update Templates used to send invoice / quotation / PO by email are cleaned. Custom style is removed. Content is simplified. For sale, only one template is kept through the various addons. Previously to this commit there are 3 templates: standard, portal and online quote. Those template are similar except the link to get the sale order. Now the base template contains some logic that should be sufficient to cover all cases. This breaks the modular approach but is easier to use for users. As templates are still mako it is not possible to use inheritance. So having a base template knowing some bits of overriding modules is necessary if we want to avoid having the same template duplicated. --- addons/account/data/invoice_action_data.xml | 77 +++----- addons/portal_sale/__openerp__.py | 1 - addons/portal_sale/portal_sale.py | 26 --- addons/portal_sale/portal_sale_data.xml | 167 ------------------ addons/purchase/data/mail_template_data.xml | 135 +++++--------- addons/sale/data/mail_template_data.xml | 81 +++------ .../data/website_quotation_data.xml | 145 --------------- addons/website_quote/models/order.py | 17 -- 8 files changed, 91 insertions(+), 558 deletions(-) delete mode 100644 addons/portal_sale/portal_sale_data.xml diff --git a/addons/account/data/invoice_action_data.xml b/addons/account/data/invoice_action_data.xml index e04a3517032..11ed429d417 100644 --- a/addons/account/data/invoice_action_data.xml +++ b/addons/account/data/invoice_action_data.xml @@ -16,58 +16,31 @@ Invoice_${(object.number or '').replace('/','_')}_${object.state == 'draft' and 'draft' or ''} ${object.partner_id.lang} -

Hello ${object.partner_id.name},

-

A new invoice is available for you:

- -

-   REFERENCES
-   Invoice number: ${object.number}
-   Invoice total: ${object.amount_total} ${object.currency_id.name}
-   Invoice date: ${object.date_invoice}
- % if object.origin: -   Order reference: ${object.origin}
- % endif - % if object.user_id: -   Your contact: ${object.user_id.name} - % endif -

- - % if object.paypal_url: -
-

It is also possible to directly pay with Paypal:

- - - - % endif - -
-

If you have any question, do not hesitate to contact us.

-

Thank you for choosing ${object.company_id.name or 'us'}!

-
-
-
-

- ${object.company_id.name}

-
-
- - ${object.company_id.partner_id.sudo().with_context(show_address=True, html_format=True).name_get()[0][1] | safe} - - % if object.company_id.phone: -
- Phone:  ${object.company_id.phone} -
- % endif - % if object.company_id.website: -
- Web : ${object.company_id.website} -
- %endif -

-
- - ]]>
+% set access_action = object.get_access_action() +% set access_name = 'View invoice' if access_action and access_action['type'] == 'ir.actions.act_url' else 'See invoice' +% set access_url = access_action['type'] == 'ir.actions.act_url' and access_action['url'] or '/report/pdf/account.report_invoice/' + str(object.id) + +

Dear +% if object.partner_id.company_type == 'company' and object.child_ids: + ${object.partner_id.child_ids[0].name} +% else : + ${object.partner_id.name} +% endif +,

+

Thank you for your inquiry. Here is your invoice ${object.name} +% if object.origin: +(with reference: ${object.origin} ) +% endif +amounting ${object.amount_total} ${object.currency_id.name} +from ${object.company_id.name}. +

+ +

+ ${access_name} +

+

If you have any question, do not hesitate to contact us.

+

Best regards,

+]]> diff --git a/addons/portal_sale/__openerp__.py b/addons/portal_sale/__openerp__.py index aaf13bbca44..1ea72f45e77 100644 --- a/addons/portal_sale/__openerp__.py +++ b/addons/portal_sale/__openerp__.py @@ -29,7 +29,6 @@ by default, you simply need to configure a Paypal account in the Accounting/Invo 'data': [ 'security/portal_security.xml', 'portal_sale_view.xml', - 'portal_sale_data.xml', 'security/ir.model.access.csv', ], 'auto_install': True, diff --git a/addons/portal_sale/portal_sale.py b/addons/portal_sale/portal_sale.py index c422c7ac57e..0c071e1c37d 100644 --- a/addons/portal_sale/portal_sale.py +++ b/addons/portal_sale/portal_sale.py @@ -9,19 +9,6 @@ from openerp import SUPERUSER_ID class sale_order(osv.Model): _inherit = 'sale.order' - def action_quotation_send(self, cr, uid, ids, context=None): - ''' Override to use a modified template that includes a portal signup link ''' - action_dict = super(sale_order, self).action_quotation_send(cr, uid, ids, context=context) - try: - template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'portal_sale', 'email_template_edi_sale')[1] - # assume context is still a dict, as prepared by super - ctx = action_dict['context'] - ctx['default_template_id'] = template_id - ctx['default_use_template'] = True - except Exception: - pass - return action_dict - def action_confirm(self, cr, uid, ids, context=None): # fetch the partner's id and subscribe the partner to the sale order assert len(ids) == 1 @@ -52,19 +39,6 @@ class sale_order(osv.Model): class account_invoice(osv.Model): _inherit = 'account.invoice' - def action_invoice_sent(self, cr, uid, ids, context=None): - ''' Override to use a modified template that includes a portal signup link ''' - action_dict = super(account_invoice, self).action_invoice_sent(cr, uid, ids, context=context) - try: - template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'portal_sale', 'email_template_edi_invoice')[1] - # assume context is still a dict, as prepared by super - ctx = action_dict['context'] - ctx['default_template_id'] = template_id - ctx['default_use_template'] = True - except Exception: - pass - return action_dict - def invoice_validate(self, cr, uid, ids, context=None): # fetch the partner's id and subscribe the partner to the invoice for invoice in self.browse(cr, uid, ids, context=context): diff --git a/addons/portal_sale/portal_sale_data.xml b/addons/portal_sale/portal_sale_data.xml deleted file mode 100644 index 0b4a0246f3e..00000000000 --- a/addons/portal_sale/portal_sale_data.xml +++ /dev/null @@ -1,167 +0,0 @@ - - - - - - - Sales Order - Send by Email (Portal) - ${(object.user_id.email or '')|safe} - ${object.company_id.name|safe} ${object.state in ('draft', 'sent') and 'Quotation' or 'Order'} (Ref ${object.name or 'n/a' }) - ${object.partner_invoice_id.id} - - - - ${(object.name or '').replace('/','_')}_${object.state == 'draft' and 'draft' or ''} - ${object.partner_id.lang} - - - -

Hello ${object.partner_id.name},

- -

Here is your ${object.state in ('draft', 'sent') and 'quotation' or 'order confirmation'} from ${object.company_id.name}:

- -

-   REFERENCES
-   Order number: ${object.name}
-   Order total: ${object.amount_total} ${object.pricelist_id.currency_id.name}
-   Order date: ${format_tz(object.date_order, tz=user.tz, context={'lang':object.partner_id.lang})}
- % if object.validity_date and object.state in ('draft', 'sent'): -   Expiration date: ${object.validity_date}
- % endif - % if object.origin: -   Order reference: ${object.origin}
- % endif - % if object.client_order_ref: -   Your reference: ${object.client_order_ref}
- % endif - % if object.user_id: -   Your contact: ${object.user_id.name} - % endif -

- - <% set signup_url = object.get_signup_url() %> - % if signup_url and object.amount_total > 0 : -

- You can access this document and pay online via our Customer Portal: -

- View ${object.state in ('draft', 'sent') and 'Quotation' or 'Order'} - % endif - - % if object.paypal_url and object.amount_total > 0 : -
-

It is also possible to directly pay with Paypal:

- - - - % endif - -
-

If you have any question, do not hesitate to contact us.

-

Thank you for choosing ${object.company_id.name or 'us'}!

-
-
-
-

- ${object.company_id.name}

-
-
- - ${object.company_id.partner_id.sudo().with_context(show_address=True, html_format=True).name_get()[0][1] | safe} - - % if object.company_id.phone: -
- Phone:  ${object.company_id.phone} -
- % endif - % if object.company_id.website: - - % endif -

-
- - ]]>
-
- - - Invoice - Send by Email (Portal) - ${(object.user_id.email or object.company_id.email or 'noreply@localhost')|safe} - ${object.company_id.name|safe} Invoice (Ref ${object.number or 'n/a' }) - ${object.partner_id.id} - - - - Invoice_${(object.number or '').replace('/','_')}_${object.state == 'draft' and 'draft' or ''} - ${object.partner_id.lang} - - -

Hello ${object.partner_id.name},

- -

A new invoice is available for you:

- -

-   REFERENCES
-   Invoice number: ${object.number}
-   Invoice total: ${object.amount_total} ${object.currency_id.name}
-   Invoice date: ${object.date_invoice}
- % if object.origin: -   Order reference: ${object.origin}
- % endif - % if object.user_id: -   Your contact: ${object.user_id.name} - % endif -

- - <% set signup_url = object.get_signup_url() %> - % if signup_url: -

- You can access the invoice document and pay online via our Customer Portal: -

- View Invoice - % endif - - % if object.paypal_url: -
-

It is also possible to directly pay with Paypal:

- - - - % endif - -
-

If you have any question, do not hesitate to contact us.

-

Thank you for choosing ${object.company_id.name or 'us'}!

-
-
-
-

- ${object.company_id.name}

-
-
- - ${object.company_id.partner_id.sudo().with_context(show_address=True, html_format=True).name_get()[0][1] | safe} - - % if object.company_id.phone: -
- Phone:  ${object.company_id.phone} -
- % endif - % if object.company_id.website: - - % endif -

-
- - ]]>
-
- -
-
diff --git a/addons/purchase/data/mail_template_data.xml b/addons/purchase/data/mail_template_data.xml index 1a743871538..35188397f11 100644 --- a/addons/purchase/data/mail_template_data.xml +++ b/addons/purchase/data/mail_template_data.xml @@ -14,54 +14,27 @@ RFQ_${(object.name or '').replace('/','_')} ${object.partner_id.lang} +

Dear +% if object.partner_id.company_type == 'company' and object.child_ids: + ${object.partner_id.child_ids[0].name} +% else : + ${object.partner_id.name} +% endif +,

+Here is a ${object.state in ('draft', 'sent') and 'request for quotation' or 'purchase order confirmation'} ${object.name} +% if object.partner_ref: + with reference: ${object.partner_ref} +% endif +% if object.origin: + (RFQ origin: ${object.origin}) +% endif +amounting ${object.amount_total} ${object.currency_id.name} +from ${object.company_id.name}. +

-

Hello ${object.partner_id.name},

- -

Here is a ${object.state in ('draft', 'sent') and 'request for quotation' or 'purchase order confirmation'} from ${object.company_id.name}:

- -

-   REFERENCES
-   RFQ number: ${object.name}
-   RFQ date: ${object.date_order}
- % if object.origin: -   RFQ reference: ${object.origin}
- % endif - % if object.partner_ref: -   Your reference: ${object.partner_ref}
- % endif - % if object.create_uid: -   Your contact: ${object.create_uid.name} - % endif -

- -
-

If you have any question, do not hesitate to contact us.

-

Thank you!

-
-
-
-

- ${object.company_id.name}

-
-
- - ${object.company_id.partner_id.sudo().with_context(show_address=True, html_format=True).name_get()[0][1] | safe} - - % if object.company_id.phone: -
- Phone:  ${object.company_id.phone} -
- % endif - % if object.company_id.website: -
- Web : ${object.company_id.website} -
- %endif -

-
- - ]]>
+

If you have any question, do not hesitate to contact us.

+

Best regards,

+]]> @@ -77,55 +50,27 @@ PO_${(object.name or '').replace('/','_')} ${object.partner_id.lang} +

Dear +% if object.partner_id.company_type == 'company' and object.child_ids: + ${object.partner_id.child_ids[0].name} +% else : + ${object.partner_id.name} +% endif +,

+Here is a ${object.state in ('draft', 'sent') and 'request for quotation' or 'purchase order confirmation'} ${object.name} +% if object.partner_ref: + with reference: ${object.partner_ref} +% endif +% if object.origin: + (RFQ origin: ${object.origin}) +% endif +amounting ${object.amount_total} ${object.currency_id.name} +from ${object.company_id.name}. +

-

Hello ${object.partner_id.name},

- -

Here is a ${object.state in ('draft', 'sent') and 'request for quotation' or 'purchase order confirmation'} from ${object.company_id.name}:

- -

-   REFERENCES
-   Order number: ${object.name}
-   Order total: ${object.amount_total} ${object.currency_id.name}
-   Order date: ${object.date_order}
- % if object.origin: -   Order reference: ${object.origin}
- % endif - % if object.partner_ref: -   Your reference: ${object.partner_ref}
- % endif - % if object.create_uid: -   Your contact: ${object.create_uid.name} - % endif -

- -
-

If you have any question, do not hesitate to contact us.

-

Thank you!

-
-
-
-

- ${object.company_id.name}

-
-
- - ${object.company_id.partner_id.sudo().with_context(show_address=True, html_format=True).name_get()[0][1] | safe} - - % if object.company_id.phone: -
- Phone:  ${object.company_id.phone} -
- % endif - % if object.company_id.website: -
- Web : ${object.company_id.website} -
- %endif -

-
- - ]]>
+

If you have any question, do not hesitate to contact us.

+

Best regards,

+]]> diff --git a/addons/sale/data/mail_template_data.xml b/addons/sale/data/mail_template_data.xml index ee245b26aac..fa069f0fc1e 100644 --- a/addons/sale/data/mail_template_data.xml +++ b/addons/sale/data/mail_template_data.xml @@ -14,63 +14,34 @@ ${(object.name or '').replace('/','_')}_${object.state == 'draft' and 'draft' or ''} ${object.partner_id.lang} +% set access_action = object.get_access_action() +% set doc_name = 'quotation' if object.state in ('draft', 'sent') else 'order confirmation' +% set is_online = access_action and access_action['type'] == 'ir.actions.act_url' +% set access_name = is_online and object.template_id and 'Accept and pay %s online' % doc_name or 'View %s' % doc_name +% set access_url = is_online and access_action['url'] or '/report/pdf/sale.report_saleorder/' + str(object.id) -

Hello ${object.partner_id.name},

- -

Here is your ${object.state in ('draft', 'sent') and 'quotation' or 'order confirmation'} from ${object.company_id.name}:

+

Dear +% if object.partner_id.company_type == 'company' and object.child_ids: + ${object.partner_id.child_ids[0].name} +% else : + ${object.partner_id.name} +% endif +,

+

Thank you for your inquiry.
+Here is your ${doc_name} ${object.name} +% if object.origin: +(with reference: ${object.origin} ) +% endif +amounting ${object.amount_total} ${object.pricelist_id.currency_id.name} +from ${object.company_id.name}. +

-

-   REFERENCES
-   Order number: ${object.name}
-   Order total: ${object.amount_total} ${object.pricelist_id.currency_id.name}
-   Order date: ${format_tz(object.date_order, tz=user.tz, context={'lang':object.partner_id.lang})}
- % if object.origin: -   Order reference: ${object.origin}
- % endif - % if object.client_order_ref: -   Your reference: ${object.client_order_ref}
- % endif - % if object.user_id: -   Your contact: ${object.user_id.name} - % endif -

- - % if object.paypal_url: -
-

It is also possible to directly pay with Paypal:

- - - - % endif - -
-

If you have any question, do not hesitate to contact us.

-

Thank you for choosing ${object.company_id.name or 'us'}!

-
-
-
-

- ${object.company_id.name}

-
-
- - ${object.company_id.partner_id.sudo().with_context(show_address=True, html_format=True).name_get()[0][1] | safe} - - % if object.company_id.phone: -
- Phone:  ${object.company_id.phone} -
- % endif - % if object.company_id.website: -
- Web : ${object.company_id.website} -
- %endif -

-
- - ]]>
+

+ ${access_name} +

+

If you have any question, do not hesitate to contact us.

+

Best regards,

+]]> diff --git a/addons/website_quote/data/website_quotation_data.xml b/addons/website_quote/data/website_quotation_data.xml index bb01e321a32..042cc39f3f0 100644 --- a/addons/website_quote/data/website_quotation_data.xml +++ b/addons/website_quote/data/website_quotation_data.xml @@ -19,71 +19,6 @@ - - - -

Hello ${object.partner_id.name},

- -

Here is your ${object.state in ('draft', 'sent') and 'quotation' or 'order confirmation'} from ${object.company_id.name}:

- -

-   REFERENCES
-   Order number: ${object.name}
-   Order total: ${object.amount_total} ${object.pricelist_id.currency_id.name}
-   Order date: ${object.date_order}
- % if object.origin: -   Order reference: ${object.origin}
- % endif - % if object.client_order_ref: -   Your reference: ${object.client_order_ref}
- % endif - % if object.user_id: -   Your contact: ${object.user_id.name} - % endif -

-

- You can view your quotation online: -

- View ${object.state in ('draft', 'sent') and 'Quotation' or 'Order'} - - % if object.paypal_url: -
-

It is also possible to directly pay with Paypal:

- - - - % endif - -
-

If you have any question, do not hesitate to contact us.

-

Thank you for choosing ${object.company_id.name or 'us'}!

-
-
-
-

- ${object.company_id.name}

-
-
- - ${object.company_id.partner_id.sudo().with_context(show_address=True, html_format=True).name_get()[0][1] | safe} - - % if object.company_id.phone: -
- Phone:  ${object.company_id.phone} -
- % endif - % if object.company_id.website: - - %endif -

-
- - ]]>
-
Default Template @@ -155,85 +90,5 @@ - - - Sales Order - Send by Email (Online Quote) - ${(object.user_id.email or '')|safe} - ${object.company_id.name|safe} ${object.state in ('draft', 'sent') and 'Quotation' or 'Order'} (Ref ${object.name or 'n/a' }) - ${object.partner_invoice_id.id} - - - - ${(object.name or '').replace('/','_')}_${object.state == 'draft' and 'draft' or ''} - ${object.partner_id.lang} - - - -

Hello ${object.partner_id.name},

- -

Here is your ${object.state in ('draft', 'sent') and 'quotation' or 'order confirmation'} from ${object.company_id.name}:

- -

-   REFERENCES
-   Order number: ${object.name}
-   Order total: ${object.amount_total} ${object.pricelist_id.currency_id.name}
-   Order date: ${object.date_order}
- % if object.origin: -   Order reference: ${object.origin}
- % endif - % if object.client_order_ref: -   Your reference: ${object.client_order_ref}
- % endif - % if object.user_id: -   Your contact: ${object.user_id.name} - % endif -

- - <% set signup_url = object.get_signup_url() %> - % if signup_url and object.amount_total > 0 : -

- You can access this document and pay online via our Customer Portal: -

- View ${object.state in ('draft', 'sent') and 'Quotation' or 'Order'} - % endif - - % if object.paypal_url and object.amount_total > 0 : -
-

It is also possible to directly pay with Paypal:

- - - - % endif - -
-

If you have any question, do not hesitate to contact us.

-

Thank you for choosing ${object.company_id.name or 'us'}!

-
-
-
-

- ${object.company_id.name}

-
-
- - ${object.company_id.partner_id.sudo().with_context(show_address=True, html_format=True).name_get()[0][1] | safe} - - % if object.company_id.phone: -
- Phone:  ${object.company_id.phone} -
- % endif - % if object.company_id.website: - - % endif -

-
- - ]]>
-
diff --git a/addons/website_quote/models/order.py b/addons/website_quote/models/order.py index 09392c0b913..904564c9bff 100644 --- a/addons/website_quote/models/order.py +++ b/addons/website_quote/models/order.py @@ -266,23 +266,6 @@ class sale_order(osv.osv): 'res_id': id, } - def action_quotation_send(self, cr, uid, ids, context=None): - action = super(sale_order, self).action_quotation_send(cr, uid, ids, context=context) - ir_model_data = self.pool.get('ir.model.data') - quote_template_id = self.read(cr, uid, ids, ['template_id'], context=context)[0]['template_id'] - if quote_template_id: - try: - template_id = ir_model_data.get_object_reference(cr, uid, 'website_quote', 'email_template_edi_sale')[1] - except ValueError: - pass - else: - action['context'].update({ - 'default_template_id': template_id, - 'default_use_template': True - }) - - return action - def _confirm_online_quote(self, cr, uid, order_id, tx, context=None): """ Payment callback: validate the order and write tx details in chatter """ order = self.browse(cr, uid, order_id, context=context)