From 1a09bcc6221e1856ece4d176205f2aaa1a205a3a Mon Sep 17 00:00:00 2001 From: amoyaux Date: Tue, 17 Oct 2017 14:46:56 +0200 Subject: [PATCH] [FIX] mrp: Handle by product tracked by SN/lot Since mrp/stock refactoring by-product tracked was not handled by the code. The best way to handle it would be to add a section in the product produce wizard. However we can't modify the model in 11.0. Thus this commit generate a move line for each by-product but without lot/SN. ! This commit should be revert in future version once the by product pass through the produce wizard --- addons/mrp_byproduct/models/mrp_production.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/addons/mrp_byproduct/models/mrp_production.py b/addons/mrp_byproduct/models/mrp_production.py index 91917da03cc..05584d0d019 100644 --- a/addons/mrp_byproduct/models/mrp_production.py +++ b/addons/mrp_byproduct/models/mrp_production.py @@ -3,6 +3,8 @@ from odoo import api, models +from odoo.tools import float_round + class MrpProduction(models.Model): _description = 'Production' @@ -42,3 +44,39 @@ class MrpProduction(models.Model): for sub_product in production.bom_id.sub_products: production._create_byproduct_move(sub_product) return res + + +class MrpProductProduce(models.TransientModel): + _name = "mrp.product.produce" + _description = "Record Production" + _inherit = "mrp.product.produce" + + @api.multi + def check_finished_move_lots(self): + """ Handle by product tracked """ + by_product_moves = self.production_id.move_finished_ids.filtered(lambda m: m.product_id != self.product_id and m.product_id.tracking != 'none' and m.state not in ('done', 'cancel')) + for by_product_move in by_product_moves: + rounding = by_product_move.product_uom.rounding + quantity = float_round(self.product_qty * by_product_move.unit_factor, precision_rounding=rounding) + values = { + 'move_id': by_product_move.id, + 'product_id': by_product_move.product_id.id, + 'production_id': self.production_id.id, + 'product_uom_id': by_product_move.product_uom.id, + 'location_id': by_product_move.location_id.id, + 'location_dest_id': by_product_move.location_dest_id.id, + } + if by_product_move.product_id.tracking == 'lot': + values.update({ + 'product_uom_qty': quantity, + 'qty_done': quantity, + }) + self.env['stock.move.line'].create(values) + else: + values.update({ + 'product_uom_qty': 1.0, + 'qty_done': 1.0, + }) + for i in range(0, int(quantity)): + self.env['stock.move.line'].create(values) + return super(MrpProductProduce, self).check_finished_move_lots()