From 42ad6511e6cab7631ed51dd23c1760b78da1fc4e Mon Sep 17 00:00:00 2001
From: Raphael Collet
Date: Thu, 13 Dec 2012 10:56:43 +0100
Subject: [PATCH 01/13] [IMP] email_template: render mako templates with jinja2
sandboxed environment
bzr revid: rco@openerp.com-20121213095643-czuw8ls0he5ru1lx
---
addons/email_template/email_template.py | 44 ++++++++++++++++++-------
1 file changed, 33 insertions(+), 11 deletions(-)
diff --git a/addons/email_template/email_template.py b/addons/email_template/email_template.py
index a9bee623f66..826b82186e4 100644
--- a/addons/email_template/email_template.py
+++ b/addons/email_template/email_template.py
@@ -29,12 +29,32 @@ from osv import fields
import tools
from tools.translate import _
from urllib import quote as quote
+
_logger = logging.getLogger(__name__)
try:
- from mako.template import Template as MakoTemplate
+ # We use a jinja2 sandboxed environment to render mako templates.
+ # Note that the rendering does not cover all the mako syntax, in particular
+ # arbitrary Python statements are not accepted, and not all expressions are
+ # allowed: only "public" attributes (not starting with '_') of objects may
+ # be accessed.
+ # This is done on purpose: it prevents incidental or malicious execution of
+ # Python code that may break the security of the server.
+ from jinja2.sandbox import SandboxedEnvironment
+ mako_template_env = SandboxedEnvironment(
+ block_start_string="<%",
+ block_end_string="%>",
+ variable_start_string="${",
+ variable_end_string="}",
+ comment_start_string="<%doc>",
+ comment_end_string="%doc>",
+ line_statement_prefix="%",
+ line_comment_prefix="##",
+ trim_blocks=True, # do not output newline after blocks
+ autoescape=True, # XML/HTML automatic escaping
+ )
except ImportError:
- _logger.warning("email_template: mako templates not available, templating features will not work!")
+ _logger.warning("jinja2 not available, templating features will not work!")
class email_template(osv.osv):
"Templates for sending email"
@@ -55,7 +75,8 @@ class email_template(osv.osv):
:param str model: model name of the document record this mail is related to.
:param int res_id: id of the document record this mail is related to.
"""
- if not template: return u""
+ if not template:
+ return u""
if context is None:
context = {}
try:
@@ -64,14 +85,15 @@ class email_template(osv.osv):
if res_id:
record = self.pool.get(model).browse(cr, uid, res_id, context=context)
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
- result = MakoTemplate(template).render_unicode(object=record,
- user=user,
- # context kw would clash with mako internals
- ctx=context,
- quote=quote,
- format_exceptions=True)
- if result == u'False':
- result = u''
+ variables = {
+ 'object': record,
+ 'user': user,
+ 'ctx': context, # context kw would clash with mako internals
+ 'quote': quote,
+ }
+ result = mako_template_env.from_string(template).render(variables)
+ if result == u"False":
+ result = u""
return result
except Exception:
_logger.exception("failed to render mako template value %r", template)
From 0619510955104a2ce1da973d4d56ca13da36e902 Mon Sep 17 00:00:00 2001
From: Raphael Collet
Date: Thu, 13 Dec 2012 15:01:05 +0100
Subject: [PATCH 02/13] [IMP] account_followup: adapt email templates
bzr revid: rco@openerp.com-20121213140105-931zv0c5hc9a5yh5
---
.../account_followup_data.xml | 81 +++++++++----------
1 file changed, 40 insertions(+), 41 deletions(-)
diff --git a/addons/account_followup/account_followup_data.xml b/addons/account_followup/account_followup_data.xml
index 62ea7bce9c6..d5b257a052f 100644
--- a/addons/account_followup/account_followup_data.xml
+++ b/addons/account_followup/account_followup_data.xml
@@ -3,19 +3,19 @@
-
-
+
+
First polite payment follow-up reminder email
- ${user.email or '' | h}
- ${user.company_id.name | h} Payment Reminder
- ${object.email | h}
- ${object.lang | h}
+ ${user.email or ''|safe}
+ ${user.company_id.name} Payment Reminder
+ ${object.email|safe}
+ ${object.lang}
- Dear ${object.name | h},
+ Dear ${object.name},
Exception made if there was a mistake of ours, it seems that the following amount stays unpaid. Please, take
appropriate measures in order to carry out this payment in the next 8 days.
@@ -28,13 +28,13 @@ contact our accounting department.
Best Regards,
-${user.name | h}
+${user.name}
-${ctx.get('followup_table','')}
+${ctx.get('followup_table','') | safe}
@@ -42,23 +42,21 @@ ${ctx.get('followup_table','')}
]]>
-
-
-
-
+
+
A bit urging second payment follow-up reminder email
- ${user.email or '' | h}
- ${user.company_id.name | h} Payment Reminder
- ${object.email | h}
- ${object.lang | h}
+ ${user.email or ''|safe}
+ ${user.company_id.name} Payment Reminder
+ ${object.email|safe}
+ ${object.lang}
- Dear ${object.name | h},
+ Dear ${object.name},
- We are disappointed to see that despite sending a reminder, that your account is now seriously overdue.
+ We are disappointed to see that despite sending a reminder, that your account is now seriously overdue.
It is essential that immediate payment is made, otherwise we will have to consider placing a stop on your account
which means that we will no longer be able to supply your company with (goods/services).
Please, take appropriate measures in order to carry out this payment in the next 8 days.
@@ -71,31 +69,32 @@ Best Regards,
-${user.name | h}
+${user.name}
-${ctx.get('followup_table','')}
+${ctx.get('followup_table','') | safe}
]]>
-
+
+
Urging payment follow-up reminder email
- ${user.email or '' | h}
- ${user.company_id.name | h} Payment Reminder
- ${object.email | h}
- ${object.lang | h}
+ ${user.email or ''|safe}
+ ${user.company_id.name} Payment Reminder
+ ${object.email|safe}
+ ${object.lang}
- Dear ${object.name | h},
+ Dear ${object.name},
Despite several reminders, your account is still not settled.
Unless full payment is made in next 8 days, legal action for the recovery of the debt will be taken without
@@ -107,12 +106,12 @@ In case of any queries concerning this matter, do not hesitate to contact our ac
Best Regards,
-${user.name | h}
+${user.name}
-${ctx.get('followup_table','')}
+${ctx.get('followup_table','') | safe}
@@ -121,19 +120,18 @@ ${ctx.get('followup_table','')}
-
-
+
Default payment follow-up reminder e-mail
- ${user.email or '' | h}
- ${user.company_id.name | h} Payment Reminder
- ${object.email | h}
- ${object.lang | h}
+ ${user.email or ''|safe}
+ ${user.company_id.name} Payment Reminder
+ ${object.email|safe}
+ ${object.lang}
- Dear ${object.name | h},
+ Dear ${object.name},
Exception made if there was a mistake of ours, it seems that the following amount stays unpaid. Please, take
appropriate measures in order to carry out this payment in the next 8 days.
@@ -144,11 +142,11 @@ contact our accounting department.
Best Regards,
-${user.name | h}
+${user.name}
-${ctx.get('followup_table','')}
+${ctx.get('followup_table','') | safe}
@@ -174,7 +172,7 @@ Would your payment have been carried out after this mail was sent, please ignore
Best Regards,
-
+
@@ -198,8 +196,9 @@ If there is a problem with paying invoice that we are not aware of, do not hesit
Details of due payments is printed below.
Best Regards,
-
+
+
Call the customer on the phone
3
@@ -221,7 +220,7 @@ I trust that this action will prove unnecessary and details of due payments is p
In case of any queries concerning this matter, do not hesitate to contact our accounting department.
Best Regards,
-
+
From 33463a6bc3cee1271fc5511b6ad1e8f5b5696ef4 Mon Sep 17 00:00:00 2001
From: Raphael Collet
Date: Thu, 13 Dec 2012 15:01:35 +0100
Subject: [PATCH 03/13] [IMP] account: adapt edi email template
bzr revid: rco@openerp.com-20121213140135-zw9zhmx85ryucn81
---
addons/account/edi/invoice_action_data.xml | 38 +++++++++++++---------
addons/email_template/email_template.py | 5 ++-
2 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/addons/account/edi/invoice_action_data.xml b/addons/account/edi/invoice_action_data.xml
index c4b0c8103f1..bdb08d66cfe 100644
--- a/addons/account/edi/invoice_action_data.xml
+++ b/addons/account/edi/invoice_action_data.xml
@@ -22,8 +22,8 @@
Invoice - Send by Email
- ${object.user_id.email or object.company_id.email or 'noreply@localhost'}
- ${object.company_id.name} Invoice (Ref ${object.number or 'n/a' })
+ ${object.user_id.email or object.company_id.email or 'noreply@localhost'|safe}
+ ${object.company_id.name} Invoice (Ref ${object.number or 'n/a'})
${object.partner_id.id}
@@ -33,7 +33,7 @@
- Hello${object.partner_id.name and ' ' or ''}${object.partner_id.name or ''},
+ Hello ${object.partner_id.name or ''},
A new invoice is available for you:
@@ -46,24 +46,32 @@
Order reference: ${object.origin}
% endif
% if object.user_id:
- Your contact: ${object.user_id.name}
+ Your contact: ${object.user_id.name}
% endif
% if object.company_id.paypal_account and object.type in ('out_invoice'):
- <%
- 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.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¤cy_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)
+ <% set paypal_url = (
+ "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick"
+ "&business=%(paypal_account)s"
+ "&item_name=%(company_name)s%%20Invoice%%20%(inv)s"
+ "&invoice=%(inv)s"
+ "&amount=%(amount)s"
+ "¤cy_code=%(currency)s"
+ "&button_subtype=services"
+ "&no_note=1"
+ "&bn=OpenERP_Invoice_PayNow_%(currency)s"
+ % {
+ 'paypal_account': quote(object.company_id.paypal_account),
+ 'company_name': quote(object.company_id.name),
+ 'inv': quote(object.number),
+ 'amount': quote(str(object.residual)),
+ 'currency': quote(object.currency_id.name),
+ })
%>
It is also possible to directly pay with Paypal:
-
+
% endif
@@ -99,7 +107,7 @@
% endif
% if object.company_id.website:
%endif
diff --git a/addons/email_template/email_template.py b/addons/email_template/email_template.py
index 826b82186e4..e4cbc20f8f6 100644
--- a/addons/email_template/email_template.py
+++ b/addons/email_template/email_template.py
@@ -53,6 +53,10 @@ try:
trim_blocks=True, # do not output newline after blocks
autoescape=True, # XML/HTML automatic escaping
)
+ mako_template_env.globals.update({
+ 'str': str,
+ 'quote': quote,
+ })
except ImportError:
_logger.warning("jinja2 not available, templating features will not work!")
@@ -89,7 +93,6 @@ class email_template(osv.osv):
'object': record,
'user': user,
'ctx': context, # context kw would clash with mako internals
- 'quote': quote,
}
result = mako_template_env.from_string(template).render(variables)
if result == u"False":
From 34cc7611f4e655c5b1762f556594aac1af0816ee Mon Sep 17 00:00:00 2001
From: Raphael Collet
Date: Thu, 13 Dec 2012 15:17:00 +0100
Subject: [PATCH 04/13] [IMP] sale, purchase: adapt edi email templates
bzr revid: rco@openerp.com-20121213141700-t7glyfnl6gfmr0e2
---
.../edi/purchase_order_action_data.xml | 8 ++---
addons/sale/edi/sale_order_action_data.xml | 36 +++++++++++--------
2 files changed, 25 insertions(+), 19 deletions(-)
diff --git a/addons/purchase/edi/purchase_order_action_data.xml b/addons/purchase/edi/purchase_order_action_data.xml
index 42efd08d44c..f861c025ae8 100644
--- a/addons/purchase/edi/purchase_order_action_data.xml
+++ b/addons/purchase/edi/purchase_order_action_data.xml
@@ -19,7 +19,7 @@
Purchase Order - Send by mail
- ${object.validator.email or ''}
+ ${object.validator.email or ''|safe}
${object.company_id.name} Order (Ref ${object.name or 'n/a' })
${object.partner_id.id}
@@ -30,7 +30,7 @@
- Hello${object.partner_id.name and ' ' or ''}${object.partner_id.name or ''},
+ Hello$ ${object.partner_id.name or ''},
Here is a ${object.state in ('draft', 'sent') and 'request for quotation' or 'purchase order confirmation'} from ${object.company_id.name}:
@@ -46,7 +46,7 @@
Your reference: ${object.partner_ref}
% endif
% if object.validator:
- Your contact: ${object.validator.name}
+ Your contact: ${object.validator.name}
% endif
@@ -81,7 +81,7 @@
% endif
% if object.company_id.website:
%endif
diff --git a/addons/sale/edi/sale_order_action_data.xml b/addons/sale/edi/sale_order_action_data.xml
index ad96ae39109..2a2061f1e6b 100644
--- a/addons/sale/edi/sale_order_action_data.xml
+++ b/addons/sale/edi/sale_order_action_data.xml
@@ -21,7 +21,7 @@
Sale Order - Send by Email
- ${object.user_id.email or ''}
+ ${object.user_id.email or ''|safe}
${object.company_id.name} ${object.state in ('draft', 'sent') and 'Quotation' or 'Order'} (Ref ${object.name or 'n/a' })
${object.partner_invoice_id.id}
@@ -32,7 +32,7 @@
- Hello${object.partner_id.name and ' ' or ''}${object.partner_id.name or ''},
+ Hello ${object.partner_id.name or ''},
Here is your ${object.state in ('draft', 'sent') and 'quotation' or 'order confirmation'} from ${object.company_id.name}:
@@ -48,25 +48,31 @@
Your reference: ${object.client_order_ref}
% endif
% if object.user_id:
- Your contact: ${object.user_id.name}
+ Your contact: ${object.user_id.name}
% 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.amount_total))
- 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¤cy_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)
+ <% set paypal_url = ("https://www.paypal.com/cgi-bin/webscr?cmd=_xclick"
+ "&business=%(paypal_account)s"
+ "&item_name=%(company_name)s%%20Order%%20%(order_name)s"
+ "&invoice=%(order_name)s"
+ "&amount=%(order_amount)s"
+ "¤cy_code=%(currency)s"
+ "&button_subtype=services"
+ "&no_note=1"
+ "&bn=OpenERP_Order_PayNow_%(currency)s"
+ % {
+ 'paypal_account': quote(object.company_id.paypal_account),
+ 'company_name': quote(object.company_id.name),
+ 'order_name': quote(object.name),
+ 'order_amount': quote(str(object.amount_total)),
+ 'currency': quote(object.pricelist_id.currency_id.name),
+ })
%>
It is also possible to directly pay with Paypal:
-
+
% endif
@@ -102,7 +108,7 @@
% endif
% if object.company_id.website:
%endif
From c90e29626456c331cda84996a17d464911dff2a2 Mon Sep 17 00:00:00 2001
From: Raphael Collet
Date: Thu, 13 Dec 2012 15:38:53 +0100
Subject: [PATCH 05/13] [IMP] portal_sale: move code around, to extend models
in one place
bzr revid: rco@openerp.com-20121213143853-uk5ohmyc4tpqc5qu
---
addons/portal_sale/__init__.py | 2 -
addons/portal_sale/account_invoice.py | 43 ------------------
addons/portal_sale/portal_sale.py | 54 +++++++++++++++++++++++
addons/portal_sale/sale.py | 63 ---------------------------
4 files changed, 54 insertions(+), 108 deletions(-)
delete mode 100644 addons/portal_sale/account_invoice.py
delete mode 100644 addons/portal_sale/sale.py
diff --git a/addons/portal_sale/__init__.py b/addons/portal_sale/__init__.py
index 296de46594a..ba847ba7169 100644
--- a/addons/portal_sale/__init__.py
+++ b/addons/portal_sale/__init__.py
@@ -19,7 +19,5 @@
#
##############################################################################
-import account_invoice
-import sale
import portal_sale
import res_config
diff --git a/addons/portal_sale/account_invoice.py b/addons/portal_sale/account_invoice.py
deleted file mode 100644
index fa81b2049e0..00000000000
--- a/addons/portal_sale/account_invoice.py
+++ /dev/null
@@ -1,43 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2011 OpenERP S.A ().
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see .
-#
-##############################################################################
-
-from osv import fields,osv
-
-class account_invoice(osv.osv):
- _inherit = 'account.invoice'
-
- def invoice_validate(self, cr, uid, ids, context=None):
- # fetch the partner's id and subscribe the partner to the sale order
- partner = self.browse(cr, uid, ids[0], context=context)['partner_id']
- if partner.id not in self.browse(cr, uid, ids[0], context=context)['message_follower_ids']:
- self.message_subscribe(cr, uid, ids, [partner.id], context=context)
- document = self.browse(cr, uid, ids[0], context=context)
- mail_values = {
- 'email_from': self.pool.get('res.users').browse(cr, uid, uid, context=context)['partner_id']['email'],
- 'email_to': partner.email,
- 'subject': 'Invitation to follow %s' % document.name_get()[0][1],
- 'body_html': 'You have been invited to follow %s' % document.name_get()[0][1],
- 'auto_delete': True,
- }
- mail_obj = self.pool.get('mail.mail')
- mail_id = mail_obj.create(cr, uid, mail_values, context=context)
- mail_obj.send(cr, uid, [mail_id], recipient_ids=[partner.id], context=context)
- return super(account_invoice, self).invoice_validate(cr, uid, ids, context=context)
\ No newline at end of file
diff --git a/addons/portal_sale/portal_sale.py b/addons/portal_sale/portal_sale.py
index 7cda77ed9ea..ba3addfb83a 100644
--- a/addons/portal_sale/portal_sale.py
+++ b/addons/portal_sale/portal_sale.py
@@ -53,6 +53,25 @@ class sale_order(osv.Model):
pass
return action_dict
+ def action_button_confirm(self, cr, uid, ids, context=None):
+ # fetch the partner's id and subscribe the partner to the sale order
+ partner = self.browse(cr, uid, ids[0], context=context)['partner_id']
+ if partner.id not in self.browse(cr, uid, ids[0], context=context)['message_follower_ids']:
+ self.message_subscribe(cr, uid, ids, [partner.id], context=context)
+ document = self.browse(cr, uid, ids[0], context=context)
+ mail_values = {
+ 'email_from': self.pool.get('res.users').browse(cr, uid, uid, context=context)['partner_id']['email'],
+ 'email_to': partner.email,
+ 'subject': 'Invitation to follow %s' % document.name_get()[0][1],
+ 'body_html': 'You have been invited to follow %s' % document.name_get()[0][1],
+ 'auto_delete': True,
+ }
+ mail_obj = self.pool.get('mail.mail')
+ mail_id = mail_obj.create(cr, uid, mail_values, context=context)
+ mail_obj.send(cr, uid, [mail_id], recipient_ids=[partner.id], context=context)
+ return super(sale_order, self).action_button_confirm(cr, uid, ids, context=context)
+
+
class account_invoice(osv.Model):
_inherit = 'account.invoice'
@@ -84,3 +103,38 @@ class account_invoice(osv.Model):
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 sale order
+ partner = self.browse(cr, uid, ids[0], context=context)['partner_id']
+ if partner.id not in self.browse(cr, uid, ids[0], context=context)['message_follower_ids']:
+ self.message_subscribe(cr, uid, ids, [partner.id], context=context)
+ document = self.browse(cr, uid, ids[0], context=context)
+ mail_values = {
+ 'email_from': self.pool.get('res.users').browse(cr, uid, uid, context=context)['partner_id']['email'],
+ 'email_to': partner.email,
+ 'subject': 'Invitation to follow %s' % document.name_get()[0][1],
+ 'body_html': 'You have been invited to follow %s' % document.name_get()[0][1],
+ 'auto_delete': True,
+ }
+ mail_obj = self.pool.get('mail.mail')
+ mail_id = mail_obj.create(cr, uid, mail_values, context=context)
+ mail_obj.send(cr, uid, [mail_id], recipient_ids=[partner.id], context=context)
+ return super(account_invoice, self).invoice_validate(cr, uid, ids, context=context)
+
+
+class mail_mail(osv.osv):
+ _inherit = 'mail.mail'
+
+ def _postprocess_sent_message(self, cr, uid, mail, context=None):
+ if mail.model == 'sale.order':
+ so_obj = self.pool.get('sale.order')
+ partner = so_obj.browse(cr, uid, mail.res_id, context=context)['partner_id']
+ # Add the customer in the SO as follower
+ if partner.id not in so_obj.browse(cr, uid, mail.res_id, context=context)['message_follower_ids']:
+ so_obj.message_subscribe(cr, uid, [mail.res_id], [partner.id], context=context)
+ # Add all recipients of the email as followers
+ for p in mail.partner_ids:
+ if p.id not in so_obj.browse(cr, uid, mail.res_id, context=context)['message_follower_ids']:
+ so_obj.message_subscribe(cr, uid, [mail.res_id], [p.id], context=context)
+ return super(mail_mail, self)._postprocess_sent_message(cr, uid, mail=mail, context=context)
diff --git a/addons/portal_sale/sale.py b/addons/portal_sale/sale.py
deleted file mode 100644
index 79fcbdef6fd..00000000000
--- a/addons/portal_sale/sale.py
+++ /dev/null
@@ -1,63 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2010 Tiny SPRL ().
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see .
-#
-##############################################################################
-
-from osv import fields, osv
-
-class sale_order(osv.osv):
- _inherit = 'sale.order'
-
- def action_button_confirm(self, cr, uid, ids, context=None):
- # fetch the partner's id and subscribe the partner to the sale order
- partner = self.browse(cr, uid, ids[0], context=context)['partner_id']
- if partner.id not in self.browse(cr, uid, ids[0], context=context)['message_follower_ids']:
- self.message_subscribe(cr, uid, ids, [partner.id], context=context)
- document = self.browse(cr, uid, ids[0], context=context)
- mail_values = {
- 'email_from': self.pool.get('res.users').browse(cr, uid, uid, context=context)['partner_id']['email'],
- 'email_to': partner.email,
- 'subject': 'Invitation to follow %s' % document.name_get()[0][1],
- 'body_html': 'You have been invited to follow %s' % document.name_get()[0][1],
- 'auto_delete': True,
- }
- mail_obj = self.pool.get('mail.mail')
- mail_id = mail_obj.create(cr, uid, mail_values, context=context)
- mail_obj.send(cr, uid, [mail_id], recipient_ids=[partner.id], context=context)
- return super(sale_order, self).action_button_confirm(cr, uid, ids, context=context)
-
-sale_order()
-
-class mail_mail(osv.osv):
- _inherit = 'mail.mail'
-
- def _postprocess_sent_message(self, cr, uid, mail, context=None):
- if mail.model == 'sale.order':
- so_obj = self.pool.get('sale.order')
- partner = so_obj.browse(cr, uid, mail.res_id, context=context)['partner_id']
- # Add the customer in the SO as follower
- if partner.id not in so_obj.browse(cr, uid, mail.res_id, context=context)['message_follower_ids']:
- so_obj.message_subscribe(cr, uid, [mail.res_id], [partner.id], context=context)
- # Add all recipients of the email as followers
- for p in mail.partner_ids:
- if p.id not in so_obj.browse(cr, uid, mail.res_id, context=context)['message_follower_ids']:
- so_obj.message_subscribe(cr, uid, [mail.res_id], [p.id], context=context)
- return super(mail_mail, self)._postprocess_sent_message(cr, uid, mail=mail, context=context)
-
-mail_mail()
\ No newline at end of file
From e65c73bc952d9905043de8963008b4027595162e Mon Sep 17 00:00:00 2001
From: Raphael Collet
Date: Thu, 13 Dec 2012 15:50:11 +0100
Subject: [PATCH 06/13] [IMP] portal_sale: refactor and clean up code
bzr revid: rco@openerp.com-20121213145011-2wcif6d2o9dbcqts
---
addons/portal_sale/portal_sale.py | 41 +++++++++++++++++--------------
1 file changed, 23 insertions(+), 18 deletions(-)
diff --git a/addons/portal_sale/portal_sale.py b/addons/portal_sale/portal_sale.py
index ba3addfb83a..62f3f1ff9cc 100644
--- a/addons/portal_sale/portal_sale.py
+++ b/addons/portal_sale/portal_sale.py
@@ -21,11 +21,12 @@
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)
+ _payment_block_proxy = lambda self, *a, **kw: self._portal_payment_block(*a, **kw)
_columns = {
'portal_payment_options': fields.function(_payment_block_proxy, type="html", string="Portal Payment Options"),
@@ -35,14 +36,14 @@ class sale_order(osv.Model):
result = dict.fromkeys(ids, False)
payment_acquirer = self.pool.get('portal.payment.acquirer')
for this in self.browse(cr, uid, ids, context=context):
- if this.state not in ('draft','cancel') and not this.invoiced:
+ if this.state not in ('draft', 'cancel') and not this.invoiced:
result[this.id] = payment_acquirer.render_payment_block(cr, uid, this, this.name,
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)
+ 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
@@ -55,12 +56,14 @@ class sale_order(osv.Model):
def action_button_confirm(self, cr, uid, ids, context=None):
# fetch the partner's id and subscribe the partner to the sale order
- partner = self.browse(cr, uid, ids[0], context=context)['partner_id']
- if partner.id not in self.browse(cr, uid, ids[0], context=context)['message_follower_ids']:
+ assert len(ids) == 1
+ document = self.browse(cr, uid, ids[0], context=context)
+ partner = document.partner_id
+ if partner.id not in document.message_follower_ids:
self.message_subscribe(cr, uid, ids, [partner.id], context=context)
- document = self.browse(cr, uid, ids[0], context=context)
+ user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
mail_values = {
- 'email_from': self.pool.get('res.users').browse(cr, uid, uid, context=context)['partner_id']['email'],
+ 'email_from': user.partner_id.email,
'email_to': partner.email,
'subject': 'Invitation to follow %s' % document.name_get()[0][1],
'body_html': 'You have been invited to follow %s' % document.name_get()[0][1],
@@ -76,7 +79,7 @@ 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)
+ _payment_block_proxy = lambda self, *a, **kw: self._portal_payment_block(*a, **kw)
_columns = {
'portal_payment_options': fields.function(_payment_block_proxy, type="html", string="Portal Payment Options"),
@@ -86,14 +89,14 @@ class account_invoice(osv.Model):
result = dict.fromkeys(ids, False)
payment_acquirer = self.pool.get('portal.payment.acquirer')
for this in self.browse(cr, uid, ids, context=context):
- if this.type == 'out_invoice' and this.state not in ('draft','done') and not this.reconciled:
+ if this.type == 'out_invoice' and 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
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)
+ 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
@@ -105,13 +108,14 @@ class account_invoice(osv.Model):
return action_dict
def invoice_validate(self, cr, uid, ids, context=None):
- # fetch the partner's id and subscribe the partner to the sale order
- partner = self.browse(cr, uid, ids[0], context=context)['partner_id']
- if partner.id not in self.browse(cr, uid, ids[0], context=context)['message_follower_ids']:
+ # fetch the partner's id and subscribe the partner to the invoice
+ document = self.browse(cr, uid, ids[0], context=context)
+ partner = document.partner_id
+ if partner.id not in document.message_follower_ids:
self.message_subscribe(cr, uid, ids, [partner.id], context=context)
- document = self.browse(cr, uid, ids[0], context=context)
+ user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
mail_values = {
- 'email_from': self.pool.get('res.users').browse(cr, uid, uid, context=context)['partner_id']['email'],
+ 'email_from': user.partner_id.email,
'email_to': partner.email,
'subject': 'Invitation to follow %s' % document.name_get()[0][1],
'body_html': 'You have been invited to follow %s' % document.name_get()[0][1],
@@ -129,12 +133,13 @@ class mail_mail(osv.osv):
def _postprocess_sent_message(self, cr, uid, mail, context=None):
if mail.model == 'sale.order':
so_obj = self.pool.get('sale.order')
- partner = so_obj.browse(cr, uid, mail.res_id, context=context)['partner_id']
+ order = so_obj.browse(cr, uid, mail.res_id, context=context)
+ partner = order.partner_id
# Add the customer in the SO as follower
- if partner.id not in so_obj.browse(cr, uid, mail.res_id, context=context)['message_follower_ids']:
+ if partner.id not in order.message_follower_ids:
so_obj.message_subscribe(cr, uid, [mail.res_id], [partner.id], context=context)
# Add all recipients of the email as followers
for p in mail.partner_ids:
- if p.id not in so_obj.browse(cr, uid, mail.res_id, context=context)['message_follower_ids']:
+ if p.id not in order.message_follower_ids:
so_obj.message_subscribe(cr, uid, [mail.res_id], [p.id], context=context)
return super(mail_mail, self)._postprocess_sent_message(cr, uid, mail=mail, context=context)
From e07f8a7519330aa7ac1b1ba66293aa71d96cca62 Mon Sep 17 00:00:00 2001
From: Raphael Collet
Date: Thu, 13 Dec 2012 16:37:28 +0100
Subject: [PATCH 07/13] [IMP] portal_sale: adapt edi email templates
bzr revid: rco@openerp.com-20121213153728-v7yv82x09qtletix
---
addons/portal_sale/portal_sale.py | 16 +++++
addons/portal_sale/portal_sale_data.xml | 89 +++++++++++++------------
2 files changed, 63 insertions(+), 42 deletions(-)
diff --git a/addons/portal_sale/portal_sale.py b/addons/portal_sale/portal_sale.py
index 62f3f1ff9cc..3556fd5ca0e 100644
--- a/addons/portal_sale/portal_sale.py
+++ b/addons/portal_sale/portal_sale.py
@@ -74,6 +74,14 @@ class sale_order(osv.Model):
mail_obj.send(cr, uid, [mail_id], recipient_ids=[partner.id], context=context)
return super(sale_order, self).action_button_confirm(cr, uid, ids, context=context)
+ def get_signup_url(self, cr, uid, ids, context=None):
+ assert len(ids) == 1
+ document = self.browse(cr, uid, ids[0], context=context)
+ partner = document.partner_id
+ action = 'portal_sale.action_quotations_portal' if document.state in ('draft', 'sent') else 'portal_sale.action_orders_portal'
+ partner.signup_prepare()
+ return partner._get_signup_url_for_action(action=action, view_type='form', res_id=document.id)[partner.id]
+
class account_invoice(osv.Model):
_inherit = 'account.invoice'
@@ -126,6 +134,14 @@ class account_invoice(osv.Model):
mail_obj.send(cr, uid, [mail_id], recipient_ids=[partner.id], context=context)
return super(account_invoice, self).invoice_validate(cr, uid, ids, context=context)
+ def get_signup_url(self, cr, uid, ids, context=None):
+ assert len(ids) == 1
+ document = self.browse(cr, uid, ids[0], context=context)
+ partner = document.partner_id
+ action = 'portal_sale.portal_action_invoices'
+ partner.signup_prepare()
+ return partner._get_signup_url_for_action(action=action, view_type='form', res_id=document.id)[partner.id]
+
class mail_mail(osv.osv):
_inherit = 'mail.mail'
diff --git a/addons/portal_sale/portal_sale_data.xml b/addons/portal_sale/portal_sale_data.xml
index f40897f6998..bdf51fd2fe7 100644
--- a/addons/portal_sale/portal_sale_data.xml
+++ b/addons/portal_sale/portal_sale_data.xml
@@ -6,7 +6,7 @@
Sale Order - Send by Email (Portal)
- ${object.user_id.email or ''}
+ ${object.user_id.email or ''|safe}
${object.company_id.name} ${object.state in ('draft', 'sent') and 'Quotation' or 'Order'} (Ref ${object.name or 'n/a' })
${object.partner_invoice_id.id}
@@ -16,7 +16,7 @@
- Hello${object.partner_id.name and ' ' or ''}${object.partner_id.name or ''},
+ Hello ${object.partner_id.name or ''},
Here is your ${object.state in ('draft', 'sent') and 'quotation' or 'order confirmation'} from ${object.company_id.name}:
@@ -32,38 +32,40 @@
Your reference: ${object.client_order_ref}
% endif
% if object.user_id:
- Your contact: ${object.user_id.name}
+ 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]
- %>
+ <% set signup_url = object.get_signup_url() %>
% if signup_url:
You can access this document and pay online via our Customer Portal:
View ${object.state in ('draft', 'sent') and 'Quotation' or 'Order'}
+ href="${signup_url|safe}">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¤cy_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)
+ <% set paypal_url = ("https://www.paypal.com/cgi-bin/webscr?cmd=_xclick"
+ "&business=%(paypal_account)s"
+ "&item_name=%(company_name)s%%20Order%%20%(order_name)s"
+ "&invoice=%(order_name)s"
+ "&amount=%(order_amount)s"
+ "¤cy_code=%(currency)s"
+ "&button_subtype=services"
+ "&no_note=1"
+ "&bn=OpenERP_Order_PayNow_%(currency)s"
+ % {
+ 'paypal_account': quote(object.company_id.paypal_account),
+ 'company_name': quote(object.company_id.name),
+ 'order_name': quote(object.name),
+ 'order_amount': quote(str(object.residual)),
+ 'currency': quote(object.pricelist_id.currency_id.name),
+ })
%>
It is also possible to directly pay with Paypal:
-
+
% endif
@@ -99,9 +101,9 @@
% endif
% if object.company_id.website:
- %endif
+ % endif
@@ -110,7 +112,7 @@
Invoice - Send by Email (Portal)
- ${object.user_id.email or object.company_id.email or 'noreply@localhost'}
+ ${object.user_id.email or object.company_id.email or 'noreply@localhost'|safe}
${object.company_id.name} Invoice (Ref ${object.number or 'n/a' })
${object.partner_id.id}
@@ -120,7 +122,7 @@
- Hello${object.partner_id.name and ' ' or ''}${object.partner_id.name or ''},
+ Hello ${object.partner_id.name or ''},
A new invoice is available for you:
@@ -133,15 +135,11 @@
Order reference: ${object.origin}
% endif
% if object.user_id:
- Your contact: ${object.user_id.name}
+ 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]
- %>
+ <% set signup_url = object.get_signup_url() %>
% if signup_url:
You can access the invoice document and pay online via our Customer Portal:
@@ -151,19 +149,26 @@
% endif
% if object.company_id.paypal_account and object.type in ('out_invoice'):
- <%
- 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.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¤cy_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)
+ <% set paypal_url = ("https://www.paypal.com/cgi-bin/webscr?cmd=_xclick"
+ "&business=%(paypal_account)s"
+ "&item_name=%(company_name)s%%20Invoice%%20%(inv)s"
+ "&invoice=%(inv)s"
+ "&amount=%(amount)s"
+ "¤cy_code=%(currency)s"
+ "&button_subtype=services"
+ "&no_note=1"
+ "&bn=OpenERP_Invoice_PayNow_%(currency)s"
+ % {
+ 'paypal_account': quote(object.company_id.paypal_account),
+ 'company_name': quote(object.company_id.name),
+ 'inv': quote(object.number),
+ 'amount': quote(str(object.residual)),
+ 'currency': quote(object.currency_id.name),
+ })
%>
It is also possible to directly pay with Paypal:
-
+
% endif
@@ -199,9 +204,9 @@
% endif
% if object.company_id.website:
- %endif
+ % endif
From a261f54c821d92fb6bb5cddf245f0188f157212c Mon Sep 17 00:00:00 2001
From: Raphael Collet
Date: Fri, 14 Dec 2012 10:03:40 +0100
Subject: [PATCH 08/13] [FIX] email_template: use urlencode to build urls, and
adapt email templates; also fixes incorrect usage of 'safe' in those
templates"
bzr revid: rco@openerp.com-20121214090340-nd3u4ahhb4460r4q
---
addons/account/edi/invoice_action_data.xml | 35 ++++------
.../account_followup_data.xml | 16 ++---
addons/email_template/email_template.py | 3 +-
addons/portal_sale/portal_sale_data.xml | 70 ++++++++-----------
.../edi/purchase_order_action_data.xml | 6 +-
addons/sale/edi/sale_order_action_data.xml | 34 ++++-----
6 files changed, 74 insertions(+), 90 deletions(-)
diff --git a/addons/account/edi/invoice_action_data.xml b/addons/account/edi/invoice_action_data.xml
index bdb08d66cfe..36bb31b1db3 100644
--- a/addons/account/edi/invoice_action_data.xml
+++ b/addons/account/edi/invoice_action_data.xml
@@ -22,7 +22,7 @@
Invoice - Send by Email
- ${object.user_id.email or object.company_id.email or 'noreply@localhost'|safe}
+ ${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}
@@ -46,32 +46,27 @@
Order reference: ${object.origin}
% endif
% if object.user_id:
- Your contact: ${object.user_id.name}
+ Your contact: ${object.user_id.name}
% endif
% if object.company_id.paypal_account and object.type in ('out_invoice'):
- <% set paypal_url = (
- "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick"
- "&business=%(paypal_account)s"
- "&item_name=%(company_name)s%%20Invoice%%20%(inv)s"
- "&invoice=%(inv)s"
- "&amount=%(amount)s"
- "¤cy_code=%(currency)s"
- "&button_subtype=services"
- "&no_note=1"
- "&bn=OpenERP_Invoice_PayNow_%(currency)s"
- % {
- 'paypal_account': quote(object.company_id.paypal_account),
- 'company_name': quote(object.company_id.name),
- 'inv': quote(object.number),
- 'amount': quote(str(object.residual)),
- 'currency': quote(object.currency_id.name),
+ <% set paypal_url = "https://www.paypal.com/cgi-bin/webscr?" +
+ urlencode({
+ "cmd": "_xclick",
+ "business": object.company_id.paypal_account,
+ "item_name": object.company_id.name + " Invoice " + object.number,
+ "invoice": object.number,
+ "amount": object.residual,
+ "currency_code": object.currency_id.name,
+ "button_subtype": "services",
+ "no_note": "1",
+ "bn": "OpenERP_Invoice_PayNow_" + object.currency_id.name,
})
%>
It is also possible to directly pay with Paypal:
-
+
% endif
@@ -107,7 +102,7 @@
% endif
% if object.company_id.website:
%endif
diff --git a/addons/account_followup/account_followup_data.xml b/addons/account_followup/account_followup_data.xml
index d5b257a052f..c35a0ffcd49 100644
--- a/addons/account_followup/account_followup_data.xml
+++ b/addons/account_followup/account_followup_data.xml
@@ -6,9 +6,9 @@
First polite payment follow-up reminder email
- ${user.email or ''|safe}
+ ${user.email or ''}
${user.company_id.name} Payment Reminder
- ${object.email|safe}
+ ${object.email}
${object.lang}
@@ -45,9 +45,9 @@ ${ctx.get('followup_table','') | safe}
A bit urging second payment follow-up reminder email
- ${user.email or ''|safe}
+ ${user.email or ''}
${user.company_id.name} Payment Reminder
- ${object.email|safe}
+ ${object.email}
${object.lang}
@@ -85,9 +85,9 @@ ${ctx.get('followup_table','') | safe}
Urging payment follow-up reminder email
- ${user.email or ''|safe}
+ ${user.email or ''}
${user.company_id.name} Payment Reminder
- ${object.email|safe}
+ ${object.email}
${object.lang}
@@ -122,9 +122,9 @@ ${ctx.get('followup_table','') | safe}
Default payment follow-up reminder e-mail
- ${user.email or ''|safe}
+ ${user.email or ''}
${user.company_id.name} Payment Reminder
- ${object.email|safe}
+ ${object.email}
${object.lang}
diff --git a/addons/email_template/email_template.py b/addons/email_template/email_template.py
index e4cbc20f8f6..619569f4c81 100644
--- a/addons/email_template/email_template.py
+++ b/addons/email_template/email_template.py
@@ -28,7 +28,7 @@ from osv import osv
from osv import fields
import tools
from tools.translate import _
-from urllib import quote as quote
+from urllib import quote, urlencode
_logger = logging.getLogger(__name__)
@@ -56,6 +56,7 @@ try:
mako_template_env.globals.update({
'str': str,
'quote': quote,
+ 'urlencode': urlencode,
})
except ImportError:
_logger.warning("jinja2 not available, templating features will not work!")
diff --git a/addons/portal_sale/portal_sale_data.xml b/addons/portal_sale/portal_sale_data.xml
index bdf51fd2fe7..60f11a5f767 100644
--- a/addons/portal_sale/portal_sale_data.xml
+++ b/addons/portal_sale/portal_sale_data.xml
@@ -6,7 +6,7 @@
Sale Order - Send by Email (Portal)
- ${object.user_id.email or ''|safe}
+ ${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}
@@ -32,7 +32,7 @@
Your reference: ${object.client_order_ref}
% endif
% if object.user_id:
- Your contact: ${object.user_id.name}
+ Your contact: ${object.user_id.name}
% endif
@@ -42,30 +42,26 @@
You can access this document and pay online via our Customer Portal:
View ${object.state in ('draft', 'sent') and 'Quotation' or 'Order'}
+ href="${signup_url}">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':
- <% set paypal_url = ("https://www.paypal.com/cgi-bin/webscr?cmd=_xclick"
- "&business=%(paypal_account)s"
- "&item_name=%(company_name)s%%20Order%%20%(order_name)s"
- "&invoice=%(order_name)s"
- "&amount=%(order_amount)s"
- "¤cy_code=%(currency)s"
- "&button_subtype=services"
- "&no_note=1"
- "&bn=OpenERP_Order_PayNow_%(currency)s"
- % {
- 'paypal_account': quote(object.company_id.paypal_account),
- 'company_name': quote(object.company_id.name),
- 'order_name': quote(object.name),
- 'order_amount': quote(str(object.residual)),
- 'currency': quote(object.pricelist_id.currency_id.name),
+ <% set paypal_url = "https://www.paypal.com/cgi-bin/webscr?" +
+ urlencode({
+ "cmd": "_xclick",
+ "business": object.company_id.paypal_account,
+ "item_name": object.company_id.name + " Order " + object.name,
+ "invoice": object.name,
+ "amount": object.amount_total,
+ "currency_code": object.pricelist_id.currency_id.name,
+ "button_subtype": "services",
+ "no_note": "1",
+ "bn": "OpenERP_Order_PayNow_" + object.pricelist_id.currency_id.name,
})
%>
It is also possible to directly pay with Paypal:
-
+
% endif
@@ -101,7 +97,7 @@
% endif
% if object.company_id.website:
% endif
@@ -112,7 +108,7 @@
Invoice - Send by Email (Portal)
- ${object.user_id.email or object.company_id.email or 'noreply@localhost'|safe}
+ ${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}
@@ -135,7 +131,7 @@
Order reference: ${object.origin}
% endif
% if object.user_id:
- Your contact: ${object.user_id.name}
+ Your contact: ${object.user_id.name}
% endif
@@ -149,26 +145,22 @@
% endif
% if object.company_id.paypal_account and object.type in ('out_invoice'):
- <% set paypal_url = ("https://www.paypal.com/cgi-bin/webscr?cmd=_xclick"
- "&business=%(paypal_account)s"
- "&item_name=%(company_name)s%%20Invoice%%20%(inv)s"
- "&invoice=%(inv)s"
- "&amount=%(amount)s"
- "¤cy_code=%(currency)s"
- "&button_subtype=services"
- "&no_note=1"
- "&bn=OpenERP_Invoice_PayNow_%(currency)s"
- % {
- 'paypal_account': quote(object.company_id.paypal_account),
- 'company_name': quote(object.company_id.name),
- 'inv': quote(object.number),
- 'amount': quote(str(object.residual)),
- 'currency': quote(object.currency_id.name),
+ <% set paypal_url = "https://www.paypal.com/cgi-bin/webscr?" +
+ urlencode({
+ "cmd": "_xclick",
+ "business": object.company_id.paypal_account,
+ "item_name": object.company_id.name + " Invoice " + object.number,
+ "invoice": object.number,
+ "amount": object.residual,
+ "currency_code": object.currency_id.name,
+ "button_subtype": "services",
+ "no_note": "1",
+ "bn": "OpenERP_Invoice_PayNow_" + object.currency_id.name,
})
%>
It is also possible to directly pay with Paypal:
-
+
% endif
@@ -204,7 +196,7 @@
% endif
% if object.company_id.website:
% endif
diff --git a/addons/purchase/edi/purchase_order_action_data.xml b/addons/purchase/edi/purchase_order_action_data.xml
index f861c025ae8..06a68aaab83 100644
--- a/addons/purchase/edi/purchase_order_action_data.xml
+++ b/addons/purchase/edi/purchase_order_action_data.xml
@@ -19,7 +19,7 @@
Purchase Order - Send by mail
- ${object.validator.email or ''|safe}
+ ${object.validator.email or ''}
${object.company_id.name} Order (Ref ${object.name or 'n/a' })
${object.partner_id.id}
@@ -46,7 +46,7 @@
Your reference: ${object.partner_ref}
% endif
% if object.validator:
- Your contact: ${object.validator.name}
+ Your contact: ${object.validator.name}
% endif
@@ -81,7 +81,7 @@
% endif
% if object.company_id.website:
%endif
diff --git a/addons/sale/edi/sale_order_action_data.xml b/addons/sale/edi/sale_order_action_data.xml
index 2a2061f1e6b..eebb63fb624 100644
--- a/addons/sale/edi/sale_order_action_data.xml
+++ b/addons/sale/edi/sale_order_action_data.xml
@@ -21,7 +21,7 @@
Sale Order - Send by Email
- ${object.user_id.email or ''|safe}
+ ${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}
@@ -48,31 +48,27 @@
Your reference: ${object.client_order_ref}
% endif
% if object.user_id:
- Your contact: ${object.user_id.name}
+ Your contact: ${object.user_id.name}
% endif
% if object.order_policy in ('prepaid','manual') and object.company_id.paypal_account and object.state != 'draft':
- <% set paypal_url = ("https://www.paypal.com/cgi-bin/webscr?cmd=_xclick"
- "&business=%(paypal_account)s"
- "&item_name=%(company_name)s%%20Order%%20%(order_name)s"
- "&invoice=%(order_name)s"
- "&amount=%(order_amount)s"
- "¤cy_code=%(currency)s"
- "&button_subtype=services"
- "&no_note=1"
- "&bn=OpenERP_Order_PayNow_%(currency)s"
- % {
- 'paypal_account': quote(object.company_id.paypal_account),
- 'company_name': quote(object.company_id.name),
- 'order_name': quote(object.name),
- 'order_amount': quote(str(object.amount_total)),
- 'currency': quote(object.pricelist_id.currency_id.name),
+ <% set paypal_url = "https://www.paypal.com/cgi-bin/webscr?" +
+ urlencode({
+ "cmd": "_xclick",
+ "business": object.company_id.paypal_account,
+ "item_name": object.company_id.name + " Order " + object.name,
+ "invoice": object.name,
+ "amount": object.amount_total,
+ "currency_code": object.pricelist_id.currency_id.name,
+ "button_subtype": "services",
+ "no_note": "1",
+ "bn": "OpenERP_Order_PayNow_" + object.pricelist_id.currency_id.name,
})
%>
It is also possible to directly pay with Paypal:
-
+
% endif
@@ -108,7 +104,7 @@
% endif
% if object.company_id.website:
%endif
From 157f1db551d4cb11a12856e8ffacbb4adc5a714d Mon Sep 17 00:00:00 2001
From: Raphael Collet
Date: Fri, 14 Dec 2012 10:10:57 +0100
Subject: [PATCH 09/13] [IMP] email_template: small simplification in email
templates
bzr revid: rco@openerp.com-20121214091057-ztar9xgmxx56cvae
---
addons/account/edi/invoice_action_data.xml | 2 +-
addons/portal_sale/portal_sale_data.xml | 4 ++--
addons/purchase/edi/purchase_order_action_data.xml | 2 +-
addons/sale/edi/sale_order_action_data.xml | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/addons/account/edi/invoice_action_data.xml b/addons/account/edi/invoice_action_data.xml
index 36bb31b1db3..93c32b1cdc5 100644
--- a/addons/account/edi/invoice_action_data.xml
+++ b/addons/account/edi/invoice_action_data.xml
@@ -33,7 +33,7 @@
- Hello ${object.partner_id.name or ''},
+ Hello ${object.partner_id.name},
A new invoice is available for you:
diff --git a/addons/portal_sale/portal_sale_data.xml b/addons/portal_sale/portal_sale_data.xml
index 60f11a5f767..d2c8d656bcb 100644
--- a/addons/portal_sale/portal_sale_data.xml
+++ b/addons/portal_sale/portal_sale_data.xml
@@ -16,7 +16,7 @@
- Hello ${object.partner_id.name or ''},
+ Hello ${object.partner_id.name},
Here is your ${object.state in ('draft', 'sent') and 'quotation' or 'order confirmation'} from ${object.company_id.name}:
@@ -118,7 +118,7 @@
- Hello ${object.partner_id.name or ''},
+ Hello ${object.partner_id.name},
A new invoice is available for you:
diff --git a/addons/purchase/edi/purchase_order_action_data.xml b/addons/purchase/edi/purchase_order_action_data.xml
index 06a68aaab83..d616ff1d116 100644
--- a/addons/purchase/edi/purchase_order_action_data.xml
+++ b/addons/purchase/edi/purchase_order_action_data.xml
@@ -30,7 +30,7 @@
- Hello$ ${object.partner_id.name or ''},
+ 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}:
diff --git a/addons/sale/edi/sale_order_action_data.xml b/addons/sale/edi/sale_order_action_data.xml
index eebb63fb624..371233b96c7 100644
--- a/addons/sale/edi/sale_order_action_data.xml
+++ b/addons/sale/edi/sale_order_action_data.xml
@@ -32,7 +32,7 @@
- Hello ${object.partner_id.name or ''},
+ Hello ${object.partner_id.name},
Here is your ${object.state in ('draft', 'sent') and 'quotation' or 'order confirmation'} from ${object.company_id.name}:
From 95a3a0677b3b3fe7432d08c7c51f03027fcdba9c Mon Sep 17 00:00:00 2001
From: Raphael Collet
Date: Fri, 14 Dec 2012 10:16:27 +0100
Subject: [PATCH 10/13] [IMP] portal_sale: small improvement in email template
bzr revid: rco@openerp.com-20121214091627-1b1z56vb59kyjzxl
---
addons/portal_sale/portal_sale_data.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/addons/portal_sale/portal_sale_data.xml b/addons/portal_sale/portal_sale_data.xml
index d2c8d656bcb..761733ee31e 100644
--- a/addons/portal_sale/portal_sale_data.xml
+++ b/addons/portal_sale/portal_sale_data.xml
@@ -32,7 +32,7 @@
Your reference: ${object.client_order_ref}
% endif
% if object.user_id:
- Your contact: ${object.user_id.name}
+ Your contact: ${object.user_id.name}
% endif
From 01bffef54898388fdf288b3e367c52d9655e79a8 Mon Sep 17 00:00:00 2001
From: Raphael Collet
Date: Fri, 14 Dec 2012 12:31:32 +0100
Subject: [PATCH 11/13] [IMP] sale, account, portal_sale: factor the paypal_url
in the templates into function fields
bzr revid: rco@openerp.com-20121214113132-skqi1tddmkjybwpn
---
addons/account/edi/invoice.py | 26 ++++++++++++++++-
addons/account/edi/invoice_action_data.xml | 17 ++---------
addons/portal_sale/portal_sale_data.xml | 34 +++-------------------
addons/sale/edi/sale_order.py | 30 +++++++++++++++++--
addons/sale/edi/sale_order_action_data.xml | 17 ++---------
5 files changed, 61 insertions(+), 63 deletions(-)
diff --git a/addons/account/edi/invoice.py b/addons/account/edi/invoice.py
index 3e27bc5ea99..ca25d4e6e90 100644
--- a/addons/account/edi/invoice.py
+++ b/addons/account/edi/invoice.py
@@ -19,7 +19,9 @@
#
##############################################################################
-from openerp.osv import osv
+from urllib import urlencode
+
+from openerp.osv import osv, fields
from edi import EDIMixin
INVOICE_LINE_EDI_STRUCT = {
@@ -258,6 +260,28 @@ class account_invoice(osv.osv, EDIMixin):
pass
return action
+ def _edi_paypal_url(self, cr, uid, ids, field, arg, context=None):
+ res = dict.fromkeys(ids, False)
+ for inv in self.browse(cr, uid, ids, context=context):
+ if inv.type == 'out_invoice' and inv.company_id.paypal_account:
+ params = {
+ "cmd": "_xclick",
+ "business": inv.company_id.paypal_account,
+ "item_name": inv.company_id.name + " Invoice " + inv.number,
+ "invoice": inv.number,
+ "amount": inv.residual,
+ "currency_code": inv.currency_id.name,
+ "button_subtype": "services",
+ "no_note": "1",
+ "bn": "OpenERP_Invoice_PayNow_" + inv.currency_id.name,
+ }
+ res[inv.id] = "https://www.paypal.com/cgi-bin/webscr?" + urlencode(params)
+ return res
+
+ _columns = {
+ 'paypal_url': fields.function(_edi_paypal_url, type='char', string='Paypal Url'),
+ }
+
class account_invoice_line(osv.osv, EDIMixin):
_inherit='account.invoice.line'
diff --git a/addons/account/edi/invoice_action_data.xml b/addons/account/edi/invoice_action_data.xml
index 93c32b1cdc5..18ac71f55ce 100644
--- a/addons/account/edi/invoice_action_data.xml
+++ b/addons/account/edi/invoice_action_data.xml
@@ -50,23 +50,10 @@
% endif
- % if object.company_id.paypal_account and object.type in ('out_invoice'):
- <% set paypal_url = "https://www.paypal.com/cgi-bin/webscr?" +
- urlencode({
- "cmd": "_xclick",
- "business": object.company_id.paypal_account,
- "item_name": object.company_id.name + " Invoice " + object.number,
- "invoice": object.number,
- "amount": object.residual,
- "currency_code": object.currency_id.name,
- "button_subtype": "services",
- "no_note": "1",
- "bn": "OpenERP_Invoice_PayNow_" + object.currency_id.name,
- })
- %>
+ % if object.paypal_url:
It is also possible to directly pay with Paypal:
-
+
% endif
diff --git a/addons/portal_sale/portal_sale_data.xml b/addons/portal_sale/portal_sale_data.xml
index 761733ee31e..0ef9b1ec5cc 100644
--- a/addons/portal_sale/portal_sale_data.xml
+++ b/addons/portal_sale/portal_sale_data.xml
@@ -45,23 +45,10 @@
href="${signup_url}">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':
- <% set paypal_url = "https://www.paypal.com/cgi-bin/webscr?" +
- urlencode({
- "cmd": "_xclick",
- "business": object.company_id.paypal_account,
- "item_name": object.company_id.name + " Order " + object.name,
- "invoice": object.name,
- "amount": object.amount_total,
- "currency_code": object.pricelist_id.currency_id.name,
- "button_subtype": "services",
- "no_note": "1",
- "bn": "OpenERP_Order_PayNow_" + object.pricelist_id.currency_id.name,
- })
- %>
+ % if object.paypal_url:
It is also possible to directly pay with Paypal:
-
+
% endif
@@ -144,23 +131,10 @@
href="${signup_url}">View Invoice
% endif
- % if object.company_id.paypal_account and object.type in ('out_invoice'):
- <% set paypal_url = "https://www.paypal.com/cgi-bin/webscr?" +
- urlencode({
- "cmd": "_xclick",
- "business": object.company_id.paypal_account,
- "item_name": object.company_id.name + " Invoice " + object.number,
- "invoice": object.number,
- "amount": object.residual,
- "currency_code": object.currency_id.name,
- "button_subtype": "services",
- "no_note": "1",
- "bn": "OpenERP_Invoice_PayNow_" + object.currency_id.name,
- })
- %>
+ % if object.paypal_url:
It is also possible to directly pay with Paypal:
-
+
% endif
diff --git a/addons/sale/edi/sale_order.py b/addons/sale/edi/sale_order.py
index 15389f1481c..b906f9a6926 100644
--- a/addons/sale/edi/sale_order.py
+++ b/addons/sale/edi/sale_order.py
@@ -19,7 +19,10 @@
#
##############################################################################
-from openerp.osv import osv
+from urllib import urlencode
+
+from openerp.osv import osv, fields
+from openerp.tools.translate import _
from edi import EDIMixin
SALE_ORDER_LINE_EDI_STRUCT = {
@@ -118,7 +121,6 @@ class sale_order(osv.osv, EDIMixin):
edi_document.pop('partner_address', None) # ignored, that's supposed to be our own address!
return partner_id
-
def _edi_get_pricelist(self, cr, uid, partner_id, currency, context=None):
# TODO: refactor into common place for purchase/sale, e.g. into product module
partner_model = self.pool.get('res.partner')
@@ -180,6 +182,30 @@ class sale_order(osv.osv, EDIMixin):
order_line.pop('price_subtotal', None)
return super(sale_order,self).edi_import(cr, uid, edi_document, context=context)
+ def _edi_paypal_url(self, cr, uid, ids, field, arg, context=None):
+ res = dict.fromkeys(ids, False)
+ for order in self.browse(cr, uid, ids, context=context):
+ if order.order_policy in ('prepaid', 'manual') and \
+ order.company_id.paypal_account and order.state != 'draft':
+ params = {
+ "cmd": "_xclick",
+ "business": order.company_id.paypal_account,
+ "item_name": order.company_id.name + " Order " + order.name,
+ "invoice": order.name,
+ "amount": order.amount_total,
+ "currency_code": order.pricelist_id.currency_id.name,
+ "button_subtype": "services",
+ "no_note": "1",
+ "bn": "OpenERP_Order_PayNow_" + order.pricelist_id.currency_id.name,
+ }
+ res[order.id] = "https://www.paypal.com/cgi-bin/webscr?" + urlencode(params)
+ return res
+
+ _columns = {
+ 'paypal_url': fields.function(_edi_paypal_url, type='char', string='Paypal Url'),
+ }
+
+
class sale_order_line(osv.osv, EDIMixin):
_inherit='sale.order.line'
diff --git a/addons/sale/edi/sale_order_action_data.xml b/addons/sale/edi/sale_order_action_data.xml
index 371233b96c7..f031daf8656 100644
--- a/addons/sale/edi/sale_order_action_data.xml
+++ b/addons/sale/edi/sale_order_action_data.xml
@@ -52,23 +52,10 @@
% endif
- % if object.order_policy in ('prepaid','manual') and object.company_id.paypal_account and object.state != 'draft':
- <% set paypal_url = "https://www.paypal.com/cgi-bin/webscr?" +
- urlencode({
- "cmd": "_xclick",
- "business": object.company_id.paypal_account,
- "item_name": object.company_id.name + " Order " + object.name,
- "invoice": object.name,
- "amount": object.amount_total,
- "currency_code": object.pricelist_id.currency_id.name,
- "button_subtype": "services",
- "no_note": "1",
- "bn": "OpenERP_Order_PayNow_" + object.pricelist_id.currency_id.name,
- })
- %>
+ % if object.paypal_url:
It is also possible to directly pay with Paypal:
-
+
% endif
From 8fb701d0b33ba21b65eb18985015b8335994618a Mon Sep 17 00:00:00 2001
From: Raphael Collet
Date: Fri, 14 Dec 2012 15:06:36 +0100
Subject: [PATCH 12/13] [IMP] account_followup: simplify code in report
bzr revid: rco@openerp.com-20121214140636-34i98k29ldl15z3h
---
.../report/account_followup_print.py | 47 +++++++++----------
1 file changed, 21 insertions(+), 26 deletions(-)
diff --git a/addons/account_followup/report/account_followup_print.py b/addons/account_followup/report/account_followup_print.py
index f101aeaa369..67ce062dcd1 100644
--- a/addons/account_followup/report/account_followup_print.py
+++ b/addons/account_followup/report/account_followup_print.py
@@ -20,6 +20,7 @@
##############################################################################
import time
+from collections import defaultdict
import pooler
from report import report_sxw
@@ -50,36 +51,30 @@ class report_rappel(report_sxw.rml_parse):
def _lines_get_with_partner(self, partner, company_id):
pool = pooler.get_pool(self.cr.dbname)
moveline_obj = pool.get('account.move.line')
- company_obj = pool.get('res.company')
- obj_currency = pool.get('res.currency')
- movelines = moveline_obj.search(self.cr, self.uid,
- [('partner_id', '=', partner.id),
- ('account_id.type', '=', 'receivable'),
- ('reconcile_id', '=', False), ('state', '<>', 'draft'),('company_id','=', company_id)])
- movelines = moveline_obj.browse(self.cr, self.uid, movelines)
- base_currency = movelines[0].company_id.currency_id
- final_res = []
- line_cur = {base_currency.id: {'line': []}}
+ moveline_ids = moveline_obj.search(self.cr, self.uid, [
+ ('partner_id', '=', partner.id),
+ ('account_id.type', '=', 'receivable'),
+ ('reconcile_id', '=', False),
+ ('state', '!=', 'draft'),
+ ('company_id', '=', company_id),
+ ])
- for line in movelines:
- if line.currency_id and (not line.currency_id.id in line_cur):
- line_cur[line.currency_id.id] = {'line': []}
+ # lines_per_currency = {currency: [line data, ...], ...}
+ lines_per_currency = defaultdict(list)
+ for line in moveline_obj.browse(self.cr, self.uid, moveline_ids):
currency = line.currency_id or line.company_id.currency_id
line_data = {
- 'name': line.move_id.name,
- 'ref': line.ref,
- 'date':line.date,
- 'date_maturity': line.date_maturity,
- 'balance': currency.id <> line.company_id.currency_id.id and line.amount_currency or (line.debit - line.credit),
- 'blocked': line.blocked,
- 'currency_id': currency,
- }
- line_cur[currency.id]['line'].append(line_data)
+ 'name': line.move_id.name,
+ 'ref': line.ref,
+ 'date': line.date,
+ 'date_maturity': line.date_maturity,
+ 'balance': line.amount_currency if currency != line.company_id.currency_id else line.debit - line.credit,
+ 'blocked': line.blocked,
+ 'currency_id': currency,
+ }
+ lines_per_currency[currency].append(line_data)
- for cur in line_cur:
- if line_cur[cur]['line']:
- final_res.append({'line': line_cur[cur]['line']})
- return final_res
+ return [{'line': lines} for lines in lines_per_currency.values()]
def _get_text(self, stat_line, followup_id, context=None):
if context is None:
From 8e43af0e70cf1ad0bd2ed397c8548c5d559dda8a Mon Sep 17 00:00:00 2001
From: Raphael Collet
Date: Fri, 14 Dec 2012 15:16:54 +0100
Subject: [PATCH 13/13] [IMP] account_followup: in email templates, move the
followup_table from the context to a partner method
bzr revid: rco@openerp.com-20121214141654-ksmjs6t73wzwedvl
---
addons/account_followup/account_followup.py | 106 ++++++++----------
.../account_followup_data.xml | 8 +-
2 files changed, 50 insertions(+), 64 deletions(-)
diff --git a/addons/account_followup/account_followup.py b/addons/account_followup/account_followup.py
index 17a09d51e6e..30bd543f7ca 100644
--- a/addons/account_followup/account_followup.py
+++ b/addons/account_followup/account_followup.py
@@ -113,66 +113,6 @@ class account_move_line(osv.osv):
}
-
-class email_template(osv.osv):
- _inherit = 'email.template'
-
- def _get_followup_table_html(self, cr, uid, res_id, context=None):
- '''
- Build the html tables to be included in emails send to partners, when reminding them their
- overdue invoices.
-
- :param res_id: ID of the partner for whom we are building the tables
- :rtype: string
- '''
- from report import account_followup_print
-
- partner = self.pool.get('res.partner').browse(cr, uid, res_id, context=context)
- followup_table = ''
- if partner.unreconciled_aml_ids:
- company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
- current_date = fields.date.context_today(cr, uid, context)
- rml_parse = account_followup_print.report_rappel(cr, uid, "followup_rml_parser")
- final_res = rml_parse._lines_get_with_partner(partner, company.id)
-
- for currency_dict in final_res:
- currency = currency_dict.get('line', [{'currency_id': company.currency_id}])[0]['currency_id']
- followup_table += '''
-
-
- | Invoice date |
- Reference |
- Due date |
- Amount (%s) |
- Lit. |
-
- ''' % (currency.symbol)
- total = 0
- for aml in currency_dict['line']:
- block = aml['blocked'] and 'X' or ' '
- total += aml['balance']
- strbegin = ""
- strend = " | "
- date = aml['date_maturity'] or aml['date']
- if date <= current_date and aml['balance'] > 0:
- strbegin = ""
- strend = " | "
- followup_table +="" + strbegin + str(aml['date']) + strend + strbegin + aml['ref'] + strend + strbegin + str(date) + strend + strbegin + str(aml['balance']) + strend + strbegin + block + strend + "
"
- total = rml_parse.formatLang(total, dp='Account', currency_obj=currency)
- followup_table += '''
-
- Amount due: %s ''' % (total)
- return followup_table
-
-
- def render_template(self, cr, uid, template, model, res_id, context=None):
- if model == 'res.partner' and context.get('followup'):
- context['followup_table'] = self._get_followup_table_html(cr, uid, res_id, context=context)
- # Adds current_date to the context. That way it can be used to put
- # the account move lines in bold that are overdue in the email
- context['current_date'] = fields.date.context_today(cr, uid, context)
- return super(email_template, self).render_template(cr, uid, template, model, res_id, context=context)
-
class res_partner(osv.osv):
def fields_view_get(self, cr, uid, view_id=None, view_type=None, context=None, toolbar=False, submenu=False):
@@ -289,6 +229,52 @@ class res_partner(osv.osv):
'payment_next_action': payment_next_action}, context=ctx)
return unknown_mails
+ def get_followup_table_html(self, cr, uid, ids, context=None):
+ """ Build the html tables to be included in emails send to partners,
+ when reminding them their overdue invoices.
+ :param ids: [id] of the partner for whom we are building the tables
+ :rtype: string
+ """
+ from report import account_followup_print
+
+ assert len(ids) == 1
+ partner = self.browse(cr, uid, ids[0], context=context)
+ followup_table = ''
+ if partner.unreconciled_aml_ids:
+ company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
+ current_date = fields.date.context_today(cr, uid, context)
+ rml_parse = account_followup_print.report_rappel(cr, uid, "followup_rml_parser")
+ final_res = rml_parse._lines_get_with_partner(partner, company.id)
+
+ for currency_dict in final_res:
+ currency = currency_dict.get('line', [{'currency_id': company.currency_id}])[0]['currency_id']
+ followup_table += '''
+
+
+ | Invoice date |
+ Reference |
+ Due date |
+ Amount (%s) |
+ Lit. |
+
+ ''' % (currency.symbol)
+ total = 0
+ for aml in currency_dict['line']:
+ block = aml['blocked'] and 'X' or ' '
+ total += aml['balance']
+ strbegin = ""
+ strend = " | "
+ date = aml['date_maturity'] or aml['date']
+ if date <= current_date and aml['balance'] > 0:
+ strbegin = ""
+ strend = " | "
+ followup_table +="" + strbegin + str(aml['date']) + strend + strbegin + aml['ref'] + strend + strbegin + str(date) + strend + strbegin + str(aml['balance']) + strend + strbegin + block + strend + "
"
+ total = rml_parse.formatLang(total, dp='Account', currency_obj=currency)
+ followup_table += '''
+
+ Amount due: %s ''' % (total)
+ return followup_table
+
def action_done(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'payment_next_action_date': False, 'payment_next_action':'', 'payment_responsible_id': False}, context=context)
diff --git a/addons/account_followup/account_followup_data.xml b/addons/account_followup/account_followup_data.xml
index c35a0ffcd49..d7e6d029ae9 100644
--- a/addons/account_followup/account_followup_data.xml
+++ b/addons/account_followup/account_followup_data.xml
@@ -34,7 +34,7 @@ ${user.name}
-${ctx.get('followup_table','') | safe}
+${object.get_followup_table_html() | safe}
@@ -74,7 +74,7 @@ ${user.name}
-${ctx.get('followup_table','') | safe}
+${object.get_followup_table_html() | safe}
@@ -111,7 +111,7 @@ ${user.name}
-${ctx.get('followup_table','') | safe}
+${object.get_followup_table_html() | safe}
@@ -146,7 +146,7 @@ ${user.name}
-${ctx.get('followup_table','') | safe}
+${object.get_followup_table_html() | safe}