From 8c69cac53725c5a3ceb2d3c1da49dc0736f99194 Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Mon, 23 May 2022 18:49:05 +0000 Subject: [PATCH] [IMP] sale_timesheet_work_entry_rate: compute billing amount, display --- .../__manifest__.py | 4 ++- .../models/timesheet.py | 10 +++++++- .../tests/test_sale_flow.py | 3 +++ .../views/account_templates.xml | 17 +++++++++++++ .../views/timesheet_views.xml | 25 +++++++++++++------ 5 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 sale_timesheet_work_entry_rate/views/account_templates.xml diff --git a/sale_timesheet_work_entry_rate/__manifest__.py b/sale_timesheet_work_entry_rate/__manifest__.py index 7b88a4f5..05dc940a 100644 --- a/sale_timesheet_work_entry_rate/__manifest__.py +++ b/sale_timesheet_work_entry_rate/__manifest__.py @@ -2,7 +2,7 @@ { 'name': 'Timesheet Billing Rate', - 'version': '15.0.1.0.0', + 'version': '15.0.1.1.0', 'category': 'Sale', 'author': 'Hibou Corp.', 'license': 'OPL-1', @@ -10,9 +10,11 @@ 'depends': [ 'hibou_professional', 'hr_timesheet_work_entry', + 'timesheet_invoice', 'sale_timesheet', ], 'data': [ + 'views/account_templates.xml', 'views/timesheet_views.xml', 'views/work_entry_views.xml', ], diff --git a/sale_timesheet_work_entry_rate/models/timesheet.py b/sale_timesheet_work_entry_rate/models/timesheet.py index 799db068..aa8ac4bb 100644 --- a/sale_timesheet_work_entry_rate/models/timesheet.py +++ b/sale_timesheet_work_entry_rate/models/timesheet.py @@ -1,9 +1,17 @@ # Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. -from odoo import fields, models +from odoo import api, fields, models class AccountAnalyticLine(models.Model): _inherit = 'account.analytic.line' work_billing_rate = fields.Float(related='work_type_id.timesheet_billing_rate', string='Billing Multiplier') + work_billing_amount = fields.Float(string='Billing Amount', + compute='_compute_work_billing_amount', store=True) + + @api.depends('unit_amount', 'work_billing_rate') + def _compute_work_billing_amount(self): + for ts in self: + ts.work_billing_amount = ts.unit_amount * \ + (ts.work_billing_rate if ts.work_type_id else 1.0) diff --git a/sale_timesheet_work_entry_rate/tests/test_sale_flow.py b/sale_timesheet_work_entry_rate/tests/test_sale_flow.py index 01bd1cd8..95d8ad40 100644 --- a/sale_timesheet_work_entry_rate/tests/test_sale_flow.py +++ b/sale_timesheet_work_entry_rate/tests/test_sale_flow.py @@ -29,6 +29,7 @@ class TestSaleFlow(TestProjectBilling): }) self.assertEqual(task.sale_line_id, timesheet1.so_line, "The timesheet should be linked to the SOL associated to the task since the pricing type of the project is task rate.") + self.assertEqual(timesheet1.work_billing_amount, 50.0) # create a subtask subtask = Task.with_context(default_project_id=self.project_task_rate.id).create({ @@ -78,6 +79,7 @@ class TestSaleFlow(TestProjectBilling): timesheet1.write({ 'work_type_id': double_rate_work_entry_type.id, }) + self.assertEqual(timesheet1.work_billing_amount, 100.0) self.assertEqual(task.sale_line_id.qty_delivered, 100.0) # Ensure that a created timesheet WITHOUT a work entry type behaves @@ -98,3 +100,4 @@ class TestSaleFlow(TestProjectBilling): 'work_type_id': zero_rate_work_entry_type.id, }) self.assertEqual(task.sale_line_id.qty_delivered, 0.0) + self.assertEqual(timesheet1.work_billing_amount, 0.0) diff --git a/sale_timesheet_work_entry_rate/views/account_templates.xml b/sale_timesheet_work_entry_rate/views/account_templates.xml new file mode 100644 index 00000000..e730f64d --- /dev/null +++ b/sale_timesheet_work_entry_rate/views/account_templates.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/sale_timesheet_work_entry_rate/views/timesheet_views.xml b/sale_timesheet_work_entry_rate/views/timesheet_views.xml index 8889c43f..89cfb1f9 100644 --- a/sale_timesheet_work_entry_rate/views/timesheet_views.xml +++ b/sale_timesheet_work_entry_rate/views/timesheet_views.xml @@ -6,17 +6,26 @@ project.task - - + + - - + + + +