[IMP] purchase: Hook for the base price of a purchase line

To be able to change the logic without copying large chunk of code
Closes #1468
This commit is contained in:
Pedro M. Baeza 2014-07-31 09:07:01 +02:00 committed by Martin Trigaux
parent cbe85f42d0
commit 617ef49959
1 changed files with 32 additions and 3 deletions

View File

@ -37,6 +37,7 @@ class purchase_order(osv.osv):
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
res = {}
cur_obj=self.pool.get('res.currency')
line_obj = self.pool['purchase.order.line']
for order in self.browse(cr, uid, ids, context=context):
res[order.id] = {
'amount_untaxed': 0.0,
@ -46,8 +47,14 @@ class purchase_order(osv.osv):
val = val1 = 0.0
cur = order.pricelist_id.currency_id
for line in order.order_line:
val1 += line.price_subtotal
for c in self.pool.get('account.tax').compute_all(cr, uid, line.taxes_id, line.price_unit, line.product_qty, line.product_id, order.partner_id)['taxes']:
val1 += line.price_subtotal
line_price = line_obj._calc_line_base_price(cr, uid, line,
context=context)
line_qty = line_obj._calc_line_quantity(cr, uid, line,
context=context)
for c in self.pool['account.tax'].compute_all(
cr, uid, line.taxes_id, line_price, line_qty,
line.product_id, order.partner_id)['taxes']:
val += c.get('amount', 0.0)
res[order.id]['amount_tax']=cur_obj.round(cr, uid, cur, val)
res[order.id]['amount_untaxed']=cur_obj.round(cr, uid, cur, val1)
@ -1020,12 +1027,34 @@ class purchase_order(osv.osv):
class purchase_order_line(osv.osv):
def _calc_line_base_price(self, cr, uid, line, context=None):
"""Return the base price of the line to be used for tax calculation.
This function can be extended by other modules to modify this base
price (adding a discount, for example).
"""
return line.price_unit
def _calc_line_quantity(self, cr, uid, line, context=None):
"""Return the base quantity of the line to be used for the subtotal.
This function can be extended by other modules to modify this base
quantity (adding for example offers 3x2 and so on).
"""
return line.product_qty
def _amount_line(self, cr, uid, ids, prop, arg, context=None):
res = {}
cur_obj=self.pool.get('res.currency')
tax_obj = self.pool.get('account.tax')
for line in self.browse(cr, uid, ids, context=context):
taxes = tax_obj.compute_all(cr, uid, line.taxes_id, line.price_unit, line.product_qty, line.product_id, line.order_id.partner_id)
line_price = self._calc_line_base_price(cr, uid, line,
context=context)
line_qty = self._calc_line_quantity(cr, uid, line,
context=context)
taxes = tax_obj.compute_all(cr, uid, line.taxes_id, line_price,
line_qty, line.product_id,
line.order_id.partner_id)
cur = line.order_id.pricelist_id.currency_id
res[line.id] = cur_obj.round(cr, uid, cur, taxes['total'])
return res