Hi, Everyone
i have been able to create a custom in sale order line there are two field 1.totalweight and priceperunit i use a help of @api.onchange so when ever the value that it depends on it will change automatically. below is my .py code
class customSaleField(models.Model):
_inherit = 'sale.order.line'
TotalWeight = fields.Float(string='Total Weight',readonly=True,store=True)
PricePerUnit = fields.Float(string='Price Per Unit',readonly=True,store=True)
@api.onchange('product_uom_qty')
def on_change_weight(self):
weight = self.product_uom_qty * self.product_id.weight
value = {
'value' : {
'TotalWeight' : weight
}
}
return value
@api.onchange('price_subtotal','TotalWeight')
def on_change_PricePerUnit(self):
try:
PricePerUnit = self.price_subtotal / self.TotalWeight
except ZeroDivisionError:
PricePerUnit = 0
value = {
'value' : {
'PricePerUnit' : PricePerUnit
}
}
return value
however,when i press "confirm sale" or "save" or perform any action the value in custom fields are disappear
Secondly, how do i actually pass these values,field to account ?? after the user press click on "create invoice"