This question has been flagged
1 Reply
6063 Views

Hiii good people,

is it possible to calculate the value of a float field in the one2many field?


if can please tell me, my current code : 

parking_log_ids=fields.One2many('parking_log','parking_log_id',string='Log Parkir')

total_bill_id=fields.Integer(string='Total Tarif', compute='_compute_biaya_total')

@api.multi def _compute_biaya_total(self): self.total_bill_id = len(self.parking_log_ids)


total_rate=fields.Float(string='Total Biaya Parkir')
@api.multi def action_close(self): bill_ = self.rate_id end_time_days = abs(fields.Datetime.from_string(fields.Datetime.now()) - fields.Datetime.from_string(self.start_time)).days end_time_seconds = abs(fields.Datetime.from_string(fields.Datetime.now()) - fields.Datetime.from_string(self.start_time)).seconds end_time_hours = end_time_days * 24.00 + end_time_seconds // 3600.00 amount = bill_ + (end_time_hours - 0.5) * bill_

self.write({'total_rate':amount})

My code currently only counts many fields instead of values ​​that are in the field.

what I want is to calculate the value in o2m(parking_log_ids) that is field 'total_rate' to 'total_bill_id'




I will appreciate all the answers, thank you very much

Avatar
Discard
Best Answer

You should create a compute type of field which will calculate the rate from the o2m field.

Ex:

total_rate = fields.Float(compute='_compute_rate', string="Total Biaya Parkir")

@api.multi
def _compute_rate(self):
for rec in self:
rec.total_rate = sum(line.my_rate_field for line in rec.parking_log_ids) # replace my_rate_field by the field inside your o2m


Avatar
Discard
Author

thank you for the answer sir, i update my question

what I want is to calculate the value in o2m(parking_log_ids) that is field 'total_rate' to 'total_bill_id'.

i mean if i have value in o2m on field 'total_rate', I want to calculate the value and save it in the 'total_bill_id' field

Author

I pulled my question, it was completed with an answer from you before.

thanks you sir :D