diff --git a/stock_available_mrp/__openerp__.py b/stock_available_mrp/__openerp__.py
index 2d6afa640..0aa748b7e 100644
--- a/stock_available_mrp/__openerp__.py
+++ b/stock_available_mrp/__openerp__.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-# © 2014 Numérigraphe SARL
+# © 2014 Numérigraphe SARL, Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Consider the production potential is available to promise',
- 'version': '8.0.3.1.1',
+ 'version': '9.0.1.0.0',
"author": u"Numérigraphe,"
u"Odoo Community Association (OCA)",
'category': 'Hidden',
diff --git a/stock_available_mrp/demo/mrp_bom.yml b/stock_available_mrp/demo/mrp_bom.yml
index 4ecdb0b64..bb197f44b 100644
--- a/stock_available_mrp/demo/mrp_bom.yml
+++ b/stock_available_mrp/demo/mrp_bom.yml
@@ -8,7 +8,6 @@
- Add a BOM whereby 0.042K "RAM SR2" can be replaced with 13 dozens "HDD-SH1" + 8 CPUa8 with 50% efficiency. This lets us test UoM conversions for the finished product and the raw materials, as well as the unfolding of phantom BoMs
- !record {model: mrp.bom, id: sr2_from_hdd}:
- name: RAM SR2 made from HDD-SH1
product_id: product.product_product_14
product_tmpl_id: product.product_product_14_product_template
product_uom: thousand
diff --git a/stock_available_mrp/models/product_product.py b/stock_available_mrp/models/product_product.py
index c6440f31a..790ca16a4 100644
--- a/stock_available_mrp/models/product_product.py
+++ b/stock_available_mrp/models/product_product.py
@@ -7,6 +7,8 @@ from collections import Counter
from openerp import models, fields, api
from openerp.addons import decimal_precision as dp
+from openerp.exceptions import AccessError
+
class ProductProduct(models.Model):
_inherit = 'product.product'
@@ -53,7 +55,12 @@ class ProductProduct(models.Model):
bom = bom_obj.browse(bom_id)
# Need by product (same product can be in many BOM lines/levels)
- component_needs = self._get_components_needs(product, bom)
+ try:
+ component_needs = self._get_components_needs(product, bom)
+ except AccessError:
+ # If user doesn't have access to BOM
+ # he can't see potential_qty
+ component_needs = None
if not component_needs:
# The BoM has no line we can use
diff --git a/stock_available_mrp/tests/test_potential_qty.py b/stock_available_mrp/tests/test_potential_qty.py
index 98eb9a545..896655dae 100644
--- a/stock_available_mrp/tests/test_potential_qty.py
+++ b/stock_available_mrp/tests/test_potential_qty.py
@@ -86,13 +86,14 @@ class TestPotentialQty(TransactionCase):
inventory.action_done()
def create_simple_bom(self, product, sub_product,
- product_qty=1, sub_product_qty=1):
+ product_qty=1, sub_product_qty=1,
+ routing_id=False):
bom = self.bom_model.create({
'product_tmpl_id': product.product_tmpl_id.id,
'product_id': product.id,
'product_qty': product_qty,
'product_uom': self.ref('product.product_uom_unit'),
-
+ 'routing_id': routing_id,
})
self.bom_line_model.create({
'bom_id': bom.id,
@@ -159,7 +160,8 @@ class TestPotentialQty(TransactionCase):
'login': 'test_demo',
'company_id': self.ref('base.main_company'),
'company_ids': [(4, self.ref('base.main_company'))],
- 'groups_id': [(4, self.ref('stock.group_stock_user'))]})
+ 'groups_id': [(4, self.ref('stock.group_stock_user')),
+ (4, self.ref('mrp.group_mrp_user'))]})
bom = self.env['mrp.bom'].search(
[('product_tmpl_id', '=', self.tmpl.id)])
@@ -185,6 +187,29 @@ class TestPotentialQty(TransactionCase):
self.assertPotentialQty(
test_user_tmpl, 1000.0, '')
+ def test_group_mrp_missing(self):
+ test_user = self.env['res.users'].create({
+ 'name': 'test_demo',
+ 'login': 'test_demo',
+ 'company_id': self.ref('base.main_company'),
+ 'company_ids': [(4, self.ref('base.main_company'))],
+ 'groups_id': [(4, self.ref('stock.group_stock_user'))],
+ })
+
+ p1 = self.product_model.create({'name': 'Test P1'})
+ p2 = self.product_model.create({'name': 'Test P2'})
+
+ self.create_simple_bom(p1, p2,
+ routing_id=self.ref('mrp.mrp_routing_0'))
+ self.create_inventory(p2.id, 1)
+
+ test_user_p1 = p1.sudo(test_user)
+ # Test user doesn't have access to mrp_routing, can't compute potential
+ self.assertEqual(0, test_user_p1.potential_qty)
+
+ test_user.groups_id = [(4, self.ref('mrp.group_mrp_user'))]
+ self.assertEqual(1, test_user_p1.potential_qty)
+
def test_potential_qty(self):
for i in [self.tmpl, self.var1, self.var2]:
self.assertPotentialQty(
@@ -313,12 +338,12 @@ class TestPotentialQty(TransactionCase):
'product_id': p2.id,
'product_qty': 2,
'product_uom': self.ref('product.product_uom_unit'),
- 'type': 'phantom',
})
bom_p2 = self.bom_model.create({
'product_tmpl_id': p2.product_tmpl_id.id,
'product_id': p2.id,
+ 'type': 'phantom',
})
# p2 need 2 unit of component
@@ -435,7 +460,7 @@ class TestPotentialQty(TransactionCase):
})
# Need 1 iMac for that
- p1_bom_line = self.bom_line_model.create({
+ self.bom_line_model.create({
'bom_id': bom_p1.id,
'product_id': imac.id,
'product_qty': 1,
@@ -464,8 +489,8 @@ class TestPotentialQty(TransactionCase):
'product_id': imac.id,
'product_qty': 1,
'product_uom': self.ref('product.product_uom_unit'),
+ 'type': 'phantom',
})
- p1_bom_line.type = 'phantom'
# Need 1 imac_component for iMac
self.bom_line_model.create({
diff --git a/stock_available_mrp/views/product_template_view.xml b/stock_available_mrp/views/product_template_view.xml
index c58512d56..446e0c5c3 100644
--- a/stock_available_mrp/views/product_template_view.xml
+++ b/stock_available_mrp/views/product_template_view.xml
@@ -9,8 +9,16 @@
-
-
+
+