|
@ -19,7 +19,7 @@ |
|
|
# |
|
|
# |
|
|
############################################################################## |
|
|
############################################################################## |
|
|
|
|
|
|
|
|
from openerp.osv import fields, osv, orm |
|
|
|
|
|
|
|
|
from openerp.osv import fields, orm |
|
|
from openerp.tools.translate import _ |
|
|
from openerp.tools.translate import _ |
|
|
import logging |
|
|
import logging |
|
|
from mako.template import Template |
|
|
from mako.template import Template |
|
@ -27,12 +27,14 @@ from datetime import datetime |
|
|
from openerp import tools |
|
|
from openerp import tools |
|
|
from openerp.tools.safe_eval import safe_eval |
|
|
from openerp.tools.safe_eval import safe_eval |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _models_get(self, cr, uid, context=None): |
|
|
def _models_get(self, cr, uid, context=None): |
|
|
obj = self.pool.get('ir.model') |
|
|
obj = self.pool.get('ir.model') |
|
|
ids = obj.search(cr, uid, []) |
|
|
ids = obj.search(cr, uid, []) |
|
|
res = obj.read(cr, uid, ids, ['model', 'name'], context) |
|
|
res = obj.read(cr, uid, ids, ['model', 'name'], context) |
|
|
return [(r['model'], r['name']) for r in res] |
|
|
return [(r['model'], r['name']) for r in res] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class super_calendar_configurator(orm.Model): |
|
|
class super_calendar_configurator(orm.Model): |
|
|
_logger = logging.getLogger('super.calendar') |
|
|
_logger = logging.getLogger('super.calendar') |
|
|
_name = 'super.calendar.configurator' |
|
|
_name = 'super.calendar.configurator' |
|
@ -60,19 +62,29 @@ class super_calendar_configurator(orm.Model): |
|
|
|
|
|
|
|
|
for current_record_id in current_record_ids: |
|
|
for current_record_id in current_record_ids: |
|
|
current_record = current_pool.browse(cr, uid, current_record_id, context=context) |
|
|
current_record = current_pool.browse(cr, uid, current_record_id, context=context) |
|
|
if line.user_field_id and \ |
|
|
|
|
|
current_record[line.user_field_id.name] and current_record[line.user_field_id.name]._table_name != 'res.users': |
|
|
|
|
|
raise osv.except_osv(_('Error'), |
|
|
|
|
|
|
|
|
if (line.user_field_id and |
|
|
|
|
|
current_record[line.user_field_id.name] and |
|
|
|
|
|
current_record[line.user_field_id.name]._table_name != 'res.users'): |
|
|
|
|
|
raise orm.except_orm( |
|
|
|
|
|
_('Error'), |
|
|
_("The 'User' field of record %s (%s) does not refer to res.users") |
|
|
_("The 'User' field of record %s (%s) does not refer to res.users") |
|
|
% (current_record[line.description_field_id.name], line.name.model)) |
|
|
% (current_record[line.description_field_id.name], line.name.model)) |
|
|
if (((line.description_field_id |
|
|
|
|
|
and current_record[line.description_field_id.name]) |
|
|
|
|
|
or line.description_code) |
|
|
|
|
|
and current_record[line.date_start_field_id.name]): |
|
|
|
|
|
|
|
|
if (((line.description_field_id and current_record[line.description_field_id.name]) or |
|
|
|
|
|
line.description_code) and |
|
|
|
|
|
current_record[line.date_start_field_id.name]): |
|
|
duration = False |
|
|
duration = False |
|
|
if not line.duration_field_id and line.date_stop_field_id and current_record[line.date_start_field_id.name] and current_record[line.date_stop_field_id.name]: |
|
|
|
|
|
date_start= datetime.strptime(current_record[line.date_start_field_id.name], tools.DEFAULT_SERVER_DATETIME_FORMAT) |
|
|
|
|
|
date_stop= datetime.strptime(current_record[line.date_stop_field_id.name], tools.DEFAULT_SERVER_DATETIME_FORMAT) |
|
|
|
|
|
|
|
|
if (not line.duration_field_id and |
|
|
|
|
|
line.date_stop_field_id and |
|
|
|
|
|
current_record[line.date_start_field_id.name] and |
|
|
|
|
|
current_record[line.date_stop_field_id.name]): |
|
|
|
|
|
date_start = datetime.strptime( |
|
|
|
|
|
current_record[line.date_start_field_id.name], |
|
|
|
|
|
tools.DEFAULT_SERVER_DATETIME_FORMAT |
|
|
|
|
|
) |
|
|
|
|
|
date_stop = datetime.strptime( |
|
|
|
|
|
current_record[line.date_stop_field_id.name], |
|
|
|
|
|
tools.DEFAULT_SERVER_DATETIME_FORMAT |
|
|
|
|
|
) |
|
|
duration = (date_stop - date_start).total_seconds() / 3600 |
|
|
duration = (date_stop - date_start).total_seconds() / 3600 |
|
|
elif line.duration_field_id: |
|
|
elif line.duration_field_id: |
|
|
duration = current_record[line.duration_field_id.name] |
|
|
duration = current_record[line.duration_field_id.name] |
|
@ -87,7 +99,12 @@ class super_calendar_configurator(orm.Model): |
|
|
'model_description': line.description, |
|
|
'model_description': line.description, |
|
|
'date_start': current_record[line.date_start_field_id.name], |
|
|
'date_start': current_record[line.date_start_field_id.name], |
|
|
'duration': duration, |
|
|
'duration': duration, |
|
|
'user_id': line.user_field_id and current_record[line.user_field_id.name] and current_record[line.user_field_id.name].id or False, |
|
|
|
|
|
|
|
|
'user_id': ( |
|
|
|
|
|
line.user_field_id and |
|
|
|
|
|
current_record[line.user_field_id.name] and |
|
|
|
|
|
current_record[line.user_field_id.name].id or |
|
|
|
|
|
False |
|
|
|
|
|
), |
|
|
'configurator_id': configurator.id, |
|
|
'configurator_id': configurator.id, |
|
|
'res_id': line.name.model+','+str(current_record['id']), |
|
|
'res_id': line.name.model+','+str(current_record['id']), |
|
|
'model_id': line.name.id, |
|
|
'model_id': line.name.id, |
|
@ -108,17 +125,26 @@ class super_calendar_configurator_line(orm.Model): |
|
|
('field', 'Field'), |
|
|
('field', 'Field'), |
|
|
('code', 'Code'), |
|
|
('code', 'Code'), |
|
|
], string="Description Type"), |
|
|
], string="Description Type"), |
|
|
'description_field_id': fields.many2one('ir.model.fields', 'Description field', |
|
|
|
|
|
|
|
|
'description_field_id': fields.many2one( |
|
|
|
|
|
'ir.model.fields', 'Description field', |
|
|
domain="[('model_id', '=', name),('ttype', '=', 'char')]"), |
|
|
domain="[('model_id', '=', name),('ttype', '=', 'char')]"), |
|
|
'description_code': fields.text('Description field', help="Use '${o}' to refer to the involved object. E.g.: '${o.project_id.name}'"), |
|
|
|
|
|
'date_start_field_id': fields.many2one('ir.model.fields', 'Start date field', |
|
|
|
|
|
|
|
|
'description_code': fields.text( |
|
|
|
|
|
'Description field', |
|
|
|
|
|
help="Use '${o}' to refer to the involved object. E.g.: '${o.project_id.name}'" |
|
|
|
|
|
), |
|
|
|
|
|
'date_start_field_id': fields.many2one( |
|
|
|
|
|
'ir.model.fields', 'Start date field', |
|
|
domain="['&','|',('ttype', '=', 'datetime'),('ttype', '=', 'date'),('model_id', '=', name)]", |
|
|
domain="['&','|',('ttype', '=', 'datetime'),('ttype', '=', 'date'),('model_id', '=', name)]", |
|
|
required=True), |
|
|
required=True), |
|
|
'date_stop_field_id': fields.many2one('ir.model.fields', 'End date field', |
|
|
|
|
|
domain="['&',('ttype', '=', 'datetime'),('model_id', '=', name)]"), |
|
|
|
|
|
'duration_field_id': fields.many2one('ir.model.fields', 'Duration field', |
|
|
|
|
|
|
|
|
'date_stop_field_id': fields.many2one( |
|
|
|
|
|
'ir.model.fields', 'End date field', |
|
|
|
|
|
domain="['&',('ttype', '=', 'datetime'),('model_id', '=', name)]" |
|
|
|
|
|
), |
|
|
|
|
|
'duration_field_id': fields.many2one( |
|
|
|
|
|
'ir.model.fields', 'Duration field', |
|
|
domain="['&',('ttype', '=', 'float'),('model_id', '=', name)]"), |
|
|
domain="['&',('ttype', '=', 'float'),('model_id', '=', name)]"), |
|
|
'user_field_id': fields.many2one('ir.model.fields', 'User field', |
|
|
|
|
|
|
|
|
'user_field_id': fields.many2one( |
|
|
|
|
|
'ir.model.fields', 'User field', |
|
|
domain="['&',('ttype', '=', 'many2one'),('model_id', '=', name)]"), |
|
|
domain="['&',('ttype', '=', 'many2one'),('model_id', '=', name)]"), |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|