~openerp-community/openobject-addons/mgmtsystem

« back to all changes in this revision

Viewing changes to account_tax_expense_include/account_tax_expense_include.py

  • Committer: Maxime Chambreuil
  • Date: 2011-01-25 16:46:58 UTC
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: maxime.chambreuil@savoirfairelinux.com-20110125164658-4ss6g0zk1zqko9t2
[ADD] account_tax_expense_include

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 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU Affero General Public License as
 
9
#    published by the Free Software Foundation, either version 3 of the
 
10
#    License, or (at your option) any later version.
 
11
#
 
12
#    This program is distributed in the hope that it will be useful,
 
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#    GNU Affero General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU Affero General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
 
19
#
 
20
##############################################################################
 
21
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
22
 
 
23
from osv import osv, fields
 
24
 
 
25
class account_tax(osv.osv):
 
26
    _inherit = 'account.tax'
 
27
    _columns = {
 
28
        'expense_include': fields.boolean('Tax Included in Expense',
 
29
                                          help="Check this if this tax is \
 
30
                                            included in the expense amount."),
 
31
    }
 
32
 
 
33
    def compute_all(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None, partner=None):
 
34
        """
 
35
        RETURN: {
 
36
                'total': 0.0,                # Total without taxes
 
37
                'total_included: 0.0,        # Total with taxes
 
38
                'taxes': []                  # List of taxes, see compute for the format
 
39
            }
 
40
        """
 
41
        precision = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')
 
42
        totalin = totalex = round(price_unit * quantity, precision)
 
43
        tin = []
 
44
        tex = []
 
45
        for tax in taxes:
 
46
            if (partner.employee and tax.expense_include) or tax.price_include:
 
47
                tin.append(tax)
 
48
            else:
 
49
                tex.append(tax)
 
50
        tin = self.compute_inv(cr, uid, tin, price_unit, quantity, address_id=address_id, product=product, partner=partner)
 
51
        for r in tin:
 
52
            totalex -= r.get('amount', 0.0)
 
53
        totlex_qty = 0.0
 
54
        try:
 
55
            totlex_qty=totalex/quantity
 
56
        except:
 
57
            pass
 
58
        tex = self._compute(cr, uid, tex, totlex_qty, quantity, address_id=address_id, product=product, partner=partner)
 
59
        for r in tex:
 
60
            totalin += r.get('amount', 0.0)
 
61
        return {
 
62
            'total': totalex,
 
63
            'total_included': totalin,
 
64
            'taxes': tin + tex
 
65
        }
 
66
 
 
67
 
 
68
account_tax()