I have error can't adapt type 'NewId'. Every time I do edit or delete line always show the error
@api.multi
@api.depends('product_id','order_id')
def _get_cost_price_currency_update2(self):
for record in self:
param2 =()
query2 = '''SELECT hpp_update,cost_price_set_lock
FROM sale_order_line
WHERE order_id = %s AND product_id = %s
'''
param2 +=(record.order_id.id,record.product_id.id)
self.env.cr.execute(query2,param2)
query_result_lines2= self.env.cr.dictfetchall()
for line in query_result_lines2:
if line['hpp_update']:
cost_price_set_update = line['hpp_update']
else:
cost_price_set_update = line['cost_price_set_lock']
record.cost_price_set_update = cost_price_set_update
cost_price_set_update = fields.Float(string='CPP Update', compute=_get_cost_price_currency_update2)
I found another similar question but I con not found the solution. Any help please? Thank you
UPDATE Base on Andrei suggestion I have made some change in the script like this
cost_price_set_lock = fields.Float(string='CPP Lock',compute=_get_cost_price_currency, store=True)
@api.depends('order_id')
def _get_cost_price_currency_update2(self):
cost_price_set_update2 = ''
invoice_pool = self.env['sale.order.line']
for record2 in self:
for invoice in invoice_pool.search([('order_id', '=', record2.order_id.id), ('product_id', '=', record2.product_id.id)]):
if invoice.hpp_update:
cost_price_set_update2 = invoice.hpp_update
else:
cost_price_set_update2 = invoice.cost_price_set_lock
record2.cost_price_set_update = cost_price_set_update2
cost_price_set_update = fields.Float(string='CPP Update', compute=_get_cost_price_currency_update2)
The problem with this is that the value of the cost_price_set_update is always change base on the compute result from cost_price_set_lock field where it should be the one that stored first time.