diff --git a/stock_reserve_sale/__openerp__.py b/stock_reserve_sale/__openerp__.py index a8b60b9e2..990c31c6e 100644 --- a/stock_reserve_sale/__openerp__.py +++ b/stock_reserve_sale/__openerp__.py @@ -59,6 +59,7 @@ insufficient at the order date, you may want to install the ], 'auto_install': False, 'test': ['test/sale_reserve.yml', + 'test/sale_line_reserve.yml', ], 'installable': True, } diff --git a/stock_reserve_sale/test/sale_line_reserve.yml b/stock_reserve_sale/test/sale_line_reserve.yml new file mode 100644 index 000000000..2dfbee6ef --- /dev/null +++ b/stock_reserve_sale/test/sale_line_reserve.yml @@ -0,0 +1,118 @@ +- + I create a product to test the stock reservation +- + !record {model: product.product, id: product_yogurt}: + default_code: 001yogurt + name: yogurt + 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 yogurt with 10 kgm +- + !record {model: stock.change.product.qty, id: change_qty}: + new_quantity: 10 + product_id: product_yogurt +- + !python {model: stock.change.product.qty}: | + context['active_id'] = ref('product_yogurt') + self.change_product_qty(cr, uid, [ref('change_qty')], context=context) +- + In order to test reservation of the sales order, I create a sales order +- + !record {model: sale.order, id: sale_reserve_02}: + partner_id: base.res_partner_2 + payment_term: account.account_payment_term +- + And I create a sales order line +- + !record {model: sale.order.line, id: sale_line_reserve_02_01, view: sale.view_order_line_tree}: + name: Yogurt + product_id: product_yogurt + product_uom_qty: 4 + product_uom: product.product_uom_kgm + order_id: sale_reserve_02 +- + And I create a stock reserve for this line +- + !record {model: sale.stock.reserve, id: wizard_reserve_02_01}: + note: Reservation for the sales order line +- + I call the wizard to reserve the products of the sales order +- + !python {model: sale.stock.reserve}: | + active_id = ref('sale_line_reserve_02_01') + context['active_id'] = active_id + context['active_ids'] = [active_id] + context['active_model'] = 'sale.order.line' + self.button_reserve(cr, uid, [ref('wizard_reserve_02_01')], context=context) +- + I check Virtual stock of yogurt after update reservation +- + !python {model: product.product}: | + product = self.browse(cr, uid, ref('product_yogurt'), context=context) + assert product.virtual_available == 6, "Stock is not updated." +- + And I create a MTO sales order line +- + !record {model: sale.order.line, id: sale_line_reserve_02_02, view: sale.view_order_line_tree}: + order_id: sale_reserve_02 + name: Mouse, Wireless + product_id: product.product_product_12 + type: make_to_order + product_uom_qty: 4 + product_uom: product.product_uom_kgm +- + And I try to create a stock reserve for this MTO line +- + !record {model: sale.stock.reserve, id: wizard_reserve_02_02}: + note: Reservation for the sales order line +- + I call the wizard to reserve the products of the sales order +- + !python {model: sale.stock.reserve}: | + active_id = ref('sale_line_reserve_02_02') + context['active_id'] = active_id + context['active_ids'] = [active_id] + context['active_model'] = 'sale.order.line' + self.button_reserve(cr, uid, [ref('wizard_reserve_02_02')], context=context) +- + I should not have a stock reservation for a MTO line +- + !python {model: stock.reservation}: | + reserv_ids = self.search( + cr, uid, + [('sale_line_id', '=', ref('sale_line_reserve_02_02'))], + context=context) + assert not reserv_ids, "No stock reservation should be created for MTO lines" +- + And I change the quantity in the first line +- + !record {model: sale.order.line, id: sale_line_reserve_02_01, view: sale.view_order_line_tree}: + product_uom_qty: 5 +- + + I check Virtual stock of yogurt after change of reservations +- + !python {model: product.product}: | + product = self.browse(cr, uid, ref('product_yogurt'), context=context) + assert product.virtual_available == 5, "Stock is not updated." +- + I release the sales order's reservations for the first line +- + !python {model: sale.order.line}: | + self.release_stock_reservation(cr, uid, [ref('sale_line_reserve_02_01')], context=context) +- + I check Virtual stock of yogurt after release of reservations +- + !python {model: product.product}: | + product = self.browse(cr, uid, ref('product_yogurt'), context=context) + assert product.virtual_available == 10, "Stock is not updated."