~jfb-tempo-consulting/unifield-wm/sync-env-ud

« back to all changes in this revision

Viewing changes to mkdb.py

  • Committer: jf
  • Date: 2019-11-13 14:29:17 UTC
  • Revision ID: jfb@tempo-consulting.fr-20191113142917-9m8tv9gtz7puletb
[IMP] Custom OC

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
            return newfile
48
48
    return filename
49
49
 
 
50
def get_oc(dbname):
 
51
    if isinstance(default_oc, dict):
 
52
        hq_name = re.findall(r'HQ[0-9]+', dbname)
 
53
        if hq_name:
 
54
            return default_oc.get(hq_name[-1], 'oca')
 
55
        return 'oca'
 
56
    return default_oc
 
57
 
50
58
def warn(*messages):
51
59
    sys.stderr.write(" ".join(messages)+"\n")
52
60
 
434
442
                    hq.write('account.target.costcenter', project_target_ids, {'is_target': True, 'is_top_cost_center': True, 'is_po_fo_cost_center' : True})
435
443
                self.sync(hq)
436
444
 
437
 
    def add_to_group(self, group_name, group_type, oc=default_oc):
 
445
    def add_to_group(self, group_name, group_type):
438
446
        Synchro.connect('admin')
 
447
        oc = get_oc(self.db.name)
439
448
        entity_ids = Synchro.get('sync.server.entity').search([('name','=',self.db.name)])
440
449
        assert len(entity_ids) == 1, "The entity must exists!"
441
450
        # Make groups
659
668
        if not hasattr(config, 'sync_user_admin') or not config.sync_user_admin:
660
669
            Synchro.user(self.db.name).add(self.db.name).addGroups('Sync / User')
661
670
        self.db.connect('admin')
662
 
        # search the current entity
663
 
        with_oc_field = False
664
 
        entity_fields = self.db.get('sync.client.entity').fields_get(['oc'])
665
 
        if entity_fields.get('oc'):
666
 
            with_oc_field = True
667
671
 
 
672
        oc = get_oc(self.db.name)
668
673
        entity_id = self.db.get('sync.client.entity').search([])
669
674
        data = {
670
675
            'name': self.db.name,
671
676
            'identifier': str(uuid.uuid1()),
672
677
        }
673
 
        if with_oc_field:
674
 
            data['oc'] = default_oc
 
678
        data['oc'] = oc
675
679
        if entity_id:
676
680
            entity_data = self.db.get('sync.client.entity').read(entity_id[0])
677
681
            if entity_data['name'] != self.db.name:
679
683
        else:
680
684
            self.db.get('sync.client.entity').create(data)
681
685
        wiz_data = {'email': config.default_email}
682
 
        if with_oc_field:
683
 
            wiz_data['oc'] = default_oc
 
686
        wiz_data['oc'] = oc
684
687
        wizard = self.db.wizard('sync.client.register_entity', wiz_data)
685
688
        # Fetch instances
686
689
        wizard.next()