| 1 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 |
|
| 3 |
from odoo import fields, models, api |
| 4 |
|
| 5 |
|
| 6 |
class ProjectUpdate(models.Model): |
| 7 |
_inherit = "project.update" |
| 8 |
|
| 9 |
display_timesheet_stats = fields.Boolean(compute="_compute_display_timesheet_stats", export_string_translation=False) |
| 10 |
allocated_time = fields.Integer("Allocated Time", readonly=True) |
| 11 |
timesheet_time = fields.Integer("Timesheet Time", readonly=True) |
| 12 |
timesheet_percentage = fields.Integer(compute="_compute_timesheet_percentage", export_string_translation=False) |
| 13 |
uom_id = fields.Many2one("uom.uom", "Unit", readonly=True, export_string_translation=False) |
| 14 |
|
| 15 |
def _compute_timesheet_percentage(self): |
| 16 |
for update in self: |
| 17 |
update.timesheet_percentage = update.allocated_time and round(update.timesheet_time * 100 / update.allocated_time) |
| 18 |
|
| 19 |
def _compute_display_timesheet_stats(self): |
| 20 |
for update in self: |
| 21 |
update.display_timesheet_stats = update.project_id.allow_timesheets |
| 22 |
|
| 23 |
# --------------------------------- |
| 24 |
# ORM Override |
| 25 |
# --------------------------------- |
| 26 |
@api.model_create_multi |
| 27 |
def create(self, vals_list): |
| 28 |
updates = super().create(vals_list) |
| 29 |
encode_uom = self.env.company.timesheet_encode_uom_id |
| 30 |
ratio = self.env.ref("uom.product_uom_hour").factor / encode_uom.factor |
| 31 |
for update in updates: |
| 32 |
project = update.project_id |
| 33 |
project.sudo().last_update_id = update |
| 34 |
update.write({ |
| 35 |
"uom_id": encode_uom, |
| 36 |
"allocated_time": round(project.allocated_hours * ratio), |
| 37 |
"timesheet_time": round(project.sudo().total_timesheet_time), |
| 38 |
}) |
| 39 |
return updates |