Two bar chart report updated

This commit is contained in:
projectsodoo 2020-12-31 11:54:34 +05:30
parent e6db96d923
commit 77b49e1e3a
4 changed files with 67 additions and 32 deletions

View File

@ -8,15 +8,17 @@ class BudgetAmtAnalysis(models.Model):
_name = "project.budget.amt.report"
_description = "Project budget amount analysis report"
_order = 'project_id'
#_order = 'project_id'
_auto = False
#analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account', readonly=True)
project_id = fields.Many2one('project.project', string='Project', readonly=True)
partner_id = fields.Many2one('res.partner', string='Client', readonly=True)
amount_type = fields.Char(string="Amount Type")
revenue = fields.Float("Revenue", digits=(16, 2), readonly=True, group_operator="sum")
#employee_id = fields.Many2one('hr.employee', string='Employee', readonly=True)
budgeted_revenue = fields.Float("Budgeted Revenue", digits=(16, 2), readonly=True, group_operator="sum")
actual_revenue = fields.Float("Actual Revenue", digits=(16, 2), readonly=True, group_operator="sum")
#budgeted_revenue = fields.Float("Budgeted Revenue", digits=(16, 2), readonly=True, group_operator="sum")
#actual_revenue = fields.Float("Actual Revenue", digits=(16, 2), readonly=True, group_operator="sum")
def init(self):
'''Create the view'''
@ -26,15 +28,32 @@ class BudgetAmtAnalysis(models.Model):
SELECT
row_number() OVER() AS id,
PRO.id AS project_id,
PRO.create_date AS create_date,
PRO.partner_id AS partner_id,
PRO.budgeted_revenue AS budgeted_revenue,
SO.amount_total AS actual_revenue
'Budgeted Revenue' as amount_type,
PRO.budgeted_revenue AS revenue
--SO.amount_total AS actual_revenue
FROM project_project PRO
LEFT JOIN sale_order SO ON PRO.sale_order_id = SO.id
LEFT JOIN account_analytic_account AA ON PRO.analytic_account_id = AA.id
LEFT JOIN account_analytic_line AAL ON AAL.account_id = AA.id and AAL.project_id = PRO.id
WHERE PRO.active = 't' and PRO.pricing_type!='fixed_rate'
group by Pro.id, PRO.partner_id, Pro.budgeted_revenue, so.amount_total
union
SELECT
row_number() OVER() AS id,
PRO.id AS project_id,
PRO.create_date AS create_date,
PRO.partner_id AS partner_id,
'Actual Revenue' as amount_type,
SO.amount_total AS revenue
FROM project_project PRO
LEFT JOIN sale_order SO ON PRO.sale_order_id = SO.id
LEFT JOIN account_analytic_account AA ON PRO.analytic_account_id = AA.id
LEFT JOIN account_analytic_line AAL ON AAL.account_id = AA.id and AAL.project_id = PRO.id
WHERE PRO.active = 't' and PRO.pricing_type!='fixed_rate'
group by Pro.id, PRO.partner_id, Pro.budgeted_revenue, so.amount_total
order by create_date desc, project_id, amount_type desc
)""" % (self._table,))

View File

@ -6,9 +6,9 @@
<field name="model">project.budget.amt.report</field>
<field name="arch" type="xml">
<pivot string="Budget Analysis" disable_linking="True" sample="1"> <!-- display_quantity="true" -->
<field name="project_id" type="row"/>
<field name="budgeted_revenue" type="measure"/>
<field name="actual_revenue" type="measure"/>
<field name="project_id" type="col"/>
<field name="amount_type" type="col"/>
<field name="revenue" type="measure"/>
</pivot>
</field>
</record>
@ -17,10 +17,11 @@
<field name="name">project.budget.amt.report.graph</field>
<field name="model">project.budget.amt.report</field>
<field name="arch" type="xml">
<graph string="Budget Analysis" type="bar" stacked="True" sample="1" disable_linking="1">
<field name="budgeted_revenue" type="row"/>
<graph string="Budget Analysis" type="bar" stacked="False" sample="1" disable_linking="1">
<field name="revenue" type="row"/>
<field name="project_id" type="row"/>
<field name="actual_revenue" type="measure"/>
<field name="amount_type" type="row"/>
<field name="revenue" type="measure"/>
</graph>
</field>
</record>
@ -37,6 +38,7 @@
<group expand="1" string="Group By">
<filter string="Project" name="group_by_project" context="{'group_by':'project_id'}"/>
<filter string="Customer" name="group_by_partner_id" context="{'group_by':'partner_id'}"/>
<filter string="Amount type" name="group_by_amount_type" context="{'group_by':'amount_type'}"/>
<!--<filter string="Consultant" name="group_by_employee_id" context="{'group_by':'employee_id'}"/>-->
</group>
</search>
@ -48,10 +50,7 @@
<field name="res_model">project.budget.amt.report</field>
<field name="view_mode">pivot,graph</field>
<field name="search_view_id" ref="project_budget_amt_report_view_search"/>
<field name="context">{
'group_by_no_leaf':1,
'group_by':[],
}</field>
<field name="context">{'search_default_group_by_project': 1,'search_default_group_by_amount_type': 1}</field>
</record>
<menuitem id="menu_project_budget_report_amt_analysis"

View File

@ -8,30 +8,33 @@ class BudgetHrsAnalysis(models.Model):
_name = "project.budget.hrs.report"
_description = "Project budget hours analysis report"
_order = 'project_id'
#_order = 'project_id'
_auto = False
#analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account', readonly=True)
project_id = fields.Many2one('project.project', string='Project', readonly=True)
partner_id = fields.Many2one('res.partner', string='Client', readonly=True)
employee_id = fields.Many2one('hr.employee', string='Employee', readonly=True)
budgeted_hours = fields.Float("Budgeted Hours", digits=(16, 2), readonly=True, group_operator="sum")
actual_hours = fields.Float("Actual Hours", digits=(16, 2), readonly=True, group_operator="sum")
hours_type = fields.Char(string="Hours Type")
hours = fields.Float("Hours", digits=(16, 2), readonly=True, group_operator="sum")
#budgeted_hours = fields.Float("Budgeted Hours", digits=(16, 2), readonly=True, group_operator="sum")
#actual_hours = fields.Float("Actual Hours", digits=(16, 2), readonly=True, group_operator="sum")
def init(self):
'''Create the view'''
tools.drop_view_if_exists(self._cr, self._table)
self._cr.execute("""
CREATE OR REPLACE VIEW %s AS (
SELECT row_number() OVER() AS id,
SELECT row_number() OVER() AS id,
PRO.id AS project_id,
PRO.create_date AS create_date,
PRO.partner_id AS partner_id,
Pro_emp.employee_id AS employee_id,
'Budgeted Hours' as hours_type,
CASE
WHEN Pro_emp.id is null THEN Pro.budgeted_hours
ELSE Pro_emp.budgeted_qty
END AS budgeted_hours,
sum(AAL.unit_amount) AS actual_hours
END AS hours
FROM project_project PRO
Left JOIN project_sale_line_employee_map Pro_emp ON Pro_emp.project_id = Pro.id
LEFT JOIN account_analytic_account AA ON Pro.analytic_account_id = AA.id
@ -39,6 +42,22 @@ class BudgetHrsAnalysis(models.Model):
and AAL.employee_id = Pro_emp.employee_id
Where PRO.active = 't' and PRO.pricing_type!='fixed_rate'
group by Pro.id, Pro_emp.id, PRO.partner_id, Pro_emp.employee_id, AAL.unit_amount
Union
SELECT row_number() OVER() AS id,
PRO.id AS project_id,
PRO.create_date AS create_date,
PRO.partner_id AS partner_id,
Pro_emp.employee_id AS employee_id,
'Actual Hours' as hours_type,
sum(AAL.unit_amount) AS hours
FROM project_project PRO
Left JOIN project_sale_line_employee_map Pro_emp ON Pro_emp.project_id = Pro.id
LEFT JOIN account_analytic_account AA ON Pro.analytic_account_id = AA.id
LEFT JOIN account_analytic_line AAL ON AAL.account_id = AA.id and AAL.project_id = Pro.id
and AAL.employee_id = Pro_emp.employee_id
Where PRO.active = 't' and PRO.pricing_type!='fixed_rate'
group by Pro.id, Pro_emp.id, PRO.partner_id, Pro_emp.employee_id, AAL.unit_amount
order by create_date desc, project_id, employee_id, hours_type desc
)""" % (self._table,))

View File

@ -5,10 +5,10 @@
<field name="name">project.budget.hrs.report.pivot</field>
<field name="model">project.budget.hrs.report</field>
<field name="arch" type="xml">
<pivot string="Budget Analysis" disable_linking="True" sample="1"> <!-- display_quantity="true" -->
<field name="project_id" type="row"/>
<field name="budgeted_hours" type="measure"/>
<field name="actual_hours" type="measure"/>
<pivot string="Budget Analysis" disable_linking="True" sample="1"> <!-- display_quantity="true" -->
<field name="project_id" type="col"/>
<field name="hours_type" type="col"/>
<field name="hours" type="measure"/>
</pivot>
</field>
</record>
@ -17,10 +17,10 @@
<field name="name">project.budget.hrs.report.graph</field>
<field name="model">project.budget.hrs.report</field>
<field name="arch" type="xml">
<graph string="Budget Analysis" type="bar" stacked="True" sample="1" disable_linking="1">
<field name="budgeted_hours" type="row"/>
<graph string="Budget Analysis" type="bar" stacked="False" sample="1" disable_linking="1">
<field name="project_id" type="row"/>
<field name="actual_hours" type="measure"/>
<field name="hours_type" type="row"/>
<field name="hours" type="measure"/>
</graph>
</field>
</record>
@ -38,6 +38,7 @@
<filter string="Project" name="group_by_project" context="{'group_by':'project_id'}"/>
<filter string="Customer" name="group_by_partner_id" context="{'group_by':'partner_id'}"/>
<filter string="Consultant" name="group_by_employee_id" context="{'group_by':'employee_id'}"/>
<filter string="Hours type" name="group_by_hours_type" context="{'group_by':'hours_type'}"/>
</group>
</search>
</field>
@ -49,10 +50,7 @@
<field name="res_model">project.budget.hrs.report</field>
<field name="view_mode">pivot,graph</field>
<field name="search_view_id" ref="project_budget_hrs_report_view_search"/>
<field name="context">{
'group_by_no_leaf':1,
'group_by':[],
}</field>
<field name="context">{'search_default_group_by_project': 1,'search_default_group_by_hours_type': 1}</field>
</record>
<menuitem id="menu_project_budget_report_hrs_analysis"