From b185760c7bf5531d61ab0f165ecffcf07ac779ae Mon Sep 17 00:00:00 2001 From: "Mayur Maheshwari (OpenERP)" Date: Thu, 30 Aug 2012 12:22:55 +0530 Subject: [PATCH] [IMP]stock : added a new filed type for set a location in or out and make a onchane & default method for it and set action of moves for its view bzr revid: mma@tinyerp.com-20120830065255-ogmp9xytwd3kr8f8 --- addons/stock/stock.py | 38 +++++++++++++++++++++++++++++++++++++ addons/stock/stock_view.xml | 20 ++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 7f0a744a62e..e49cc0ffa5c 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1653,6 +1653,7 @@ class stock_move(osv.osv): # used for colors in tree views: 'scrapped': fields.related('location_dest_id','scrap_location',type='boolean',relation='stock.location',string='Scrapped', readonly=True), + 'type': fields.selection([('out', 'Sending Goods'), ('in', 'Getting Goods'), ('internal', 'Internal')], 'Shipping Type', required=True, select=True, help="Shipping type specify, goods coming in or going out."), } def _check_location(self, cr, uid, ids, context=None): for record in self.browse(cr, uid, ids, context=context): @@ -1732,10 +1733,27 @@ class stock_move(osv.osv): user = self.pool.get('res.users').browse(cr, uid, uid, context=context) return user.company_id.partner_id.id + def _default_move_type(self, cr, uid, context=None): + """ Gets default type of move + @return: type + """ + picking_type = context.get('picking_type') + type = False + if context is None: + context = {} + if picking_type == 'in': + type = 'in' + elif picking_type == 'out': + type = 'out' + else: + type = 'internal' + return type + _defaults = { 'location_id': _default_location_source, 'location_dest_id': _default_location_destination, 'partner_id': _default_destination_address, + 'type': _default_move_type, 'state': 'draft', 'priority': '1', 'product_qty': 1.0, @@ -1889,6 +1907,26 @@ class stock_move(osv.osv): result['location_dest_id'] = loc_dest_id return {'value': result} + def onchange_move_type(self, cr, uid, ids, type, context=None): + """ On change of move type gives sorce and destination location. + @param type: Move Type + @return: Dictionary of values + """ + mod_obj = self.pool.get('ir.model.data') + location_source_id = False + location_dest_id = False + if type == 'in': + location_source_id = 'stock_location_suppliers' + location_dest_id = 'stock_location_stock' + elif type == 'out': + location_source_id = 'stock_location_stock' + location_dest_id = 'stock_location_customers' + if location_source_id: + location_model, location_source_id = mod_obj.get_object_reference(cr, uid, 'stock', location_source_id) + if location_dest_id: + location_model, location_dest_id = mod_obj.get_object_reference(cr, uid, 'stock', location_dest_id) + return {'value':{'location_id': location_source_id, 'location_dest_id': location_dest_id}} + def onchange_date(self, cr, uid, ids, date, date_expected, context=None): """ On change of Scheduled Date gives a Move date. @param date_expected: Scheduled Date diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index d6ae96cf121..cdce4c3dc94 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -1126,6 +1126,7 @@ + @@ -1239,6 +1240,7 @@ + @@ -1279,7 +1281,7 @@ stock.move.form stock.move - +
@@ -1294,6 +1296,7 @@ +