From 439836ba63cb6c4ade35b63791728bb24bc7ef12 Mon Sep 17 00:00:00 2001 From: "Audric Onockx (auon)" Date: Thu, 5 May 2022 13:04:14 +0000 Subject: [PATCH] [IMP] sale_{project,timesheet} : format hours and differenciate sol With this improvement, * in the Project Updates kanban/tree side pannel : > Hours are displayed 'HH:mm Hours' * in the Project Updates form description : > idem > Sales Order Items with the same products also display their price to differentiate them. task-2841685 closes odoo/odoo#90624 Related: odoo/enterprise#27753 Signed-off-by: Laurent Stukkens (ltu) --- .../src/right_panel/project_right_panel.js | 5 ++++ .../src/right_panel/project_right_panel.xml | 6 ++--- .../sale_timesheet/models/project_update.py | 25 +++++++++++++------ .../views/project_update_templates.xml | 12 ++++----- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/addons/sale_project/static/src/right_panel/project_right_panel.js b/addons/sale_project/static/src/right_panel/project_right_panel.js index dc2ceafccd4..5c3c3a509db 100644 --- a/addons/sale_project/static/src/right_panel/project_right_panel.js +++ b/addons/sale_project/static/src/right_panel/project_right_panel.js @@ -1,6 +1,7 @@ /** @odoo-module */ import { patch } from 'web.utils'; +import { formatFloatTime, formatFloat } from "@web/fields/formatters"; import ProjectRightPanel from '@project/js/right_panel/project_right_panel'; patch(ProjectRightPanel.prototype, '@sale_project/right_panel/project_right_panel', { @@ -24,5 +25,9 @@ patch(ProjectRightPanel.prototype, '@sale_project/right_panel/project_right_pane if (saleItems && saleItems.total > saleItems.data.length) { await this._loadAdditionalSalesOrderItems(); } + }, + + formatValue(value, unit) { + return unit === 'Hours' ? formatFloatTime(value) : formatFloat(value); } }); diff --git a/addons/sale_project/static/src/right_panel/project_right_panel.xml b/addons/sale_project/static/src/right_panel/project_right_panel.xml index 973f8eaaa33..a738bed8e50 100644 --- a/addons/sale_project/static/src/right_panel/project_right_panel.xml +++ b/addons/sale_project/static/src/right_panel/project_right_panel.xml @@ -42,9 +42,9 @@ - - - + + + diff --git a/addons/sale_timesheet/models/project_update.py b/addons/sale_timesheet/models/project_update.py index 9b0753191bb..5ac11adeaa1 100644 --- a/addons/sale_timesheet/models/project_update.py +++ b/addons/sale_timesheet/models/project_update.py @@ -3,6 +3,7 @@ from odoo import api, models from odoo.tools import float_utils, format_amount, formatLang +from odoo.tools.misc import format_duration class ProjectUpdate(models.Model): @@ -21,12 +22,14 @@ class ProjectUpdate(models.Model): 'show_activities': template_values['show_activities'] or show_sold or bool(profitability), 'services': services, 'profitability': profitability, + 'format_value': lambda value, is_hour: str(round(value, 2)) if not is_hour else format_duration(value), } @api.model def _get_services_values(self, project): if not project.allow_billable: return {} + services = [] total_sold, total_effective, total_remaining = 0, 0, 0 sols = self.env['sale.order.line'].search( @@ -35,33 +38,39 @@ class ProjectUpdate(models.Model): ('is_downpayment', '=', False), ]), ) - name_by_sol = dict(sols.name_get()) + name_by_sol = dict(sols.with_context(with_price_unit=True).name_get()) product_uom_unit = self.env.ref('uom.product_uom_unit') + product_uom_hour = self.env.ref('uom.product_uom_hour') + company_uom = self.env.company.timesheet_encode_uom_id for sol in sols: #We only want to consider hours and days for this calculation is_unit = sol.product_uom == product_uom_unit - if sol.product_uom.category_id == self.env.company.timesheet_encode_uom_id.category_id or is_unit: - product_uom_qty = sol.product_uom._compute_quantity(sol.product_uom_qty, self.env.company.timesheet_encode_uom_id, raise_if_failure=False) - qty_delivered = sol.product_uom._compute_quantity(sol.qty_delivered, self.env.company.timesheet_encode_uom_id, raise_if_failure=False) + if sol.product_uom.category_id == company_uom.category_id or is_unit: + product_uom_qty = sol.product_uom._compute_quantity(sol.product_uom_qty, company_uom, raise_if_failure=False) + qty_delivered = sol.product_uom._compute_quantity(sol.qty_delivered, company_uom, raise_if_failure=False) + unit = sol.product_uom if is_unit else company_uom services.append({ - 'name': name_by_sol[sol.id] if len(sols.order_id) > 1 else sol.name, + 'name': name_by_sol[sol.id], 'sold_value': product_uom_qty, 'effective_value': qty_delivered, 'remaining_value': product_uom_qty - qty_delivered, - 'unit': sol.product_uom.name if is_unit else self.env.company.timesheet_encode_uom_id.name, + 'unit': unit.name, 'is_unit': is_unit, + 'is_hour': unit == product_uom_hour, 'sol': sol, }) - if sol.product_uom.category_id == self.env.company.timesheet_encode_uom_id.category_id: + if sol.product_uom.category_id == company_uom.category_id: total_sold += product_uom_qty total_effective += qty_delivered total_remaining = total_sold - total_effective + return { 'data': services, 'total_sold': total_sold, 'total_effective': total_effective, 'total_remaining': total_remaining, - 'company_unit_name': self.env.company.timesheet_encode_uom_id.name, + 'company_unit_name': company_uom.name, + 'is_hour': company_uom == product_uom_hour, } @api.model diff --git a/addons/sale_timesheet/views/project_update_templates.xml b/addons/sale_timesheet/views/project_update_templates.xml index d1396388a78..b528e7766ae 100644 --- a/addons/sale_timesheet/views/project_update_templates.xml +++ b/addons/sale_timesheet/views/project_update_templates.xml @@ -17,15 +17,15 @@ - - - + + + Total - - - + + +