From a6343387d756f53e3538992601e0680eded0caa3 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 17 Oct 2014 14:22:13 +0200 Subject: [PATCH] [IMP] point_of_sale: add constraint on company Using a payment method belonging to another company will raise errors when closing the session. To avoid being stuck at session closing, forbid to create a POS using a journal of another company. --- addons/point_of_sale/point_of_sale.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index 28b3795..87e4bf5 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -110,10 +110,21 @@ class pos_config(osv.osv): return False return True + def _check_company_payment(self, cr, uid, ids, context=None): + for config in self.browse(cr, uid, ids, context=context): + journal_ids = [j.id for j in config.journal_ids] + if self.pool['account.journal'].search(cr, uid, [ + ('id', 'in', journal_ids), + ('company_id', '!=', config.company_id.id) + ], count=True, context=context): + 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']), + (_check_company_payment, "The company of a payment method is different than the one of point of sale", ['company_id', 'journal_ids']), ] def name_get(self, cr, uid, ids, context=None): -- 1.7.10.4