Files
mymach_fleet_intelligence/populate_fuel_data.py
cerenX9 03b97ca431 21.07v
2026-07-21 17:17:25 +03:00

58 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import random
from datetime import timedelta, date
env = env(su=True)
company = env.company
if company.currency_id and getattr(company.currency_id, 'rounding', 0.0) == 0.0:
company.currency_id.write({'rounding': 0.01})
try_currency = env.ref('base.TRY', raise_if_not_found=False)
if try_currency:
try_currency.write({'active': True})
if getattr(try_currency, 'rounding', 0.0) == 0.0:
try_currency.write({'rounding': 0.01})
currency = try_currency or company.currency_id
product = env['product.template'].search([('type', '=', 'service')], limit=1)
if not product:
product = env['product.template'].create({'name': 'Akaryakıt (Litre)', 'type': 'service', 'list_price': 42.5})
vehicles = env['fleet.vehicle'].search([], limit=2)
if not vehicles:
print("Sistemde araç bulunamadı.")
else:
today = date.today()
for v in vehicles:
print(f"Araç {v.license_plate} için KM ve Yakıt verileri oluşturuluyor...")
base_km = v.odometer if v.odometer > 1000 else 45000
for i in range(30, -1, -2):
record_date = today - timedelta(days=i)
increment = random.randint(50, 150)
base_km += increment
env['fleet.vehicle.odometer'].create({
'vehicle_id': v.id,
'date': record_date,
'value': base_km
})
liters = random.uniform(20.0, 50.0)
price_per_liter = 42.5
total_cost = liters * price_per_liter
env['mymach.fleet.maintenance.cost'].create({
'vehicle_id': v.id,
'date': record_date,
'name': f"Akaryakıt Alımı ({liters:.1f} L)",
'amount': total_cost,
'currency_id': currency.id,
'product_id': product.id
})
print(f"Araç {v.license_plate} için son değer KM: {base_km}, başarıyla tamamlandı.")
env.cr.commit()
print("Tüm örnek KM ve Yakıt verileri sisteme başarıyla yüklendi!")