Skip to content
Permalink
Browse files

[FIX] sale_timesheet:

opw:1969143
  • Loading branch information...
simongoffin committed Apr 25, 2019
1 parent 82c1397 commit 871fd7e32c24a27e532426d31ace47a2b9708b2b
Showing with 35 additions and 7 deletions.
  1. +35 −7 addons/sale_timesheet/report/project_profitability_report_analysis.py
@@ -64,11 +64,11 @@ def init(self):
ELSE 0.0
END AS expense_amount_untaxed_invoiced,
CASE
WHEN SOL.qty_delivered_method IN ('timesheet', 'manual') THEN (SOL.untaxed_amount_to_invoice / CASE COALESCE(S.currency_rate, 0) WHEN 0 THEN 1.0 ELSE S.currency_rate END)
WHEN SOL.qty_delivered_method IN ('timesheet', 'manual') THEN (SOL.untaxed_amount_to_invoice / CASE COALESCE(S.currency_rate, 0) WHEN 0 THEN 1.0 ELSE S.currency_rate END)
ELSE 0.0
END AS amount_untaxed_to_invoice,
CASE
WHEN SOL.qty_delivered_method IN ('timesheet', 'manual') THEN (SOL.untaxed_amount_invoiced / CASE COALESCE(S.currency_rate, 0) WHEN 0 THEN 1.0 ELSE S.currency_rate END)
WHEN SOL.qty_delivered_method IN ('timesheet', 'manual') THEN ( COALESCE(SOL.untaxed_amount_invoiced, COST_SUMMARY.downpayment_invoiced )/ CASE COALESCE(S.currency_rate, 0) WHEN 0 THEN 1.0 ELSE S.currency_rate END)
ELSE 0.0
END AS amount_untaxed_invoiced,
COST_SUMMARY.timesheet_unit_amount AS timesheet_unit_amount,
@@ -83,15 +83,19 @@ def init(self):
sale_line_id,
SUM(timesheet_unit_amount) AS timesheet_unit_amount,
SUM(timesheet_cost) AS timesheet_cost,
SUM(expense_cost) AS expense_cost
SUM(expense_cost) AS expense_cost,
SUM(downpayment_to_invoice) AS downpayment_to_invoice,
SUM(downpayment_invoiced) AS downpayment_invoiced
FROM (
SELECT
P.id AS project_id,
P.analytic_account_id AS analytic_account_id,
TS.so_line AS sale_line_id,
SUM(TS.unit_amount) AS timesheet_unit_amount,
SUM(TS.amount) AS timesheet_cost,
0.0 AS expense_cost
0.0 AS expense_cost,
0.0 AS downpayment_to_invoice,
0.0 AS downpayment_invoiced
FROM account_analytic_line TS, project_project P
WHERE TS.project_id IS NOT NULL AND P.id = TS.project_id AND P.active = 't' AND P.allow_timesheets = 't'
GROUP BY P.id, TS.so_line
@@ -104,7 +108,9 @@ def init(self):
AAL.so_line AS sale_line_id,
0.0 AS timesheet_unit_amount,
0.0 AS timesheet_cost,
SUM(AAL.amount) AS expense_cost
SUM(AAL.amount) AS expense_cost,
0.0 AS downpayment_to_invoice,
0.0 AS downpayment_invoiced
FROM project_project P
LEFT JOIN account_analytic_account AA ON P.analytic_account_id = AA.id
LEFT JOIN account_analytic_line AAL ON AAL.account_id = AA.id
@@ -113,13 +119,33 @@ def init(self):
UNION
SELECT
P.id AS project_id,
P.analytic_account_id AS analytic_account_id,
MY_SOLS.id AS sale_line_id,
0.0 AS timesheet_unit_amount,
0.0 AS timesheet_cost,
0.0 AS expense_cost,
CASE WHEN MY_SOLS.invoice_status = 'to invoice' THEN MY_SOLS.price_reduce ELSE 0.0 END AS downpayment_to_invoice,
CASE WHEN MY_SOLS.invoice_status = 'invoiced' THEN MY_SOLS.price_reduce ELSE 0.0 END AS downpayment_invoiced
FROM project_project P
LEFT JOIN sale_order_line MY_SOL ON P.sale_line_id = MY_SOL.id
LEFT JOIN sale_order MY_S ON MY_SOL.order_id = MY_S.id
LEFT JOIN sale_order_line MY_SOLS ON MY_SOLS.order_id = MY_S.id
WHERE MY_SOLS.is_downpayment = 't'
GROUP BY P.id, MY_SOLS.id
UNION
SELECT
P.id AS project_id,
P.analytic_account_id AS analytic_account_id,
SOL.id AS sale_line_id,
0.0 AS timesheet_unit_amount,
0.0 AS timesheet_cost,
0.0 AS expense_cost
0.0 AS expense_cost,
0.0 AS downpayment_to_invoice,
0.0 AS downpayment_invoiced
FROM sale_order_line SOL
INNER JOIN project_project P ON SOL.project_id = P.id
WHERE P.active = 't' AND P.allow_timesheets = 't'
@@ -132,7 +158,9 @@ def init(self):
SOL.id AS sale_line_id,
0.0 AS timesheet_unit_amount,
0.0 AS timesheet_cost,
0.0 AS expense_cost
0.0 AS expense_cost,
0.0 AS downpayment_to_invoice,
0.0 AS downpayment_invoiced
FROM sale_order_line SOL
INNER JOIN project_task T ON SOL.task_id = T.id
INNER JOIN project_project P ON P.id = T.project_id

0 comments on commit 871fd7e

Please sign in to comment.
You can’t perform that action at this time.