[IMP] point_of_sale: prevent multicompany configuration issues
authorMartin Trigaux <mat@openerp.com>
Tue, 26 Aug 2014 12:21:59 +0000 (14:21 +0200)
committerMartin Trigaux <mat@openerp.com>
Tue, 26 Aug 2014 14:15:22 +0000 (16:15 +0200)
If the pos.config is not properly configured for multicompany (e.g. using location belonging to another company), launching a session with this config may fail (access rights).
This prevents to configure an incorrect point of sale in the first place.

addons/point_of_sale/point_of_sale.py

index bdfdf4f..9d731e6 100644 (file)
@@ -98,8 +98,22 @@ class pos_config(osv.osv):
             for record in self.browse(cr, uid, ids, context=context)
         )
 
+    def _check_company_location(self, cr, uid, ids, context=None):
+        for config in self.browse(cr, uid, ids, context=context):
+            if config.stock_location_id.company_id and config.stock_location_id.company_id.id != config.company_id.id:
+                return False
+        return True
+
+    def _check_company_journal(self, cr, uid, ids, context=None):
+        for config in self.browse(cr, uid, ids, context=context):
+            if config.journal_id and config.journal_id.company_id.id != config.company_id.id:
+                return False
+        return True
+
     _constraints = [
         (_check_cash_control, "You cannot have two cash controls in one Point Of Sale !", ['journal_ids']),
+        (_check_company_location, "The company of the stock location is different than the one of point of sale", ['company_id', 'stock_location_id']),
+        (_check_company_journal, "The company of the sale journal is different than the one of point of sale", ['company_id', 'journal_id']),
     ]
 
     def name_get(self, cr, uid, ids, context=None):