From 62c64d5c4df1fdb7dddd94d132b85b964ec1ed79 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 16 Nov 2012 18:06:43 +0100 Subject: [PATCH] [IMP] sale_portal: override default `Send by Email` templates to include portal signup link bzr revid: odo@openerp.com-20121116170643-usandzkdhi0idn2d --- addons/portal_sale/__openerp__.py | 1 + addons/portal_sale/portal_sale.py | 29 +++- addons/portal_sale/portal_sale_data.xml | 212 ++++++++++++++++++++++++ 3 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 addons/portal_sale/portal_sale_data.xml diff --git a/addons/portal_sale/__openerp__.py b/addons/portal_sale/__openerp__.py index 3ed124c0beb..a993ab9c462 100644 --- a/addons/portal_sale/__openerp__.py +++ b/addons/portal_sale/__openerp__.py @@ -48,6 +48,7 @@ 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', 'res_config_view.xml', 'security/ir.model.access.csv', ], diff --git a/addons/portal_sale/portal_sale.py b/addons/portal_sale/portal_sale.py index 09d71fc1d2b..818da5e8784 100644 --- a/addons/portal_sale/portal_sale.py +++ b/addons/portal_sale/portal_sale.py @@ -24,6 +24,7 @@ from openerp.osv import osv, fields class sale_order(osv.Model): _inherit = 'sale.order' + # make the real method inheritable _payment_block_proxy = lambda self,*a,**kw: self._portal_payment_block(*a, **kw) _columns = { @@ -39,10 +40,23 @@ class sale_order(osv.Model): this.pricelist_id.currency_id, this.amount_total, context=context) return result + 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 class account_invoice(osv.Model): _inherit = 'account.invoice' + # make the real method inheritable _payment_block_proxy = lambda self,*a,**kw: self._portal_payment_block(*a, **kw) _columns = { @@ -56,4 +70,17 @@ class account_invoice(osv.Model): if this.state not in ('draft','done') and not this.reconciled: result[this.id] = payment_acquirer.render_payment_block(cr, uid, this, this.number, this.currency_id, this.residual, context=context) - return result \ No newline at end of file + return result + + 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 diff --git a/addons/portal_sale/portal_sale_data.xml b/addons/portal_sale/portal_sale_data.xml new file mode 100644 index 00000000000..2abb70b068c --- /dev/null +++ b/addons/portal_sale/portal_sale_data.xml @@ -0,0 +1,212 @@ + + + + + + + Sale Order - Send by Email (Portal) + ${object.user_id.email or ''} + ${object.company_id.name} ${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 ''} + + +

Hello${object.partner_id.name and ' ' or ''}${object.partner_id.name or ''},

+ +

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 +

+ + <% + action = 'portal_sale.action_quotations_portal' if object.state in ('draft', 'sent') else 'portal_sale.action_orders_portal' + object.partner_id.signup_prepare() + signup_url = object.partner_id._get_signup_url_for_action(action=action,view_type='form',res_id=object.id)[object.partner_id.id] + %> + % if signup_url: +

+ You can access this document and pay online via our Customers Portal: +

+ View ${object.state in ('draft', 'sent') and 'Quotation' or 'Order'} + % endif + + % if object.order_policy in ('prepaid','manual') and object.company_id.paypal_account and object.state != 'draft': + <% + comp_name = quote(object.company_id.name) + order_name = quote(object.name) + paypal_account = quote(object.company_id.paypal_account) + order_amount = quote(str(object.residual)) + cur_name = quote(object.pricelist_id.currency_id.name) + paypal_url = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=%s&item_name=%s%%20Order%%20%s" \ + "&invoice=%s&amount=%s&currency_code=%s&button_subtype=services&no_note=1" \ + "&bn=OpenERP_Order_PayNow_%s" % \ + (paypal_account,comp_name,order_name,order_name,order_amount,cur_name,cur_name) + %> +
+

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}

+
+
+ + % if object.company_id.street: + ${object.company_id.street}
+ % endif + % if object.company_id.street2: + ${object.company_id.street2}
+ % endif + % if object.company_id.city or object.company_id.zip: + ${object.company_id.zip} ${object.company_id.city}
+ % endif + % if object.company_id.country_id: + ${object.company_id.state_id and ('%s, ' % object.company_id.state_id.name) or ''} ${object.company_id.country_id.name or ''}
+ % endif +
+ % 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'} + ${object.company_id.name} Invoice (Ref ${object.number or 'n/a' }) + ${object.partner_id.id} + + + + Invoice_${(object.number or '').replace('/','_')}_${object.state == 'draft' and 'draft' or ''} + + +

Hello${object.partner_id.name and ' ' or ''}${object.partner_id.name or ''},

+ +

A new invoice is available for ${object.partner_id.name}:

+ +

+   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 +

+ + <% + action = 'portal_sale.portal_action_invoices' + object.partner_id.signup_prepare() + signup_url = object.partner_id._get_signup_url_for_action(action=action,view_type='form',res_id=object.id)[object.partner_id.id] + %> + % if signup_url: +

+ You can access the invoice document and pay online via our Customers Portal: +

+ View Invoice + % endif + + % if object.company_id.paypal_account and object.type in ('out_invoice', 'in_refund'): + <% + comp_name = quote(object.company_id.name) + inv_number = quote(object.number) + paypal_account = quote(object.company_id.paypal_account) + inv_amount = quote(str(object.amount_residual)) + cur_name = quote(object.currency_id.name) + paypal_url = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=%s&item_name=%s%%20Invoice%%20%s&" \ + "invoice=%s&amount=%s&currency_code=%s&button_subtype=services&no_note=1&bn=OpenERP_Invoice_PayNow_%s" % \ + (paypal_account,comp_name,inv_number,inv_number,inv_amount,cur_name,cur_name) + %> +
+

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}

+
+
+ + % if object.company_id.street: + ${object.company_id.street}
+ % endif + % if object.company_id.street2: + ${object.company_id.street2}
+ % endif + % if object.company_id.city or object.company_id.zip: + ${object.company_id.zip} ${object.company_id.city}
+ % endif + % if object.company_id.country_id: + ${object.company_id.state_id and ('%s, ' % object.company_id.state_id.name) or ''} ${object.company_id.country_id.name or ''}
+ % endif +
+ % if object.company_id.phone: +
+ Phone:  ${object.company_id.phone} +
+ % endif + % if object.company_id.website: + + %endif +

+
+ + ]]>
+
+ +
+
\ No newline at end of file