From a04d43faf25d03e5a82e41ae5281715263e0609f Mon Sep 17 00:00:00 2001 From: dip-odoo Date: Tue, 7 Feb 2017 10:38:51 +0530 Subject: [PATCH] [IMP] stock: Update quantity on hand inventory adjustment When the update quantity on hand is clicked on a product tracked by lot or serial number or if the database is in multi location, the button update quantity on hand will open an inventory adjustment to allow you to add multiple lot/serial number and/or choose the lopcation in which you are updateing quantities TASK-30921 --- addons/stock/models/product.py | 27 +++++++++++++++++++ addons/stock/models/stock_inventory.py | 2 ++ addons/stock/views/product_views.xml | 8 +++--- .../stock/wizard/stock_change_product_qty.py | 16 +++-------- .../wizard/stock_change_product_qty_views.xml | 19 ++----------- 5 files changed, 38 insertions(+), 34 deletions(-) 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 @@
-