Skip to content

Commit

Permalink
[FIX] wizards and api core
Browse files Browse the repository at this point in the history
  • Loading branch information
archetipo committed Nov 18, 2024
1 parent c970783 commit 036c949
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def aggiungi_riga_accesso(

def rest_get_record(self):
vals = {
"id": self.id,
"codice_lettore_grum": self.codice_lettore_grum,
"datetime_event": self.f_datetime(self.datetime_event),
"direction": self.f_selection('direction', self.direction),
Expand Down
11 changes: 8 additions & 3 deletions inrim_anagrafiche/models/ca_model_base_mixin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import json
import logging
import urllib.parse
from datetime import datetime

from odoo import models
import json

logger = logging.getLogger(__name__)


class CaModelBase(models.AbstractModel):
Expand Down Expand Up @@ -31,7 +35,8 @@ def rest_put_eval_body(self, body):
return body, ""

def rest_get(self, params: dict):
domain: list = json.loads(params.get('domain', '[]'))
strparams = urllib.parse.unquote(params.get('domain', '[]'))
domain: list = json.loads(strparams)
offset: int = params.get('offset', None)
limit: int = params.get('limit', None)
order: str = params.get('order', None)
Expand Down Expand Up @@ -117,7 +122,7 @@ def f_date(cls, record_o):
if record_o:
return record_o.strftime("%Y-%m-%d")
return record_o

@classmethod
def f_datetime(cls, record_o):
if record_o:
Expand Down
1 change: 1 addition & 0 deletions inrim_anagrafiche/models/ca_tag_persona.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def set_retuned(self):
self.date_end = fields.Datetime.now()
self.ca_tag_id.in_use = False
self.state = 'returned'
self.active = False

@api.onchange('date_start', 'date_end')
def check_date(self):
Expand Down
2 changes: 1 addition & 1 deletion inrim_controllo_accessi/models/ca_persona.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
class CaPersona(models.Model):
_inherit = 'ca.persona'

person_access_ids = fields.Many2many('ca.anag_registro_accesso')
person_access_ids = fields.One2many('ca.anag_registro_accesso', 'ca_persona_id')
10 changes: 0 additions & 10 deletions inrim_controllo_accessi/wizard/ca_aggiungi_movimento_accesso.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ class CaAggiungiMovimentoAccesso(models.TransientModel):
ca_ente_azienda_id = fields.Many2one('ca.ente_azienda', string="Position")
ca_punto_accesso = fields.Many2one('ca.punto_accesso', required=True)
ca_tag_persona_id = fields.Many2one('ca.tag_persona', required=True)
ca_tag_persona_ids = fields.Many2many(
'ca.tag_persona', compute="_compute_ca_tag_persona_ids",
store=True)
datetime = fields.Datetime(required=True, default=lambda self:fields.datetime.now())
type = fields.Selection([
('manual', 'Manual'),
Expand All @@ -24,13 +21,6 @@ def default_tipo_ente_azienda_ids(self):
self.env.ref('inrim_anagrafiche.tipo_ente_azienda_sede_distaccata').id
])]

@api.depends('ca_punto_accesso')
def _compute_ca_tag_persona_ids(self):
self.ca_tag_persona_ids = False
if self.ca_punto_accesso:
for tag in self.ca_punto_accesso.ca_spazio_id.righe_persona_ids:
if tag.tag_persona_id:
self.ca_tag_persona_ids += tag.tag_persona_id

@api.onchange('ca_ente_azienda_id')
def _onchange_ca_ente_azienda_id(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@
/>
<field
name="ca_tag_persona_id"
domain="[('id', 'in', ca_tag_persona_ids)]"
domain="[('state', '=', 'to_give_back')]"
options="{'no_create': True}"
invisible="not ca_punto_accesso"
/>
<field name="ca_tag_persona_ids" invisible="True"/>
<field name="type"/>
<field name="datetime"/>
</group>
Expand Down
37 changes: 28 additions & 9 deletions inrim_controllo_accessi/wizard/ca_registra_persona.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ def ente_azienda_domain(self):
]

def eval_ente_azienda_id(self, ente_az_id):
self.ensure_one()
ente_az_found = self.env['ca.ente_azienda'].browse(ente_az_id)
self.ente_azienda = ente_az_found
self.ente_azienda = ente_az_found.id
self.ca_ente_name = ente_az_found.name
self.tipo_ente_azienda_id = ente_az_found.tipo_ente_azienda_id
self.ente_azienda = ente_az_found.id
self.vat = ente_az_found.vat
self.ente_interno = ente_az_found.tipo_ente_azienda_id.id in [
self.env.ref('inrim_anagrafiche.tipo_ente_azienda_sede').id,
self.env.ref('inrim_anagrafiche.tipo_ente_azienda_sede_distaccata').id,
Expand All @@ -62,19 +63,24 @@ def eval_ente_azienda_id(self, ente_az_id):
def reset_ente_azienda_id(self, ):
self.ente_azienda = False
self.ca_ente_name = ""
self.vat = ""
self.tipo_ente_azienda_id = False
self.ente_azienda = False
self.ente_interno = False

@api.onchange('vat')
def _compute_eval_vat(self):
if self._context.get("no_change_vat"):
return
for record in self:
if not record.vat:
return
ente_az_found = self.env['ca.ente_azienda'].search([
('vat', 'ilike', record.vat)], limit=1)
if ente_az_found:
self.eval_ente_azienda_id(ente_az_found)
if record.ente_azienda.id != ente_az_found.id:
self.with_context(
no_change_vat=True).eval_ente_azienda_id(ente_az_found.id)
else:
self.reset_ente_azienda_id()

Expand All @@ -87,9 +93,8 @@ def populate_person(self, rec):
self.email = rec.email
self.persona_id = rec.id
self.compute_available_tags()
self.eval_ente_azienda_id(
rec.ca_ente_azienda_ids.ids[0] if rec.ca_ente_azienda_ids else []
)
ent_az_id = rec.ca_ente_azienda_ids.ids[0] if rec.ca_ente_azienda_ids else []
self.eval_ente_azienda_id(ent_az_id)
current_winfo = self.persona_id.get_current_winfo()
self.ca_work_info_type_id = current_winfo.ca_work_info_type_id.id
self.ca_title_id = current_winfo.ca_title_id.id
Expand Down Expand Up @@ -131,13 +136,18 @@ def compute_available_tags(self):

@api.onchange('fiscalcode')
def _compute_eval_fiscalcode(self):
if self._context.get("no_change_person"):
return
for record in self:
if not record.fiscalcode:
return
persona_id = self.env['ca.persona'].search([
('fiscalcode', '=', record.fiscalcode)], limit=1)
if persona_id:
self.populate_person(persona_id)
if record.persona_id.id != persona_id.id:
self.with_context(
no_change_person=True,
no_change_vat=True).populate_person(persona_id)
else:
self.reset_person()

Expand All @@ -148,19 +158,28 @@ def _compute_tag_id_number(self):

@api.onchange('persona_id')
def _compute_tag_id_number(self):
if self._context.get("no_change_person"):
return
for record in self:
if record.persona_id:
self.populate_person(record.persona_id)
self.with_context(
no_change_person=True,
no_change_vat=True).populate_person(record.persona_id)

@api.onchange('email')
def _compute_available_email(self):
if self._context.get("no_change_person"):
return
for record in self:
if not record.email:
return
persona_ids = self.env['ca.persona'].search([
('email', 'ilike', record.email)], limit=1)
if len(persona_ids) == 1:
self.populate_person(persona_ids[0])
if record.persona_id.id != persona_ids[0].id:
self.with_context(
no_change_person=True,
no_change_vat=True).populate_person(persona_ids[0])
else:
self.reset_person()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ def success_response(body, headers=None):
return Response(data, status=200, headers=headers.to_wsgi_list())

def handle_response(self, record, msg="", delete=False, is_list=False):
if not record:
raise BadRequest(description=msg)
if is_list:
return self.success_response(record)
if delete:
return self.success_response({})
elif is_list:
return self.success_response(record)
elif not record:
raise BadRequest(description=msg)
else:
return self.success_response(record.rest_get_record())

Expand Down

0 comments on commit 036c949

Please sign in to comment.