1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# Copyright (c) 2013 Camptocamp (http://www.camptocamp.com)
7
# Author : Vincent Renaville (Camptocamp)
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU Affero General Public License as
11
# published by the Free Software Foundation, either version 3 of the
12
# License, or (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU Affero General Public License for more details.
19
# You should have received a copy of the GNU Affero General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
##############################################################################
24
from openerp.osv import orm, fields
25
import openerp.addons.decimal_precision as dp
28
class account_move_line(orm.Model):
29
_inherit = "account.move.line"
31
# We set the tax_amount invisible, because we recompute it in every case.
33
'tax_amount': fields.float('Tax/Base Amount',
34
digits_compute=dp.get_precision('Account'),
37
help="If the Tax account is a tax code account, "
38
"this field will contain the taxed amount. "
39
"If the tax account is base tax code, "
40
"this field will contain the basic amount (without tax)."),
43
def create(self, cr, uid, vals, context=None, check=True):
44
result = super(account_move_line, self).create(cr, uid, vals,
48
move_line = self.read(cr, uid, result,
49
['credit', 'debit', 'tax_code_id'],
51
if move_line['tax_code_id']:
52
tax_amount = move_line['credit'] - move_line['debit']
53
self.write(cr, uid, [result],
54
{'tax_amount': tax_amount},
58
def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
59
result = super(account_move_line,self).write(cr, uid, ids, vals,
62
update_check=update_check)
64
if ('debit' in vals) or ('credit' in vals):
65
move_lines = self.read(cr, uid, ids,
66
['credit', 'debit', 'tax_code_id'],
68
for move_line in move_lines:
69
if move_line['tax_code_id']:
70
tax_amount = move_line['credit'] - move_line['debit']
73
{'tax_amount': tax_amount},