From 5b9c93ef0460745ab08700014b0cc52a20ff5ae6 Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Thu, 27 Oct 2022 13:42:35 +0000 Subject: [PATCH] [FIX] repair: handle uom without view exposure Previous fix https://github.com/odoo/odoo/commit/72dff43a4da277b002966f5fd4045b7f9a3855ad re-exposed uoms in the view even if the setting is not active, but we prefer to avoid this if possible. In order to do this we ensure that the uom is set even if it is not visible in the view. Most of these are already handled by compute methods, but except for `repair.fee` so we only add in a guarantee for that model. Note that the write case is included in cases when: - the uoms were previously activated and set => deactivated again - demo data has different uoms set and uoms setting is not active X-original-commit: 7e64ebb3d8d3f3d3749304a325eb073777b129dc Part-of: odoo/odoo#104900 --- addons/repair/models/repair.py | 10 +++++++++- addons/repair/views/repair_views.xml | 5 ----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/addons/repair/models/repair.py b/addons/repair/models/repair.py index 1426ebab4c6..4cfc2b9e9ef 100644 --- a/addons/repair/models/repair.py +++ b/addons/repair/models/repair.py @@ -816,7 +816,10 @@ class RepairFee(models.Model): domain="[('type', '=', 'service'), '|', ('company_id', '=', company_id), ('company_id', '=', False)]") product_uom_qty = fields.Float('Quantity', digits='Product Unit of Measure', required=True, default=1.0) price_unit = fields.Float('Unit Price', required=True, digits='Product Price') - product_uom = fields.Many2one('uom.uom', 'Product Unit of Measure', required=True, domain="[('category_id', '=', product_uom_category_id)]") + product_uom = fields.Many2one( + 'uom.uom', 'Product Unit of Measure', + compute='_compute_product_uom', store=True, readonly=False, precompute=True, + required=True, domain="[('category_id', '=', product_uom_category_id)]") product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id') price_subtotal = fields.Float('Subtotal', compute='_compute_price_total_and_subtotal', store=True, digits=0) price_total = fields.Float('Total', compute='_compute_price_total_and_subtotal', store=True, digits=0) @@ -833,6 +836,11 @@ class RepairFee(models.Model): fee.price_subtotal = taxes['total_excluded'] fee.price_total = taxes['total_included'] + @api.depends('product_id') + def _compute_product_uom(self): + for fee in self: + fee.product_uom = fee.product_id.uom_id + @api.onchange('repair_id', 'product_id', 'product_uom_qty') def onchange_product_id(self): """ On change of product it sets product quantity, tax account, name, diff --git a/addons/repair/views/repair_views.xml b/addons/repair/views/repair_views.xml index a847072c020..c5e81a4b062 100644 --- a/addons/repair/views/repair_views.xml +++ b/addons/repair/views/repair_views.xml @@ -83,7 +83,6 @@