From f6dceb2ef6e17202ce47b637c7e83ed2402e3d4b Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 26 Aug 2014 14:21:59 +0200 Subject: [PATCH] [IMP] point_of_sale: prevent multicompany configuration issues 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 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index bdfdf4f728d..9d731e677d2 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -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):