From 63298c2cbf6dc698fe7ef9a0c27a7a43305e1372 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 18 Nov 2009 12:28:55 +0100 Subject: [PATCH] split get_line into helper functions, map over browse_records instead of imperative iteration bzr revid: xmo@tinyerp.com-20091118112855-2dftiyn131em5nk3 --- addons/account/report/account_tax_code.py | 45 ++++++++++++----------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/addons/account/report/account_tax_code.py b/addons/account/report/account_tax_code.py index 4c284e28528..17b549e1eb1 100644 --- a/addons/account/report/account_tax_code.py +++ b/addons/account/report/account_tax_code.py @@ -26,6 +26,25 @@ import copy from report import report_sxw import re +def _get_country(record): + if record.partner_id \ + and record.partner_id.address \ + and record.partner_id.address[0].country_id: + return record.partner_id.address[0].country_id.code + else: + return '' + +def _record_to_report_line(record): + return {'date': record.date, + 'ref': record.ref, + 'acode': record.account_id.code, + 'name': record.name, + 'debit': record.debit, + 'credit': record.credit, + 'pname': record.partner_id and record.partner_id.name or '', + 'country': _get_country(record) + } + class account_tax_code_report(rml_parse.rml_parse): #_name = 'report.account.tax.code.entries' @@ -40,28 +59,10 @@ class account_tax_code_report(rml_parse.rml_parse): line_ids = self.pool.get('account.move.line').search(self.cr,self.uid,[('tax_code_id','=',obj.id)]) if not line_ids: return [] - result = [] - move_line_objs = self.pool.get('account.move.line').browse(self.cr,self.uid,line_ids) - for line in move_line_objs: - res = {'date': line.date, - 'ref': line.ref, - 'acode': line.account_id.code, - 'name': line.name, - 'debit': line.debit, - 'credit': line.credit, - 'pname': line.partner_id and line.partner_id.name or '', - } - - if line.partner_id \ - and line.partner_id.address \ - and line.partner_id.address[0].country_id: - res['country'] = line.partner_id.address[0].country_id.code - else: - res['country'] = '' - - result.append(res) - - return result + return map(_record_to_report_line, + self.pool.get('account.move.line')\ + .browse(self.cr, self.uid, line_ids)) + report_sxw.report_sxw('report.account.tax.code.entries', 'account.tax.code', 'addons/account/report/account_tax_code.rml', parser=account_tax_code_report, header=False)