From: Raphael Collet Date: Fri, 14 Dec 2012 14:06:36 +0000 (+0100) Subject: [IMP] account_followup: simplify code in report X-Git-Tag: 7.0-server~365^2~1 X-Git-Url: http://git.inspyration.org/?a=commitdiff_plain;h=8fb701d0b33ba21b65eb18985015b8335994618a;hp=01bffef54898388fdf288b3e367c52d9655e79a8;p=odoo%2Fodoo.git [IMP] account_followup: simplify code in report bzr revid: rco@openerp.com-20121214140636-34i98k29ldl15z3h --- diff --git a/addons/account_followup/report/account_followup_print.py b/addons/account_followup/report/account_followup_print.py index f101aea..67ce062 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: