fix: apply travel-day quantity rules
Some checks failed
ERP CI/CD Pipeline / test (push) Has been cancelled
ERP CI/CD Pipeline / Deploy (server git pull + compose) (push) Has been cancelled

Use business-rule based daily quantity for travel expense calculations and cover it with regression tests.
This commit is contained in:
mariomitte
2026-08-08 03:09:24 +02:00
parent 681f73d85a
commit a9ab83c202
2 changed files with 27 additions and 8 deletions

View File

@@ -196,6 +196,17 @@ def _parse_report_decimal_value(value):
return Decimal('0.00')
def _calculate_daily_quantity_from_hours(total_hours):
numeric = Decimal(str(total_hours)) if total_hours not in (None, '') else Decimal('0.00')
if numeric <= 0:
return 0.0
if numeric < Decimal('8'):
return 0.0
if numeric < Decimal('12'):
return 0.5
return 1.0
def _task_work_hours_entries(task):
table_data = getattr(getattr(task, 'work_hours_table', None), 'data', None)
rows = table_data.get('rows', []) if isinstance(table_data, dict) else []
@@ -720,7 +731,7 @@ def _build_work_order_pdf(work_order):
start_candidates = [entry['start_dt'] for entry in trip_entries if entry.get('start_dt')]
end_candidates = [entry['end_dt'] for entry in trip_entries if entry.get('end_dt')]
total_hours = sum((entry['total_hours'] for entry in trip_entries), Decimal('0.00'))
travel_hours = float(total_hours)
travel_hours = float(total_hours.quantize(Decimal('0.01')))
if entry_dates:
trip_start_date = min(entry_dates)
trip_end_date = max(entry_dates)
@@ -729,7 +740,7 @@ def _build_work_order_pdf(work_order):
if end_candidates:
travel_end = max(end_candidates)
daily_qty = round(travel_hours / 24.0, 1) if travel_hours > 0 else 0.0
daily_qty = _calculate_daily_quantity_from_hours(travel_hours)
daily_rate = 0.0
daily_total = daily_qty * daily_rate
transport_total = float(work_order.servicer_vehicle_fuel_cost or 0.0)