From ec42279960a9a3f643de5cee27f0791c24b5c5da Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 13 Sep 2013 11:42:16 +0200 Subject: [PATCH] [IMP] group push rules by purchase, purchase order line has procurements, one route on product bzr revid: jco@openerp.com-20130913094216-lyfj84amuxlcnpq9 --- addons/purchase/purchase.py | 22 ++++++++++++++----- addons/purchase/purchase_view.xml | 2 +- addons/stock/product.py | 2 +- addons/stock_location/stock_location.py | 6 ++--- addons/stock_location/stock_location_view.xml | 14 ------------ 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index e336e14f3c7..4c0d0f16019 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -682,7 +682,7 @@ class purchase_order(osv.osv): 'picking_type_id': type_id, } - def _prepare_order_line_move(self, cr, uid, order, order_line, picking_id, context=None): + def _prepare_order_line_move(self, cr, uid, order, order_line, picking_id, group_id, context=None): ''' prepare the stock move data from the PO line ''' type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'picking_type_in')[1] price_unit = order_line.price_unit @@ -710,6 +710,7 @@ class purchase_order(osv.osv): 'company_id': order.company_id.id, 'price_unit': price_unit, 'picking_type_id': type_id, + 'group_id': group_id, } def _create_pickings(self, cr, uid, order, order_lines, picking_id=False, context=None): @@ -736,11 +737,19 @@ class purchase_order(osv.osv): picking_id = stock_picking.create(cr, uid, self._prepare_order_picking(cr, uid, order, context=context)) todo_moves = [] stock_move = self.pool.get('stock.move') + + new_group = False + if any([(x.group_id == False) for x in order_lines]): + new_group = self.pool.get("procurement.group").create(cr, uid, {'name':order.name, 'partner_id': order.partner_id.id}, context=context) + + for order_line in order_lines: if not order_line.product_id: continue + if order_line.product_id.type in ('product', 'consu'): - move = stock_move.create(cr, uid, self._prepare_order_line_move(cr, uid, order, order_line, picking_id, context=context)) + group_id = order_line.group_id and order_line.group_id.id or new_group + move = stock_move.create(cr, uid, self._prepare_order_line_move(cr, uid, order, order_line, picking_id, group_id, context=context)) if order_line.move_dest_id: order_line.move_dest_id.write({'location_id': order.location_id.id}) todo_moves.append(move) @@ -957,6 +966,8 @@ class purchase_order_line(osv.osv): 'invoiced': fields.boolean('Invoiced', readonly=True), 'partner_id': fields.related('order_id','partner_id',string='Partner',readonly=True,type="many2one", relation="res.partner", store=True), 'date_order': fields.related('order_id','date_order',string='Order Date',readonly=True,type="date"), + 'procurement_ids': fields.one2many('procurement.order', 'purchase_line_id', string='Associated procurements'), + 'group_id': fields.related('procurement_ids', 'group_id', type='many2one', relation='procurement.group', string='Procurement Group'), } _defaults = { 'product_qty': lambda *a: 1.0, @@ -1115,7 +1126,7 @@ class procurement_rule(osv.osv): class procurement_order(osv.osv): _inherit = 'procurement.order' _columns = { - 'purchase_id': fields.many2one('purchase.order', 'Purchase Order'), + 'purchase_line_id': fields.many2one('purchase.order.line', 'Purchase Order'), } def _find_suitable_rule(self, cr, uid, procurement, context=None): @@ -1133,7 +1144,7 @@ class procurement_order(osv.osv): return super(procurement_order, self)._run(cr, uid, procurement, context=context) def _check(self, cr, uid, procurement, context=None): - if procurement.purchase_id and procurement.purchase_id.shipped: # TOCHECK: does it work for several deliveries? + if procurement.purchase_line_id and procurement.purchase_line_id.order_id.shipped: # TOCHECK: does it work for several deliveries? return True return super(procurement_order, self)._check(cr, uid, procurement, context=context) @@ -1290,7 +1301,8 @@ class procurement_order(osv.osv): 'payment_term_id': partner.property_supplier_payment_term.id or False, } res[procurement.id] = self.create_procurement_purchase_order(cr, uid, procurement, po_vals, line_vals, context=new_context) - self.write(cr, uid, [procurement.id], {'purchase_id': res[procurement.id]}) + procurement_line = self.pool.get('purchase.order').browse(cr, uid, res[procurement.id]).order_line[0].id + self.write(cr, uid, [procurement.id], {'purchase_line_id': procurement_line}, context=context) pass_ids += [procurement.id] if pass_ids: self.message_post(cr, uid, pass_ids, body=_("Draft Purchase Order created"), context=context) diff --git a/addons/purchase/purchase_view.xml b/addons/purchase/purchase_view.xml index 5e520537d79..b23a71b8fa0 100644 --- a/addons/purchase/purchase_view.xml +++ b/addons/purchase/purchase_view.xml @@ -550,7 +550,7 @@ - + diff --git a/addons/stock/product.py b/addons/stock/product.py index fdfbf0e88ba..9e436dd49c3 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -216,7 +216,7 @@ class product_product(osv.osv): 'location_id': fields.dummy(string='Location', relation='stock.location', type='many2one'), 'warehouse_id': fields.dummy(string='Warehouse', relation='stock.warehouse', type='many2one'), 'orderpoint_ids': fields.one2many('stock.warehouse.orderpoint', 'product_id', 'Minimum Stock Rules'), - 'route_ids': fields.many2many('stock.location.route', 'stock_location_route_product', 'product_id', 'route_id', 'Routes', + 'route_ids': fields.many2many('stock.location.route', 'stock_route_product', 'product_id', 'route_id', 'Routes', help="Depending on the modules installed, this will allow you to define the route of the product: whether it will be bought, manufactured, MTO/MTS,..."), } diff --git a/addons/stock_location/stock_location.py b/addons/stock_location/stock_location.py index 94681524afb..cf6cd4b0afa 100644 --- a/addons/stock_location/stock_location.py +++ b/addons/stock_location/stock_location.py @@ -153,7 +153,7 @@ class procurement_order(osv.osv): '''we try to first find a rule among the ones defined on the procurement order group and if none is found, we try on the routes defined for the product, and finally we fallback on the default behavior''' categ_obj = self.pool.get("product.category") categ_id = procurement.product_id.categ_id.id - route_ids = [x.id for x in procurement.route_ids] + [x.id for x in procurement.product_id.route_ids] + categ_obj.calculate_total_routes(cr, uid, [categ_id], False, False, context=context)[categ_id] + route_ids = [x.id for x in procurement.product_id.route_ids + procurement.product_id.categ_id.total_route_ids] res = self.pool.get('procurement.rule').search(cr, uid, domain + [('route_id', 'in', route_ids)], order = 'route_sequence, sequence', context=context) if not res: res = self.pool.get('procurement.rule').search(cr, uid, domain + [('route_id', '=', False)], order='sequence', context=context) @@ -186,7 +186,7 @@ class product_removal_strategy(osv.osv): class product_product(osv.osv): _inherit = 'product.product' _columns = { - 'route_ids': fields.many2many('stock.location.route', 'stock_location_route_product', 'product_id', 'route_id', 'Routes', domain="[('product_selectable', '=', True)]"), #Adds domain + 'route_ids': fields.many2many('stock.location.route', 'stock_route_product', 'product_id', 'route_id', 'Routes', domain="[('product_selectable', '=', True)]"), #Adds domain } class product_category(osv.osv): @@ -249,7 +249,7 @@ class stock_move(osv.osv): for move in moves: if not move.move_dest_id: categ_id = move.product_id.categ_id.id - routes = [x.id for x in move.product_id.route_ids] + categ_obj.calculate_total_routes(cr, uid, [categ_id], False, False, context=context)[categ_id] + routes = [x.id for x in move.product_id.route_ids + move.product_id.categ_id.total_route_ids] rules = push_obj.search(cr, uid, [('route_id', 'in', routes), ('location_from_id', '=', move.location_dest_id.id)], context=context) if rules: rule = push_obj.browse(cr, uid, rules[0], context=context) diff --git a/addons/stock_location/stock_location_view.xml b/addons/stock_location/stock_location_view.xml index 260788365c1..a8cd0ce81bc 100644 --- a/addons/stock_location/stock_location_view.xml +++ b/addons/stock_location/stock_location_view.xml @@ -115,20 +115,6 @@ - - product.product.form - product.product - - - - - - - - - - - product.category.form