From c00ed70c95c8a86a68cc727fa636896032fb2ca6 Mon Sep 17 00:00:00 2001 From: Vincent Renaville Date: Fri, 24 May 2013 10:54:33 +0200 Subject: [PATCH 1/9] [ADD] account_compute_tax_amount : This module recompute tax_amount field if a tax is set on the account.move.line, it prevent to have sign problem on account_move_line if line is created manually, in addition we set this field invisible everywhere --- account_compute_tax_amount/__init__.py | 23 ++++++++ account_compute_tax_amount/__openerp__.py | 33 +++++++++++ .../account_move_line.py | 58 +++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 account_compute_tax_amount/__init__.py create mode 100644 account_compute_tax_amount/__openerp__.py create mode 100644 account_compute_tax_amount/account_move_line.py diff --git a/account_compute_tax_amount/__init__.py b/account_compute_tax_amount/__init__.py new file mode 100644 index 000000000..b0afae26c --- /dev/null +++ b/account_compute_tax_amount/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author Vincent Renaville. Copyright 2013 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import account_move_line +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/account_compute_tax_amount/__openerp__.py b/account_compute_tax_amount/__openerp__.py new file mode 100644 index 000000000..5efd4711e --- /dev/null +++ b/account_compute_tax_amount/__openerp__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author Vincent Renaville. Copyright 2013 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + "name" : "Recompute tax_amount", + "version" : "1.0", + "depends" : ["base", + "account", + ], + "author" : "Camptocamp", + "description": """Recompute tax_amount to avoid sign problem""", + 'website': 'http://www.camptocamp.com', + 'date' : [], + 'installable': True, + 'active': False, +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_compute_tax_amount/account_move_line.py b/account_compute_tax_amount/account_move_line.py new file mode 100644 index 000000000..f050b876c --- /dev/null +++ b/account_compute_tax_amount/account_move_line.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2013 Camptocamp (http://www.camptocamp.com) +# All Right Reserved +# +# Author : Vincent Renaville (Camptocamp) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.tools.translate import _ +from openerp.osv import osv, orm, fields +import openerp.addons.decimal_precision as dp + +class account_move_line(orm.TransientModel): + _inherit = "account.move.line" + + def create(self, cr, uid, vals, context=None, check=True): + result = super(account_move_line,self).create(cr, uid, vals, context=context, check=check) + if result: + move_line = self.read(cr,uid,result,['credit','debit','tax_code_id']) + if move_line['tax_code_id']: + tax_amount = move_line['credit'] - move_line['debit'] + self.write(cr,uid,[result],{'tax_amount':tax_amount}) + return result + + def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True): + result = super(account_move_line,self).write(cr, uid, ids, vals, context=context, check=check, update_check=update_check) + if result: + if ('debit' in vals) or ('credit' in vals): + move_lines = self.read(cr,uid,ids,['credit','debit','tax_code_id']) + for move_line in move_lines: + if move_line['tax_code_id']: + tax_amount = move_line['credit'] - move_line['debit'] + self.write(cr,uid,[move_line['id']],{'tax_amount':tax_amount}) + + return result + + # We set the tax_amount invisible, because we recompute it in every case. + _columns = { + 'tax_amount': fields.float('Tax/Base Amount', digits_compute=dp.get_precision('Account'),invisible=True, select=True, help="If the Tax account is a tax code account, this field will contain the taxed amount.If the tax account is base tax code, "\ + "this field will contain the basic amount(without tax)."), + } + + \ No newline at end of file From 32aaf38981d2cb683ef8be7fbfd7ca4744f72cde Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 27 May 2013 08:47:58 +0200 Subject: [PATCH 2/9] [REF] account_compute_tax_amount: mall cleanup --- .../account_move_line.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/account_compute_tax_amount/account_move_line.py b/account_compute_tax_amount/account_move_line.py index f050b876c..b4844e5b1 100644 --- a/account_compute_tax_amount/account_move_line.py +++ b/account_compute_tax_amount/account_move_line.py @@ -29,7 +29,8 @@ class account_move_line(orm.TransientModel): _inherit = "account.move.line" def create(self, cr, uid, vals, context=None, check=True): - result = super(account_move_line,self).create(cr, uid, vals, context=context, check=check) + result = super(account_move_line,self).create(cr, uid, vals, + context=context, check=check) if result: move_line = self.read(cr,uid,result,['credit','debit','tax_code_id']) if move_line['tax_code_id']: @@ -38,7 +39,10 @@ class account_move_line(orm.TransientModel): return result def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True): - result = super(account_move_line,self).write(cr, uid, ids, vals, context=context, check=check, update_check=update_check) + result = super(account_move_line,self).write(cr, uid, ids, vals, + context=context, + check=check, + update_check=update_check) if result: if ('debit' in vals) or ('credit' in vals): move_lines = self.read(cr,uid,ids,['credit','debit','tax_code_id']) @@ -46,13 +50,17 @@ class account_move_line(orm.TransientModel): if move_line['tax_code_id']: tax_amount = move_line['credit'] - move_line['debit'] self.write(cr,uid,[move_line['id']],{'tax_amount':tax_amount}) - + return result - + # We set the tax_amount invisible, because we recompute it in every case. _columns = { - 'tax_amount': fields.float('Tax/Base Amount', digits_compute=dp.get_precision('Account'),invisible=True, select=True, help="If the Tax account is a tax code account, this field will contain the taxed amount.If the tax account is base tax code, "\ - "this field will contain the basic amount(without tax)."), + 'tax_amount': fields.float('Tax/Base Amount', digits_compute=dp.get_precision('Account'), + invisible=True, + select=True, + help=("If the Tax account is a tax code account, " + "this field will contain the taxed amount. " + "If the tax account is base tax code, " + "this field will contain the basic amount (without tax)."), } - \ No newline at end of file From eab761da7e8595bfc8975cba12e42d2fb2ec89c1 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 27 May 2013 08:49:11 +0200 Subject: [PATCH 3/9] [FIX] account_compute_tax_amount: rename field in __openerp__.py --- account_compute_tax_amount/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_compute_tax_amount/__openerp__.py b/account_compute_tax_amount/__openerp__.py index 5efd4711e..a1344d71d 100644 --- a/account_compute_tax_amount/__openerp__.py +++ b/account_compute_tax_amount/__openerp__.py @@ -26,7 +26,7 @@ "author" : "Camptocamp", "description": """Recompute tax_amount to avoid sign problem""", 'website': 'http://www.camptocamp.com', - 'date' : [], + 'data' : [], 'installable': True, 'active': False, } From 1449b68a7e39d4aa3d01e11e831147655013da31 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 27 May 2013 08:51:08 +0200 Subject: [PATCH 4/9] [REF] account_compute_tax_amount: add some missing spaces --- account_compute_tax_amount/account_move_line.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/account_compute_tax_amount/account_move_line.py b/account_compute_tax_amount/account_move_line.py index b4844e5b1..1789d0168 100644 --- a/account_compute_tax_amount/account_move_line.py +++ b/account_compute_tax_amount/account_move_line.py @@ -29,13 +29,13 @@ class account_move_line(orm.TransientModel): _inherit = "account.move.line" def create(self, cr, uid, vals, context=None, check=True): - result = super(account_move_line,self).create(cr, uid, vals, + result = super(account_move_line, self).create(cr, uid, vals, context=context, check=check) if result: - move_line = self.read(cr,uid,result,['credit','debit','tax_code_id']) + move_line = self.read(cr, uid, result, ['credit', 'debit', 'tax_code_id']) if move_line['tax_code_id']: tax_amount = move_line['credit'] - move_line['debit'] - self.write(cr,uid,[result],{'tax_amount':tax_amount}) + self.write(cr, uid, [result], {'tax_amount': tax_amount}) return result def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True): @@ -45,11 +45,11 @@ class account_move_line(orm.TransientModel): update_check=update_check) if result: if ('debit' in vals) or ('credit' in vals): - move_lines = self.read(cr,uid,ids,['credit','debit','tax_code_id']) + move_lines = self.read(cr, uid, ids, ['credit', 'debit', 'tax_code_id']) for move_line in move_lines: if move_line['tax_code_id']: tax_amount = move_line['credit'] - move_line['debit'] - self.write(cr,uid,[move_line['id']],{'tax_amount':tax_amount}) + self.write(cr, uid, [move_line['id']], {'tax_amount': tax_amount}) return result From 1f9b181c1f315d2bc078f501516b8f6780b90cf5 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 18 Jun 2013 10:11:41 +0200 Subject: [PATCH 5/9] [FIX] missing propagation of the context --- .../account_move_line.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/account_compute_tax_amount/account_move_line.py b/account_compute_tax_amount/account_move_line.py index 1789d0168..74095a8db 100644 --- a/account_compute_tax_amount/account_move_line.py +++ b/account_compute_tax_amount/account_move_line.py @@ -30,12 +30,17 @@ class account_move_line(orm.TransientModel): def create(self, cr, uid, vals, context=None, check=True): result = super(account_move_line, self).create(cr, uid, vals, - context=context, check=check) + context=context, + check=check) if result: - move_line = self.read(cr, uid, result, ['credit', 'debit', 'tax_code_id']) + move_line = self.read(cr, uid, result, + ['credit', 'debit', 'tax_code_id'], + context=context) if move_line['tax_code_id']: tax_amount = move_line['credit'] - move_line['debit'] - self.write(cr, uid, [result], {'tax_amount': tax_amount}) + self.write(cr, uid, [result], + {'tax_amount': tax_amount}, + context=context) return result def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True): @@ -45,11 +50,16 @@ class account_move_line(orm.TransientModel): update_check=update_check) if result: if ('debit' in vals) or ('credit' in vals): - move_lines = self.read(cr, uid, ids, ['credit', 'debit', 'tax_code_id']) + move_lines = self.read(cr, uid, ids, + ['credit', 'debit', 'tax_code_id'], + context=context) for move_line in move_lines: if move_line['tax_code_id']: tax_amount = move_line['credit'] - move_line['debit'] - self.write(cr, uid, [move_line['id']], {'tax_amount': tax_amount}) + self.write(cr, uid, + [move_line['id']], + {'tax_amount': tax_amount}, + context=context) return result @@ -63,4 +73,3 @@ class account_move_line(orm.TransientModel): "If the tax account is base tax code, " "this field will contain the basic amount (without tax)."), } - From 7f02fa2311bf72da67731a173d19f3940145f0b8 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 18 Jun 2013 10:12:58 +0200 Subject: [PATCH 6/9] [FIX] 2 lines before class (pep-8), cut a long line, removed useless parenthesis --- account_compute_tax_amount/account_move_line.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/account_compute_tax_amount/account_move_line.py b/account_compute_tax_amount/account_move_line.py index 74095a8db..f6ea50150 100644 --- a/account_compute_tax_amount/account_move_line.py +++ b/account_compute_tax_amount/account_move_line.py @@ -25,6 +25,7 @@ from openerp.tools.translate import _ from openerp.osv import osv, orm, fields import openerp.addons.decimal_precision as dp + class account_move_line(orm.TransientModel): _inherit = "account.move.line" @@ -65,11 +66,12 @@ class account_move_line(orm.TransientModel): # We set the tax_amount invisible, because we recompute it in every case. _columns = { - 'tax_amount': fields.float('Tax/Base Amount', digits_compute=dp.get_precision('Account'), + 'tax_amount': fields.float('Tax/Base Amount', + digits_compute=dp.get_precision('Account'), invisible=True, select=True, - help=("If the Tax account is a tax code account, " - "this field will contain the taxed amount. " - "If the tax account is base tax code, " - "this field will contain the basic amount (without tax)."), + help="If the Tax account is a tax code account, " + "this field will contain the taxed amount. " + "If the tax account is base tax code, " + "this field will contain the basic amount (without tax)."), } From a588cda474052ca770f12bc85da6a4977fc091d3 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 18 Jun 2013 10:13:39 +0200 Subject: [PATCH 7/9] [CHG] move the _columns before the orm public methods --- .../account_move_line.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/account_compute_tax_amount/account_move_line.py b/account_compute_tax_amount/account_move_line.py index f6ea50150..3d4ecbcfe 100644 --- a/account_compute_tax_amount/account_move_line.py +++ b/account_compute_tax_amount/account_move_line.py @@ -29,6 +29,18 @@ import openerp.addons.decimal_precision as dp class account_move_line(orm.TransientModel): _inherit = "account.move.line" + # We set the tax_amount invisible, because we recompute it in every case. + _columns = { + 'tax_amount': fields.float('Tax/Base Amount', + digits_compute=dp.get_precision('Account'), + invisible=True, + select=True, + help="If the Tax account is a tax code account, " + "this field will contain the taxed amount. " + "If the tax account is base tax code, " + "this field will contain the basic amount (without tax)."), + } + def create(self, cr, uid, vals, context=None, check=True): result = super(account_move_line, self).create(cr, uid, vals, context=context, @@ -63,15 +75,3 @@ class account_move_line(orm.TransientModel): context=context) return result - - # We set the tax_amount invisible, because we recompute it in every case. - _columns = { - 'tax_amount': fields.float('Tax/Base Amount', - digits_compute=dp.get_precision('Account'), - invisible=True, - select=True, - help="If the Tax account is a tax code account, " - "this field will contain the taxed amount. " - "If the tax account is base tax code, " - "this field will contain the basic amount (without tax)."), - } From ccf0ce7c0f42f89f588df559a09e598ef3ce2d15 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 12 Aug 2013 08:08:32 +0200 Subject: [PATCH 8/9] [FIX] wrong class used for the Model --- account_compute_tax_amount/account_move_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_compute_tax_amount/account_move_line.py b/account_compute_tax_amount/account_move_line.py index 3d4ecbcfe..6266f9e7f 100644 --- a/account_compute_tax_amount/account_move_line.py +++ b/account_compute_tax_amount/account_move_line.py @@ -26,7 +26,7 @@ from openerp.osv import osv, orm, fields import openerp.addons.decimal_precision as dp -class account_move_line(orm.TransientModel): +class account_move_line(orm.Model): _inherit = "account.move.line" # We set the tax_amount invisible, because we recompute it in every case. From be077d0cb58059c21554a3d50db17054c14825c7 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 12 Aug 2013 08:08:55 +0200 Subject: [PATCH 9/9] [FIX] remove unused imports --- account_compute_tax_amount/account_move_line.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/account_compute_tax_amount/account_move_line.py b/account_compute_tax_amount/account_move_line.py index 6266f9e7f..e2e84bbf9 100644 --- a/account_compute_tax_amount/account_move_line.py +++ b/account_compute_tax_amount/account_move_line.py @@ -21,8 +21,7 @@ # ############################################################################## -from openerp.tools.translate import _ -from openerp.osv import osv, orm, fields +from openerp.osv import orm, fields import openerp.addons.decimal_precision as dp