From 1de4c8e2107f930bbbb20a32dad7c2cde5d64572 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Fri, 30 Nov 2012 16:42:08 +0100 Subject: [PATCH] [FIX] account_followup: multi currency handling bzr revid: qdp-launchpad@openerp.com-20121130154208-q3gj23y9iqq92ko1 --- addons/account_followup/account_followup.py | 10 +- .../account_followup_data.xml | 294 ++++++++---------- .../report/account_followup_print.py | 11 +- .../report/account_followup_print.rml | 4 +- 4 files changed, 138 insertions(+), 181 deletions(-) diff --git a/addons/account_followup/account_followup.py b/addons/account_followup/account_followup.py index 97eba3abc3c..5f7f3ba3f8e 100644 --- a/addons/account_followup/account_followup.py +++ b/addons/account_followup/account_followup.py @@ -66,7 +66,7 @@ class followup_line(osv.osv): _sql_constraints = [('days_uniq', 'unique(followup_id, delay)', 'Days of the follow-up levels must be different')] _defaults = { 'send_email': True, - 'send_letter': False, + 'send_letter': True, 'manual_action':False, 'description': """ Dear %(partner_name)s, @@ -218,10 +218,10 @@ class res_partner(osv.osv): mtp = self.pool.get('email.template') unknown_mails = 0 for partner in self.browse(cr, uid, partner_ids, context=context): - if partner.email != False and partner.email != '' and partner.email != ' ': - p = partner.latest_followup_level_id_without_lit - if p and p.send_email and p.email_template_id.id != False: - mtp.send_mail(cr, uid, p.email_template_id.id, partner.id, context=context) + if partner.email and partner.email.strip(): + level = partner.latest_followup_level_id_without_lit + if level and level.send_email and level.email_template_id and level.email_template_id.id: + mtp.send_mail(cr, uid, level.email_template_id.id, partner.id, context=context) else: mail_template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_followup', 'email_template_account_followup_default') diff --git a/addons/account_followup/account_followup_data.xml b/addons/account_followup/account_followup_data.xml index 0ded41c536a..ce2df1d03d6 100644 --- a/addons/account_followup/account_followup_data.xml +++ b/addons/account_followup/account_followup_data.xml @@ -1,9 +1,5 @@ - - - - @@ -11,18 +7,19 @@ Follow-up of overdue invoices level 0 ${user.email or ''} - ${object.company_id.name} Payment Follow-up + ${user.company_id.name} Payment Follow-up ${object.email} ${object.lang} - -

Dear ${object.name and ' ' or ''},

+ +

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. + Would your payment have been carried out after this mail was sent, please ignore this message. Do not hesitate to contact our accounting department at (+32).10.68.94.39. @@ -32,57 +29,46 @@ Best Regards,
${user.name} - -
-
- +
+
+<% + from openerp.addons.account_followup.report import account_followup_print + rml_parse = account_followup_print.report_rappel(object._cr, user.id, "followup_rml_parser") + final_res = rml_parse._lines_get_with_partner(object, user.company_id.id) + followup_table = '' + for currency_dict in final_res: + currency_symbol = currency_dict.get('line', [{'currency_id': user.company_id.currency_id}])[0]['currency_id'].symbol + followup_table += ''' +
- + + ''' % (currency_symbol) + total = 0 + for aml in currency_dict['line']: + block = aml['blocked'] and 'X' or ' ' + total += aml['balance'] + strbegin = " " + date = aml['date_maturity'] or aml['date'] + if date <= ctx['current_date'] and aml['balance'] > 0: + strbegin = "" + 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=object.company_id.currency_id) + followup_table += ''' +
Invoice date Reference Due dateAmountAmount (%s) Lit.
" + strend = "" + strend = "
+

Amount due: %s
''' % (total) -<% - amls = object.unreconciled_aml_ids - mel = {} - total = 0 - for aml in amls: - strbegin = " " - strend = " " - date = False - if aml.date_maturity: - date = aml.date_maturity - if aml.date_maturity <= ctx['current_date'] and aml.debit > 0: - strbegin = "" - strend = "" - else: - if aml.date <= ctx['current_date'] and aml.debit > 0: - strbegin = "" - strend = "" - else: - strbegin = "" - strend = "" - date = aml.date - block = " " - if aml.blocked: - block = "X" - mel[aml.id] = "" + strbegin + str(aml.date) + strend + strbegin + aml.ref + strend + strbegin + str(date) + strend + strbegin + str(aml.result) + strend + strbegin + block + strend + "" - if (aml.company_id.id != user.company_id.id): - mel[aml.id] = "" - else: - total += aml.result %> - - -% for aml in amls: -${mel[aml.id]} -% endfor - -
Amount due: ${total} ${object.company_id.currency_id.name}
+${followup_table} +
@@ -95,7 +81,7 @@ ${mel[aml.id]} Follow-up of overdue invoices level 1 ${user.email or ''} - ${object.company_id.name} Payment Follow-up + ${user.company_id.name} Payment Follow-up ${object.email} ${object.lang} @@ -103,7 +89,7 @@ ${mel[aml.id]} -

Dear ${object.name and ' ' or ''},

+

Dear ${object.name},

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 @@ -123,54 +109,43 @@ ${user.name}
- - +<% + from openerp.addons.account_followup.report import account_followup_print + rml_parse = account_followup_print.report_rappel(object._cr, user.id, "followup_rml_parser") + final_res = rml_parse._lines_get_with_partner(object, user.company_id.id) + followup_table = '' + for currency_dict in final_res: + currency_symbol = currency_dict.get('line', [{'currency_id': user.company_id.currency_id}])[0]['currency_id'].symbol + followup_table += ''' +
- + + ''' % (currency_symbol) + total = 0 + for aml in currency_dict['line']: + block = aml['blocked'] and 'X' or ' ' + total += aml['balance'] + strbegin = " " + date = aml['date_maturity'] or aml['date'] + if date <= ctx['current_date'] and aml['balance'] > 0: + strbegin = "" + 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=object.company_id.currency_id) + followup_table += ''' +
Invoice date Reference Due dateAmountAmount (%s) Lit.
" + strend = "" + strend = "
+

Amount due: %s
''' % (total) -<% - amls = object.unreconciled_aml_ids - mel = {} - total = 0 - for aml in amls: - strbegin = " " - strend = " " - date = False - if aml.date_maturity: - date = aml.date_maturity - if aml.date_maturity <= ctx['current_date'] and aml.debit > 0: - strbegin = "" - strend = "" - else: - if aml.date <= ctx['current_date'] and aml.debit > 0: - strbegin = "" - strend = "" - else: - strbegin = "" - strend = "" - date = aml.date - block = " " - if aml.blocked: - block = "X" - mel[aml.id] = "" + strbegin + str(aml.date) + strend + strbegin + aml.ref + strend + strbegin + str(date) + strend + strbegin + str(aml.result) + strend + strbegin + block + strend + "" - if (aml.company_id.id != user.company_id.id): - mel[aml.id] = "" - else: - total += aml.result %> - - -% for aml in amls: -${mel[aml.id]} -% endfor - -
Amount due: ${total} ${object.company_id.currency_id.name}
+${followup_table} +
@@ -180,7 +155,7 @@ ${mel[aml.id]} Follow-up of overdue invoices level 2 ${user.email or ''} - ${object.company_id.name} Payment Follow-up + ${user.company_id.name} Payment Follow-up ${object.email} ${object.lang} @@ -188,7 +163,7 @@ ${mel[aml.id]} -

Dear ${object.name and ' ' or ''},

+

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 @@ -206,54 +181,44 @@ ${user.name}
- +<% + from openerp.addons.account_followup.report import account_followup_print + rml_parse = account_followup_print.report_rappel(object._cr, user.id, "followup_rml_parser") + final_res = rml_parse._lines_get_with_partner(object, user.company_id.id) + followup_table = '' + for currency_dict in final_res: + currency_symbol = currency_dict.get('line', [{'currency_id': user.company_id.currency_id}])[0]['currency_id'].symbol + followup_table += ''' +
- + + ''' % (currency_symbol) + total = 0 + for aml in currency_dict['line']: + block = aml['blocked'] and 'X' or ' ' + total += aml['balance'] + strbegin = " " + date = aml['date_maturity'] or aml['date'] + if date <= ctx['current_date'] and aml['balance'] > 0: + strbegin = "" + 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=object.company_id.currency_id) + followup_table += ''' +
Invoice date Reference Due dateAmountAmount (%s) Lit.
" + strend = "" + strend = "
+

Amount due: %s
''' % (total) -<% - amls = object.unreconciled_aml_ids - mel = {} - total = 0 - for aml in amls: - strbegin = " " - strend = " " - date = False - if aml.date_maturity: - date = aml.date_maturity - if aml.date_maturity <= ctx['current_date'] and aml.debit > 0: - strbegin = "" - strend = "" - else: - if aml.date <= ctx['current_date'] and aml.debit > 0: - strbegin = "" - strend = "" - else: - strbegin = "" - strend = "" - date = aml.date - block = " " - if aml.blocked: - block = "X" - mel[aml.id] = "" + strbegin + str(aml.date) + strend + strbegin + aml.ref + strend + strbegin + str(date) + strend + strbegin + str(aml.result) + strend + strbegin + block + strend + "" - if (aml.company_id.id != user.company_id.id): - mel[aml.id] = "" - else: - total += aml.result %> - - -% for aml in amls: -${mel[aml.id]} -% endfor - -
Amount due: ${total} ${object.company_id.currency_id.name}
+${followup_table} +
@@ -265,7 +230,7 @@ ${mel[aml.id]} Default follow-up of overdue invoices ${user.email or ''} - ${object.company_id.name} Payment Follow-up + ${user.company_id.name} Payment Follow-up ${object.email} ${object.lang} @@ -273,7 +238,7 @@ ${mel[aml.id]} -

Dear ${object.name and ' ' or ''},

+

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. @@ -291,54 +256,44 @@ ${user.name}
- +<% + from openerp.addons.account_followup.report import account_followup_print + rml_parse = account_followup_print.report_rappel(object._cr, user.id, "followup_rml_parser") + final_res = rml_parse._lines_get_with_partner(object, user.company_id.id) + followup_table = '' + for currency_dict in final_res: + currency_symbol = currency_dict.get('line', [{'currency_id': user.company_id.currency_id}])[0]['currency_id'].symbol + followup_table += ''' +
- + + ''' % (currency_symbol) + total = 0 + for aml in currency_dict['line']: + block = aml['blocked'] and 'X' or ' ' + total += aml['balance'] + strbegin = " " + date = aml['date_maturity'] or aml['date'] + if date <= ctx['current_date'] and aml['balance'] > 0: + strbegin = "" + 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=object.company_id.currency_id) + followup_table += ''' +
Invoice date Reference Due dateAmountAmount (%s) Lit.
" + strend = "" + strend = "
+

Amount due: %s
''' % (total) -<% - amls = object.unreconciled_aml_ids - mel = {} - total = 0 - for aml in amls: - strbegin = " " - strend = " " - date = False - if aml.date_maturity: - date = aml.date_maturity - if aml.date_maturity <= ctx['current_date'] and aml.debit > 0: - strbegin = "" - strend = "" - else: - if aml.date <= ctx['current_date'] and aml.debit > 0: - strbegin = "" - strend = "" - else: - strbegin = "" - strend = "" - date = aml.date - block = " " - if aml.blocked: - block = "X" - mel[aml.id] = "" + strbegin + str(aml.date) + strend + strbegin + aml.ref + strend + strbegin + str(date) + strend + strbegin + str(aml.result) + strend + strbegin + block + strend + "" - if (aml.company_id.id != user.company_id.id): - mel[aml.id] = "" - else: - total += aml.result %> - - -% for aml in amls: -${mel[aml.id]} -% endfor - -
Amount due: ${total} ${object.company_id.currency_id.name}
+${followup_table} +
@@ -350,7 +305,6 @@ ${mel[aml.id]} - Default Follow-up diff --git a/addons/account_followup/report/account_followup_print.py b/addons/account_followup/report/account_followup_print.py index 29f2ad38e31..90dd5969d53 100644 --- a/addons/account_followup/report/account_followup_print.py +++ b/addons/account_followup/report/account_followup_print.py @@ -25,7 +25,7 @@ import pooler from report import report_sxw class report_rappel(report_sxw.rml_parse): - def __init__(self, cr, uid, name, context): + def __init__(self, cr, uid, name, context=None): super(report_rappel, self).__init__(cr, uid, name, context=context) self.localcontext.update({ 'time': time, @@ -43,14 +43,17 @@ class report_rappel(report_sxw.rml_parse): return all_lines def _lines_get(self, stat_by_partner_line): + return self._lines_get_with_partner(stat_by_partner_line.partner_id, stat_by_partner_line.company_id.id) + + 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', '=', stat_by_partner_line.partner_id.id), + [('partner_id', '=', partner.id), ('account_id.type', '=', 'receivable'), - ('reconcile_id', '=', False), ('state', '<>', 'draft'),('company_id','=', stat_by_partner_line.company_id.id)]) + ('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 = [] @@ -67,7 +70,7 @@ class report_rappel(report_sxw.rml_parse): '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.symbol or currency.name, + 'currency_id': currency, } line_cur[currency.id]['line'].append(line_data) diff --git a/addons/account_followup/report/account_followup_print.rml b/addons/account_followup/report/account_followup_print.rml index 7f2242991de..fd3a35ab19c 100644 --- a/addons/account_followup/report/account_followup_print.rml +++ b/addons/account_followup/report/account_followup_print.rml @@ -194,7 +194,7 @@ [[ line['date_maturity'] and formatLang(line['date_maturity'], date=True) ]] - [[ formatLang(line['balance']) ]] [[ line['currency_id'] ]] + [[ formatLang(line['balance'], currency_obj=line['currency_id']) ]] [[ line['blocked'] and 'X' or '' ]] @@ -212,7 +212,7 @@ Total: - [[formatLang(reduce(lambda x,y: x+y['balance'], cur_lines['line'], 0.00)) ]] [[ line['currency_id'] ]] + [[formatLang(reduce(lambda x,y: x+y['balance'], cur_lines['line'], 0.00), currency_obj=line['currency_id']) ]]