Reputation: 315
price=fields.Integer(string="Price")
service_date=fields.Date(string="Last servicing date")
service_charge=fields.Integer(string="Last Service Charge")
total_charge=fields.Integer(string="Total Spent")
@api.onchange('service_date')
def _onchange_total_charge(self):
if self.total_charge > 0:
self.total_charge+=self.service_charge
else:
self.total_charge=self.price+self.service_charge
Upvotes: 2
Views: 1026
Reputation: 211
@api.onchange('service_date')
@api.depends('service_date')
def _onchange_total_charge(self):
if self.total_charge > 0:
self.total_charge += self.service_charge
else:
self.total_charge = self.price + self.service_charge
Try to re-write the code like this
Upvotes: 2
Reputation: 726
I've used your code it works on my odoo instance. Please make sure that you call the same in field in your xml file. you can also use compute field to get your calculation done.
Upvotes: 2