[IMP] sale_timesheet: change timesheet action to get the correct pivot
Before this commit, in the project right side panel, we use the action used with the stat button displayed in project form view. This action has a pivot view grouped by invoice type. However, in the right side panel, the timesheet invoice types shown in revenues and costs subsection of the project profitability section does not need this group by but we would like to group by invoice (if the row concerned "Timesheet (Billed on Time)") or group by employee (for the other rows) This commit changes the action to use the action as template created for Sales section in project right side panel. With this changes, we no longer have to change the views to have the ones expected, we will just change the pivot view according to the row selected (concerning the timesheets part) in Profitability section. task-2814466 Part-of: odoo/odoo#88219
This commit is contained in:
@@ -286,23 +286,14 @@ class Project(models.Model):
|
||||
|
||||
def action_billable_time_button(self):
|
||||
self.ensure_one()
|
||||
action = self.env["ir.actions.actions"]._for_xml_id("hr_timesheet.timesheet_action_all")
|
||||
action = self.env["ir.actions.actions"]._for_xml_id("sale_timesheet.timesheet_action_from_sales_order_item")
|
||||
action.update({
|
||||
'context': {
|
||||
'grid_range': 'week',
|
||||
'search_default_groupby_timesheet_invoice_type': True,
|
||||
'pivot_row_groupby': ['date:month'],
|
||||
'default_project_id': self.id,
|
||||
},
|
||||
'domain': [('project_id', '=', self.id)],
|
||||
'view_mode': 'tree,kanban,pivot,graph,form',
|
||||
'views': [
|
||||
[self.env.ref('hr_timesheet.timesheet_view_tree_user').id, 'tree'],
|
||||
[self.env.ref('hr_timesheet.view_kanban_account_analytic_line').id, 'kanban'],
|
||||
[self.env.ref('sale_timesheet.view_hr_timesheet_line_pivot_billing_rate').id, 'pivot'],
|
||||
[self.env.ref('hr_timesheet.view_hr_timesheet_line_graph_all').id, 'graph'],
|
||||
[self.env.ref('hr_timesheet.timesheet_view_form_user').id, 'form'],
|
||||
],
|
||||
})
|
||||
return action
|
||||
|
||||
@@ -310,10 +301,18 @@ class Project(models.Model):
|
||||
self.ensure_one()
|
||||
if section_name in ['billable_fixed', 'billable_time', 'billable_milestones', 'billable_manual', 'non_billable']:
|
||||
action = self.action_billable_time_button()
|
||||
action['name'] = _('Timesheets')
|
||||
if domain:
|
||||
action['domain'] = expression.AND([[('project_id', '=', self.id)], domain])
|
||||
action['context'].update(search_default_groupby_timesheet_invoice_type=False, **self.env.context)
|
||||
pivot_view = False
|
||||
if section_name == 'billable_time':
|
||||
pivot_view = self.env.ref('sale_timesheet.view_hr_timesheet_pivot_view_per_invoice').id
|
||||
else:
|
||||
pivot_view = self.env.ref('sale_timesheet.timesheet_view_pivot_revenue').id
|
||||
action['views'] = [
|
||||
(view_id, view_type) if view_type != 'pivot' else (pivot_view, view_type)
|
||||
for view_id, view_type in action['views']
|
||||
]
|
||||
if res_id:
|
||||
if 'views' in action:
|
||||
action['views'] = [
|
||||
@@ -322,8 +321,7 @@ class Project(models.Model):
|
||||
if view_type == 'form'
|
||||
] or [False, 'form']
|
||||
action['view_mode'] = 'form'
|
||||
if res_id:
|
||||
action['res_id'] = res_id
|
||||
action['res_id'] = res_id
|
||||
return action
|
||||
return super().action_profitability_items(section_name, domain, res_id)
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
<field name="employee_id" type="row"/>
|
||||
<field name="date" interval="month" type="col"/>
|
||||
<field name="unit_amount" type="measure"/>
|
||||
<field name="amount" string="Timesheet Costs"/>
|
||||
</pivot>
|
||||
</field>
|
||||
</record>
|
||||
@@ -68,6 +69,7 @@
|
||||
<field name="model">account.analytic.line</field>
|
||||
<field name="arch" type="xml">
|
||||
<pivot string="Timesheets" sample="1">
|
||||
<field name="date" interval="month" type="row"/>
|
||||
<field name="timesheet_invoice_type" type="col"/>
|
||||
<field name="unit_amount" type="measure" widget="timesheet_uom"/>
|
||||
<field name="amount" string="Timesheet Costs"/>
|
||||
@@ -75,6 +77,18 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_hr_timesheet_pivot_view_per_invoice" model="ir.ui.view">
|
||||
<field name="name">account.analytic.line.pivot.per.invoice</field>
|
||||
<field name="model">account.analytic.line</field>
|
||||
<field name="inherit_id" ref="view_hr_timesheet_line_pivot_billing_rate"/>
|
||||
<field name="mode">primary</field>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='timesheet_invoice_type']" position="attributes">
|
||||
<attribute name="name">timesheet_invoice_id</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!--
|
||||
Timesheet from Sales Order
|
||||
-->
|
||||
|
||||
Reference in New Issue
Block a user