mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[11.0] mrp_multi_level:
* fix api.depends fields fro main supplier. * fix ordering and missing demo file in manifest. * Update README. * fix action_view* methods. * readd hook to exclude in mrp initialization * fix computation of qty available (it was considering several times sub-locations). * Remove contraint for outoing and incoming moves to be moved in/outside the company, they can be internal transfers. * mrp.moves visible with technical settings. * Show product and allow to search by it in mrp.inventory.
This commit is contained in:
@@ -17,7 +17,6 @@ class MrpInventory(models.Model):
|
||||
# TODO: name to pass to procurements?
|
||||
# TODO: compute procurement_date to pass to the wizard? not needed for
|
||||
# PO at least. Check for MO and moves
|
||||
# TODO: substract qty already procured.
|
||||
# TODO: show a LT based on the procure method?
|
||||
|
||||
mrp_area_id = fields.Many2one(
|
||||
@@ -25,9 +24,14 @@ class MrpInventory(models.Model):
|
||||
related='product_mrp_area_id.mrp_area_id', store=True,
|
||||
)
|
||||
product_mrp_area_id = fields.Many2one(
|
||||
comodel_name='product.mrp.area', string='Product',
|
||||
comodel_name='product.mrp.area', string='Product Parameters',
|
||||
index=True,
|
||||
)
|
||||
product_id = fields.Many2one(
|
||||
comodel_name='product.product',
|
||||
related='product_mrp_area_id.product_id',
|
||||
store=True,
|
||||
)
|
||||
uom_id = fields.Many2one(
|
||||
comodel_name='product.uom', string='Product UoM',
|
||||
compute='_compute_uom_id',
|
||||
|
||||
@@ -11,19 +11,21 @@ class ProductMRPArea(models.Model):
|
||||
_description = 'Product MRP Area'
|
||||
|
||||
active = fields.Boolean(default=True)
|
||||
mrp_area_id = fields.Many2one('mrp.area',
|
||||
required=True,
|
||||
)
|
||||
product_id = fields.Many2one('product.product',
|
||||
required=True,
|
||||
string='Product',
|
||||
)
|
||||
product_tmpl_id = fields.Many2one('product.template',
|
||||
readonly=True,
|
||||
related='product_id.product_tmpl_id',
|
||||
store=True,
|
||||
)
|
||||
|
||||
mrp_area_id = fields.Many2one(
|
||||
comodel_name='mrp.area',
|
||||
required=True,
|
||||
)
|
||||
product_id = fields.Many2one(
|
||||
comodel_name='product.product',
|
||||
required=True,
|
||||
string='Product',
|
||||
)
|
||||
product_tmpl_id = fields.Many2one(
|
||||
comodel_name='product.template',
|
||||
readonly=True,
|
||||
related='product_id.product_tmpl_id',
|
||||
store=True,
|
||||
)
|
||||
# TODO: applicable and exclude... redundant??
|
||||
mrp_applicable = fields.Boolean(string='MRP Applicable')
|
||||
mrp_exclude = fields.Boolean(string='Exclude from MRP')
|
||||
@@ -71,10 +73,11 @@ class ProductMRPArea(models.Model):
|
||||
|
||||
qty_available = fields.Float('Quantity Available',
|
||||
compute='_compute_qty_available')
|
||||
mrp_move_ids = fields.One2many(comodel_name='mrp.move',
|
||||
inverse_name='product_mrp_area_id',
|
||||
readonly=True,
|
||||
)
|
||||
mrp_move_ids = fields.One2many(
|
||||
comodel_name='mrp.move',
|
||||
inverse_name='product_mrp_area_id',
|
||||
readonly=True,
|
||||
)
|
||||
_sql_constraints = [
|
||||
('product_mrp_area_uniq', 'unique(product_id, mrp_area_id)',
|
||||
'The product/MRP Area parameters combination must be unique.'),
|
||||
@@ -89,17 +92,9 @@ class ProductMRPArea(models.Model):
|
||||
@api.multi
|
||||
def _compute_qty_available(self):
|
||||
for rec in self:
|
||||
qty_available = 0.0
|
||||
product_obj = self.env['product.product']
|
||||
# TODO: move mrp_qty_available computation, maybe unreserved??
|
||||
location_ids = self.env['stock.location'].search(
|
||||
[('id', 'child_of',
|
||||
rec.mrp_area_id.location_id.id)])
|
||||
for location in location_ids:
|
||||
product_l = product_obj.with_context(
|
||||
{'location': location.id}).browse(rec.product_id.id)
|
||||
qty_available += product_l.qty_available
|
||||
rec.qty_available = qty_available
|
||||
rec.qty_available = rec.product_id.with_context(
|
||||
{'location': rec.mrp_area_id.location_id.id}).qty_available
|
||||
|
||||
@api.multi
|
||||
def _compute_supply_method(self):
|
||||
@@ -115,7 +110,8 @@ class ProductMRPArea(models.Model):
|
||||
rec.supply_method = rule.action if rule else 'none'
|
||||
|
||||
@api.multi
|
||||
@api.depends('supply_method')
|
||||
@api.depends('supply_method', 'product_id.route_ids',
|
||||
'product_id.seller_ids')
|
||||
def _compute_main_supplier(self):
|
||||
"""Simplified and similar to procurement.rule logic."""
|
||||
for rec in self.filtered(lambda r: r.supply_method == 'buy'):
|
||||
|
||||
@@ -28,7 +28,8 @@ class Product(models.Model):
|
||||
mrp_area_count = fields.Integer(
|
||||
string='MRP Area Parameter Count',
|
||||
readonly=True,
|
||||
compute='_compute_mrp_area_count')
|
||||
compute='_compute_mrp_area_count',
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _compute_mrp_area_count(self):
|
||||
@@ -40,12 +41,11 @@ class Product(models.Model):
|
||||
self.ensure_one()
|
||||
action = self.env.ref('mrp_multi_level.product_mrp_area_action')
|
||||
result = action.read()[0]
|
||||
product_ids = self.ids
|
||||
if len(product_ids) > 1:
|
||||
result['domain'] = [('product_id', 'in', product_ids)]
|
||||
area_ids = self.mrp_area_ids.ids
|
||||
if self.mrp_area_count != 1:
|
||||
result['domain'] = [('id', 'in', area_ids)]
|
||||
else:
|
||||
res = self.env.ref('mrp_multi_level.product_mrp_area_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = product_ids[0]
|
||||
result['context'] = {'default_product_id': product_ids[0]}
|
||||
result['res_id'] = area_ids[0]
|
||||
return result
|
||||
|
||||
@@ -15,7 +15,8 @@ class ProductTemplate(models.Model):
|
||||
mrp_area_count = fields.Integer(
|
||||
string='MRP Area Parameter Count',
|
||||
readonly=True,
|
||||
compute='_compute_mrp_area_count')
|
||||
compute='_compute_mrp_area_count',
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _compute_mrp_area_count(self):
|
||||
@@ -29,12 +30,10 @@ class ProductTemplate(models.Model):
|
||||
result = action.read()[0]
|
||||
mrp_area_ids = self.with_context(
|
||||
active_test=False).mrp_area_ids.ids
|
||||
if len(mrp_area_ids) > 1:
|
||||
if len(mrp_area_ids) != 1:
|
||||
result['domain'] = [('id', 'in', mrp_area_ids)]
|
||||
else:
|
||||
res = self.env.ref('mrp_multi_level.product_mrp_area_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = mrp_area_ids[0]
|
||||
result['context'] = {
|
||||
'default_product_id': self.product_variant_ids[0].id}
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user