diff --git a/stock_reserve/__openerp__.py b/stock_reserve/__openerp__.py index 8633fcfcd..17ccb24a7 100644 --- a/stock_reserve/__openerp__.py +++ b/stock_reserve/__openerp__.py @@ -52,6 +52,7 @@ reservations are canceled. 'security/ir.model.access.csv', ], 'auto_install': False, - 'test': [], + 'test': ['test/stock_reserve.yml', + ], 'installable': True, } diff --git a/stock_reserve/model/stock_reserve.py b/stock_reserve/model/stock_reserve.py index f3b8241b1..6466ac233 100644 --- a/stock_reserve/model/stock_reserve.py +++ b/stock_reserve/model/stock_reserve.py @@ -145,7 +145,13 @@ class stock_reservation(orm.Model): result = move_obj.onchange_product_id( cr, uid, move_ids, prod_id=product_id, loc_id=False, loc_dest_id=False, partner_id=False) - del result['value']['product_qty'] # keeps the current value + if result.get('value'): + vals = result['value'] + # only keep the existing fields on the view + keep = ('product_uom', 'name') + result['value'] = dict((key, value) for key, value in + result['value'].iteritems() if + key in keep) return result def onchange_quantity(self, cr, uid, ids, product_id, product_qty, context=None): diff --git a/stock_reserve/test/stock_reserve.yml b/stock_reserve/test/stock_reserve.yml new file mode 100644 index 000000000..5cd92e29f --- /dev/null +++ b/stock_reserve/test/stock_reserve.yml @@ -0,0 +1,63 @@ +- + I create a product to test the stock reservation +- + !record {model: product.product, id: product_sorbet}: + default_code: 001SORBET + name: Sorbet + type: product + categ_id: product.product_category_1 + list_price: 100.0 + standard_price: 70.0 + uom_id: product.product_uom_kgm + uom_po_id: product.product_uom_kgm + procure_method: make_to_stock + valuation: real_time + cost_method: average + property_stock_account_input: account.o_expense + property_stock_account_output: account.o_income +- + I update the current stock of the Sorbet with 10 kgm +- + !record {model: stock.change.product.qty, id: change_qty}: + new_quantity: 10 + product_id: product_sorbet +- + !python {model: stock.change.product.qty}: | + context['active_id'] = ref('stock_reserve.product_sorbet') + self.change_product_qty(cr, uid, [ref('change_qty')], context=context) +- + I check Virtual stock of Sorbet after update stock. +- + !python {model: product.product}: | + product = self.browse(cr, uid, ref('stock_reserve.product_sorbet'), context=context) + assert product.virtual_available == 10, "Stock is not updated." +- + I create a stock reservation for 5 kgm +- + !record {model: stock.reservation, id: reserv_sorbet1}: + product_id: product_sorbet + product_qty: 5.0 + product_uom: product.product_uom_kgm + name: reserve 5 kgm of sorbet for test +- + I confirm the reservation +- + !python {model: stock.reservation}: | + self.reserve(cr, uid, [ref('reserv_sorbet1')], context=context) +- + I check Virtual stock of Sorbet after update reservation +- + !python {model: product.product}: | + product = self.browse(cr, uid, ref('stock_reserve.product_sorbet'), context=context) + assert product.virtual_available == 5, "Stock is not updated." +- + I release the reservation +- + !python {model: stock.reservation}: | + self.release(cr, uid, [ref('reserv_sorbet1')], context=context) +- + I check Virtual stock of Sorbet after update reservation +- + !python {model: product.product}: | + product = self.browse(cr, uid, ref('stock_reserve.product_sorbet'), context=context) + assert product.virtual_available == 10, "Stock is not updated."