Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
2507 Vistas

In purchase order line i need to show the list_price of the product but that have a condition, today(may 30) if i make a purchase then the list_price is 100 will shown and after confirming the purchase if i change the list_price to 120 in the purchase it still needs to show 100 for that i have create a function with api.onchange()
It works well, 
but if i create a replenish with buy it creates a purchase order in that order the list_price is not updating
below is my onchange code

class PurchaseOrderInherit(models.Model):
_inherit = 'purchase.order.line'

mrp = fields.Float("MRP", help="Load from Product MRP(Latest)", digits='Product Price')

@api.onchange('product_template_id', 'product_id')
def _compute_mrp(self):
for rec in self:
if rec.product_id:
rec.mrp = rec.product_id.list_price
else:
rec.mrp = False

Kindly help me

Avatar
Descartar
Autor

NOTE : I have enabled purchase_product_matrix this module it will create product_template_id in po_order_line

Mejor respuesta

I suggest replace on_change with compute method in you case sir, on_change doesn't store in the database, it just temporary data so that might be the cause

Avatar
Descartar
Autor

If i use compute every time i change list_price in product it changes in purchase
i don't need that, if the purchase confirmed after that even the list_price chnage i need the one before confirm that's why i use onchange

No, if you depend on fields ('product_template_id', 'product_id') when you change list_price on product it will not change 'mrp' unless you depend like this ('product_template_id.list_price', 'product_id.list_price')

Autor

I have checked now, even though i use ('product_template_id', 'product_id') this on depends if i change list_price in product it changes in purchase

Publicaciones relacionadas Respuestas Vistas Actividad
1
ene 25
1150
0
dic 24
1152
1
ene 24
1620
2
dic 24
14895
2
mar 15
5189