~domsense/openobject-italia/6.1-fix-primanota-lep

« back to all changes in this revision

Viewing changes to account_invoice_tax_by_column/account.py

  • Committer: eLBati
  • Date: 2011-08-23 16:36:37 UTC
  • Revision ID: lorenzo.battistini@agilebg.com-20110823163637-k268yxwt8q4y88ip
reverted to 118

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2010-2010 Camptocamp Austria (<http://www.camptocamp.at>)
 
6
#    Copyright (C) 2011
 
7
#    Associazione OpenERP Italia (<http://www.openerp-italia.org>)
 
8
#
 
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.
 
13
#
 
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.
 
18
#
 
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/>.
 
21
#
 
22
##############################################################################
 
23
 
 
24
from osv import fields, osv
 
25
import decimal_precision as dp
 
26
from decimal import *
 
27
 
 
28
class account_tax(osv.osv):
 
29
 
 
30
    _inherit = 'account.tax'
 
31
    
 
32
    _columns = {
 
33
        'line_precision' : fields.boolean('Rounding Precision', help="Calculates floating point tax per line to simulate vertical calculation"),
 
34
    }
 
35
    
 
36
    _defaults = {
 
37
        'line_precision': True
 
38
    }
 
39
 
 
40
    def _compute(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None, partner=None):
 
41
        res = super(account_tax, self)._compute(cr, uid, taxes, price_unit, quantity, address_id, product, partner)
 
42
        tax_pool=self.pool.get('account.tax')
 
43
        total = 0.0
 
44
        for r in res:
 
45
            tax = tax_pool.browse(cr, uid, r['id'])
 
46
            if tax.line_precision:
 
47
                if r.get('balance',False):
 
48
                    r['amount'] = r.get('balance', 0.0) * quantity - total
 
49
                else:
 
50
                    r['amount'] = r.get('amount', 0.0) * quantity
 
51
                    total += r['amount']
 
52
        return res
 
53
 
 
54
 
 
55
account_tax()