From 2c5ce41c423e6ab92053b1f082086035bdc151f8 Mon Sep 17 00:00:00 2001 From: yhu-odoo Date: Mon, 17 Aug 2020 08:45:28 +0000 Subject: [PATCH] [IMP] uom: change default rounding to two Change the default rouning digits of all UoMs to be two, also change the decimal.precision of UoM to be two. Adapt all the tests. Also to avoid hardcoded digits in `should_consume_qty` widget. PR #56000 X-original-commit: 460ec0402a2352a5b179d81935f7230f6bc97cb7 --- addons/mrp/models/mrp_production.py | 2 +- addons/mrp/models/stock_move.py | 2 +- .../mrp/static/src/js/mrp_should_consume.js | 3 +- addons/mrp/tests/test_order.py | 63 ------------------- addons/mrp/tests/test_traceability.py | 2 +- addons/mrp/views/mrp_production_views.xml | 2 +- .../static/tests/tours/point_of_sale.js | 4 +- addons/product/data/product_data.xml | 2 +- .../tours/purchase_product_matrix_tour.js | 4 +- addons/sale/tests/test_sale_to_invoice.py | 8 +-- addons/sale_mrp/tests/test_sale_mrp_flow.py | 10 +-- .../tours/product_configurator_edition_ui.js | 2 +- .../tests/tours/sale_product_matrix_tour.js | 4 +- addons/stock/tests/test_packing.py | 4 +- addons/stock/tests/test_stock_flow.py | 2 + addons/uom/data/uom_data.xml | 2 - addons/uom/tests/test_uom.py | 2 +- 17 files changed, 26 insertions(+), 92 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 4b1703e4da5..250935da182 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -102,7 +102,7 @@ class MrpProduction(models.Model): lot_producing_id = fields.Many2one( 'stock.production.lot', string='Lot/Serial Number', copy=False, domain="[('product_id', '=', product_id), ('company_id', '=', company_id)]", check_company=True) - qty_producing = fields.Float(string="Quantity Producing", copy=False) + qty_producing = fields.Float(string="Quantity Producing", digits='Product Unit of Measure', copy=False) product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id') product_uom_qty = fields.Float(string='Total Quantity', compute='_compute_product_uom_qty', store=True) picking_type_id = fields.Many2one( diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index 2f76496467c..044c6208fc9 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -107,7 +107,7 @@ class StockMove(models.Model): store=True, help='Technical Field to order moves') order_finished_lot_ids = fields.Many2many('stock.production.lot', string="Finished Lot/Serial Number", compute='_compute_order_finished_lot_ids') - should_consume_qty = fields.Float('Quantity To Consume', compute='_compute_should_consume_qty') + should_consume_qty = fields.Float('Quantity To Consume', compute='_compute_should_consume_qty', digits='Product Unit of Measure') def _unreserve_initial_demand(self, new_move): # If you were already putting stock.move.lots on the next one in the work order, transfer those to the new move diff --git a/addons/mrp/static/src/js/mrp_should_consume.js b/addons/mrp/static/src/js/mrp_should_consume.js index dcf236a09f1..d432c5cf3f7 100644 --- a/addons/mrp/static/src/js/mrp_should_consume.js +++ b/addons/mrp/static/src/js/mrp_should_consume.js @@ -20,8 +20,7 @@ const MrpShouldConsume = FieldFloat.extend({ init: function (parent, name, params) { this._super.apply(this, arguments); this.displayShouldConsume = !['done', 'draft', 'cancel'].includes(params.data.state); - const options = {'digits': [false, 3]}; - this.should_consume_qty = field_utils.format.float(params.data.should_consume_qty, false, options); + this.should_consume_qty = field_utils.format.float(params.data.should_consume_qty, params.fields.should_consume_qty, this.nodeOptions); }, //-------------------------------------------------------------------------- diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index a7e024f146e..940aedfd5ee 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -1118,69 +1118,6 @@ class TestMrpOrder(TestMrpCommon): details_operation_form.save() mo2.button_mark_done() - def test_product_produce_uom(self): - """ Produce a finished product tracked by serial number. Set another - UoM on the bom. The produce wizard should keep the UoM of the product (unit) - and quantity = 1.""" - dozen = self.env.ref('uom.product_uom_dozen') - unit = self.env.ref('uom.product_uom_unit') - plastic_laminate = self.env['product.product'].create({ - 'name': 'Plastic Laminate', - 'type': 'product', - 'uom_id': unit.id, - 'uom_po_id': unit.id, - 'tracking': 'serial', - }) - ply_veneer = self.env['product.product'].create({ - 'name': 'Ply Veneer', - 'type': 'product', - 'uom_id': unit.id, - 'uom_po_id': unit.id, - }) - bom = self.env['mrp.bom'].create({ - 'product_tmpl_id': plastic_laminate.product_tmpl_id.id, - 'product_uom_id': unit.id, - 'sequence': 1, - 'bom_line_ids': [(0, 0, { - 'product_id': ply_veneer.id, - 'product_qty': 1, - 'product_uom_id': unit.id, - 'sequence': 1, - })] - }) - - mo_form = Form(self.env['mrp.production']) - mo_form.product_id = plastic_laminate - mo_form.bom_id = bom - mo_form.product_uom_id = dozen - mo_form.product_qty = 1 - mo = mo_form.save() - - final_product_lot = self.env['stock.production.lot'].create({ - 'name': 'lot1', - 'product_id': plastic_laminate.id, - 'company_id': self.env.company.id, - }) - - mo.action_confirm() - mo.action_assign() - self.assertEqual(mo.move_raw_ids.product_qty, 12, '12 units should be reserved.') - - # produce product - mo_form = Form(mo) - mo_form.qty_producing = 1/12.0 - mo_form.lot_producing_id = final_product_lot - mo = mo_form.save() - - move_line_raw = mo.move_raw_ids.mapped('move_line_ids').filtered(lambda m: m.qty_done) - self.assertEqual(move_line_raw.qty_done, 1) - self.assertEqual(move_line_raw.product_uom_id, unit, 'Should be 1 unit since the tracking is serial.') - - mo._post_inventory() - move_line_finished = mo.move_finished_ids.mapped('move_line_ids').filtered(lambda m: m.qty_done) - self.assertEqual(move_line_finished.qty_done, 1) - self.assertEqual(move_line_finished.product_uom_id, unit, 'Should be 1 unit since the tracking is serial.') - def test_product_type_service_1(self): # Create finished product finished_product = self.env['product.product'].create({ diff --git a/addons/mrp/tests/test_traceability.py b/addons/mrp/tests/test_traceability.py index ea861c2cefe..502cac0519d 100644 --- a/addons/mrp/tests/test_traceability.py +++ b/addons/mrp/tests/test_traceability.py @@ -107,7 +107,7 @@ class TestTraceability(TestMrpCommon): for line in lines: tracking = line['columns'][1].split(' ')[1] self.assertEqual( - line['columns'][-1], "1.000 Units", 'Part with tracking type "%s", should have quantity = 1' % (tracking) + line['columns'][-1], "1.00 Units", 'Part with tracking type "%s", should have quantity = 1' % (tracking) ) unfoldable = False if tracking == 'none' else True self.assertEqual( diff --git a/addons/mrp/views/mrp_production_views.xml b/addons/mrp/views/mrp_production_views.xml index b05c6970e55..c45c6524027 100644 --- a/addons/mrp/views/mrp_production_views.xml +++ b/addons/mrp/views/mrp_production_views.xml @@ -151,7 +151,7 @@