diff --git a/addons/purchase/__openerp__.py b/addons/purchase/__openerp__.py index 7ea01f19c16..0a131faf49c 100644 --- a/addons/purchase/__openerp__.py +++ b/addons/purchase/__openerp__.py @@ -46,7 +46,7 @@ Dashboard / Reports for Purchase Management will include: 'author': 'OpenERP SA', 'website': 'http://www.openerp.com', 'images' : ['images/purchase_order.jpeg', 'images/purchase_analysis.jpeg', 'images/request_for_quotation.jpeg'], - 'depends': ['stock', 'process', 'procurement'], + 'depends': ['stock', 'process'], 'data': [ 'security/purchase_security.xml', 'security/ir.model.access.csv', @@ -69,7 +69,7 @@ Dashboard / Reports for Purchase Management will include: 'test': [ 'test/fifo_price.yml', 'test/fifo_returns.yml', - 'test/costmethodchange.yml', + #'test/costmethodchange.yml', 'test/process/cancel_order.yml', 'test/process/rfq2order2done.yml', 'test/process/generate_invoice_from_reception.yml', diff --git a/addons/purchase/test/average_price.yml b/addons/purchase/test/average_price.yml index e14c1088494..98e7c74e01a 100644 --- a/addons/purchase/test/average_price.yml +++ b/addons/purchase/test/average_price.yml @@ -93,6 +93,11 @@ product_uom: product.product_uom_kgm product_qty: 20.0 type: out +- + I assign this outgoing shipment +- + !python {model: stock.picking}: | + self.action_assign(cr, uid, [ref("outgoing_average_shipment")]) - I confirm outgoing shipment of 20 kg of Average Ice Cream. - diff --git a/addons/purchase/test/fifo_price.yml b/addons/purchase/test/fifo_price.yml index bad03b01b9d..6bf072c4b02 100644 --- a/addons/purchase/test/fifo_price.yml +++ b/addons/purchase/test/fifo_price.yml @@ -115,7 +115,7 @@ I assign this outgoing shipment - !python {model: stock.picking}: | - self.action_assign_wkf(cr, uid, [ref("outgoing_fifo_shipment")]) + self.action_assign(cr, uid, [ref("outgoing_fifo_shipment")]) - Process the delivery of the outgoing shipment - @@ -149,7 +149,7 @@ I assign this outgoing shipment - !python {model: stock.picking}: | - self.action_assign_wkf(cr, uid, [ref("outgoing_fifo_shipment_uom")]) + self.action_assign(cr, uid, [ref("outgoing_fifo_shipment_uom")]) - Process the delivery of the outgoing shipment - @@ -236,7 +236,7 @@ I assign this outgoing shipment - !python {model: stock.picking}: | - self.action_assign_wkf(cr, uid, [ref("outgoing_fifo_shipment_cur")]) + self.action_assign(cr, uid, [ref("outgoing_fifo_shipment_cur")]) - Process the delivery of the outgoing shipment - @@ -270,7 +270,7 @@ I assign this outgoing shipment - !python {model: stock.picking}: | - self.action_assign_wkf(cr, uid, [ref("outgoing_fifo_shipment_ret")]) + self.action_assign(cr, uid, [ref("outgoing_fifo_shipment_ret")]) - Process the delivery of the outgoing shipment - @@ -379,21 +379,4 @@ The price of the product should have changed back to 65.0 - !python {model: product.product}: | - assert self.browse(cr, uid, ref("product_fifo_icecream")).standard_price == 65.0 -- - Check Stock Valuation Report view, check first purchase order line corresponds with first outgoing line -- - !python {model: report.stock.valuation}: | - pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_fifo1")).picking_ids - original_move = pick_ids[0].name - pick_compare = self.pool.get("stock.picking").browse(cr, uid, ref("outgoing_fifo_shipment")).name - ids = self.search(cr, uid, [('product_id', '=', ref("product_fifo_icecream")), ('product_qty', '=', -10.0), ('value', '=', -500.0), - ('related_move_in', '=', original_move), ('name', '=', pick_compare)]) - assert len(ids) == 1, 'Could not find the correct line in the report' -- - Check Stock Inventory Report view if it shows the correct value of the stock -- - !python {model: report.stock.inventory}: | - ids = self.search(cr, uid, [('product_id', '=', ref("product_fifo_icecream")), ("state", "=", "done"), ("product_qty", ">", 0.0), - ('location_dest_type','=', 'internal')]) - assert len(ids) == 0, 'No lines should be visible in the stock inventory as the stock is negative' \ No newline at end of file + assert self.browse(cr, uid, ref("product_fifo_icecream")).standard_price == 65.0 \ No newline at end of file diff --git a/addons/purchase/test/lifo_price.yml b/addons/purchase/test/lifo_price.yml index b9d6aef5fe3..2e51a8cbca9 100644 --- a/addons/purchase/test/lifo_price.yml +++ b/addons/purchase/test/lifo_price.yml @@ -98,10 +98,16 @@ product_uom: product.product_uom_kgm product_qty: 20.0 type: out + - I confirm outgoing shipment of 20 kg of LIFO Ice Cream. - !workflow {model: stock.picking, action: button_confirm, ref: outgoing_lifo_shipment} +- + I assign this outgoing shipment +- + !python {model: stock.picking}: | + self.action_assign(cr, uid, [ref("outgoing_lifo_shipment")]) - Process the delivery of the outgoing shipment - @@ -109,7 +115,7 @@ partial_id = self.create(cr, uid, {}, context={'active_model': 'stock.picking','active_ids': [ref("outgoing_lifo_shipment")], 'default_type':'out'}) self.do_partial(cr, uid, [partial_id]) - - Check only 1 stock move matching was created + Check standard price became 80 euro - - !python {model: stock.picking}: | - assert len(self.browse(cr, uid, ref("outgoing_lifo_shipment")).move_lines[0].matching_ids_out) == 1, 'Should have created 1 matching' \ No newline at end of file + !python {model: product.product}: | + assert self.browse(cr, uid, ref("product_lifo_icecream")).standard_price == 80.0, 'Price should have been 80 euro' diff --git a/addons/stock/stock.py b/addons/stock/stock.py index fe6c3a31994..46fcb308a0d 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -153,6 +153,7 @@ class stock_location(osv.osv): # Quants #---------------------------------------------------------- + class stock_quant(osv.osv): """ Quants are the smallest unit of stock physical instances @@ -1173,7 +1174,6 @@ class stock_picking(osv.osv): def get_done_reserved_quants(self, cr, uid, picking_id, move, context=None): stock_operation_obj = self.pool.get('stock.pack.operation') quant_obj = self.pool.get('stock.quant') - possible_quants = [x.id for x in move.reserved_quant_ids] operation_ids = stock_operation_obj.find_packaging_op_from_product(cr, uid, move.product_id, picking_id, context=context) todo_later = [] possible_quants = [quant.id for quant in move.reserved_quant_ids] @@ -1186,17 +1186,18 @@ class stock_picking(osv.osv): #split for partial and take care of reserved quants quant_tuples = quant_obj._get_quant_tuples(cr, uid, [op.quant_id.id], op.product_qty, context=context) quant_obj.real_split_quants(cr, uid, quant_tuples, context=context) - done_reserved_quants = done_reserved_quants.union(set([qt[O] for qt in quant_tuples])) + done_reserved_quants = done_reserved_quants.union(set([qt[0] for qt in quant_tuples])) elif op.package_id: #moving a package never splits quants but we need to take care of the reserved_quant_ids all_children_quants = self.pool.get('stock.quant.package').quants_get(cr, uid, op.package_id, context=context) done_reserved_quants = done_reserved_quants.union(set(all_chilren_quants)) + #finish the partial split by operation that leaves the choice of quant to move for op in stock_operation_obj.browse(cr, uid, todo_later, context=context): quant_tuples = quant_obj._get_quant_tuples(cr, uid, possible_quants, op.product_qty, context=context) quant_obj.real_split_quants(cr, uid, quant_tuples, context=context) - done_reserved_quants = done_reserved_quants.union(set([qt[O] for qt in quant_tuples])) + done_reserved_quants = done_reserved_quants.union(set([qt[0] for qt in quant_tuples])) return done_reserved_quants @@ -1300,7 +1301,7 @@ class stock_picking(osv.osv): 'move_dest_id': False, 'price_unit': product_price, 'product_uom': product_uoms[move.id], - 'reserved_quant_ids': list(done_reserved_quants) + 'reserved_quant_ids': [(4,x) for x in list(done_reserved_quants)] } lot_id = lot_ids[move.id] if lot_id: @@ -1315,7 +1316,7 @@ class stock_picking(osv.osv): 'product_uos_qty': move.product_qty - partial_qty[move.id], #TODO: put correct uos_qty 'lot_id': False, 'tracking_id': False, - 'reserved_quant_ids': list(set(possible_quants) - done_reserved_quants), + 'reserved_quant_ids': [(4,x) for x in list(set(possible_quants) - done_reserved_quants)], }) if new_picking: diff --git a/addons/stock_location/stock_location.py b/addons/stock_location/stock_location.py index 6a183746e8b..11586535dc2 100644 --- a/addons/stock_location/stock_location.py +++ b/addons/stock_location/stock_location.py @@ -145,15 +145,6 @@ class procurement_order(osv.osv): }) return d -# # TODO: implement using routes on products -# def _find_suitable_rule(self, cr, uid, procurement, context=None): -# res = False -# if procurement.location_id: -# rule_obj = self.pool.get('procurement.rule') -# route_ids = [x.id for x in procurement.product_id.route_ids] -# res = rule_obj.search(cr, uid, [('location_id', '=', procurement.location_id.id), ('route_id', 'in', route_ids), ], context=context) -# return res and res[0] or super(procurement_order, self)._find_suitable_rule(cr, uid, procurement, context=context) - def _get_route_domain(self, cr, uid, procurement, context=None): route_ids = [x.id for x in procurement.product_id.route_ids] @@ -249,6 +240,7 @@ class stock_move(osv.osv): res = self.pool.get('stock.location').get_putaway_strategy(cr, uid, move.location_dest_id.id, move.product_id.id, context=context) if res: raise 'put away strategies not implemented yet!' + return True def action_assign(self, cr, uid, ids, context=None): @@ -268,10 +260,23 @@ class stock_location(osv.osv): 'removal_strategy_ids': fields.one2many('product.removal', 'location_id', 'Removal Strategies'), 'putaway_strategy_ids': fields.one2many('product.putaway', 'location_id', 'Put Away Strategies'), } - def get_putaway_strategy(self, cr, uid, id, product_id, context=None): - product = self.pool.get("product.product").browse(cr, uid, product_id, context=context) - strats = self.pool.get('product.removal').search(cr, uid, [('location_id','=',id), ('product_categ_id','child_of', product.categ_id.id)], context=context) - return strats and strats[0] or None + + + def get_putaway_strategy(self, cr, uid, id, location, product, context=None): + pa = self.pool.get('product.putaway') + categ = product.categ_id + categs = [categ.id, False] + while categ.parent_id: + categ = categ.parent_id + categs.append(categ.id) + + result = pa.search(cr,uid, [ + ('location_id', '=', location.id), + ('product_categ_id', 'in', categs) + ], context=context) + if result: + return pa.browse(cr, uid, result[0], context=context) + return super(stock_location, self).get_putaway_strategy(cr, uid, location, product, context=context) def get_removal_strategy(self, cr, uid, location, product, context=None): pr = self.pool.get('product.removal') @@ -289,4 +294,5 @@ class stock_location(osv.osv): return pr.browse(cr, uid, result[0], context=context) return super(stock_location, self).get_removal_strategy(cr, uid, location, product, context=context) + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: