diff --git a/mrp_production_request/README.rst b/mrp_production_request/README.rst index 3699ced9d..7233d338a 100644 --- a/mrp_production_request/README.rst +++ b/mrp_production_request/README.rst @@ -47,6 +47,10 @@ To create MOs from MRs you have to: #. Use the proposed quantity or change it and click on *Create MO* at the bottom of the wizard. +**NOTE:** This module does not restrict the quantity that can be converted +from a MR to MOs. It is in hands of the user to decide when a MR is ended and +to set it to *Done* state. + .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot :target: https://runbot.odoo-community.org/runbot/129/9.0 diff --git a/mrp_production_request/models/mrp_production_request.py b/mrp_production_request/models/mrp_production_request.py index a20453ac6..4649fc784 100644 --- a/mrp_production_request/models/mrp_production_request.py +++ b/mrp_production_request/models/mrp_production_request.py @@ -51,14 +51,15 @@ class MrpProductionRequest(models.Model): def _get_mo_valid_states(self): return ['draft', 'confirmed', 'ready', 'in_production', 'done'] - @api.one + @api.multi @api.depends('mrp_production_ids', 'mrp_production_ids.state', 'state') def _compute_manufactured_qty(self): valid_states = self._get_mo_valid_states() - valid_mo = self.mrp_production_ids.filtered( - lambda mo: mo.state in valid_states).mapped('product_qty') - self.manufactured_qty = sum(valid_mo) - self.pending_qty = max(self.product_qty - self.manufactured_qty, 0.0) + for req in self: + valid_mo = req.mrp_production_ids.filtered( + lambda mo: mo.state in valid_states).mapped('product_qty') + req.manufactured_qty = sum(valid_mo) + req.pending_qty = max(req.product_qty - req.manufactured_qty, 0.0) name = fields.Char( default="/", required=True, @@ -160,15 +161,22 @@ class MrpProductionRequest(models.Model): @api.multi def button_done(self): self.write({'state': 'done'}) + if self.mapped('procurement_id'): + self.mapped('procurement_id').write({'state': 'done'}) return True @api.multi def _check_reset_allowed(self): + if any([s in self._get_mo_valid_states() for s in self.mapped( + 'mrp_production_ids.state')]): + raise UserError( + _("You cannot reset a manufacturing request with " + "manufacturing orders not cancelled.")) if any([s in ['done', 'cancel'] for s in self.mapped( 'procurement_id.state')]): raise UserError( - _('You cannot reset a manufacturing request related to ' - 'done or cancelled procurement orders.')) + _("You cannot reset a manufacturing request related to " + "done or cancelled procurement orders.")) @api.multi def button_draft(self): diff --git a/mrp_production_request/models/procurement.py b/mrp_production_request/models/procurement.py index 4af6a3f90..5c505552f 100644 --- a/mrp_production_request/models/procurement.py +++ b/mrp_production_request/models/procurement.py @@ -24,6 +24,10 @@ class ProcurementOrder(models.Model): if (procurement.rule_id and procurement.rule_id.action == 'manufacture' and procurement.product_id.mrp_production_request): + if not procurement.check_bom_exists(): + procurement.message_post( + body=_("No BoM exists for this product!")) + return False if not self.mrp_production_request_id: request_data = self._prepare_mrp_production_request( procurement)