53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
import time
|
||
from datetime import date
|
||
|
||
# Yetki yükselt (sudo)
|
||
env = env(su=True)
|
||
|
||
print("="*50)
|
||
print("AKARYAKIT FİYAT ENDEKSİ TESTİ")
|
||
print("="*50)
|
||
|
||
fuel_model = env['mymach.fleet.fuel.index']
|
||
|
||
# 1. İlk gün fiyatlarını oluştur
|
||
print("\n[Adım 1] Geçmiş Fiyat Simülasyonu (Geçen Ay ve Geçen Yıl)")
|
||
last_year = date.today().replace(year=date.today().year - 1)
|
||
last_month = date.today().replace(month=date.today().month - 1) if date.today().month > 1 else date.today().replace(year=date.today().year - 1, month=12)
|
||
|
||
# Geçen yılki benzin fiyatı (Örn: 25.0 TL)
|
||
fuel_model.create({
|
||
'date': last_year,
|
||
'fuel_type': 'gasoline',
|
||
'unit_price': 25.0,
|
||
'source': 'Test Data (Geçen Yıl)'
|
||
})
|
||
|
||
# Geçen ayki benzin fiyatı (Örn: 42.0 TL)
|
||
fuel_model.create({
|
||
'date': last_month,
|
||
'fuel_type': 'gasoline',
|
||
'unit_price': 42.0,
|
||
'source': 'Test Data (Geçen Ay)'
|
||
})
|
||
|
||
print("✅ Geçmiş fiyatlar (1 Yıl ve 1 Ay Öncesi) başarıyla oluşturuldu.")
|
||
|
||
# 2. Otonom Cron Job Metodunu Çalıştır (Bugünün fiyatını çeksin/simüle etsin)
|
||
print("\n[Adım 2] Otonom Fiyat Çekme (Cron) Metodu Tetikleniyor...")
|
||
fuel_model.action_auto_fetch_fuel_prices()
|
||
|
||
# 3. Sonuçları Kontrol Et
|
||
print("\n[Adım 3] Sonuçlar Analiz Ediliyor...")
|
||
today_record = fuel_model.search([('fuel_type', '=', 'gasoline')], order='date desc', limit=1)
|
||
|
||
print(f"Bugünkü Benzin Fiyatı: {today_record.unit_price} TL")
|
||
print(f"Aylık Değişim (MoM): %{today_record.mom_change_perc:.2f}")
|
||
print(f"Yıllık Değişim (YoY): %{today_record.yoy_change_perc:.2f}")
|
||
|
||
print("\n" + "="*50)
|
||
print("TEST TAMAMLANDI")
|
||
print("="*50)
|
||
|
||
env.cr.rollback()
|