OCA / vertical-medical

Open Source Healthcare System for Odoo
GNU Affero General Public License v3.0
262 stars 277 forks source link

trying to inherit calendar.event from medical.appointment #111

Closed askz closed 7 years ago

askz commented 8 years ago

Hi, I'm trying to enhance your appointment's module by inherit calendar.event instead of re-create a calendar. The main goal is to get native event recurrence and attendee's functionality, or maybe I'm wrong with doing that and I need to create my recurrence code in appointments? (not sure ahah) I'm pretty new in odoo development but I made the whole part I think. There's an error when I'm trying to create an appointment saying that :

## Logging vals var of medical.appointment create func :
2016-05-30 16:06:47,050 6644 DEBUG erp-cdm-virgin openerp.addons.medical.models.medical_appointment: {'message_follower_ids': False, 'consultations': 2, 'categ_ids': [[6, False, []]], 'we': False, 'month_by': 'date', 'allday': False, 'byday': False, 'duration': 0.0, 'final_date': False, 'message_ids': False, 'user_id': 1, 'start': '2016-05-30 16:06:41', 'tu': False, 'recurrency': False, 'week_list': False, 'show_as': 'busy', 'attendee_ids': [], 'state': 'confirm', 'location': False, 'th': False, 'partner_ids': [[6, False, [3]]], 'physician_id': 2, 'start_date': None, 'start_datetime': '2016-05-30 16:06:41', 'recurrent_id_date': False, 'description': False, 'appointment_date': '2016-05-30 00:00:00', 'stop_date': None, 'stop': '2016-05-30 16:06:45', 'stop_datetime': '2016-05-30 16:06:45', 'fr': False, 'alarm_ids': [[6, False, []]], 'class': 'public', 'day': 0, 'count': 1, 'end_type': 'count', 'name': 'Testing', 'mo': False, 'interval': 1, 'su': False, 'patient_id': 1, 'recurrent_id': 0, 'sa': False, 'rrule_type': False}
2016-05-30 16:06:47,191 6644 ERROR erp-cdm-virgin openerp.sql_db: bad query: INSERT INTO "calendar_attendee" ("id", "event_id", "access_token", "state", "partner_id", "email", "create_uid", "write_uid", "create_date", "write_date") VALUES(nextval('calendar_attendee_id_seq'), 1, 'c663559e27fe46c9bca7d94b8bb83aa2', 'accepted', 3, 'admin@example.com', 1, 1, (now() at time zone 'UTC'), (now() at time zone 'UTC')) RETURNING id

# The three errors are below

Traceback (most recent call last):
  File "/home/maxime/Projects/agile/dev/OCB/openerp/sql_db.py", line 234, in execute
    res = self._obj.execute(query, params)
IntegrityError: insert or update on table "calendar_attendee" violates foreign key constraint "calendar_attendee_event_id_fkey"
DETAIL:  Key (event_id)=(1) is not present in table "calendar_event".

2016-05-30 16:06:47,192 6644 DEBUG erp-cdm-virgin openerp.service.model: IntegrityError
Traceback (most recent call last):
  File "/home/maxime/Projects/agile/dev/OCB/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/http.py", line 309, in checked_call
    return self.endpoint(*a, **kw)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/http.py", line 805, in __call__
    return self.method(*args, **kw)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/http.py", line 405, in response_wrap
    response = f(*args, **kw)
  File "/home/maxime/Projects/agile/dev/OCB/addons/web/controllers/main.py", line 944, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/home/maxime/Projects/agile/dev/OCB/addons/web/controllers/main.py", line 936, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/maxime/Projects/agile/dev/medicagile-master/medical_appointment_invoice/models/medical_appointment.py", line 60, in create
    res = super(appointment, self).create(cr, uid, values, context=context)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/maxime/Projects/agile/dev/OCB/addons/calendar/calendar.py", line 1646, in create
    self.create_attendees(cr, uid, [res], context=context)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/maxime/Projects/agile/dev/OCB/addons/calendar/calendar.py", line 1112, in create_attendees
    att_id = self.pool['calendar.attendee'].create(cr, uid, values, context=context)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/maxime/Projects/agile/dev/OCB/addons/calendar/calendar.py", line 288, in create
    res = super(calendar_attendee, self).create(cr, uid, vals, context=context)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/api.py", line 372, in old_api
    result = method(recs, *args, **kwargs)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/models.py", line 4094, in create
    record = self.browse(self._create(old_vals))
  File "/home/maxime/Projects/agile/dev/OCB/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/api.py", line 508, in new_api
    result = method(self._model, cr, uid, *args, **old_kwargs)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/models.py", line 4232, in _create
    tuple([u[2] for u in updates if len(u) > 2])
  File "/home/maxime/Projects/agile/dev/OCB/openerp/sql_db.py", line 158, in wrapper
    return f(self, *args, **kwargs)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/sql_db.py", line 234, in execute
    res = self._obj.execute(query, params)
IntegrityError: insert or update on table "calendar_attendee" violates foreign key constraint "calendar_attendee_event_id_fkey"
DETAIL:  Key (event_id)=(1) is not present in table "calendar_event".

2016-05-30 16:06:47,195 6644 ERROR erp-cdm-virgin openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/home/maxime/Projects/agile/dev/OCB/openerp/http.py", line 539, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/http.py", line 576, in dispatch
    result = self._call_function(**self.params)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/http.py", line 312, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/maxime/Projects/agile/dev/OCB/openerp/service/model.py", line 154, in wrapper
    raise openerp.osv.orm.except_orm(_('Integrity Error'), msg)

    except_orm: (u"Erreur d'int\xe9grit\xe9", u"L'op\xe9ration n'a pas pu \xeatre termin\xe9e, probablement \xe0 la suite d'une :\n- suppression : vous essayez de supprimer un enregistrement auquel d'autres enregistrements font r\xe9f\xe9rence\n- cr\xe9ation/modification : un champ requis n'est pas correctement rempli\n\n[objet r\xe9f\xe9renc\xe9 : Event - calendar.event]")

I'll be glad to hear advices I must forget something. The actual work is here https://github.com/BusinessAgile/vertical-medical/tree/recurrency Don't bother of appointment cluster's it isn't the problem.

Thanks for your good work.

lasley commented 8 years ago

HI @askz - Apologies, but I think I am missing something here. I don't see any inheritance w/ calendar modules in your branch.

lasley commented 8 years ago

(Although I totally agree with your logic of inheriting from core - these medical modules duplicate a lot of logic and model attributes that exist in Odoo)

askz commented 8 years ago

Hi @lasley! Sorry I should guide you, check this out.

I didn't worked a lot on medical module, just some tuning to meet my needs. The important part is in medical_appointment_invoice. I was first coding automatic generation of an invoice when an appointment was done - this part's gonna be improved and gonna be more dynamic in the future, it's just some introduction and tests.

It's really WIP right now so don't be too hard w/me ahah, thanks in advance!

lasley commented 8 years ago

Awesome, thanks @askz

I am kind of confused though, as the error is being thrown due to calendar.attendee insert/update constraint violation, not a calendar.event, which is what the model is inheriting from.

Are you using calendar.attendee anywhere in your branch, or is this somehow bubbling directly from the medical.appointment.new model/inheritance chain?

askz commented 8 years ago

Yup me too, at the beginning this was about calendar.event and after I added calendar_attendee and res_partner class and now I still can't create an appointment. And I can confirm I use it just on this file and in the corresponding view medical_appointment.xml And in fact the actual calendar.event code and other snippets from other models helped me to understand a lot to understand how's working

lasley commented 8 years ago

Hi @askz I took a look at your code, and the issue lies in https://github.com/BusinessAgile/vertical-medical/blob/recurrency/medical_appointment_invoice/models/medical_appointment.py#L62

You'll see that it tries to use event_id - https://github.com/odoo/odoo/blob/f9688cc63f6f89081c649ff365dcd738f0eff26e/addons/calendar/calendar.py#L1072

But I am betting that it is null (empty recordset) in your test case.

lasley commented 7 years ago

Hi @askz - any updates on this?

askz commented 7 years ago

Hi @lasley !

I had totally forgotten this issue since I'm not using anymore the vertical-medical modules. I finally managed to inherit calendar.event with my own module from scratch and it works like a charm !

So I think we can close that.

Thanks for your help :)