Files
mymach_fleet_intelligence/test_suite.py

103 lines
4.2 KiB
Python
Raw 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 datetime
import urllib.request
import json
from odoo import fields
env = env(user=1)
print("\n" + "="*50)
print("MYMACH AKILLI FILO - KAPSAMLI FOTOĞRAFLI TESLİM & İADE TEST SUİTİ")
print("="*50)
# --- HAZIRLIK ---
print("\n[HAZIRLIK] Test Verileri Oluşturuluyor...")
partner = env['res.partner'].create({'name': 'TEST_Sürücü_Teslim'})
employee = env['hr.employee'].create({'name': 'TEST_Personel_Teslim', 'work_contact_id': partner.id})
contract = env['mymach.fleet.contract'].create({
'name': 'CON-HANDOVER-TEST',
'driver_id': partner.id,
'personal_use_policy': 'forbidden',
'commute_allowed': 'allowed',
'driver_score': 100
})
model_id = env['fleet.vehicle.model'].search([], limit=1)
vehicle = env['fleet.vehicle'].create({
'model_id': model_id.id,
'license_plate': '34 TESLIM 26',
'driver_id': partner.id,
'purchase_value': 50000,
'tank_capacity': 60.0,
'factory_avg_consumption': 6.0
})
print(f" -> Sözleşme oluşturuldu: {contract.name}")
print(f" -> Araç oluşturuldu: {vehicle.license_plate}")
# ---------------------------------------------------------
# BÖLÜM 1: ARAÇ TESLİM ALIM (GİRİŞ) İŞLEMİ
# ---------------------------------------------------------
print("\n[TEST 1] ARAÇ TESLİM ALIM (GİRİŞ) YAZILIM TESTİ")
# Sahte bir fotoğraf (Binary string)
dummy_photo = b"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="
handover = env['mymach.fleet.handover'].create({
'vehicle_id': vehicle.id,
'driver_id': partner.id,
'start_odometer': 12000.0,
'start_fuel_level': 80.0, # %80 depo ile aldı
'start_photo': dummy_photo
})
print(f" -> Kayıt Oluşturuldu: {handover.name} (Durum: {handover.state})")
handover.action_take()
print(f" -> Teslim Alındı Sonrası Durum: {handover.state}")
print(f" -> Araç Depo Durumu (Litre): {vehicle.current_fuel_level} L (Kapasite: {vehicle.tank_capacity} L)")
# ---------------------------------------------------------
# BÖLÜM 2: ARAÇ TESLİM ETME (İADE) İŞLEMİ
# ---------------------------------------------------------
print("\n[TEST 2] ARAÇ İADE VE ODOMETER GÜNCELLEME TESTİ")
handover.write({
'end_odometer': 12350.0, # 350 KM yol yapmış
'end_fuel_level': 45.0, # %45 depo ile iade etti
'end_photo': dummy_photo
})
handover.action_return()
print(f" -> İade Edildi Sonrası Durum: {handover.state}")
print(f" -> Yapılan Yol (Hesaplanan): {handover.odometer_diff} KM")
print(f" -> Yakıt Değişimi: %{handover.fuel_diff}")
# En son odometer değerini kontrol edelim
last_odometer = env['fleet.vehicle.odometer'].search([('vehicle_id', '=', vehicle.id)], order='value desc', limit=1)
print(f" -> Araç Son Kilometresi (Odometer): {last_odometer.value} KM")
# ---------------------------------------------------------
# BÖLÜM 3: YÖNETİCİ DENETİM VE ONAYI
# ---------------------------------------------------------
print("\n[TEST 3] YÖNETİCİ KIYASLAMA VE ONAYLAMA")
handover.write({
'manager_note': 'Yakıt farkı makul seviyede, hasarsız teslim alındı.'
})
handover.action_compare()
print(f" -> Denetim Sonrası Durum: {handover.state} (Onaylandı mı?: {handover.is_approved})")
# ---------------------------------------------------------
# BÖLÜM 4: OTONOM FOTOĞRAF PURGE (CRON) TESTİ
# ---------------------------------------------------------
print("\n[TEST 4] 10 GÜNLÜK FOTOĞRAF OTONOM PURGE CRON TESTİ")
# İade tarihini 11 gün öncesine alalım
eleven_days_ago = fields.Datetime.now() - datetime.timedelta(days=11)
handover.write({'return_datetime': eleven_days_ago})
print(f" -> İade Tarihi Geriye Alındı: {handover.return_datetime}")
print(f" -> Temizlik Öncesi Fotoğraflar Mevcut mu?: (Alış: {bool(handover.start_photo)}, İade: {bool(handover.end_photo)})")
# Cron fonksiyonunu çalıştır
deleted_count = env['mymach.fleet.handover'].action_purge_expired_photos()
print(f" -> Cron Çalıştırıldı. Temizlenen Kayıt Sayısı: {deleted_count}")
print(f" -> Temizlik Sonrası Fotoğraflar Mevcut mu?: (Alış: {bool(handover.start_photo)}, İade: {bool(handover.end_photo)})")
print("\n" + "="*50)
print("FOTOĞRAFLI TESLİM/İADE VE CRON TESTLERİ BAŞARIYLA TAMAMLANDI!")
print("="*50 + "\n")