From 8d276bb938efe779a567fd55684eedf52917fde4 Mon Sep 17 00:00:00 2001 From: Pablo Castellano Date: Sat, 7 Jan 2017 19:03:07 +0100 Subject: [PATCH] =?UTF-8?q?Extinci=C3=B3n=20de=20sociedad?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/PabloCastellano/libreborme/issues/42 --- borme/importer.py | 4 ++++ borme/models.py | 15 ++++++++++++++ borme/tests/files/4_extincion.json | 33 ++++++++++++++++++++++++++++++ borme/tests/test_import.py | 19 ++++++++++++++++- 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 borme/tests/files/4_extincion.json diff --git a/borme/importer.py b/borme/importer.py index 81a6f94..3dc5cb9 100644 --- a/borme/importer.py +++ b/borme/importer.py @@ -162,6 +162,10 @@ def _import1(borme): # not bormeparser.borme.BormeActoCargo nuevo_anuncio.actos[acto.name] = acto.value + if acto.name == 'Extinción': + company.is_active = False + company._finalizar_cargos(borme.date) + company.anuncios.append(anuncio.id) # TODO: year company.date_updated = borme.date company.save() diff --git a/borme/models.py b/borme/models.py index d485364..cda6cb6 100644 --- a/borme/models.py +++ b/borme/models.py @@ -219,6 +219,21 @@ def update_cargos_salientes(self, cargos): else: raise ValueError('type: invalid value') + def _finalizar_cargos(self, date): + """ Se llama a este método cuando una sociedad se extingue. + Todos los cargos vigentes pasan a estar en la lista de cargos cesados. + """ + for cargo in self.cargos_actuales_c: + cargo['date_to'] = date + self.cargos_historial_c.append(cargo) + + for cargo in self.cargos_actuales_p: + cargo['date_to'] = date + self.cargos_historial_p.append(cargo) + + self.cargos_actuales_c = [] + self.cargos_actuales_p = [] + def get_absolute_url(self): return reverse('borme-empresa', args=[str(self.slug)]) diff --git a/borme/tests/files/4_extincion.json b/borme/tests/files/4_extincion.json new file mode 100644 index 0000000..5cd66dd --- /dev/null +++ b/borme/tests/files/4_extincion.json @@ -0,0 +1,33 @@ +{ + "cve": "BORME-Z-2015-3-04", + "date": "2015-01-04", + "seccion": "A", + "provincia": "Almer\u00eda", + "num": 1, + "url": "unused_url", + "from_anuncio": 1, + "to_anuncio": 1, + "anuncios": { + "1": { + "empresa": "EMPRESA EXTINGUIDA SL", + "datos registrales": "T 1 , F 2, S 3, H AL 42885, I/A 2 (19.12.14).", + "actos": { + "Nombramientos": { + "Adm. Solid.": [ + "FRANCISCO GOMEZ", + ] + } + }, + "num_actos": 1 + }, + "2": { + "empresa": "EMPRESA EXTINGUIDA SL", + "datos registrales": "T 1 , F 2, S 3, H AL 42885, I/A 2 (19.12.14).", + "actos": { + "Extinci\u00f3n": true + }, + "num_actos": 1 + } + }, + "num_anuncios": 2 +} diff --git a/borme/tests/test_import.py b/borme/tests/test_import.py index 2012802..c8fcf37 100644 --- a/borme/tests/test_import.py +++ b/borme/tests/test_import.py @@ -47,7 +47,7 @@ def test_nombramientos_ceses(self): class TestImport3(TestCase): - + def test_nombramientos_ceses(self): companies = Company.objects.all() self.assertEqual(len(companies), 0) @@ -61,3 +61,20 @@ def test_nombramientos_ceses(self): self.assertEqual(company.name, 'EMPRESA TRES') self.assertEqual(len(company.get_cargos_actuales(limit=0)), 1) self.assertEqual(len(company.get_cargos_historial(limit=0)), 2) + + +class TestImport4(TestCase): + + def test_extincion(self): + companies = Company.objects.all() + self.assertEqual(len(companies), 0) + + json_path = os.path.join(THIS_PATH, 'files', '4_extincion.json') + ret = import_borme_json(json_path) + self.assertTrue(ret) + companies = Company.objects.all() + self.assertEqual(len(companies), 1) + company = companies[0] + self.assertEqual(company.name, 'EMPRESA EXTINGUIDA') + self.assertEqual(len(company.get_cargos_actuales(limit=0)), 0) + self.assertEqual(len(company.get_cargos_historial(limit=0)), 1)