Skip to content

Commit

Permalink
[FIX] project
Browse files Browse the repository at this point in the history
  • Loading branch information
archetipo committed Nov 13, 2024
1 parent 33c4a0c commit 9b12c49
Show file tree
Hide file tree
Showing 53 changed files with 1,340 additions and 1,036 deletions.
5 changes: 4 additions & 1 deletion controllo_accessi_inrim_app/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
'data/ir_config_parameter_data.xml',
'data/ir_cron.xml',
'views/users_ldap.xml',
'views/ca_punto_accesso_views.xml',
],
'demo': [
"demo/ca_punto_accesso_data.xml",
],
'demo': [],
'installable': True,
'application': True,
}
37 changes: 37 additions & 0 deletions controllo_accessi_inrim_app/data/ente_azienda_inrim_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
<field name="country_id" ref="base.it"/>
<field name="tipo_ente_azienda_id"
ref="inrim_anagrafiche.tipo_ente_azienda_sede"/>
<field name="vat">09261710017</field>
<field name="note">Campus</field>
<field name="tz">Europe/Rome</field>
<field name="ref">cacce</field>
<field name="lock" eval="True"/>
</record>

<record id="inrim_sede_mda" model="ca.ente_azienda">
Expand All @@ -27,6 +29,7 @@
eval="ref('inrim_anagrafiche.tipo_ente_azienda_sede_distaccata')"/>
<field name="note">Sede Storica</field>
<field name="tz">Europe/Rome</field>
<field name="lock" eval="True"/>
</record>

<record id="inrim_sede_fi" model="ca.ente_azienda">
Expand All @@ -41,6 +44,7 @@
eval="ref('inrim_anagrafiche.tipo_ente_azienda_sede_distaccata')"/>
<field name="note">Lens</field>
<field name="tz">Europe/Rome</field>
<field name="lock" eval="True"/>
</record>

<record id="inrim_sede_pv" model="ca.ente_azienda">
Expand All @@ -55,6 +59,39 @@
eval="ref('inrim_anagrafiche.tipo_ente_azienda_sede_distaccata')"/>
<field name="note">Pavia</field>
<field name="tz">Europe/Rome</field>
<field name="lock" eval="True"/>
</record>


<record id="inrim_azienda_esterna_da_gestire" model="ca.ente_azienda">
<field name="name">Azienda estena da Gestire</field>
<field name="street">Strada delle Cacce, 91</field>
<field name="zip">10135</field>
<field name="state_id" ref="base.state_it_to"/>
<field name="country_id" ref="base.it"/>
<field name="tipo_ente_azienda_id"
ref="inrim_anagrafiche.tipo_ente_azienda_azienda_todo"/>
<field name="note">Azienda Esterna Defaulta da Gestire su persona
</field>
<field name="tz">Europe/Rome</field>
<field name="ref">azienda_esterna_da_gestire</field>
<field name="lock" eval="True"/>
</record>

<record id="inrim_ente_esterno_da_gestire" model="ca.ente_azienda">
<field name="name">Azienda estena da Gestire</field>
<field name="street">Strada delle Cacce, 91</field>
<field name="zip">10135</field>
<field name="state_id" ref="base.state_it_to"/>
<field name="country_id" ref="base.it"/>
<field name="tipo_ente_azienda_id"
ref="inrim_anagrafiche.tipo_ente_azienda_ente_todo"/>
<field name="note">Ente Esterno Defaulta da Gestire su persona
</field>
<field name="tz">Europe/Rome</field>
<field name="ref">ente_esterno_da_gestire</field>
<field name="lock" eval="True"/>
</record>

</data>
</odoo>
25 changes: 21 additions & 4 deletions controllo_accessi_inrim_app/data/ir_config_parameter_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,42 @@
<record id="inrim_ir_config_parameter_people_key"
model="ir.config_parameter">
<field name="key">people.key</field>
<field name="value">In base al sistema</field>
<field name="value"></field>
</record>

<record id="inrim_ir_config_parameter_people_url"
model="ir.config_parameter">
<field name="key">people.url</field>
<field name="value">In base al sistema</field>
<field name="value">https://people.ininrim.it</field>
</record>

<record id="inrim_ir_config_parameter_iam_key"
model="ir.config_parameter">
<field name="key">iam.key</field>
<field name="value">In base al sistema</field>
<field name="value"></field>
</record>

<record id="inrim_ir_config_parameter_iam_url"
model="ir.config_parameter">
<field name="key">iam.url</field>
<field name="value">In base al sistema</field>
<field name="value">https://iam.ininrim.it</field>
</record>


<record id="inrim_controllo_accessi_rfidglobal.inrim_ir_config_parameter_service_reader_url"
model="ir.config_parameter">
<field name="value">https://access-reader.docker.ininrim.it</field>
</record>

<record id="inrim_ir_config_parameter_default_internal_people_types"
model="ir.config_parameter">
<field name="key">default_ca.internal_people_types</field>
<field name="value">
["dipendentit.d._employeetype","assegni_employeetype","dipendentit.i._employeetype","tesisti_employeetype","associazionitipoa_tipopersonale","associazionitipob_tipopersonale",
"associazionitipoc_tipopersonale",
"borse_employeetype","dottorandi_employeetype",
"stage_employeetype"]
</field>
</record>

</data>
Expand Down
17 changes: 17 additions & 0 deletions controllo_accessi_inrim_app/demo/ca_punto_accesso_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="inrim_controllo_accessi.ca_punto_accesso_1p001"
model="ca.punto_accesso">
<field name="ca_category"
ref="controllo_accessi_inrim_app.punto_accesso_category_portineria_cacce"/>
<field name="codice_lettore_grum">20</field>
</record>

<record id="inrim_controllo_accessi.ca_punto_accesso_1p002"
model="ca.punto_accesso">
<field name="ca_category"
ref="controllo_accessi_inrim_app.punto_accesso_category_portineria_cacce"/>
<field name="codice_lettore_grum">21</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions controllo_accessi_inrim_app/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import ca_persona
from . import ca_spazio
from . import res_company_ldap
from . import ca_punto_accesso
156 changes: 116 additions & 40 deletions controllo_accessi_inrim_app/models/ca_persona.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
import logging
from datetime import datetime

import requests
from odoo import models, api
from odoo import models, api, fields

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -45,63 +46,88 @@ def _cron_people_get_addressbook(self):
for upath in [get_personal_types, get_job_titles, get_addressbook_path]:
data = self.get_people_data(upath)
if data and upath == get_personal_types:
self.update_tipo_persona(data)
self.update_work_info_type(data)
if data and upath == get_job_titles:
self.update_titolo_persona(data)
if data and upath == get_personal_types:
if data and upath == get_addressbook_path:
self.get_addressbook_data(data)

def update_titolo_persona(self, data):
logger.info("Update titolo persona")
def update_work_info_type(self, data):
logger.info("Update tipo persona work_info_type")
ext_company = 'ditteesterne_tipopersonale'
ext_entity = 'entiesterni_tipopersonale'
with self.env.cr.savepoint():
try:
for dt in data:
if dt.get('code') and dt.get('name'):
titolo_persona_id = self.env['ca.titolo_persona'].search([
work_info_type_id = self.env['ca.work_info_type'].search([
('code', '=', dt.get('code'))
])
if not titolo_persona_id:
], limit=1)
if not work_info_type_id:
vals = {
'name': dt['name'],
'code': dt['code'],
'structured': True
'structured': dt['code'] not in [ext_company, ext_entity]
}
self.env['ca.titolo_persona'].create(vals)
res = self.env['ca.work_info_type'].create(vals)
else:
titolo_persona_id.name = dt['name']
work_info_type_id.name = dt['name']
except Exception as e:
logger.error(f"Error: {e}", exc_info=True)

def update_tipo_persona(self, data):
logger.info("Update tipo persona")
def update_titolo_persona(self, data):
logger.info("Update titolo persona")
with self.env.cr.savepoint():
try:
for dt in data:
if dt.get('code') and dt.get('name'):
tipo_persona_id = self.env['ca.tipo_persona'].search([
titolo_persona_id = self.env['ca.titolo_persona'].search([
('code', '=', dt.get('code'))
])
if not tipo_persona_id:
], limit=1)
if not titolo_persona_id:
vals = {
'name': dt['name'],
'code': dt['code'],
'structured': True
}
self.env['ca.tipo_persona'].create(vals)
self.env['ca.titolo_persona'].create(vals)
else:
tipo_persona_id.name = dt['name']
titolo_persona_id.name = dt['name']
except Exception as e:
logger.error(f"Error: {e}", exc_info=True)

def get_addressbook_data(self, data):
logger.info("Update persona")
# internal_types = self.env.ref('default_ca.internal_people_types')

internal_types = json.loads(self.env['ir.config_parameter'].sudo().get_param(
'default_ca.internal_people_types'))
ext_company = 'ditteesterne_tipopersonale'
ext_entity = 'entiesterni_tipopersonale'
base_institute = self.env.ref(
'controllo_accessi_inrim_app.inrim_campus_cacce')
base_default_ente_todo = self.env.ref(
'controllo_accessi_inrim_app.inrim_ente_esterno_da_gestire')
base_default_azienda_todo = self.env.ref(
'controllo_accessi_inrim_app.inrim_azienda_esterna_da_gestire')
interno = self.env.ref(
'inrim_anagrafiche.tipo_persona_interno').id
esterno = self.env.ref(
'inrim_anagrafiche.tipo_persona_esterno').id
date_end_forever = self.env.ref(
'inrim_controllo_accessi.inrim_ir_config_parameter_forever').value
with self.env.cr.savepoint():
try:
for dt in data:
if dt.get('uid') and dt.get('name'):
for dt in data:
try:
azienda_ids = []
if dt.get('uid') and dt.get('name') and dt.get(
'tipo_personale') != "":
user_id = self.env['res.users'].search([
('login', '=', dt['uid'])
])
], limit=1)
type_ids = []
title_ids = []

if not user_id:
user_id = self.env['res.users'].create({
'name': dt['name'],
Expand All @@ -110,10 +136,31 @@ def get_addressbook_data(self, data):
'lang': 'it_IT',
"tz": "Europe/Rome"
})
persona_id = self.env['ca.persona'].search([
('freshman', '=', dt['matricola']),
work_info_type_id = self.env['ca.work_info_type'].get_by_name(
dt.get('tipo_personale'))

persona_id = self.env['ca.persona'].with_context(
massive_create=True).search([
('fiscalcode', '=', dt['codicefiscale'])
])
], limit=1)
resp_id = self.get_by_login_uid(dt.get("referente_uid"))
if not resp_id:
resp_id = self.with_context(
massive_create=True).get_by_login_uid(
dt.get("responsabile_uid"))
if work_info_type_id:
logger.info(
f"{work_info_type_id.name} , {work_info_type_id.code}, {work_info_type_id.code in internal_types}")
if work_info_type_id.code in internal_types:
type_ids.append(interno)
azienda_ids.append(base_institute.id)
else:
type_ids.append(esterno)
if work_info_type_id.code == ext_company:
azienda_ids.append(base_default_azienda_todo.id)
elif work_info_type_id.code == ext_entity:
azienda_ids.append(base_default_ente_todo.id)

if not persona_id:
birth_date = ''
if dt.get('data_di_nascita'):
Expand All @@ -124,26 +171,55 @@ def get_addressbook_data(self, data):
'uid': dt['uid'],
'name': dt['nome'],
'lastname': dt['cognome'],
'type_ids': self.env.ref(
'inrim_anagrafiche.tipo_persona_interno').ids,
'email': dt['mail'],
'mobile': dt['cell_phone_service'],
'private_mobile': dt['private_cell_phone'],
'phone': dt['telephonNumber'],
'type_ids': type_ids,
'birth_date': birth_date,
'associated_user_id': user_id.id
'ca_ente_azienda_ids': azienda_ids,
'associated_user_id': user_id.id,
'parent_id': resp_id.id if resp_id else False
}
if dt.get('matricola'):
vals['freshman'] = dt['matricola']
if dt.get('codicefiscale'):
vals['fiscalcode'] = dt['codicefiscale']
persona_id = self.create(vals)
persona_id = self.with_context(
massive_create=True).create(vals)
persona_id.action_completed()

else:
tipo_persona_id = self.env['ca.tipo_persona'].search([
('name', '=', dt.get('tipo_personale'))
])
if tipo_persona_id:
persona_id.type_ids = [
self.env.ref(
'inrim_anagrafiche.tipo_persona_interno').id,
tipo_persona_id.id
]
except Exception as e:
logger.error(f"Error: {e}", exc_info=True)
if not persona_id.parent_id:
resp_id = self.with_context(
massive_create=True).get_by_login_uid(
dt.get("referente_uid"))
if not resp_id:
resp_id = self.with_context(
massive_create=True).get_by_login_uid(
dt.get("responsabile_uid"))
persona_id.parent_id = resp_id.id if resp_id else False
title_id = self.env['ca.titolo_persona'].get_by_name(
dt.get('qualifica'))
vals = {
'ca_persona_id': persona_id.id,
'work_id_number': dt['matricola'],
'ca_div_uo_code': dt['divisione_code'],
'ca_work_info_type_id': work_info_type_id.id if work_info_type_id else False,
'ca_title_id': title_id.id if title_id else False,
}
if dt.get('data_inizio'):
vals['date_start'] = fields.Date.to_date(
dt['data_inizio'])
if not dt.get('data_fine'):
vals['date_end'] = fields.Date.to_date(
date_end_forever.split(" ")[0])
else:
vals['date_end'] = fields.Date.to_date(
dt['data_fine'])

persona_id.with_context(
massive_create=True).update_work_info(vals)
except Exception as e:
logger.error(
f"Error Skip {dt.get('uid')}: {e}", exc_info=True)
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class CaPuntoAccesso(models.Model):
@api.constrains('codice_lettore_grum', 'typology')
def _check_codice_lettore_grum(self):
for record in self:
if record.typology == 'stamping' and not record.codice_lettore_grum:
raise UserError("Il codice lettore GRUM è obbligatorio se la tipologia è: Timbratura.")
# if record.typology == 'stamping' and not record.codice_lettore_grum:
# raise UserError("Il codice lettore GRUM è obbligatorio se la tipologia è: Timbratura.")
if record.codice_lettore_grum:
if not (20 <= record.codice_lettore_grum <= 999):
raise UserError("Il codice lettore GRUM deve essere compreso tra 20 e 999.")
1 change: 0 additions & 1 deletion controllo_accessi_inrim_app/tests/__init__.py

This file was deleted.

Loading

0 comments on commit 9b12c49

Please sign in to comment.