Compare commits

...

2 Commits
main ... main

  1. 5
      center_pilote/civicrm/management/to_creme.py
  2. 1
      center_pilote/civicrm/model_builder/__init__.py
  3. 25
      center_pilote/civicrm/model_builder/organisation_adhesion_append.py
  4. 19
      center_pilote/civicrm/models/contact.py
  5. 17
      center_pilote/civicrm/models/orig.py

5
center_pilote/civicrm/management/to_creme.py

@ -2,6 +2,7 @@ import logging @@ -2,6 +2,7 @@ import logging
from ..model_builder import (
ContactModelBuilder,
OrganisationAdhesionAppend,
OrganisationModelBuilder,
RelationModelBuilder,
)
@ -27,6 +28,10 @@ def import_contact(dryrun=True): @@ -27,6 +28,10 @@ def import_contact(dryrun=True):
logger.warning("Start relation loop")
for obj_in in CivicrmRelationship.objects.to_import():
RelationModelBuilder(obj_in, dryrun=dryrun).process()
for obj_in in CivicrmContact.objects.organisations().filter(
extadhesion__contact_adhesion__isnull=False
):
OrganisationAdhesionAppend(obj_in, dryrun=dryrun).process()
logger.warning("Start chaufferie loop")
for obj_in in CivicrmActivity.objects.chaufferies():
pass

1
center_pilote/civicrm/model_builder/__init__.py

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
from .contact_builder import ContactModelBuilder # noqa
from .organisation_adhesion_append import OrganisationAdhesionAppend # noqa
from .organisation_builder import OrganisationModelBuilder # noqa
from .relation_builder import RelationModelBuilder # noqa

25
center_pilote/civicrm/model_builder/organisation_adhesion_append.py

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
import logging
from creme.persons import get_contact_model, get_organisation_model
logger = logging.getLogger(__name__)
class OrganisationAdhesionAppend:
model = get_organisation_model()
model_contact = get_contact_model()
def __init__(self, obj_in, dryrun=True):
self.obj_in = obj_in
self.dryrun = dryrun
def process(self):
self.orga = self.model.objects.get(import_id=self.obj_in.id)
self.contact_id = self.model_contact.objects.get(
import_id=self.obj_in.contact_adhesion.id
).id
self.orga.contact_adherent_id = self.contact_id
if not self.dryrun:
self.orga.save()
return self

19
center_pilote/civicrm/models/contact.py

@ -104,6 +104,7 @@ class CivicrmContact(ExtFieldMixin, models.Model): @@ -104,6 +104,7 @@ class CivicrmContact(ExtFieldMixin, models.Model):
'extrenseignements__siren',
'extrenseignements__effectif',
'extrenseignements__chiffre_affaire',
'extadhesion__contact_adhesion',
]
tags = models.ManyToManyField(
@ -714,3 +715,21 @@ class ExtRenseignements(models.Model): @@ -714,3 +715,21 @@ class ExtRenseignements(models.Model):
def __str__(self):
return str(self.entity)
class ExtAdhesion(models.Model):
class Meta:
managed = False
db_table = 'civicrm_value_adh_sion_22'
entity = models.OneToOneField(
'CivicrmContact', models.DO_NOTHING, unique=True
)
contact_adhesion = models.ForeignKey(
'CivicrmContact',
models.DO_NOTHING,
db_column='contact_adh_sion_147',
related_name='representant_pour',
blank=True,
null=True,
)

17
center_pilote/civicrm/models/orig.py

@ -2818,23 +2818,6 @@ class CivicrmUfMatch(models.Model): @@ -2818,23 +2818,6 @@ class CivicrmUfMatch(models.Model):
)
class CivicrmValueAdhSion22(models.Model):
entity = models.ForeignKey(
'CivicrmContact', models.DO_NOTHING, unique=True
)
contact_adh_sion_147 = models.ForeignKey(
'CivicrmContact',
models.DO_NOTHING,
db_column='contact_adh_sion_147',
blank=True,
null=True,
)
class Meta:
managed = False
db_table = 'civicrm_value_adh_sion_22'
class CivicrmValueDTailsChaufferie12(models.Model):
entity = models.ForeignKey(
'CivicrmActivity', models.DO_NOTHING, unique=True

Loading…
Cancel
Save
Map all the world