From f8fcb29645fcbf0171c0baf4db499e0a8a4995d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 8 Jul 2016 10:50:58 +0200 Subject: [PATCH] Allow all carriers if there is no selection This allows to keep the same default behaviour as before the creation of CarrierSelection. issue5285 review31311002 --- carrier.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/carrier.py b/carrier.py index 72b28f9378..25628681d7 100644 --- a/carrier.py +++ b/carrier.py @@ -50,6 +50,21 @@ class Carrier(ModelSQL, ModelView): return self.carrier_product.cost_price, user.company.currency.id return 0, None + @classmethod + def create(cls, *args, **kwargs): + pool = Pool() + CarrierSelection = pool.get('carrier.selection') + carriers = super(Carrier, cls).create(*args, **kwargs) + CarrierSelection._get_carriers_cache.clear() + return carriers + + @classmethod + def delete(cls, *args, **kwargs): + pool = Pool() + CarrierSelection = pool.get('carrier.selection') + super(Carrier, cls).delete(*args, **kwargs) + CarrierSelection._get_carriers_cache.clear() + class CarrierSelection(MatchMixin, ModelSQL, ModelView): 'Carrier Selection' @@ -106,9 +121,14 @@ class CarrierSelection(MatchMixin, ModelSQL, ModelView): return Carrier.browse(carriers) carriers = [] - for selection in cls.search([]): - if selection.match(pattern): - carriers.append(selection.carrier) + selections = cls.search([]) + if not selections: + with Transaction().set_context(active_test=False): + carriers = Carrier.search([]) + else: + for selection in selections: + if selection.match(pattern): + carriers.append(selection.carrier) cls._get_carriers_cache.set(key, map(int, carriers)) return carriers