This commit is contained in:
gsinghpal
2026-02-25 09:40:41 -05:00
parent 0e1aebe60b
commit e71bc503f9
69 changed files with 7537 additions and 82 deletions

View File

@@ -388,6 +388,30 @@ class FusionTechnicianTask(models.Model):
string='Notified At',
)
# ------------------------------------------------------------------
# RENTAL INSPECTION (added by fusion_rental)
# ------------------------------------------------------------------
rental_inspection_condition = fields.Selection([
('excellent', 'Excellent'),
('good', 'Good'),
('fair', 'Fair'),
('damaged', 'Damaged'),
], string='Inspection Condition')
rental_inspection_notes = fields.Text(
string='Inspection Notes',
)
rental_inspection_photo_ids = fields.Many2many(
'ir.attachment',
'technician_task_inspection_photo_rel',
'task_id',
'attachment_id',
string='Inspection Photos',
)
rental_inspection_completed = fields.Boolean(
string='Inspection Completed',
default=False,
)
# ------------------------------------------------------------------
# COMPUTED FIELDS
# ------------------------------------------------------------------
@@ -1608,22 +1632,37 @@ class FusionTechnicianTask(models.Model):
'res_id': self.purchase_order_id.id,
}
def _is_rental_pickup_task(self):
"""Check if this is a pickup task for a rental order."""
self.ensure_one()
return (
self.task_type == 'pickup'
and self.sale_order_id
and self.sale_order_id.is_rental_order
)
def action_complete_task(self):
"""Mark task as Completed."""
for task in self:
if task.status not in ('in_progress', 'en_route', 'scheduled'):
raise UserError(_("Task must be in progress to complete."))
if task._is_rental_pickup_task() and not task.rental_inspection_completed:
raise UserError(_(
"Rental pickup tasks require a security inspection before "
"completion. Please complete the inspection from the "
"technician portal first."
))
task.with_context(skip_travel_recalc=True).write({
'status': 'completed',
'completion_datetime': fields.Datetime.now(),
})
task._post_status_message('completed')
# Post completion notes to linked order chatter
if task.completion_notes and (task.sale_order_id or task.purchase_order_id):
task._post_completion_to_linked_order()
# Notify the person who scheduled the task
task._notify_scheduler_on_completion()
# Auto-advance ODSP status for delivery tasks
if (task.task_type == 'delivery'
and task.sale_order_id
and task.sale_order_id.x_fc_is_odsp_sale
@@ -1633,6 +1672,44 @@ class FusionTechnicianTask(models.Model):
"Delivery task completed by technician. Order marked as delivered.",
)
if task._is_rental_pickup_task():
task._apply_rental_inspection_results()
def _apply_rental_inspection_results(self):
"""Write inspection results from the task back to the rental order."""
self.ensure_one()
order = self.sale_order_id
if not order or not order.is_rental_order:
return
inspection_status = 'passed'
if self.rental_inspection_condition in ('fair', 'damaged'):
inspection_status = 'flagged'
vals = {
'rental_inspection_status': inspection_status,
'rental_inspection_notes': self.rental_inspection_notes or '',
}
if self.rental_inspection_photo_ids:
vals['rental_inspection_photo_ids'] = [(6, 0, self.rental_inspection_photo_ids.ids)]
order.write(vals)
if inspection_status == 'passed':
order._refund_security_deposit()
elif inspection_status == 'flagged':
order.activity_schedule(
'mail.mail_activity_data_todo',
date_deadline=fields.Date.today(),
summary=_("Review rental inspection: %s", order.name),
note=_(
"Technician flagged rental pickup for %s. "
"Condition: %s. Please review inspection photos and notes.",
order.partner_id.name,
self.rental_inspection_condition or 'Unknown',
),
user_id=order.user_id.id or self.env.uid,
)
def action_cancel_task(self):
"""Cancel the task. Sends cancellation email and reverts sale order if delivery."""
for task in self: