diff --git a/__unported__/account_compute_tax_amount/account_move_line.py b/__unported__/account_compute_tax_amount/account_move_line.py deleted file mode 100644 index 1bd6809a0..000000000 --- a/__unported__/account_compute_tax_amount/account_move_line.py +++ /dev/null @@ -1,81 +0,0 @@ -# -*- 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.osv import orm, fields -import openerp.addons.decimal_precision as dp - - -class account_move_line(orm.Model): - _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, - check=check) - if result: - 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}, - context=context) - 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'], - 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}, - context=context) - - return result diff --git a/account_compute_tax_amount/README.rst b/account_compute_tax_amount/README.rst new file mode 100644 index 000000000..eee02f1be --- /dev/null +++ b/account_compute_tax_amount/README.rst @@ -0,0 +1,13 @@ +Recompute tax amount +==================== + +The way the tax amount is computed in journal entries in the core +``account`` module is prone to input errors. + +This module forces the the tax amount to always be: ``credit - debit`` +whatever the configuration of the tax is and whatever the user types in +the tax amount. + +**Warning**: there is no guarantee that this module will work for every +country, at least it works for Switzerland and France where the tax +amount is always ``credit - debit``. diff --git a/__unported__/account_compute_tax_amount/__init__.py b/account_compute_tax_amount/__init__.py similarity index 100% rename from __unported__/account_compute_tax_amount/__init__.py rename to account_compute_tax_amount/__init__.py diff --git a/__unported__/account_compute_tax_amount/__openerp__.py b/account_compute_tax_amount/__openerp__.py similarity index 87% rename from __unported__/account_compute_tax_amount/__openerp__.py rename to account_compute_tax_amount/__openerp__.py index a07bf4463..630099bf3 100644 --- a/__unported__/account_compute_tax_amount/__openerp__.py +++ b/account_compute_tax_amount/__openerp__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Author Vincent Renaville. Copyright 2013 Camptocamp SA +# Author Vincent Renaville. Copyright 2013-2014 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 @@ -23,9 +23,8 @@ "depends": ["base", "account"], "author": "Camptocamp", - "description": """Recompute tax_amount to avoid sign problem""", 'website': 'http://www.camptocamp.com', 'data': [], - 'installable': False, + 'installable': True, 'active': False, } 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..3993e956d --- /dev/null +++ b/account_compute_tax_amount/account_move_line.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2013-2014 Camptocamp (http://www.camptocamp.com) +# +# 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 import models, fields, api + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + # We set the tax_amount readonly, because we recompute it in every case. + tax_amount = fields.Float(readonly=True) + + @api.one + def force_compute_tax_amount(self): + if self.tax_code_id: + self.tax_amount = self.credit - self.debit + + @api.cr_uid_context + def create(self, cr, uid, vals, context=None, check=True): + record_id = super(AccountMoveLine, self).create(cr, uid, vals, + context=context, + check=check) + self.force_compute_tax_amount(cr, uid, [record_id], context=context) + return record_id + + @api.cr_uid_ids_context + def write(self, cr, uid, ids, vals, context=None, check=True, + update_check=True): + result = super(AccountMoveLine, self).write(cr, uid, ids, vals, + context=context, + check=check, + update_check=update_check) + + if ('debit' in vals) or ('credit' in vals): + self.force_compute_tax_amount(cr, uid, ids, context=context) + return result diff --git a/__unported__/account_compute_tax_amount/i18n/account_compute_tax_amount.pot b/account_compute_tax_amount/i18n/account_compute_tax_amount.pot similarity index 100% rename from __unported__/account_compute_tax_amount/i18n/account_compute_tax_amount.pot rename to account_compute_tax_amount/i18n/account_compute_tax_amount.pot diff --git a/__unported__/account_compute_tax_amount/i18n/es.po b/account_compute_tax_amount/i18n/es.po similarity index 100% rename from __unported__/account_compute_tax_amount/i18n/es.po rename to account_compute_tax_amount/i18n/es.po diff --git a/__unported__/account_compute_tax_amount/i18n/pt_BR.po b/account_compute_tax_amount/i18n/pt_BR.po similarity index 100% rename from __unported__/account_compute_tax_amount/i18n/pt_BR.po rename to account_compute_tax_amount/i18n/pt_BR.po