[9.0][IMP] mrp_production_request:

* Add a constrain
* Set procurements to done when marking as done a MR.
* Change to exception if no BoM is found in procurment.
* Fix api.one deprecated.
* Add a note in README.
This commit is contained in:
lreficent
2017-06-26 17:49:42 +02:00
committed by Chandresh Thakkar
parent f579cbf8b5
commit d19101ebaf
3 changed files with 23 additions and 7 deletions

View File

@@ -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

View File

@@ -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(
for req in self:
valid_mo = req.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)
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):

View File

@@ -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)