summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHetal Dhanak <hdh@odoo.com>2019-05-24 08:48:23 +0000
committerHetal Dhanak <hdh@odoo.com>2019-08-23 13:06:42 +0000
commit2f2ac551423ba5c746b7fedf0971a4ea25a04ab3 (patch)
tree91be281367327c59407f6f4b9dbe79fe5d6997c7
parent71308383160c1d3f4be15880271d9cb1210740c3 (diff)
[IMP] stock: filter data for field 'product_id' in form view
of 'stock.production.lot' previously in the selection field 'product_id' of 'stock.production.lot', all the products were always visible no matter from where this view was getting opened from. which is not ideal because if a user is creating a new lot for a specific product, i.e. let's say if he opens this view from 'product.template', he must not be able to select a product variant other than of the product itself. after this commit, if a user opens form view of 'stock.production.lot' by clicking on the menu action, all the products will be visible. if he opens it from product.template, only variants of the given products will be visible. if he opens it from product.product, only that particular variant will be visible and it will be readonly because there are no other valid values. Task-1943397
-rw-r--r--addons/stock/models/product.py8
-rw-r--r--addons/stock/models/stock_production_lot.py9
-rw-r--r--addons/stock/views/stock_production_lot_views.xml4
3 files changed, 13 insertions, 8 deletions
diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py
index cd838f35c93..0a0c6faf05a 100644
--- a/addons/stock/models/product.py
+++ b/addons/stock/models/product.py
@@ -471,7 +471,7 @@ class Product(models.Model):
self.ensure_one()
action = self.env.ref('stock.action_production_lot_form').read()[0]
action['domain'] = [('product_id', '=', self.id)]
- action['context'] = {'default_product_id': self.id}
+ action['context'] = {'default_product_id': self.id, 'set_product_readonly': True}
return action
# Be aware that the exact same function exists in product.template
@@ -769,11 +769,11 @@ class ProductTemplate(models.Model):
self.ensure_one()
action = self.env.ref('stock.action_production_lot_form').read()[0]
action['domain'] = [('product_id.product_tmpl_id', '=', self.id)]
+ action['context'] = {'default_product_tmpl_id': self.id}
if self.product_variant_count == 1:
- action['context'] = {
+ action['context'].update({
'default_product_id': self.product_variant_id.id,
- }
-
+ })
return action
def action_product_tmpl_forecast_report(self):
diff --git a/addons/stock/models/stock_production_lot.py b/addons/stock/models/stock_production_lot.py
index 82c50565c39..17f0275c84e 100644
--- a/addons/stock/models/stock_production_lot.py
+++ b/addons/stock/models/stock_production_lot.py
@@ -3,6 +3,7 @@
from odoo import api, fields, models, _
from odoo.exceptions import UserError
+from odoo.osv import expression
class ProductionLot(models.Model):
@@ -16,7 +17,7 @@ class ProductionLot(models.Model):
ref = fields.Char('Internal Reference', help="Internal reference number in case it differs from the manufacturer's lot/serial number")
product_id = fields.Many2one(
'product.product', 'Product',
- domain=[('type', '=', 'product')], required=True)
+ domain=lambda self: self._domain_product_id(), required=True)
product_uom_id = fields.Many2one(
'uom.uom', 'Unit of Measure',
related='product_id.uom_id', store=True, readonly=False)
@@ -29,6 +30,12 @@ class ProductionLot(models.Model):
('name_ref_uniq', 'unique (name, product_id)', 'The combination of serial number and product must be unique !'),
]
+ def _domain_product_id(self):
+ domain = [('type', '=', 'product')]
+ if self.env.context.get('default_product_tmpl_id'):
+ domain = expression.AND([domain, [('product_tmpl_id', '=', self.env.context['default_product_tmpl_id'])]])
+ return domain
+
def _check_create(self):
active_picking_id = self.env.context.get('active_picking_id', False)
if active_picking_id:
diff --git a/addons/stock/views/stock_production_lot_views.xml b/addons/stock/views/stock_production_lot_views.xml
index 7caf76f7dde..937cdde3dcf 100644
--- a/addons/stock/views/stock_production_lot_views.xml
+++ b/addons/stock/views/stock_production_lot_views.xml
@@ -21,9 +21,7 @@
</div>
<group name="main_group">
<group>
- <field name="product_id"
- help="Product this lot/serial number contains. You cannot change it anymore if it has already been moved."
- attrs="{'readonly': [('id', '!=', False), ('product_id', '!=', False)]}"/>
+ <field name="product_id" readonly="context.get('set_product_readonly', False)" force_save="1" help="Product this lot/serial number contains. You cannot change it anymore if it has already been moved."/>
<label for="product_qty" attrs="{'invisible': [('display_complete', '=', False)]}"/>
<div class="o_row" attrs="{'invisible': [('display_complete', '=', False)]}">
<field name="product_qty"/>