[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
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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"/>
|
||||
|
||||
Reference in New Issue
Block a user