Skip to Content
Menu
This question has been flagged
Hello,
I'm trying to insert a smart button but I'm having problems using the domain (filter) as it directs me to a blank model, when I try to direct it to the model related to the name.
I hope you can help me, thank you very much.

.py

class Agenda_citas (models.Model):
_name = 'agendacitas'
_inherit =['mail.thread','mail.activity.mixin']
_description = "Agenda y estructura de el modulo de citas "
state = fields.Selection(string="Estado",
selection=[('ag', 'Agendada'),
('co', 'Confirmada'),
('ca', 'Cancelada'),
('re', 'Reprogramada')])
name = fields.Many2one(
comodel_name = 'res.partner',
string = 'Paciente'

)
inicio_cita = fields.Datetime (
string = 'Fecha inicio',
required=True,
default=fields.Date.today
)
final_cita = fields.Datetime (
string = 'Fecha Fin',
readonly=False,
default = lambda self: fields.Datetime.today() + timedelta(minutes=20),
compute='_compute_final_cita',
store = True,
)
duracion_cita = fields.Float(
'Duración',
compute='_compute_duration',
store=True,
readonly=False
)
doctor_base =fields.Many2one(
comodel_name = 'res.partner',
string = 'Doctor Tratante'

)
referencia = fields.Many2one(
comodel_name = 'res.partner',
string = 'Referencia'
)

observaciones_cita = fields.Text(string="Observaciones")
motivo = fields.Char(string="Motivo de Consulta")
#doctor_clinica = fields.Many2one(
# comodel_name = 'res.partner',
#string = 'doctor que atiende' )

@api.depends('inicio_cita' , 'final_cita')
def _compute_duration(self):
for event in self:
event.duracion_cita = self._get_duracion_cita(event.inicio_cita, event.final_cita)
@api.depends('inicio_cita', 'duracion_cita')
def _compute_final_cita(self):
# stop and duration fields both depends on the start field.
# But they also depends on each other.
# When start is updated, we want to update the stop datetime based on
# the *current* duration. In other words, we want: change start => keep the duration fixed and
# recompute stop accordingly.
# However, while computing stop, duration is marked to be recomputed. Calling `event.duration` would trigger
# its recomputation. To avoid this we manually mark the field as computed.
duration_field = self._fields['duracion_cita']
self.env.remove_to_compute(duration_field, self)
for event in self:
# Round the duration (in hours) to the minute to avoid weird situations where the event
# stops at 4:19:59, later displayed as 4:19.
event.final_cita = event.inicio_cita and event.inicio_cita + timedelta(seconds =round((event.duracion_cita or 1.0) * 60))

def _get_duracion_cita(self, inicio_cita, final_cita):
""" Get the duration value between the 2 given dates. """
if not inicio_cita or not final_cita:
return 0
duracion_cita = (final_cita - inicio_cita).total_seconds() / 60
return round(duracion_cita, 2)

def action_abrir_expediente (self):
return {
'type': 'ir.actions.act_window',
'name': 'Notas Médicas',
'res_model': 'res.partner',
'domain': [('name','=', self.id)],
'view_mode': 'form',
'target': 'current',
}

.xml

 
Agenda de Citas
agendacitas











Agendar Cita Paciente






domain = "[('es_convenio', '=', True)]"
options="{'no_create':True, 'no_open': True}"
/>





domain = "[('es_medico', '=', True)]"
options="{'no_create':True, 'no_open': True}"
/>


Observaciones



placeholder = 'Observaciones'
nolabel="1"/>












Vista de arbol Citas
agendacitas







widget="badge"
decoration-warning = "state =='re'"
decoration-success ="state == 'co'"
decoration-danger = "state == 'ca'"
decoration-info = "state =='ag'">




Thanks


Avatar
Discard
Related Posts Replies Views Activity
2
Nov 22
1790
3
Oct 22
9115
1
Jan 23
2000
1
Jun 22
9881
2
Dec 24
3133