Hi, I don't know if it's a best practise, but... my need is to give the possibility to aprox manually net price in sale.order (line) so I decide (in my installation ubu 10.4, oerp 6.0.2, sale and sale_layout moudle installed) to override _amount_line method that compute function field price_subtotal value (the one represent in order form in tree view)
sale/sale.py:Code:
class sale_order_line(osv.osv):
def _amount_line(self, cr, uid, ids, field_name, arg, context=None):
tax_obj = self.pool.get('account.tax')
cur_obj = self.pool.get('res.currency')
res = {}
if context is None:
context = {}
for line in self.browse(cr, uid, ids, context=context):
price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
taxes = tax_obj.compute_all(cr, uid, line.tax_id, price, line.product_uom_qty, line.order_id.partner_invoice_id.id, 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
sale_layoutCode:
class sale_order_line(osv.osv)
def _amount_line(self, cr, uid, ids, field_name, arg, context=None):
res = {}
for line in self.browse(cr, uid, ids, context=context):
if line.layout_type == 'article':
return super(sale_order_line, self)._amount_line(cr, uid, ids, field_name, arg, context)
return res
my_module:Code:
class fiam_sale_order_line_fields(osv.osv):
def _amount_line(self, cr, uid, ids, field_name, arg, context=None):
tax_obj = self.pool.get('account.tax')
cur_obj = self.pool.get('res.currency')
res = {}
if context is None:
context = {}
for line in self.browse(cr, uid, ids, context=context):
# MODIFIED PART ######################
if line.price_use_manual:
price = line.price_unit_manual
else:
price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
#################################
taxes = tax_obj.compute_all(cr, uid, line.tax_id, price, line.product_uom_qty, line.order_id.partner_invoice_id.id, 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
I see a problem, with pdb I see that openerp execute only sale.py method instead or my (or sale_layout), so... what's wrong and is that the correct way to modify the "not present" field net price AKA price_subtotal?
Thanks for any clues