[IMP] account_followup: in email templates, move the followup_table from the context to a partner method
bzr revid: rco@openerp.com-20121214141654-ksmjs6t73wzwedvl
This commit is contained in:
parent
8fb701d0b3
commit
8e43af0e70
|
@ -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 += '''
|
||||
<table border="2" width=100%%>
|
||||
<tr>
|
||||
<td>Invoice date</td>
|
||||
<td>Reference</td>
|
||||
<td>Due date</td>
|
||||
<td>Amount (%s)</td>
|
||||
<td>Lit.</td>
|
||||
</tr>
|
||||
''' % (currency.symbol)
|
||||
total = 0
|
||||
for aml in currency_dict['line']:
|
||||
block = aml['blocked'] and 'X' or ' '
|
||||
total += aml['balance']
|
||||
strbegin = "<TD>"
|
||||
strend = "</TD>"
|
||||
date = aml['date_maturity'] or aml['date']
|
||||
if date <= current_date and aml['balance'] > 0:
|
||||
strbegin = "<TD><B>"
|
||||
strend = "</B></TD>"
|
||||
followup_table +="<TR>" + strbegin + str(aml['date']) + strend + strbegin + aml['ref'] + strend + strbegin + str(date) + strend + strbegin + str(aml['balance']) + strend + strbegin + block + strend + "</TR>"
|
||||
total = rml_parse.formatLang(total, dp='Account', currency_obj=currency)
|
||||
followup_table += '''<tr> </tr>
|
||||
</table>
|
||||
<center>Amount due: %s </center>''' % (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 += '''
|
||||
<table border="2" width=100%%>
|
||||
<tr>
|
||||
<td>Invoice date</td>
|
||||
<td>Reference</td>
|
||||
<td>Due date</td>
|
||||
<td>Amount (%s)</td>
|
||||
<td>Lit.</td>
|
||||
</tr>
|
||||
''' % (currency.symbol)
|
||||
total = 0
|
||||
for aml in currency_dict['line']:
|
||||
block = aml['blocked'] and 'X' or ' '
|
||||
total += aml['balance']
|
||||
strbegin = "<TD>"
|
||||
strend = "</TD>"
|
||||
date = aml['date_maturity'] or aml['date']
|
||||
if date <= current_date and aml['balance'] > 0:
|
||||
strbegin = "<TD><B>"
|
||||
strend = "</B></TD>"
|
||||
followup_table +="<TR>" + strbegin + str(aml['date']) + strend + strbegin + aml['ref'] + strend + strbegin + str(date) + strend + strbegin + str(aml['balance']) + strend + strbegin + block + strend + "</TR>"
|
||||
total = rml_parse.formatLang(total, dp='Account', currency_obj=currency)
|
||||
followup_table += '''<tr> </tr>
|
||||
</table>
|
||||
<center>Amount due: %s </center>''' % (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)
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ ${user.name}
|
|||
<br/>
|
||||
|
||||
|
||||
${ctx.get('followup_table','') | safe}
|
||||
${object.get_followup_table_html() | safe}
|
||||
|
||||
<br/>
|
||||
|
||||
|
@ -74,7 +74,7 @@ ${user.name}
|
|||
<br/>
|
||||
<br/>
|
||||
|
||||
${ctx.get('followup_table','') | safe}
|
||||
${object.get_followup_table_html() | safe}
|
||||
|
||||
<br/>
|
||||
|
||||
|
@ -111,7 +111,7 @@ ${user.name}
|
|||
<br/>
|
||||
|
||||
|
||||
${ctx.get('followup_table','') | safe}
|
||||
${object.get_followup_table_html() | safe}
|
||||
|
||||
<br/>
|
||||
|
||||
|
@ -146,7 +146,7 @@ ${user.name}
|
|||
<br/>
|
||||
<br/>
|
||||
|
||||
${ctx.get('followup_table','') | safe}
|
||||
${object.get_followup_table_html() | safe}
|
||||
|
||||
<br/>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue