|
|
@@ -101,13 +101,26 @@ class WebsiteHelpdeskHours(http.Controller):
|
|
|
SaleOrderLine = request.env["sale.order.line"].sudo()
|
|
|
|
|
|
# Use the same domain that Odoo uses in _get_last_sol_of_customer
|
|
|
- # This ensures we follow Odoo's standard procedure
|
|
|
- domain = [
|
|
|
+ # But extend it to include parent/child commercial partner
|
|
|
+ # And also include orders where the partner is the invoice or shipping address
|
|
|
+ # This is important for contacts that act as billing contacts for a company
|
|
|
+
|
|
|
+ # Base domain for partner matching
|
|
|
+ partner_domain = expression.OR([
|
|
|
+ [("order_partner_id", "child_of", partner.id)],
|
|
|
+ [("order_id.partner_invoice_id", "child_of", partner.id)],
|
|
|
+ [("order_id.partner_shipping_id", "child_of", partner.id)],
|
|
|
+ ])
|
|
|
+
|
|
|
+ base_domain = [
|
|
|
("company_id", "=", company.id),
|
|
|
- ("order_partner_id", "child_of", partner.id),
|
|
|
+ # ("order_partner_id", "child_of", partner.id), # Replaced by partner_domain
|
|
|
("state", "in", ["sale", "done"]),
|
|
|
("remaining_hours", ">", 0), # Only lines with remaining hours
|
|
|
]
|
|
|
+
|
|
|
+ # Combine base domain with partner domain
|
|
|
+ domain = expression.AND([base_domain, partner_domain])
|
|
|
|
|
|
# Check if sale_timesheet module is installed
|
|
|
has_sale_timesheet = "sale_timesheet" in request.env.registry._init_modules
|
|
|
@@ -181,11 +194,15 @@ class WebsiteHelpdeskHours(http.Controller):
|
|
|
|
|
|
# Calculate hours used from ALL prepaid lines (including those fully consumed)
|
|
|
# This gives a complete picture of hours used by the customer
|
|
|
- hours_used_domain = [
|
|
|
+
|
|
|
+ # Use the same extended partner domain
|
|
|
+ base_hours_used_domain = [
|
|
|
("company_id", "=", company.id),
|
|
|
- ("order_partner_id", "child_of", partner.id),
|
|
|
+ # ("order_partner_id", "child_of", partner.id),
|
|
|
("state", "in", ["sale", "done"]),
|
|
|
]
|
|
|
+
|
|
|
+ hours_used_domain = expression.AND([base_hours_used_domain, partner_domain])
|
|
|
|
|
|
if has_sale_timesheet:
|
|
|
try:
|