Project amount and per updated per consul in report

This commit is contained in:
prakash 2022-04-26 10:25:20 +05:30
parent d12bc8939d
commit af77ddde0a
1 changed files with 43 additions and 30 deletions

View File

@ -86,7 +86,7 @@ class ProjectRevenueCustomReport(models.Model):
0.0 AS actual_revenue,
(AAL.amount * -1) AS actual_cost,
0.0 AS expenses_amt,
0.0 AS profit_amt,
0.0 - (AAL.amount * -1) AS profit_amt,
0.0 AS profit_per,
AAL.unit_amount,
((AAL.amount * -1)/NULLIF(AAL.unit_amount, 0)) as timesheet_cost,
@ -110,9 +110,9 @@ class ProjectRevenueCustomReport(models.Model):
0.0 AS overall_hourly_rate,
0.0 AS actual_revenue,
0.0 AS actual_cost,
pro.expenses_amt AS expenses_amt,
pro.profit_amt,
pro.profit_per,
pro.expenses_amt AS expenses_amt,
0.0 AS profit_amt,
0.0 AS profit_per,
0.0 as unit_amount,
0.0 as timesheet_cost,
null::timestamp as timesheet_sdatetime
@ -134,8 +134,8 @@ class ProjectRevenueCustomReport(models.Model):
(AAL.unit_amount * pro.hourly_rate) AS actual_revenue,
(AAL.amount * -1) AS actual_cost,
0.0 AS expenses_amt,
0.0 AS profit_amt,
0.0 AS profit_per,
((AAL.unit_amount * pro.hourly_rate) - (AAL.amount * -1)) AS profit_amt,
((AAL.unit_amount * pro.hourly_rate) - (AAL.amount * -1))/NULLIF((AAL.unit_amount * pro.hourly_rate),0) AS profit_per,
AAL.unit_amount,
((AAL.amount * -1)/NULLIF(AAL.unit_amount, 0)) as timesheet_cost,
AAL.start_datetime AS timesheet_sdatetime
@ -185,8 +185,8 @@ class ProjectRevenueCustomReport(models.Model):
0.0 AS actual_revenue,
0.0 AS actual_cost,
pro.expenses_amt AS expenses_amt,
pro.profit_amt,
pro.profit_per,
0.0 as profit_amt,
0.0 as profit_per,
0.0 as unit_amount,
0.0 as timesheet_cost,
null::timestamp as timesheet_sdatetime
@ -208,8 +208,10 @@ class ProjectRevenueCustomReport(models.Model):
(AAL.unit_amount * pro_emp.price_unit) AS actual_revenue,
case when pro_emp.employee_price is null then (AAL.amount * -1) else (AAL.unit_amount * pro_emp.employee_price) end as actual_cost,
0.0 AS expenses_amt,
0.0 AS profit_amt,
0.0 AS profit_per,
(AAL.unit_amount * pro_emp.price_unit) - case when pro_emp.employee_price is null then (AAL.amount * -1) else (AAL.unit_amount * pro_emp.employee_price) end
as profit_amt,
(((AAL.unit_amount * pro_emp.price_unit) - case when pro_emp.employee_price is null then (AAL.amount * -1) else (AAL.unit_amount * pro_emp.employee_price) end)
/ NULLIF((AAL.unit_amount * pro_emp.price_unit), 0)) * 100 as profit_per,
AAL.unit_amount,
case when pro_emp.employee_price is null then ((AAL.amount * -1)/NULLIF(AAL.unit_amount, 0)) else pro_emp.employee_price end as timesheet_cost,
AAL.start_datetime AS timesheet_sdatetime
@ -229,25 +231,36 @@ class ProjectRevenueCustomReport(models.Model):
#accounts = self.env['account.analytic.account']
for line in res:
hourly_rate = 0
if 'pro_hourly_rate' in line:
hourly_rate = line['pro_hourly_rate']
if 'unit_amount' in line and 'pro_hourly_rate' in line and 'id' in line:
if hourly_rate != 0:
line['actual_revenue'] = hourly_rate * line['unit_amount']
if 'unit_amount' in line and 'timesheet_cost' in line and 'id' in line:
line['actual_cost'] = line['timesheet_cost'] * line['unit_amount']
if 'overall_budgeted_revenue' in line and 'budgeted_hours' in line and 'id' in line:
if line['budgeted_hours'] > 0:
line['overall_hourly_rate'] = line['overall_budgeted_revenue'] / line['budgeted_hours']
if 'pro_hourly_rate' in line and 'budgeted_hours' in line and 'id' in line:
if line['budgeted_hours'] > 0:
line['pro_hourly_rate'] = line['budgeted_revenue'] / line['budgeted_hours']
if 'actual_revenue' in line and 'actual_cost' in line and 'expenses_amt' in line and 'id' in line:
line['profit_amt'] = line['actual_revenue'] - line['actual_cost'] - line['expenses_amt']
if 'profit_amt' in line and 'actual_revenue' in line and 'id' in line:
try:
line['profit_per'] = (line['profit_amt'] / line['actual_revenue']) * 100
except ZeroDivisionError:
pass
actual_cost = 0
try:
if 'pro_hourly_rate' in line:
actual_cost = line['actual_cost']
if 'actual_cost' in line:
hourly_rate = line['pro_hourly_rate']
if 'unit_amount' in line and 'pro_hourly_rate' in line and 'id' in line:
if hourly_rate != 0:
line['actual_revenue'] = hourly_rate * line['unit_amount']
if 'unit_amount' in line and 'timesheet_cost' in line and 'id' in line:
line['actual_cost'] = line['timesheet_cost'] * line['unit_amount']
if 'overall_budgeted_revenue' in line and 'budgeted_hours' in line and 'id' in line:
if line['budgeted_hours'] > 0:
line['overall_hourly_rate'] = line['overall_budgeted_revenue'] / line['budgeted_hours']
if 'pro_hourly_rate' in line and 'budgeted_hours' in line and 'id' in line:
if line['budgeted_hours'] > 0:
line['pro_hourly_rate'] = line['budgeted_revenue'] / line['budgeted_hours']
if 'actual_revenue' in line and 'actual_cost' in line and 'expenses_amt' in line and 'id' in line:
line['profit_amt'] = line['actual_revenue'] - line['actual_cost'] - line['expenses_amt']
if 'profit_amt' in line and 'actual_revenue' in line and 'id' in line:
try:
line['profit_per'] = (line['profit_amt'] / line['actual_revenue']) * 100
except ZeroDivisionError:
pass
if 'unit_amount' in line and 'id' in line:
try:
line['timesheet_cost'] = actual_cost / line['unit_amount']
except ZeroDivisionError:
pass
except Exception:
pass
return res