1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
6 # $Id: account.py 1005 2005-07-25 08:41:42Z nicoe $
8 # WARNING: This program as such is intended to be used by professional
9 # programmers who take the whole responsability of assessing all potential
10 # consequences resulting from its eventual inadequacies and bugs
11 # End users who are looking for a ready-to-use solution with commercial
12 # garantees and support are strongly adviced to contract a Free Software
15 # This program is Free Software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 ##############################################################################
32 from osv import fields, osv
34 class account_tax(osv.osv):
35 _inherit = 'account.tax'
38 'python_compute_inv':fields.text('Python Code (VAT Incl)'),
41 'python_compute_inv': lambda *a: '''# price_unit\n# address : res.partner.address object or False\n# product : product.product object or False\n\nresult = price_unit * 0.10''',
43 def _unit_compute_inv(self, cr, uid, taxes, price_unit, address_id=None, product=None):
44 taxes = self._applicable(cr, uid, taxes, price_unit, address_id)
48 cur_price_unit=price_unit
50 # we compute the amount for the current tax object and append it to the result
51 if tax.type=='percent':
52 amount = cur_price_unit - (cur_price_unit / (1 + tax.amount))
53 res.append({'id':tax.id, 'name':tax.name, 'amount':amount, 'account_collected_id':tax.account_collected_id.id, 'account_paid_id':tax.account_paid_id.id, 'base_code_id': tax.base_code_id.id, 'ref_base_code_id': tax.ref_base_code_id.id, 'sequence': tax.sequence, 'base_sign': tax.base_sign, 'ref_base_sign': tax.ref_base_sign, 'price_unit': cur_price_unit - amount,})
54 elif tax.type=='fixed':
55 res.append({'id':tax.id, 'name':tax.name, 'amount':tax.amount, 'account_collected_id':tax.account_collected_id.id, 'account_paid_id':tax.account_paid_id.id, 'base_code_id': tax.base_code_id.id, 'ref_base_code_id': tax.ref_base_code_id.id, 'sequence': tax.sequence, 'base_sign': tax.base_sign, 'ref_base_sign': tax.ref_base_sign, 'price_unit': 1,})
56 elif tax.type=='code':
57 address = address_id and self.pool.get('res.partner.address').browse(cr, uid, address_id) or None
58 localdict = {'price_unit':cur_price_unit, 'address':address, 'product':product,}
59 exec tax.python_compute_inv in localdict
60 amount = localdict['result']
65 'account_collected_id': tax.account_collected_id.id,
66 'account_paid_id': tax.account_paid_id.id,
67 'base_code_id': tax.base_code_id.id,
68 'ref_base_code_id': tax.ref_base_code_id.id,
69 'sequence': tax.sequence,
70 'base_sign': tax.base_sign,
71 'ref_base_sign': tax.ref_base_sign,
72 'price_unit': cur_price_unit - amount,
74 amount2 = res[-1]['amount']
75 if len(tax.child_ids):
81 for t in tax.child_ids:
82 parent_tax = self._unit_compute_inv(cr, uid, [t], amount, address_id)
83 res.extend(parent_tax)
84 if tax.include_base_amount:
85 cur_price_unit-=amount
89 def compute_inv(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None):
91 Compute tax values for given PRICE_UNIT, QUANTITY and a buyer/seller ADDRESS_ID.
92 Price Unit is a VAT included price
96 tax = {'name':'', 'amount':0.0, 'account_collected_id':1, 'account_paid_id':2}
97 one tax for each tax id in IDS and their childs
99 res = self._unit_compute_inv(cr, uid, taxes, price_unit, address_id, product)
101 r['amount'] *= quantity