From cd462b7c8d182c5e554351d45f652dff33707fa4 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Mon, 8 Sep 2014 15:20:01 +0200 Subject: [PATCH] [IMP] Invoice_state on move and search custom picking type --- addons/mrp/mrp.py | 22 ++++++++++++++++++--- addons/stock/stock.py | 11 +++++++++++ addons/stock_account/stock.py | 7 ------- addons/stock_account/stock_account_view.xml | 10 ++++++++++ 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index c06acff1153..5f84cdaf730 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -1065,16 +1065,32 @@ class mrp_production(osv.osv): + def _create_previous_move(self, cr, uid, move_id, product, source_location_id, dest_location_id, context=None): ''' When the routing gives a different location than the raw material location of the production order, we should create an extra move from the raw material location to the location of the routing, which - precedes the consumption line (chained) + precedes the consumption line (chained). The picking type depends on the warehouse in which this happens + and the type of locations. ''' - + loc_obj = self.pool.get("stock.location") stock_move = self.pool.get('stock.move') type_obj = self.pool.get('stock.picking.type') - types = type_obj.search(cr, uid, [('code','=','outgoing')], context=context) + # Need to search for a picking type + src_loc = loc_obj.browse(cr, uid, source_location_id, context=context) + dest_loc = loc_obj.browse(cr, uid, dest_location_id, context=context) + code = 'internal' + check_loc = dest_loc + if src_loc.usage == 'internal' and dest_loc.usage != 'internal': + code = 'outgoing' + check_loc = src_loc + if src_loc.usage != 'internal' and dest_loc.usage == 'internal': + code = 'incoming' + wh = loc_obj.get_warehouse(cr, uid, check_loc, context=context) + domain = [('code','=', code)] + if wh: + domain += [('warehouse_id', '=', wh)] + types = type_obj.search(cr, uid, domain, context=context) move = stock_move.copy(cr, uid, move_id, default = { 'location_id': source_location_id, 'location_dest_id': dest_location_id, diff --git a/addons/stock/stock.py b/addons/stock/stock.py index f033b4d5e6a..9b9d8a5c0d9 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -189,6 +189,16 @@ class stock_location(osv.osv): return self._default_removal_strategy(cr, uid, context=context) + def get_warehouse(self, cr, uid, location, context=None): + """ + Returns warehouse id of warehouse that contains location + :param location: browse record (stock.location) + """ + wh_obj = self.pool.get("stock.warehouse") + whs = wh_obj.search(cr, uid, [('view_location_id.parent_left', '<=', location.parent_left), + ('view_location_id.parent_right', '>=', location.parent_left)], context=context) + return whs and whs[0] or False + #---------------------------------------------------------- # Routes #---------------------------------------------------------- @@ -3460,6 +3470,7 @@ class stock_warehouse(osv.osv): 'limit': 20 } + class stock_location_path(osv.osv): _name = "stock.location.path" _description = "Pushed Flows" diff --git a/addons/stock_account/stock.py b/addons/stock_account/stock.py index 12f6c76573d..f1a3680eca7 100644 --- a/addons/stock_account/stock.py +++ b/addons/stock_account/stock.py @@ -97,7 +97,6 @@ class stock_move(osv.osv): def _get_master_data(self, cr, uid, move, company, context=None): ''' returns a tuple (browse_record(res.partner), ID(res.users), ID(res.currency)''' currency = company.currency_id.id - import pdb; pdb.set_trace() partner = move.picking_id and move.picking_id.partner_id if partner: if partner.property_product_pricelist and move.location_id.usage == 'internal' and move.location_dest_id.usage != 'internal': @@ -193,11 +192,6 @@ class stock_picking(osv.osv): res.append(move.picking_id.id) return res - def _set_inv_state(self, cr, uid, picking_id, name, value, arg, context=None): - pick = self.browse(cr, uid, picking_id, context=context) - moves = [x.id for x in pick.move_lines] - move_obj= self.pool.get("stock.move") - move_obj.write(cr, uid, moves, {'invoice_state': pick.invoice_state}) _columns = { @@ -206,7 +200,6 @@ class stock_picking(osv.osv): ("2binvoiced", "To Be Invoiced"), ("none", "Not Applicable") ], string="Invoice Control", required=True, - #fnct_inv = _set_inv_state, store={ 'stock.picking': (lambda self, cr, uid, ids, c={}: ids, ['state'], 10), 'stock.move': (__get_picking_move, ['picking_id', 'invoice_state'], 10), diff --git a/addons/stock_account/stock_account_view.xml b/addons/stock_account/stock_account_view.xml index dbce1a96bdd..a3dd6260189 100644 --- a/addons/stock_account/stock_account_view.xml +++ b/addons/stock_account/stock_account_view.xml @@ -82,5 +82,15 @@ + + stock.move.form.invoice_state + stock.move + + + + + + +