Permalink
Browse files

Merge pull request #44 from PabloCastellano/acto_extincion

Extinción de sociedad
  • Loading branch information...
PabloCastellano committed Jan 7, 2017
2 parents 7ba185d + fcfff80 commit 4c45c94cfcb1d46564abfc9ce2a29c019f99d269
View
@@ -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()
@@ -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:')
@@ -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:')
@@ -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:')
@@ -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):
@@ -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())):
@@ -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())):
@@ -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),
),
]
View
@@ -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)
@@ -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)])
@@ -23,7 +23,8 @@ <h1>Sociedad «{{ company.fullname }}»</h1>
<p>
<strong>Empresas relacionadas:</strong> {{ companies|length }}<br/>
<strong>Personas relacionadas:</strong> {{ persons|length }}
<strong>Personas relacionadas:</strong> {{ persons|length }}<br/>
<strong>Situación mercantil:</strong> {{ activity }}
</p>
{% comment %}
@@ -62,7 +63,11 @@ <h2>Cargos directivos:</h2>
</tbody>
</table>
{% else %}
{% if company.is_active %}
<i>No hay datos</i> <a href="#" data-toggle="modal" data-target="#myModal">[?]</a>
{% else %}
<i>La sociedad está inactiva.</i>
{% endif %}
{% endif %}
</div>
</div>
@@ -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
}
View
@@ -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()[0]), 0)
self.assertEqual(len(company.get_cargos_historial()[0]), 1)
View
@@ -434,6 +434,7 @@ def get_context_data(self, **kwargs):
context['companies'] = sorted(list(set(context['companies'])))
context['persons'] = sorted(list(set(context['persons'])))
context['activity'] = 'Activa' if self.company.is_active else 'Inactiva'
return context

0 comments on commit 4c45c94

Please sign in to comment.