diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index c257b07f6aa..27f158ca111 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -346,6 +346,9 @@ class Product(models.Model): res['fields']['qty_available']['string'] = _('Produced Qty') return res + def action_update_quantity_on_hand(self): + return self.product_tmpl_id.with_context({'default_product_id': self.id}).action_update_quantity_on_hand() + def action_view_routes(self): return self.mapped('product_tmpl_id').action_view_routes() @@ -527,6 +530,30 @@ class ProductTemplate(models.Model): action['domain'] = [('id', 'in', routes.ids)] return action + def action_update_quantity_on_hand(self): + default_product_id = self.env.context.get('default_product_id', self.product_variant_id.id) + if self.env.user.user_has_groups('stock.group_stock_multi_locations') or (self.env.user.user_has_groups('stock.group_production_lot') and self.tracking != 'none'): + product_ref_name = self.name + ' - ' + datetime.today().strftime('%m/%d/%y') + ctx = {'default_filter': 'product', 'default_product_id': default_product_id, 'default_name': product_ref_name} + return { + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'stock.inventory', + 'context': ctx, + } + else: + wiz = self.env['stock.change.product.qty'].create({'product_id': default_product_id}) + return { + 'name': _('Update quantity on hand'), + 'type': 'ir.actions.act_window', + 'view_mode': 'form', + 'res_model': 'stock.change.product.qty', + 'target': 'new', + 'res_id': wiz.id, + 'context': {'default_product_id': self.env.context.get('default_product_id')} + } + def action_open_quants(self): products = self.mapped('product_variant_ids') action = self.env.ref('stock.product_open_quants').read()[0] diff --git a/addons/stock/models/stock_inventory.py b/addons/stock/models/stock_inventory.py index 269aed19998..72a673905fa 100644 --- a/addons/stock/models/stock_inventory.py +++ b/addons/stock/models/stock_inventory.py @@ -136,6 +136,8 @@ class Inventory(models.Model): self.category_id = False if self.filter == 'product': self.exhausted = True + if self.product_id: + return {'domain': {'product_id': [('product_tmpl_id', '=', self.product_id.product_tmpl_id.id)]}} @api.onchange('location_id') def onchange_location_id(self): diff --git a/addons/stock/views/product_views.xml b/addons/stock/views/product_views.xml index f59ae7baf5c..0803c9c88f5 100644 --- a/addons/stock/views/product_views.xml +++ b/addons/stock/views/product_views.xml @@ -151,7 +151,7 @@ - + - + + attrs="{'readonly': [('product_variant_count', '=', 1)]}" + readonly="context.get('default_product_id')"/> - - - When you select a serial number (lot), the quantity is corrected with respect to - the quantity of that serial number (lot) and not to the total quantity of the product. - - - - Update Product Quantity - ir.actions.act_window - stock.change.product.qty - form - form - - new - -
- When you select a serial number (lot), the quantity is corrected with respect to - the quantity of that serial number (lot) and not to the total quantity of the product. -