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 ##############################################################################
33 from osv import fields, osv
36 class purchase_order(osv.osv):
37 _inherit = "purchase.order"
38 def _amount_tax(self, cr, uid, ids, field_name, arg, context):
40 cur_obj=self.pool.get('res.currency')
41 for order in self.browse(cr, uid, ids):
43 cur=order.pricelist_id.currency_id
44 for line in order.order_line:
45 if order.price_type=='tax_included':
46 ttt = self.pool.get('account.tax').compute_inv(cr, uid, line.taxes_id, line.price_unit, line.product_qty, order.partner_address_id.id, line.product_id, order.partner_id)
48 ttt = self.pool.get('account.tax').compute(cr, uid, line.taxes_id, line.price_unit, line.product_qty, order.partner_address_id.id, line.product_id, order.partner_id)
50 val += cur_obj.round(cr, uid, cur, c['amount'])
51 res[order.id]=cur_obj.round(cr, uid, cur, val)
54 'price_type': fields.selection([
55 ('tax_included','Tax included'),
56 ('tax_excluded','Tax excluded')
57 ], 'Price method', required=True),
58 'amount_tax': fields.function(_amount_tax, method=True, string='Taxes'),
61 'price_type': lambda *a: 'tax_excluded',
63 def _inv_get(self, cr, uid, order, context={}):
65 'price_type': order.price_type
69 class purchase_order_line(osv.osv):
70 _inherit = 'purchase.order.line'
71 def _amount_line(self, cr, uid, ids, name, arg, context):
73 cur_obj=self.pool.get('res.currency')
74 tax_obj = self.pool.get('account.tax')
75 res = super(purchase_order_line, self)._amount_line(cr, uid, ids, name, arg, context)
77 for line in self.browse(cr, uid, ids):
78 if line.order_id.price_type == 'tax_included':
80 for tax in tax_obj.compute_inv(cr, uid, line.product_id.supplier_taxes_id, res[line.id]/line.product_qty, line.product_qty):
81 res[line.id] = res[line.id] - tax['amount']
83 for tax in tax_obj.compute_inv(cr, uid, line.taxes_id, res[line.id]/line.product_qty, line.product_qty):
84 res[line.id] = res[line.id] - tax['amount']
85 if name == 'price_subtotal_incl' and line.order_id.price_type == 'tax_included':
87 prod_taxe_ids = [ t.id for t in line.product_id.supplier_taxes_id ]
89 line_taxe_ids = [ t.id for t in line.taxes_id ]
91 if line.product_id and prod_taxe_ids == line_taxe_ids:
92 res[line.id] = res2[line.id]
93 elif not line.product_id:
94 res[line.id] = res2[line.id]
96 for tax in tax_obj.compute(cr, uid, line.taxes_id, res[line.id]/line.product_qty, line.product_qty):
97 res[line.id] = res[line.id] + tax['amount']
98 cur = line.order_id.pricelist_id.currency_id
99 res[line.id] = cur_obj.round(cr, uid, cur, res[line.id])
102 'price_subtotal': fields.function(_amount_line, method=True, string='Subtotal w/o tax'),
103 'price_subtotal_incl': fields.function(_amount_line, method=True, string='Subtotal'),
105 purchase_order_line()