[FIX] sale_timesheet: display timesheeted quantity correctly on sale order

There was a stat-button on sale orders coming from a task with
timesheet that displayed the quantity of timesheets linked to the
origin task. This stat-button was re labeled with the rimesheet uom
(hours/days/...) but the field still displayed the number of
timesheets instead of the total timesheeted amount in the correct
uom.

This commit introduces a new computed field on the sale order, which
computes the amount of time on timesheets depending on the used uom.

The compute method uses the product_uom_hour record as it is the uom
in which the amount is stored on the model, that record is guaranteed
to exist as it's model unlink method was overridden to prevent
removing working-time uom.

Task-2065079
This commit is contained in:
MaxLarue
2019-09-17 06:51:23 +00:00
committed by jem-odoo
parent dde0746725
commit 21a51d04c3
2 changed files with 15 additions and 1 deletions
@@ -24,6 +24,7 @@ class SaleOrder(models.Model):
help='Select a non billable project on which tasks can be created.')
project_ids = fields.Many2many('project.project', compute="_compute_project_ids", string='Projects', copy=False, groups="project.group_project_user", help="Projects used in this sales order.")
timesheet_encode_uom_id = fields.Many2one('uom.uom', related='company_id.timesheet_encode_uom_id')
timesheet_total_duration = fields.Float("Timesheet Total Duration", compute='_compute_timesheet_total_duration', help="Total recorded duration, expressed in the encoding UoM")
@api.depends('analytic_account_id.line_ids')
def _compute_timesheet_ids(self):
@@ -60,6 +61,18 @@ class SaleOrder(models.Model):
projects |= order.project_id
order.project_ids = projects
@api.depends('timesheet_ids', 'company_id.timesheet_encode_uom_id')
def _compute_timesheet_total_duration(self):
for sale_order in self:
duration_list = []
for timesheet in sale_order.timesheet_ids:
timesheet_uom = timesheet.product_uom_id or timesheet.company_id.project_time_mode_id
if timesheet_uom != sale_order.timesheet_encode_uom_id and timesheet_uom.category_id == sale_order.timesheet_encode_uom_id.category_id:
duration_list.append(timesheet_uom._compute_quantity(timesheet.unit_amount, sale_order.timesheet_encode_uom_id))
else:
duration_list.append(timesheet.unit_amount)
sale_order.timesheet_total_duration = sum(duration_list)
@api.onchange('project_id')
def _onchange_project_id(self):
""" Set the SO analytic account to the selected project's analytic account """
@@ -26,6 +26,7 @@
groups="project.group_project_user">
<field name="tasks_count" widget="statinfo" string="Tasks"/>
</button>
<field name="timesheet_count" invisible="1" />
<button type="object"
name="action_view_timesheet"
class="oe_stat_button"
@@ -34,7 +35,7 @@
groups="hr_timesheet.group_hr_timesheet_user">
<div class="o_field_widget o_stat_info">
<span class="o_stat_value">
<field name="timesheet_count" class="mr4"/>
<field name="timesheet_total_duration" class="mr4" widget="timesheet_uom"/>
<field name="timesheet_encode_uom_id" options="{'no_open' : True}"/>
</span>
<span class="o_stat_text">Recorded</span>