Hai,
Please help, so I need help with the formula for calculating parking rates from Datetime field references, such as the price increase every hour. examples of field activities such as car parking activities on the street in general.
and i have a model,
class ParkingLog(models.Model): _name='parking_management' _rec_name='vehicle_number' vehicle_number=fields.Many2one('vehicle_log',string='Nomor Kendaraan') vehicle_type=fields.Many2one('type_vehicle', string='Jenis Kendaraan', ondelete='cascade', related='vehicle_number.vehicle_tipe',) parking_start=fields.Datetime(string='Masuk', default=fields.Datetime.now, required='True', readonly='True') parking_end=fields.Datetime(string='Keluar',compute='' ,states={'in' : [('readonly', 'False')], 'paid' : [('readonly', 'False')]}) billing_id=fields.Integer('Tarif', related='vehicle_type.billing_ids') staff_id=fields.Many2one('res.users',string='Petugas', default=lambda self: self.env.user, readonly='true')
and this is for the code on api that i tried to make,
@api.depends('parking_end') def tarif_parkir(self): if self.parking_end: tarif = datetime.strptime(self.tarif, '%m/%d/%Y') self.parking_end = (parking_start.today() - tarif).hours + 2000
example;
for cars, the first 1 hour = 100 USD and the next hour increases by 200 USD / hour
for motorbikes, the first hour = 50 USD and the next hour increases by 100 USD / hour
for almost a month I tried to explore, tried it myself, but no solution was found. and finally I tried asking it directly on the forum.
Beforehand, any answer I would appreciate. Thanks you 😃
right sir that's my problem, but I have a different price calculation every hour. depending on the vehicle that will park. So what should I change is the API code and how is the code?
You just need to playing with python dates:
1- http://learnopenerp.blogspot.com/2018/02/python-timedelta.html
2- http://learnopenerp.blogspot.com/2018/02/python-strftime-datetime-formatting.html
3- http://learnopenerp.blogspot.com/2018/01/python-date-manipulation.html