[FIX] stock: update and request procurment button use active_id to se the product. Fix to use this buttons on product template.
This commit is contained in:
@@ -20,7 +20,8 @@
|
||||
##############################################################################
|
||||
|
||||
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.osv import fields, osv, orm
|
||||
from openerp.tools.translate import _
|
||||
|
||||
class make_procurement(osv.osv_memory):
|
||||
_name = 'make.procurement'
|
||||
@@ -108,6 +109,13 @@ class make_procurement(osv.osv_memory):
|
||||
context = {}
|
||||
record_id = context.get('active_id')
|
||||
|
||||
if context.get('active_model') == 'product.template':
|
||||
product_ids = self.pool.get('product.product').search(cr, uid, [('product_tmpl_id', '=', context.get('active_id'))], context=context)
|
||||
if len(product_ids) == 1:
|
||||
record_id = product_ids[0]
|
||||
else:
|
||||
raise orm.except_orm(_('Warning'), _('Please use the Product Variant vue to request a procurement.'))
|
||||
|
||||
res = super(make_procurement, self).default_get(cr, uid, fields, context=context)
|
||||
|
||||
if record_id and 'product_id' in fields:
|
||||
|
||||
@@ -50,6 +50,13 @@ class stock_change_product_qty(osv.osv_memory):
|
||||
|
||||
res = super(stock_change_product_qty, self).default_get(cr, uid, fields, context=context)
|
||||
|
||||
if context.get('active_model') == 'product.template':
|
||||
product_ids = self.pool.get('product.product').search(cr, uid, [('product_tmpl_id', '=', context.get('active_id'))], context=context)
|
||||
if len(product_ids) == 1:
|
||||
res['product_id'] = product_ids[0]
|
||||
else:
|
||||
raise orm.except_orm(_('Warning'), _('Please use the Product Variant vue to update the product quantity.'))
|
||||
|
||||
if 'location_id' in fields:
|
||||
location_id = res.get('location_id', False)
|
||||
if not location_id:
|
||||
@@ -77,12 +84,8 @@ class stock_change_product_qty(osv.osv_memory):
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
rec_id = context and context.get('active_id', False)
|
||||
assert rec_id, _('Active ID is not set in Context')
|
||||
|
||||
inventory_obj = self.pool.get('stock.inventory')
|
||||
inventory_line_obj = self.pool.get('stock.inventory.line')
|
||||
prod_obj_pool = self.pool.get('product.product')
|
||||
|
||||
for data in self.browse(cr, uid, ids, context=context):
|
||||
if data.new_quantity < 0:
|
||||
@@ -90,15 +93,18 @@ class stock_change_product_qty(osv.osv_memory):
|
||||
ctx = context.copy()
|
||||
ctx['location'] = data.location_id.id
|
||||
ctx['lot_id'] = data.lot_id.id
|
||||
res_original = prod_obj_pool.browse(cr, uid, rec_id, context=ctx)
|
||||
inventory_id = inventory_obj.create(cr, uid, {'name': _('INV: %s') % tools.ustr(res_original.name), 'product_id': rec_id, 'location_id': data.location_id.id, 'lot_id': data.lot_id.id}, context=context)
|
||||
th_qty = res_original.qty_available
|
||||
inventory_id = inventory_obj.create(cr, uid, {
|
||||
'name': _('INV: %s') % tools.ustr(data.product_id.name),
|
||||
'product_id': data.product_id.id,
|
||||
'location_id': data.location_id.id,
|
||||
'lot_id': data.lot_id.id}, context=context)
|
||||
th_qty = data.product_id.qty_available
|
||||
line_data = {
|
||||
'inventory_id': inventory_id,
|
||||
'product_qty': data.new_quantity,
|
||||
'location_id': data.location_id.id,
|
||||
'product_id': rec_id,
|
||||
'product_uom_id': res_original.uom_id.id,
|
||||
'product_id': data.product_id.id,
|
||||
'product_uom_id': data.product_id.uom_id.id,
|
||||
'th_qty': th_qty,
|
||||
'prod_lot_id': data.lot_id.id
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user