GOLEM/test/models/test.py

110 lines
3.7 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# Copyright 2017 Fabien Bourgeois <fabien@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
""" GOLEM activities related models """
from odoo import models, fields, api, _
class Test(models.Model):
""" GOLEM Activity Type test """
_name = 'test.test'
_description = 'GOLEM Test'
name = fields.Char('Name', required=True, translate=True)
number = fields.Integer('number')
is_recurrent = fields.Boolean('Is recurrent?')
@api.model
def create(self, vals):
print '_________________________________'
print 'create call'
return super(Test, self).create(vals)
@api.multi
def write(self, vals):
print '_________________________________'
print 'write call'
return super(Test, self).write(vals)
@api.multi
def get_recurrent_ids(self):
result = []
for test in self:
result.append(test.id)
result.append(test.real_id2virtual_id(test.id))
return result
@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
print '_______________________________________'
print 'search call'
result = super(Test, self).search(args=args, offset=offset, limit=limit, order=order, count=count)
result = self.env['test.test'].browse(result.get_recurrent_ids())
print result
print ' search end'
print '________________________________________'
return result
@api.multi
def read(self, fields=None, load='_classic_read'):
fields2 = fields and fields[:] or None
print '_________________________________'
print 'read call start'
print 'fields '+str(fields)
print 'load '+str(load)
print "<<<<<"
print self
print ">>>>>"
select = map(lambda x: (x, self.virtual_id2real_id(x)), self.ids)
print "select: "
print select
real_tests = self.browse([real_id for virtual_id, real_id in select])
print "real_tests: "
print real_tests
real_data = super(Test, real_tests).read(fields=fields2, load=load)
print "real_data : "
print real_data
real_data = dict((d['id'], d) for d in real_data)
print "real_data 2 : "
print real_data
result = []
for calendar_id, real_id in select:
res = real_data[real_id].copy()
res['id'] = calendar_id
result.append(res)
print "result : "
print result
print 'read call stop'
print '_________________________________'
return result
@api.model
def real_id2virtual_id(self,record_id):
return '%s-%s' % (record_id, 'vir')
@api.model
def virtual_id2real_id(self,calendar_id=None, with_date=False):
if calendar_id and isinstance(calendar_id, (basestring)):
res = filter(None, calendar_id.split('-'))
if len(res) == 2:
real_id = res[0]
return int(real_id)
return calendar_id and int(calendar_id) or calendar_id