From f737dbb644fe71f19a651737576a096d7d76f934 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Sun, 18 Jan 2009 23:32:56 +0100 Subject: [PATCH] modifs bzr revid: fp@tinyerp.com-20090118223256-239pjvqa7bjh141k --- addons/account/account.py | 30 ++++++++++++++++++++++++++++++ addons/account/account_view.xml | 2 ++ 2 files changed, 32 insertions(+) diff --git a/addons/account/account.py b/addons/account/account.py index 46c923850eb..e1f9d699815 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1108,6 +1108,35 @@ class account_tax_code(osv.osv): This code is used for some tax declarations. """ + def _sum(self, cr, uid, ids, name, args, context, where =''): + ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) + acc_set = ",".join(map(str, ids2)) + if context.get('based_on', 'invoices') == 'payments': + cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \ + FROM account_move_line AS line, \ + account_move AS move \ + LEFT JOIN account_invoice invoice ON \ + (invoice.move_id = move.id) \ + WHERE line.tax_code_id in ('+acc_set+') '+where+' \ + AND move.id = line.move_id \ + AND ((invoice.state = \'paid\') \ + OR (invoice.id IS NULL)) \ + GROUP BY line.tax_code_id') + else: + cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \ + FROM account_move_line AS line \ + WHERE line.tax_code_id in ('+acc_set+') '+where+' \ + GROUP BY line.tax_code_id') + res=dict(cr.fetchall()) + for record in self.browse(cr, uid, ids, context): + def _rec_get(record): + amount = res.get(record.id, 0.0) + for rec in record.child_ids: + amount += _rec_get(rec) * rec.sign + return amount + res[record.id] = round(_rec_get(record), 2) + return res + def _sum_period(self, cr, uid, ids, name, args, context): if 'period_id' in context and context['period_id']: period_id = context['period_id'] @@ -1126,6 +1155,7 @@ class account_tax_code(osv.osv): 'name': fields.char('Tax Case Name', size=64, required=True), 'code': fields.char('Case Code', size=64), 'info': fields.text('Description'), + 'sum': fields.function(_sum, method=True, string="Year Sum"), 'sum_period': fields.function(_sum_period, method=True, string="Period Sum"), 'parent_id': fields.many2one('account.tax.code', 'Parent Code', select=True), 'child_ids': fields.one2many('account.tax.code', 'parent_id', 'Childs Codes'), diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index ec6470f8c36..42fa70cd174 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -527,6 +527,7 @@ + @@ -543,6 +544,7 @@ +