I have tree models and i want to overwrite create function of calendar.event models to get in the patners_ids field, who is patient and append it on the medical.appointment model on create.
Here a part of code :
Class MedicalAppointment(models.Model):
_name = "medical.appointment"
patient = fields.Many2one ('medical.patient', 'Patient', readonly=True, states={'draft': [('readonly', False)]}, help="Patient Name", required=True,)
class MedicalPatient(models.Model):
_name = "medical.patient"
name = fields.Many2one('res.partner', 'Patient', required="1", track_visibility='onchange', domain=[('is_patient', '=', True), ('is_person', '=', True)], help="Patient Name")
@api.multi
@api.depends('name', 'patient_id')
def name_get(self):
result = []
for partner in self:
name = partner.name.name
if partner.patient_id:
name = '[' + partner.patient_id + ']' + name
result.append((partner.id, name))
return result
@api.model
def name_search(self, name, args=None, operator='ilike', limit=100):
args = args or []
recs = self.browse()
# if name:
# recs = self.search(['|', '|', '|', '|', '|', ('name', operator , name), ('patient_id', operator , name), ('mobile', operator , name), ('other_mobile', operator , name), ('lastname', operator , name), ('middle_name', operator , name) ] )
if not recs:
recs = self.search([('name', operator, name)])
return recs.name_get()
class Meeting(models.Model):
_name = 'calendar.event'
partner_ids = fields.Many2many('res.partner', 'calendar_event_res_partner_rel', string='Attendees', states={'done': [('readonly', True)]}, default=_default_partners)
I write this code but it is not working well :
class Meeting(models.Model):
_name = 'calendar.event'
_inherit = ["calendar.event"]
@api.model
def create(self, values):
if not 'user_id' in values: # Else bug with quick_create when we are filter on an other user
values['user_id'] = self.env.user.id
# compute duration, if not given
if not 'duration' in values:
values['duration'] = self._get_duration(values['start'], values['stop'])
meeting = super(Meeting, self).create(values)
final_date = meeting._get_recurrency_end_date()
# `dont_notify=True` in context to prevent multiple notify_next_alarm
meeting.with_context(dont_notify=True).write({'final_date': final_date})
meeting.with_context(dont_notify=True).create_attendees()
# Notify attendees if there is an alarm on the created event, as it might have changed their
# next event notification
if not self._context.get('dont_notify'):
if len(meeting.alarm_ids) > 0:
self.env['calendar.alarm_manager'].notify_next_alarm(meeting.partner_ids.ids)
if meeting.partner_ids:
patients = meeting.partner_ids.search([('is_patient', '=', True)])
patient = patients[0]
pat_name = patient.name
patient_obj = self.env['medical.patient']
current_patient = patient_obj.search(pat_name)
if meeting.start:
self.env['medical.appointment'].create({'patient': current_patient})
return meeting
I need a help
Whats the error log?