[IMP] Onchange on picking type in pos.config
authorJosse Colpaert <jco@openerp.com>
Mon, 24 Mar 2014 12:54:41 +0000 (13:54 +0100)
committerJosse Colpaert <jco@openerp.com>
Mon, 24 Mar 2014 12:54:41 +0000 (13:54 +0100)
bzr revid: jco@openerp.com-20140324125441-eh4wb77pwzop0zon

addons/point_of_sale/point_of_sale.py
addons/point_of_sale/point_of_sale_view.xml

index 3085cc6..040874d 100644 (file)
@@ -162,6 +162,14 @@ class pos_config(osv.osv):
         'company_id': _get_default_company,
     }
 
+
+    def onchange_picking_type_id(self, cr, uid, ids, picking_type_id, context=None):
+        p_type_obj = self.pool.get("stock.picking.type")
+        p_type = p_type_obj.browse(cr, uid, picking_type_id, context=context)
+        if p_type.default_location_src_id and p_type.default_location_src_id.usage == 'internal' and p_type.default_location_dest_id and p_type.default_location_dest_id.usage == 'customer':
+            return {'value': {'stock_location_id': p_type.default_location_src_id.id}}
+        return False
+
     def set_active(self, cr, uid, ids, context=None):
         return self.write(cr, uid, ids, {'state' : 'active'}, context=context)
 
index 8182fa5..9a076d2 100644 (file)
                             <field name="name"/>
                         </h1>
                         <group col="4">
-                            <field name="picking_type_id" widget="selection" groups="stock.group_locations" /><!-- TODO Group? -->
+                            <field name="picking_type_id" widget="selection" groups="stock.group_locations" 
+                                on_change="onchange_picking_type_id(picking_type_id)"/>
                             <field name="stock_location_id" groups="stock.group_locations"/>
                             <field name="pricelist_id" groups="product.group_sale_pricelist"/>
                             <field name="currency_id" invisible="1"/>