Hello guys, well my problem is that I installed "Super Calendar" module in my Odoo 9, in this super calendar module I added differents models for see them in the Super Calendar, but I have a problem. I added the event.event model in the super calendar and works fine, late I create a new field, for the attendes of the events, because in the super calendar I would like see the attendes of that event. The Super Calendar module has 3 classes:
-super_calendar_configurator_line (in this one you assign fields, here is where I created the attendes field)
-super_calendar_configurator (in this one you put the data from super_calendar_configurator_line to super_calendar)
-super_calendar (in this one you get the data from super_calendar_configurator for show it in the super calendar)
Super_calendar_configurar_line code:
from openerp import fields, models
class SuperCalendarConfiguratorLine(models.Model):
_name = 'super.calendar.configurator.line'
name = fields.Many2one(
comodel_name='ir.model',
string='Model',
required=True,
)
domain = fields.Char(
string='Domain',
)
configurator_id = fields.Many2one(
comodel_name='super.calendar.configurator',
string='Configurator',
)
description_type = fields.Selection(
[('field', 'Field'),
('code', 'Code')],
string="Description Type",
default='field',
)
description_field_id = fields.Many2one(
comodel_name='ir.model.fields',
string='Description field',
domain="[('ttype', 'in', ('char', 'text')), ('model_id', '=', name)]",
)
description_code = fields.Text(
string='Description field',
help=("""Use '${o}' to refer to the involved object.
E.g.: '${o.project_id.name}'"""),
)
date_start_field_id = fields.Many2one(
comodel_name='ir.model.fields',
string='Start date field',
domain="[('ttype', 'in', ('datetime', 'date')), "
"('model_id', '=', name)]",
required=True,
)
date_stop_field_id = fields.Many2one(
comodel_name='ir.model.fields',
string='End date field',
domain="[('ttype', 'in', ('datetime', 'date')), "
"('model_id', '=', name)]",
)
duration_field_id = fields.Many2one(
comodel_name='ir.model.fields',
string='Duration field',
domain="[('ttype', '=', 'float'), ('model_id', '=', name)]",
)
user_field_id = fields.Many2one(
comodel_name='ir.model.fields',
string='User field',
domain="[('ttype', '=', 'many2one'), ('model_id', '=', name)]",
)
asistentes_reuniones_line = fields.Many2one(
comodel_name='ir.model.fields',
string='Asistentes',
domain="[('model_id', '=', name),('ttype', '=', 'many2many')]",
)
asistentes_eventos_line = fields.Many2one( // this one is the field that I was talking about
comodel_name='ir.model.fields',
string='Asistentes eventos',
domain="[('model_id', '=', name),('ttype', '=', 'one2many')]",
)
super_calendar_configurator code:
import logging
from datetime import datetime
from pytz import timezone, utc
from mako.template import Template
from openerp import _, api, exceptions, fields, models, tools
from openerp.tools.safe_eval import safe_eval
_logger = logging.getLogger(__name__)
class SuperCalendarConfigurator(models.Model):
_name = 'super.calendar.configurator'
name = fields.Char(
string='Name',
required=True,
)
line_ids = fields.One2many(
comodel_name='super.calendar.configurator.line',
inverse_name='configurator_id',
string='Lines',
)
def _clear_super_calendar_records(self):
"""
Remove old super_calendar records
"""
super_calendar_pool = self.env['super.calendar']
super_calendar_list = super_calendar_pool.search([])
super_calendar_list.unlink()
@api.multi
def generate_calendar_records(self):
"""
At every CRON execution, every 'super calendar' data is deleted and
regenerated again.
"""
# Remove old records
self._clear_super_calendar_records()
# Rebuild all calendar records
configurator_list = self.search([])
for configurator in configurator_list:
for line in configurator.line_ids:
configurator._generate_record_from_line(line)
_logger.info('Calendar generated')
return True
@api.multi
def _generate_record_from_line(self, line):
"""
Create super_calendar records from super_calendar_configurator_line
objects.
"""
super_calendar_pool = self.env['super.calendar']
values = self._get_record_values_from_line(line)
for record in values:
super_calendar_pool.create(values[record])
@api.multi
def _get_record_values_from_line(self, line):
"""
Get super_calendar fields values from super_calendar_configurator_line
objects.
Check if the User value is a res.users.
"""
res = {}
current_pool = self.env[line.name.model]
domain = line.domain and safe_eval(line.domain) or []
current_record_list = current_pool.search(domain)
for cur_rec in current_record_list:
f_user = line.user_field_id.name
f_descr = line.description_field_id.name
f_date_start = line.date_start_field_id.name
f_date_stop = line.date_stop_field_id.name
f_duration = line.duration_field_id.name
f_asistentes_reuniones = line.asistentes_reuniones_line.name
f_asistentes_eventos = line.asistentes_eventos_line.name
# Check if f_user refer to a res.users
if (f_user and cur_rec[f_user] and
cur_rec[f_user]._model._name != 'res.users'):
raise exceptions.ValidationError(
_("The 'User' field of record %s (%s) "
"does not refer to res.users")
% (cur_rec[f_descr], line.name.model))
if ((cur_rec[f_descr] or line.description_code) and
cur_rec[f_date_start]):
duration = False
if line.date_start_field_id.ttype == 'date':
date_format = tools.DEFAULT_SERVER_DATE_FORMAT
else:
date_format = tools.DEFAULT_SERVER_DATETIME_FORMAT
date_start = datetime.strptime(
cur_rec[f_date_start], date_format
)
if (not line.duration_field_id and
line.date_stop_field_id and
cur_rec[f_date_start] and
cur_rec[f_date_stop]):
if line.date_stop_field_id.ttype == 'date':
date_format = tools.DEFAULT_SERVER_DATE_FORMAT
else:
date_format = tools.DEFAULT_SERVER_DATETIME_FORMAT
date_stop = datetime.strptime(
cur_rec[f_date_stop], date_format
)
date_diff = (date_stop - date_start)
duration = date_diff.total_seconds() / 3600
elif line.duration_field_id:
duration = cur_rec[f_duration]
if line.description_type != 'code':
name = cur_rec[f_descr]
else:
parse_dict = {'o': cur_rec}
mytemplate = Template(line.description_code)
name = mytemplate.render(**parse_dict)
# Convert date_start to UTC timezone if it is a date field
# in order to be stored in UTC in the database
if line.date_start_field_id.ttype == 'date':
tz = timezone(self._context.get('tz') or
self.env.user.tz or
'UTC')
local_date_start = tz.localize(date_start)
utc_date_start = local_date_start.astimezone(utc)
date_start = utc_date_start
date_start = datetime.strftime(
date_start,
tools.DEFAULT_SERVER_DATETIME_FORMAT
)
# Recurrent events have an string id like '14-20151110120000'
# We need to split that to get the first part (id)
if isinstance(cur_rec['id'], basestring):
rec_id = cur_rec['id'].split('-')[0]
else:
rec_id = cur_rec['id']
pruebaaux2= []
if f_asistentes_reuniones:
pruebaaux2 = [(4,[cur_rec[f_asistentes_reuniones].ids])]
pruebaaux3= []
if f_asistentes_eventos:
pruebaaux3 = [(4,[cur_rec[f_asistentes_eventos].ids])]
super_calendar_values = {
'name': name,
'date_start': date_start,
'duration': duration,
'user_id': (f_user and cur_rec[f_user].id),
'asistentes_reuniones': pruebaaux2,
'asistentes_eventos': pruebaaux3,
'configurator_id': self.id,
'res_id': line.name.model + ',' + str(rec_id),
'model_id': line.name.id,
}
res[cur_rec] = super_calendar_values
return res
and finally super_calendar code:
from openerp import fields, models
def _models_get(self):
model_obj = self.env['ir.model']
model_list = model_obj.search([])
return [(model.model, model.name) for model in model_list]
class SuperCalendar(models.Model):
_name = 'super.calendar'
name = fields.Char(
string='Description',
required=True,
readonly=True,
)
date_start = fields.Datetime(
string='Start date',
required=True,
readonly=True,
)
duration = fields.Float(
string='Duration',
readonly=True,
)
user_id = fields.Many2one(
comodel_name='res.users',
string='User',
readonly=True,
)
configurator_id = fields.Many2one(
comodel_name='super.calendar.configurator',
string='Configurator',
readonly=True,
)
res_id = fields.Reference(
selection=_models_get,
string='Resource',
readonly=True,
)
model_id = fields.Many2one(
comodel_name='ir.model',
string='Model',
readonly=True,
)
asistentes_reuniones = fields.Many2many(
comodel_name='res.partner',
string='asistentes prueba',
readonly=True,
)
asistentes_eventos = fields.One2many(
comodel_name='event.registration',
string='asistentes prueba eventos',
readonly=True,
)
My problem is with the asistentes_eventos and asistentes_eventos_line field, in the super_calendar_configurator class, I get this error in Odoo when I press the generate calendar button:
TypeError: unhashable type: 'list'