Files
mymach_fleet_intelligence/test_scenario.py

63 lines
1.9 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.

from odoo import fields
env = env(user=1)
print("\n--- [TEST SENARYOSU BASLIYOR] ---")
# 1. Örnek Personel ve Partner (Sürücü) Yarat
partner = env['res.partner'].create({'name': 'Ahmet Yılmaz (Test Sürücüsü)'})
employee = env['hr.employee'].create({
'name': 'Ahmet Yılmaz'
})
# 2. Araç Yarat (Model yoksa ilk bulduğunu alır)
model_id = env['fleet.vehicle.model'].search([], limit=1)
vehicle = env['fleet.vehicle'].create({
'model_id': model_id.id,
'license_plate': '34 YAPAY 2026',
'purchase_value': 25000,
'depreciation_years': 5,
'annual_fixed_cost': 1500,
'tank_capacity': 60,
'factory_avg_consumption': 6.0,
'driver_id': partner.id
})
# 3. Sözleşme Yarat (Sıfır Tolerans: Şahsi Kullanım Yasak)
contract = env['mymach.fleet.contract'].create({
'name': 'CON-TEST-001',
'driver_id': partner.id,
'personal_use_policy': 'forbidden',
'commute_allowed': 'forbidden'
})
# Ürün (Hizmet/Masraf) bulalım
product = env['product.product'].search([], limit=1)
if not product:
product = env['product.product'].create({'name': 'Genel Bakım/Yakıt', 'type': 'service'})
# 4. Kestirimci Bakımı Tetikleyecek Veri Girişi (Çok Sayıda Yüksek Masraf)
for i in range(3):
env['mymach.fleet.maintenance.cost'].create({
'vehicle_id': vehicle.id,
'product_id': product.id,
'amount': 5500.0,
'name': f'Yakıt/Bakım Alımı {i+1} (Yüksek Tüketim Simülasyonu)'
})
# 5. Prediktif Bakım AI (Cron Job) Manuel Tetikleme
env['mymach.fleet.maintenance.cost'].action_sync_fuel_data_cron()
# 6. Güvenlik İhlali İçin Personeli Ofiste (İçeride) Gösterme (hr.attendance)
env['hr.attendance'].create({
'employee_id': employee.id,
'check_in': fields.Datetime.now(),
})
env.cr.commit()
print(f"\n--- [BASARILI] ---")
print(f"Araç Plakası: {vehicle.license_plate}")
print(f"Araç ID: {vehicle.id}")
print(f"Personel: {employee.name}")
print("API'den Ping Atmaya Hazır!\n")