diff --git a/lemarche/siaes/models.py b/lemarche/siaes/models.py index 5a408e21e..0f1602b03 100644 --- a/lemarche/siaes/models.py +++ b/lemarche/siaes/models.py @@ -949,6 +949,10 @@ def save(self, *args, **kwargs): else: raise e + @property + def is_live(self) -> bool: + return self.is_active and not self.is_delisted + @property def kind_is_esat_or_ea_or_eatt(self) -> bool: return self.kind in [siae_constants.KIND_ESAT, siae_constants.KIND_EA, siae_constants.KIND_EATT] diff --git a/lemarche/siaes/tests.py b/lemarche/siaes/tests.py index 2bba795f2..755b69285 100644 --- a/lemarche/siaes/tests.py +++ b/lemarche/siaes/tests.py @@ -83,6 +83,15 @@ def test_str(self): siae = SiaeFactory(name="Ma boite") self.assertEqual(str(siae), "Ma boite") + def test_is_live(self): + siae_live = SiaeFactory(is_active=True, is_delisted=False) + siae_not_live_1 = SiaeFactory(is_active=True, is_delisted=True) + siae_not_live_2 = SiaeFactory(is_active=False, is_delisted=False) + siae_not_live_3 = SiaeFactory(is_active=False, is_delisted=True) + self.assertTrue(siae_live.is_live) + for s in [siae_not_live_1, siae_not_live_2, siae_not_live_3]: + self.assertFalse(s.is_live) + def test_name_display_property(self): siae_without_brand = SiaeFactory(name="Ma raison sociale") siae_with_brand = SiaeFactory(name="Ma raison sociale", brand="Mon enseigne") @@ -408,10 +417,10 @@ def setUpTestData(cls): pass def test_is_live_queryset(self): - SiaeFactory(is_active=True, is_delisted=True) - SiaeFactory(is_active=False, is_delisted=True) SiaeFactory(is_active=True, is_delisted=False) # live + SiaeFactory(is_active=True, is_delisted=True) SiaeFactory(is_active=False, is_delisted=False) + SiaeFactory(is_active=False, is_delisted=True) self.assertEqual(Siae.objects.count(), 4) self.assertEqual(Siae.objects.is_live().count(), 1) self.assertEqual(Siae.objects.is_not_live().count(), 3)