From f313b7e8e8c4ce69eb448a79e3f8bf7101b956ca Mon Sep 17 00:00:00 2001 From: Fatemi Lokhandwala Date: Fri, 6 Jul 2018 13:28:57 +0530 Subject: [PATCH 01/13] [ADD]:Added Upstream Patch for mrp_repair --- addons/mrp_repair/models/mrp_repair.py | 17 ++++++++++++++--- .../mrp_repair_templates_repair_order.xml | 3 +-- addons/mrp_repair/views/mrp_repair_views.xml | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/addons/mrp_repair/models/mrp_repair.py b/addons/mrp_repair/models/mrp_repair.py index 2d32dade..ee7d365e 100644 --- a/addons/mrp_repair/models/mrp_repair.py +++ b/addons/mrp_repair/models/mrp_repair.py @@ -207,9 +207,11 @@ class Repair(models.Model): def action_validate(self): self.ensure_one() precision = self.env['decimal.precision'].precision_get('Product Unit of Measure') - available_qty = self.env['stock.quant']._get_available_quantity(self.product_id, self.location_id, self.lot_id, strict=True) - if float_compare(available_qty, self.product_qty, precision_digits=precision) >= 0: - return self.action_repair_confirm() + available_qty_owner = self.env['stock.quant']._get_available_quantity(self.product_id, self.location_id, self.lot_id, owner_id=self.partner_id, strict=True) + available_qty_noown = self.env['stock.quant']._get_available_quantity(self.product_id, self.location_id, self.lot_id, strict=True) + for available_qty in [available_qty_owner, available_qty_noown]: + if float_compare(available_qty, self.product_qty, precision_digits=precision) >= 0: + return self.action_repair_confirm() else: return { 'name': _('Insufficient Quantity'), @@ -435,8 +437,15 @@ class Repair(models.Model): if self.filtered(lambda repair: not repair.repaired): raise UserError(_("Repair must be repaired in order to make the product moves.")) res = {} + precision = self.env['decimal.precision'].precision_get('Product Unit of Measure') Move = self.env['stock.move'] for repair in self: + # Try to create move with the appropriate owner + owner_id = False + available_qty_owner = self.env['stock.quant']._get_available_quantity(repair.product_id, repair.location_id, repair.lot_id, owner_id=repair.partner_id, strict=True) + if float_compare(available_qty_owner, repair.product_qty, precision_digits=precision) >= 0: + owner_id = repair.partner_id.id + moves = self.env['stock.move'] for operation in repair.operations: move = Move.create({ @@ -454,6 +463,7 @@ class Repair(models.Model): 'qty_done': operation.product_uom_qty, 'package_id': False, 'result_package_id': False, + 'owner_id': owner_id, 'location_id': operation.location_id.id, #TODO: owner stuff 'location_dest_id': operation.location_dest_id.id,})], 'repair_id': repair.id, @@ -476,6 +486,7 @@ class Repair(models.Model): 'qty_done': repair.product_qty, 'package_id': False, 'result_package_id': False, + 'owner_id': owner_id, 'location_id': repair.location_id.id, #TODO: owner stuff 'location_dest_id': repair.location_dest_id.id,})], 'repair_id': repair.id, diff --git a/addons/mrp_repair/report/mrp_repair_templates_repair_order.xml b/addons/mrp_repair/report/mrp_repair_templates_repair_order.xml index 8eb1257b..8a7e9912 100644 --- a/addons/mrp_repair/report/mrp_repair_templates_repair_order.xml +++ b/addons/mrp_repair/report/mrp_repair_templates_repair_order.xml @@ -2,7 +2,7 @@