mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[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:
committed by
Chandresh Thakkar
parent
f579cbf8b5
commit
d19101ebaf
@@ -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
|
#. Use the proposed quantity or change it and click on *Create MO* at the
|
||||||
bottom of the wizard.
|
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
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||||
:alt: Try me on Runbot
|
:alt: Try me on Runbot
|
||||||
:target: https://runbot.odoo-community.org/runbot/129/9.0
|
:target: https://runbot.odoo-community.org/runbot/129/9.0
|
||||||
|
|||||||
@@ -51,14 +51,15 @@ class MrpProductionRequest(models.Model):
|
|||||||
def _get_mo_valid_states(self):
|
def _get_mo_valid_states(self):
|
||||||
return ['draft', 'confirmed', 'ready', 'in_production', 'done']
|
return ['draft', 'confirmed', 'ready', 'in_production', 'done']
|
||||||
|
|
||||||
@api.one
|
@api.multi
|
||||||
@api.depends('mrp_production_ids', 'mrp_production_ids.state', 'state')
|
@api.depends('mrp_production_ids', 'mrp_production_ids.state', 'state')
|
||||||
def _compute_manufactured_qty(self):
|
def _compute_manufactured_qty(self):
|
||||||
valid_states = self._get_mo_valid_states()
|
valid_states = self._get_mo_valid_states()
|
||||||
valid_mo = self.mrp_production_ids.filtered(
|
for req in self:
|
||||||
lambda mo: mo.state in valid_states).mapped('product_qty')
|
valid_mo = req.mrp_production_ids.filtered(
|
||||||
self.manufactured_qty = sum(valid_mo)
|
lambda mo: mo.state in valid_states).mapped('product_qty')
|
||||||
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(
|
name = fields.Char(
|
||||||
default="/", required=True,
|
default="/", required=True,
|
||||||
@@ -160,15 +161,22 @@ class MrpProductionRequest(models.Model):
|
|||||||
@api.multi
|
@api.multi
|
||||||
def button_done(self):
|
def button_done(self):
|
||||||
self.write({'state': 'done'})
|
self.write({'state': 'done'})
|
||||||
|
if self.mapped('procurement_id'):
|
||||||
|
self.mapped('procurement_id').write({'state': 'done'})
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _check_reset_allowed(self):
|
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(
|
if any([s in ['done', 'cancel'] for s in self.mapped(
|
||||||
'procurement_id.state')]):
|
'procurement_id.state')]):
|
||||||
raise UserError(
|
raise UserError(
|
||||||
_('You cannot reset a manufacturing request related to '
|
_("You cannot reset a manufacturing request related to "
|
||||||
'done or cancelled procurement orders.'))
|
"done or cancelled procurement orders."))
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def button_draft(self):
|
def button_draft(self):
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ class ProcurementOrder(models.Model):
|
|||||||
if (procurement.rule_id and
|
if (procurement.rule_id and
|
||||||
procurement.rule_id.action == 'manufacture' and
|
procurement.rule_id.action == 'manufacture' and
|
||||||
procurement.product_id.mrp_production_request):
|
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:
|
if not self.mrp_production_request_id:
|
||||||
request_data = self._prepare_mrp_production_request(
|
request_data = self._prepare_mrp_production_request(
|
||||||
procurement)
|
procurement)
|
||||||
|
|||||||
Reference in New Issue
Block a user