Skip to content
This repository has been archived by the owner on Sep 29, 2022. It is now read-only.

Commit

Permalink
Extinción de sociedad
Browse files Browse the repository at this point in the history
DB: Company.is_active default True
#42
  • Loading branch information
PabloCastellano committed Jan 7, 2017
1 parent 7ba185d commit fb24b56
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 8 deletions.
16 changes: 10 additions & 6 deletions borme/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.isoformat())

company.anuncios.append(anuncio.id) # TODO: year
company.date_updated = borme.date
company.save()
Expand Down Expand Up @@ -318,7 +322,7 @@ def _import_borme_download_range2(begin, end, seccion, local_only, strict=False,
try:
bormes.append(bormeparser.parse(filepath, seccion))
except Exception as e:
logger.error('[X] Error grave en bormeparser.parse(): %s' % filepath)
logger.error('[X] Error grave (I) en bormeparser.parse(): %s' % filepath)
logger.error('[X] %s: %s' % (e.__class__.__name__, e))
if strict:
logger.error('[X] Una vez arreglado, reanuda la importación:')
Expand All @@ -337,7 +341,7 @@ def _import_borme_download_range2(begin, end, seccion, local_only, strict=False,
try:
bormes.append(bormeparser.Borme.from_json(filepath))
except Exception as e:
logger.error('[X] Error grave en bormeparser.Borme.from_json(): %s' % filepath)
logger.error('[X] Error grave (I) en bormeparser.Borme.from_json(): %s' % filepath)
logger.error('[X] %s: %s' % (e.__class__.__name__, e))
if strict:
logger.error('[X] Una vez arreglado, reanuda la importación:')
Expand All @@ -350,7 +354,7 @@ def _import_borme_download_range2(begin, end, seccion, local_only, strict=False,
try:
bormes.append(bormeparser.parse(filepath, seccion))
except Exception as e:
logger.error('[X] Error grave en bormeparser.parse(): %s' % filepath)
logger.error('[X] Error grave (II) en bormeparser.parse(): %s' % filepath)
logger.error('[X] %s: %s' % (e.__class__.__name__, e))
if strict:
logger.error('[X] Una vez arreglado, reanuda la importación:')
Expand All @@ -372,7 +376,7 @@ def _import_borme_download_range2(begin, end, seccion, local_only, strict=False,
try:
bormes.append(bormeparser.Borme.from_json(filepath))
except Exception as e:
logger.error('[X] Error grave en bormeparser.Borme.from_json(): %s' % filepath)
logger.error('[X] Error grave (II) en bormeparser.Borme.from_json(): %s' % filepath)
logger.error('[X] %s: %s' % (e.__class__.__name__, e))

for borme in sorted(bormes):
Expand Down Expand Up @@ -440,7 +444,7 @@ def import_borme_pdf(filename, create_json=True):
json_filepath = os.path.join(json_path, '%s.json' % borme.cve)
borme.to_json(json_filepath)
except Exception as e:
logger.error('[X] Error grave en bormeparser.parse(): %s' % filename)
logger.error('[X] Error grave (III) en bormeparser.parse(): %s' % filename)
logger.error('[X] %s: %s' % (e.__class__.__name__, e))

if not all(map(lambda x: x == 0, results.values())):
Expand All @@ -458,7 +462,7 @@ def import_borme_json(filename):
borme = bormeparser.Borme.from_json(filename)
results = _import1(borme)
except Exception as e:
logger.error('[X] Error grave en bormeparser.Borme.from_json(): %s' % filename)
logger.error('[X] Error grave (III) en bormeparser.Borme.from_json(): %s' % filename)
logger.error('[X] %s: %s' % (e.__class__.__name__, e))

if not all(map(lambda x: x == 0, results.values())):
Expand Down
20 changes: 20 additions & 0 deletions borme/migrations/0002_company_is_active_default_true.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.8 on 2017-01-07 16:30
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('borme', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='company',
name='is_active',
field=models.BooleanField(default=True),
),
]
18 changes: 17 additions & 1 deletion borme/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Company(Model):
nif = CharField(max_length=10)
slug = CharField(max_length=260, primary_key=True)
date_creation = DateField(blank=True, null=True)
is_active = BooleanField(default=False)
is_active = BooleanField(default=True)
type = CharField(max_length=50, choices=SOCIEDADES)

date_updated = DateField(db_index=True)
Expand Down Expand Up @@ -219,6 +219,22 @@ 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.
date: str iso format
"""
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)])

Expand Down
33 changes: 33 additions & 0 deletions borme/tests/files/4_extincion.json
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 18 additions & 1 deletion borme/tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()[0]), 0)
self.assertEqual(len(company.get_cargos_historial()[0]), 1)

0 comments on commit fb24b56

Please sign in to comment.