From c00ed70c95c8a86a68cc727fa636896032fb2ca6 Mon Sep 17 00:00:00 2001 From: Vincent Renaville Date: Fri, 24 May 2013 10:54:33 +0200 Subject: [PATCH] [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