[tryton] Re: migration from 3.8 -> 4.0 with webdav

2016-05-06 Thread Richard PALO
Le 06/05/16 18:55, Cédric Krier a écrit :
> First, it is trytond-admin that manages now the upgrade.
> And clearly you don't have an up to date calendar module.
> 

I asked here primarily for the migration guide.

For instance, I find no mention about 'trytond-admin' in the
release announcement nor here (at least not what I can find).

grepping the Mercurial repository doc/topics/setup_databases.rst
indicates only that a database can be initialised with trytond-admin.

Yes, my fault for calendar, omitted to update the package list
with the new localisations, so 3.8 re-installed instead of 4.0.
Updated now via tryton-admin and am trying to get accustomed to
the new interface to GL and balance.

cheers

-- 
Richard PALO

-- 
You received this message because you are subscribed to the Google Groups 
"tryton" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton/572D72DC.6070409%40netbsd.org.


Re: [tryton-dev] Problem trying connect to server Tryton 4.0

2016-05-06 Thread Cédric Krier
On 2016-05-06 16:45, Oscar Alvarez wrote:
> Do I create  an new issue?

Yes

-- 
Cédric Krier - B2CK SPRL
Email/Jabber: cedric.kr...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

-- 
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/20160506220603.GL13326%40tetsuo.


Re: [tryton-dev] Problem trying connect to server Tryton 4.0

2016-05-06 Thread Oscar Alvarez



On 06/05/16 12:02, Cédric Krier wrote:

On 2016-05-06 11:44, Oscar Alvarez wrote:

   File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/trytond/protocols/jsonrpc.py",
line 126, in parsed_data
 raise BadRequest('Unable to read JSON request')
werkzeug.exceptions.BadRequest: 400: Bad Request

Please could you look at which exception trigger this raise?



Here the result:

10846 139708903905024 [2016-05-06 21:37:53,104] ERROR werkzeug Error on 
request:

Traceback (most recent call last):
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/werkzeug/serving.py", 
line 193, in run_wsgi

execute(self.server.app)
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/werkzeug/serving.py", 
line 181, in execute

application_iter = app(environ, start_response)
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/werkzeug/wsgi.py", 
line 599, in __call__

return self.app(environ, start_response)
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/trytond/wsgi.py", 
line 84, in __call__

return self.wsgi_app(environ, start_response)
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/trytond/wsgi.py", 
line 74, in wsgi_app

response = cls.response(data, request)
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/trytond/protocols/jsonrpc.py", 
line 149, in response

response = {'id': request.parsed_data.get('id', 0)}
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/werkzeug/utils.py", 
line 73, in __get__

value = self.func(obj)
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/trytond/protocols/jsonrpc.py", 
line 124, in parsed_data

return json.loads(self.decoded_data, object_hook=JSONDecoder())
  File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'

I think that the problem is self.decoded_data variable because is type 
"bytes", I added a "print" before this line and I could confirm this, so
when I convert this variable using .decode("utf-8"), the problem was 
solved!.


Do I create  an new issue?

Oscar Alvarez

--
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/572D106B.3000809%40gmail.com.


Re: [tryton-dev] Problem trying connect to server Tryton 4.0

2016-05-06 Thread Cédric Krier
On 2016-05-06 11:44, Oscar Alvarez wrote:
>   File 
> "/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/trytond/protocols/jsonrpc.py",
> line 126, in parsed_data
> raise BadRequest('Unable to read JSON request')
> werkzeug.exceptions.BadRequest: 400: Bad Request

Please could you look at which exception trigger this raise?

-- 
Cédric Krier - B2CK SPRL
Email/Jabber: cedric.kr...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

-- 
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/20160506170245.GK13326%40tetsuo.


Re: [tryton] How is the way to refresh a tree/form view from other tree view with on_change?

2016-05-06 Thread Cédric Krier
On 2016-05-06 08:16, Fabyc wrote:
> Hi.
> 
> If I have a tree view (TV1) and I have another one (TV2), how is it the way 
> with 
> on_change to refresh the data of the other tree view?
> 
> Example:
> - TV1 has 50 records
> - Select any of the records
> - Data on TV2 now displays a group of records. Based on the selected 
> record, TV2 data is refreshed.

I guess you are talking about dashboard.
You can use the Eval on the action id of the other actions like
explained in the doc:
http://doc.tryton.org/4.0/trytond/doc/topics/views/index.html#board-view
You can find an example in the timesheet module: work_hours_board

-- 
Cédric Krier - B2CK SPRL
Email/Jabber: cedric.kr...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

-- 
You received this message because you are subscribed to the Google Groups 
"tryton" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton/20160506165925.GJ13326%40tetsuo.


Re: [tryton] migration from 3.8 -> 4.0 with webdav

2016-05-06 Thread Cédric Krier
On 2016-05-06 16:50, Richard PALO wrote:
> Is there a 4.0 migration guide that indicates how deal with webdav?
> I can only find mention of 3.8.
> 
> I'm experiencing the following (actually --all -d  makes no difference)
> > richard@omnis:/home/richard/src$ trytond2.7 -c trytond.conf --all -d  
> > Traceback (most recent call last):
> >   File "/opt/local/bin/trytond2.7", line 17, in 
> > from trytond.application import app
> >   File "/opt/local/lib/python2.7/site-packages/trytond/application.py", 
> > line 8, in 
> > Pool.start()
> >   File "/opt/local/lib/python2.7/site-packages/trytond/pool.py", line 97, 
> > in start
> > register_classes()
> >   File 
> > "/opt/local/lib/python2.7/site-packages/trytond/modules/__init__.py", line 
> > 362, in register_classes
> > mod_file, pathname, description)
> >   File 
> > "/opt/local/lib/python2.7/site-packages/trytond/modules/calendar/__init__.py",
> >  line 5, in 
> > from . import caldav
> >   File 
> > "/opt/local/lib/python2.7/site-packages/trytond/modules/calendar/caldav.py",
> >  line 11, in 
> > from trytond.protocols.webdav import TrytonDAVInterface, CACHE, \
> > ImportError: No module named webdav
> 
> I have built trytond_webdav (4.0.1) and installed it, all the other modules 
> used have been updated to 4.0.0

First, it is trytond-admin that manages now the upgrade.
And clearly you don't have an up to date calendar module.

-- 
Cédric Krier - B2CK SPRL
Email/Jabber: cedric.kr...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

-- 
You received this message because you are subscribed to the Google Groups 
"tryton" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton/20160506165545.GI13326%40tetsuo.


Re: [tryton-dev] Using of Model. __post_setup__

2016-05-06 Thread edbo . design


On Friday, May 6, 2016 at 3:55:03 PM UTC+2, Cédric Krier wrote:
>
> On 2016-05-06 05:41, edbo@gmail.com  wrote: 
> > Hello, 
> > 
> > I think I'm using the Model. __post_setup__ class not correctly, but how 
> > I'm using it is working in Tryton-3.6.5 but not in Tryton-4.0.0 and 
> maybe 
> > there are other ways to do it. 
> > 
> > What I'm trying to do, is to build an IOT-platform into Tryton where 
> agents 
> > can connect to and update several values they allowed to change. To 
> > minimize database-queries and updating database-records or inserting new 
> > ones, I build a dict which lives in memory. The agents send the new 
> values 
> > in and Tryton will update the values in the dict, and a cron-job will 
> > archive those values into the database at certain moments. The new 
> values 
> > are also used to trigger events like sending mail, executing scripts 
> etc. 
> > 
> > To create the dict in memory I'm using the __post_setup__ class to 
> populate 
> > the dict with the several values. 
> > 
> > @classmethod 
> > def __post_setup__(cls): 
> > super(Trigger, cls).__post_setup__() 
> > 
> > # get the triggers 
> > triggers = cls.search( [('id', '>', 0 )] ) 
> > 
> > if triggers: 
> > # Build the datastructure in memory 
> > for trigger in cls.browse( triggers ): 
> > 
> > sensors = [] 
> > on_activate = [] 
> > on_deactivate = [] 
> > 
> > # get the sensors and conditions 
> > for sensor in trigger.sensor: 
> > if len(sensor.condition) > 2: 
> > sensors.append({ 
> > "id": sensor.id, 
> > "sensor": sensor.sensor.id, 
> > "condition" : sensor.condition, 
> > }) 
> > 
> > # only add the trigger to the list when there are 
> > # sensors and conditions 
> > if len(sensors): 
> > MEM_TRIGGERS.append({ 
> > "id" : trigger.id, 
> > "name"   : trigger.name, 
> > "sequence"   : trigger.sequence, 
> > "min_delay"  : trigger.minimum_time_delay, 
> > "min_active" : trigger.minimum_time_active, 
> > "when"   : datetime.datetime.utcnow(), 
> > "activated"  : trigger.activated, 
> > "enabled": trigger.enabled, 
> > "sensors": sensors 
> > }) 
> > 
> > I have extended the ir.trigger with 
> > sensor = fields.One2Many('iot.triggersensors', 'trigger', 'Sensor') 
> > 
> > And the iot.triggersensors 
> > 
> > class TriggerSensor(ModelSQL, ModelView): 
> > "TriggerSensor" 
> > __name__ = 'iot.triggersensors' 
> > 
> > name = fields.Char('Name') 
> > trigger = fields.Many2One('ir.trigger', 'Trigger', 
> > domain=[('on_sensor','=',True)], ondelete='CASCADE') 
> > condition = fields.Char('Condition') 
> > 
> > 
> > This is working in Tryton version 3.65, but in 4.0.0 I get 
> > 
> >   File "/home/ed/ERP/iot/trytond-4.0.0/trytond/pool.py", line 229, in 
> setup 
> > cls.__post_setup__() 
> >   File "/home/ed/ERP/iot/trytond-4.0.0/trytond/modules/iot/iot.py", line 
> > 1173, in __post_setup__ 
> > for sensor in trigger.sensor: 
> >   File "/home/ed/ERP/iot/trytond-4.0.0/trytond/model/modelstorage.py", 
> line 
> > 1352, in __getattr__ 
> > read_data = self.read(list(ids), ffields.keys()) 
> >   File "/home/ed/ERP/iot/trytond-4.0.0/trytond/model/modelsql.py", line 
> > 744, in read 
> > getter_result = field.get(ids, cls, fname, values=result) 
> >   File 
> "/home/ed/ERP/iot/trytond-4.0.0/trytond/model/fields/one2many.py", 
> > line 86, in get 
> > field = Relation._fields[self.field] 
> > AttributeError: type object 'iot.triggersensors' has no attribute 
> '_fields' 
> > 
> > So my question is, are there other methods to accomplish this (after the 
> > Tryton-server is started create a dict into memory)? or is this a bug in 
> > Tryton-4.0.0? 
>
> It is definitely not a bug in 4.0. Your code was working before by 
> chance. The ORM should never be used during the initialization of the 
> Pool. Your code doesn't work any more probably because of the 
> optimization of the pool initialization. 
>
> Hmm, ok, but the documentation says "Setup the class AFTER added into the 
trytond.pool.Pool". So IMO this means that the class is added into the pool 
and then __post_setup__ will be called.

 

> Also you should be careful with global variable, your structure is 
> probably not thread-safe. 
>

I don't use global. In my iot.py I have
MEM_SENSORS = {}  # store sensor values in memory

just 

[tryton-dev] Problem trying connect to server Tryton 4.0

2016-05-06 Thread Oscar Alvarez

Hi Devs,

I getting next errors and I can not to create new database on Tryton 4.0 
server, (fresh install ubuntu 16.04, postgresql 9.5), trytond is on 
virtualenv python 3.5 and client about python 2.7:



Client side traceback

psk@psk-SAMS:~$ tryton -v
INFO:tryton.rpc:common.db.list_lang(())
INFO:tryton.rpc:common.db.list_lang(())
ERROR:tryton.common.common:Traceback (most recent call last):
  File 
"/usr/local/lib/python2.7/dist-packages/tryton-4.0.0-py2.7.egg/tryton/gui/window/dbcreate.py", 
line 65, in server_change

common.refresh_langlist(self.combo_language, host, port)
  File 
"/usr/local/lib/python2.7/dist-packages/tryton-4.0.0-py2.7.egg/tryton/common/common.py", 
line 253, in refresh_langlist

lang_list = rpc.db_exec(host, port, 'list_lang')
  File 
"/usr/local/lib/python2.7/dist-packages/tryton-4.0.0-py2.7.egg/tryton/rpc.py", 
line 55, in db_exec

result = getattr(connection.common.db, method)(*args)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1240, in __call__
return self.__send(self.__name, args)
  File 
"/usr/local/lib/python2.7/dist-packages/tryton-4.0.0-py2.7.egg/tryton/jsonrpc.py", 
line 283, in __request

verbose=self.__verbose
  File "/usr/lib/python2.7/xmlrpclib.py", line 1280, in request
return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1328, in single_request
response.msg,
ProtocolError: ERROR>





Server side traceback

4415 140271277958912 [2016-05-06 16:28:03,481] INFO trytond.config using 
/home/psk/.trytond/trytond.conf as configuration file
4415 140271115093760 [2016-05-06 16:28:24,471] INFO werkzeug 127.0.0.1 - 
- [06/May/2016 16:28:24] "POST / HTTP/1.1" 500 -
4415 140271115093760 [2016-05-06 16:28:24,473] ERROR werkzeug Error on 
request:

Traceback (most recent call last):
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/werkzeug/serving.py", 
line 193, in run_wsgi

execute(self.server.app)
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/werkzeug/serving.py", 
line 181, in execute

application_iter = app(environ, start_response)
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/werkzeug/wsgi.py", 
line 599, in __call__

return self.app(environ, start_response)
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/trytond/wsgi.py", 
line 84, in __call__

return self.wsgi_app(environ, start_response)
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/trytond/wsgi.py", 
line 74, in wsgi_app

response = cls.response(data, request)
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/trytond/protocols/jsonrpc.py", 
line 149, in response

response = {'id': request.parsed_data.get('id', 0)}
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/werkzeug/utils.py", 
line 73, in __get__

value = self.func(obj)
  File 
"/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/trytond/protocols/jsonrpc.py", 
line 126, in parsed_data

raise BadRequest('Unable to read JSON request')
werkzeug.exceptions.BadRequest: 400: Bad Request


my trytond.conf  file:


[database]
uri = postgresql://psk:xxx@127.0.0.1:5432/
path = /var/lib/trytond/
language = es_CO
retry = 5


[session]
timeout = 6000
super_pwd = xxx


[web]
listen = *:8100
hostname = 127.0.0.1
root = /var/www/localhost/tryton


So postgresql is running fine:

psk@psk-SAMS:~$ ps -Af | grep postgres
postgres  4100 1  0 11:04 ?00:00:00 
/usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c 
config_file=/etc/postgresql/9.5/main/postgresql.conf
postgres  4102  4100  0 11:04 ?00:00:00 postgres: checkpointer 
process



1. Somebody has the same problem?,

2. How can I improvement the traceback output?

3. Is it a bug?


Thanks for advance.

Oscar Alvarez

--
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/572CCA06.2080006%40gmail.com.


[tryton] How is the way to refresh a tree/form view from other tree view with on_change?

2016-05-06 Thread Fabyc
Hi.

If I have a tree view (TV1) and I have another one (TV2), how is it the way 
with 
on_change to refresh the data of the other tree view?

Example:
- TV1 has 50 records
- Select any of the records
- Data on TV2 now displays a group of records. Based on the selected 
record, TV2 data is refreshed.

Thanks in advanced

--
Regards

-- 
You received this message because you are subscribed to the Google Groups 
"tryton" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton/89d615ab-a245-4dcd-a2d7-7afbcf0bdfca%40googlegroups.com.


[tryton] migration from 3.8 -> 4.0 with webdav

2016-05-06 Thread Richard PALO
Is there a 4.0 migration guide that indicates how deal with webdav?
I can only find mention of 3.8.

I'm experiencing the following (actually --all -d  makes no difference)
> richard@omnis:/home/richard/src$ trytond2.7 -c trytond.conf --all -d  
> Traceback (most recent call last):
>   File "/opt/local/bin/trytond2.7", line 17, in 
> from trytond.application import app
>   File "/opt/local/lib/python2.7/site-packages/trytond/application.py", line 
> 8, in 
> Pool.start()
>   File "/opt/local/lib/python2.7/site-packages/trytond/pool.py", line 97, in 
> start
> register_classes()
>   File "/opt/local/lib/python2.7/site-packages/trytond/modules/__init__.py", 
> line 362, in register_classes
> mod_file, pathname, description)
>   File 
> "/opt/local/lib/python2.7/site-packages/trytond/modules/calendar/__init__.py",
>  line 5, in 
> from . import caldav
>   File 
> "/opt/local/lib/python2.7/site-packages/trytond/modules/calendar/caldav.py", 
> line 11, in 
> from trytond.protocols.webdav import TrytonDAVInterface, CACHE, \
> ImportError: No module named webdav

I have built trytond_webdav (4.0.1) and installed it, all the other modules 
used have been updated to 4.0.0

cheers
-- 
Richard PALO

-- 
You received this message because you are subscribed to the Google Groups 
"tryton" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton/572CAF39.6080409%40netbsd.org.


Re: [tryton-dev] Using of Model. __post_setup__

2016-05-06 Thread Cédric Krier
On 2016-05-06 05:41, edbo.des...@gmail.com wrote:
> Hello,
> 
> I think I'm using the Model. __post_setup__ class not correctly, but how 
> I'm using it is working in Tryton-3.6.5 but not in Tryton-4.0.0 and maybe 
> there are other ways to do it.
> 
> What I'm trying to do, is to build an IOT-platform into Tryton where agents 
> can connect to and update several values they allowed to change. To 
> minimize database-queries and updating database-records or inserting new 
> ones, I build a dict which lives in memory. The agents send the new values 
> in and Tryton will update the values in the dict, and a cron-job will 
> archive those values into the database at certain moments. The new values 
> are also used to trigger events like sending mail, executing scripts etc.
> 
> To create the dict in memory I'm using the __post_setup__ class to populate 
> the dict with the several values.
> 
> @classmethod
> def __post_setup__(cls):
> super(Trigger, cls).__post_setup__()
> 
> # get the triggers
> triggers = cls.search( [('id', '>', 0 )] )
> 
> if triggers:
> # Build the datastructure in memory
> for trigger in cls.browse( triggers ):
> 
> sensors = []
> on_activate = []
> on_deactivate = []
> 
> # get the sensors and conditions
> for sensor in trigger.sensor:
> if len(sensor.condition) > 2:
> sensors.append({
> "id": sensor.id,
> "sensor": sensor.sensor.id,
> "condition" : sensor.condition,
> })
> 
> # only add the trigger to the list when there are 
> # sensors and conditions
> if len(sensors):
> MEM_TRIGGERS.append({
> "id" : trigger.id,
> "name"   : trigger.name,
> "sequence"   : trigger.sequence,
> "min_delay"  : trigger.minimum_time_delay,
> "min_active" : trigger.minimum_time_active,
> "when"   : datetime.datetime.utcnow(),
> "activated"  : trigger.activated,
> "enabled": trigger.enabled,
> "sensors": sensors
> })
> 
> I have extended the ir.trigger with 
> sensor = fields.One2Many('iot.triggersensors', 'trigger', 'Sensor') 
> 
> And the iot.triggersensors
> 
> class TriggerSensor(ModelSQL, ModelView):
> "TriggerSensor"
> __name__ = 'iot.triggersensors'
> 
> name = fields.Char('Name')
> trigger = fields.Many2One('ir.trigger', 'Trigger', 
> domain=[('on_sensor','=',True)], ondelete='CASCADE')
> condition = fields.Char('Condition')
> 
> 
> This is working in Tryton version 3.65, but in 4.0.0 I get
> 
>   File "/home/ed/ERP/iot/trytond-4.0.0/trytond/pool.py", line 229, in setup
> cls.__post_setup__()
>   File "/home/ed/ERP/iot/trytond-4.0.0/trytond/modules/iot/iot.py", line 
> 1173, in __post_setup__
> for sensor in trigger.sensor:
>   File "/home/ed/ERP/iot/trytond-4.0.0/trytond/model/modelstorage.py", line 
> 1352, in __getattr__
> read_data = self.read(list(ids), ffields.keys())
>   File "/home/ed/ERP/iot/trytond-4.0.0/trytond/model/modelsql.py", line 
> 744, in read
> getter_result = field.get(ids, cls, fname, values=result)
>   File "/home/ed/ERP/iot/trytond-4.0.0/trytond/model/fields/one2many.py", 
> line 86, in get
> field = Relation._fields[self.field]
> AttributeError: type object 'iot.triggersensors' has no attribute '_fields'
> 
> So my question is, are there other methods to accomplish this (after the 
> Tryton-server is started create a dict into memory)? or is this a bug in 
> Tryton-4.0.0?

It is definitely not a bug in 4.0. Your code was working before by
chance. The ORM should never be used during the initialization of the
Pool. Your code doesn't work any more probably because of the
optimization of the pool initialization.

Also you should be careful with global variable, your structure is
probably not thread-safe.

Finally, are you sure you need this? Of course database query is
expensive but included in all the stack of a request, I don't think it
has so much effect.

-- 
Cédric Krier - B2CK SPRL
Email/Jabber: cedric.kr...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

-- 
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/20160506135357.GB13326%40tetsuo.


[tryton-dev] Using of Model. __post_setup__

2016-05-06 Thread edbo . design
Hello,

I think I'm using the Model. __post_setup__ class not correctly, but how 
I'm using it is working in Tryton-3.6.5 but not in Tryton-4.0.0 and maybe 
there are other ways to do it.

What I'm trying to do, is to build an IOT-platform into Tryton where agents 
can connect to and update several values they allowed to change. To 
minimize database-queries and updating database-records or inserting new 
ones, I build a dict which lives in memory. The agents send the new values 
in and Tryton will update the values in the dict, and a cron-job will 
archive those values into the database at certain moments. The new values 
are also used to trigger events like sending mail, executing scripts etc.

To create the dict in memory I'm using the __post_setup__ class to populate 
the dict with the several values.

@classmethod
def __post_setup__(cls):
super(Trigger, cls).__post_setup__()

# get the triggers
triggers = cls.search( [('id', '>', 0 )] )

if triggers:
# Build the datastructure in memory
for trigger in cls.browse( triggers ):

sensors = []
on_activate = []
on_deactivate = []

# get the sensors and conditions
for sensor in trigger.sensor:
if len(sensor.condition) > 2:
sensors.append({
"id": sensor.id,
"sensor": sensor.sensor.id,
"condition" : sensor.condition,
})

# only add the trigger to the list when there are 
# sensors and conditions
if len(sensors):
MEM_TRIGGERS.append({
"id" : trigger.id,
"name"   : trigger.name,
"sequence"   : trigger.sequence,
"min_delay"  : trigger.minimum_time_delay,
"min_active" : trigger.minimum_time_active,
"when"   : datetime.datetime.utcnow(),
"activated"  : trigger.activated,
"enabled": trigger.enabled,
"sensors": sensors
})

I have extended the ir.trigger with 
sensor = fields.One2Many('iot.triggersensors', 'trigger', 'Sensor') 

And the iot.triggersensors

class TriggerSensor(ModelSQL, ModelView):
"TriggerSensor"
__name__ = 'iot.triggersensors'

name = fields.Char('Name')
trigger = fields.Many2One('ir.trigger', 'Trigger', 
domain=[('on_sensor','=',True)], ondelete='CASCADE')
condition = fields.Char('Condition')


This is working in Tryton version 3.65, but in 4.0.0 I get

  File "/home/ed/ERP/iot/trytond-4.0.0/trytond/pool.py", line 229, in setup
cls.__post_setup__()
  File "/home/ed/ERP/iot/trytond-4.0.0/trytond/modules/iot/iot.py", line 
1173, in __post_setup__
for sensor in trigger.sensor:
  File "/home/ed/ERP/iot/trytond-4.0.0/trytond/model/modelstorage.py", line 
1352, in __getattr__
read_data = self.read(list(ids), ffields.keys())
  File "/home/ed/ERP/iot/trytond-4.0.0/trytond/model/modelsql.py", line 
744, in read
getter_result = field.get(ids, cls, fname, values=result)
  File "/home/ed/ERP/iot/trytond-4.0.0/trytond/model/fields/one2many.py", 
line 86, in get
field = Relation._fields[self.field]
AttributeError: type object 'iot.triggersensors' has no attribute '_fields'

So my question is, are there other methods to accomplish this (after the 
Tryton-server is started create a dict into memory)? or is this a bug in 
Tryton-4.0.0?



Regards,

Ed

-- 
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/fa7af54a-45a9-46d9-aad8-c0a9b3792e4c%40googlegroups.com.


Re: [tryton-dev] Warnings Tryton server about python 3.5

2016-05-06 Thread Cédric Krier
On 2016-05-05 22:44, Oscar Alvarez wrote:
> Hi, Devs
> 
> I trying to run tryton server 4.0 about python 3.5, and it server runs but I
> get some warnings:
> 
> /home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/relatorio/templates/__init__.py:29:
> UserWarning: Unable to load plugin 'chart'
>   warnings.warn("Unable to load plugin '%s'" % name)

This is not particularly linked to Python3. This is bacause relatorio
has a weak dependency on pycha. If you think this behaviour could be
improved you can report it on https://relatorio.tryton.org/

> /home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/trytond/modules/__init__.py:143:
> DeprecationWarning: This method will be removed in future versions.  Use
> 'parser.read_file()' instead.
>   module_config.readfp(fp)

Yes, readfp was changed for read_file in Python 3.2 but it is not
available in Python 2.7. So this feature is kept to ease the transition
between 2 to 3: https://bugs.python.org/issue13248#msg146500
I don't think we should do anything about it until we drop support for
2.7.

> /home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/stdnum/numdb.py:202:
> ResourceWarning: unclosed file <_io.BufferedReader 
> name='/home/psk/.virtualenvs/tryton40/lib/python3.5/site-packages/stdnum/iban.dat'>
>   db = read(reader(resource_stream(__name__, name + '.dat')))

I think this one should be reported to python-stdnum:
https://github.com/arthurdejong/python-stdnum/issues

-- 
Cédric Krier - B2CK SPRL
Email/Jabber: cedric.kr...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

-- 
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/20160506090754.GW13326%40tetsuo.


Re: [tryton-dev] from sql import Cast, Literal, Values, With ?

2016-05-06 Thread Cédric Krier
On 2016-05-04 12:52, Lucas Riccombene wrote:
> from sql import Cast, Literal, Values, With
> ImportError: cannot import name Values

Values was added in python-sql 0.5 so if you want to use it, you must
update to at least this version (better to use the latest as it is
backward compatible).

-- 
Cédric Krier - B2CK SPRL
Email/Jabber: cedric.kr...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

-- 
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/20160506090924.GX13326%40tetsuo.


Re: [tryton-dev] Updating a one2many via on_change_*

2016-05-06 Thread Cédric Krier
On 2016-05-05 17:43, Sergi Almacellas Abellana wrote:
> El 05/05/16 a les 17:35, Clemens Hupka ha escrit:
> >Hello!
> >
> >I'm working on a ticket reservation and selling system based on tryton 3.8.
> >
> >As discussed with pokoli on #tryton, my model is quite special because i
> >have two one2many-relations towards ticket.ticket (one from
> >ticket.reservation and one from ticket.sale).
> 
> Here is the link to the discussion on the irc:
> 
> http://www.tryton.org/~irclog/2016-05-05.log.html#t2016-05-05%2015:09
> >
> >The goal was to get all tickets of a reservation into a sale with the
> >following on_change function (the number of tickets in the system should
> >be kept constant). The problem is, that with this piece of code the
> >number of reserved ticket is newly created, so if i select a reservation
> >with tickets id:162 and id:163 it creates me two new empty tickets
> >instead of updating the reserved ones...
> 
> As shown in the irclog, this Returns:
> 
>   [{'tickets': defaultdict(, {'add': [(0, {}), (1, {})]})}]
> 
> To the client code, because the records have no modified property.
> So I'm wondering if we should at least return the id in order to relate
> already existing records.

The code managed this behaviour is:
http://hg.tryton.org/trytond/file/default/trytond/model/modelview.py#l673
With the active record design, it had to choose the behaviour of the
on_change for the One2Many and the Many2Many. We could not mix both
because they have incompatible design (dict actions vs list of ids).
I think the older design was a little bit problematic because when
overriding we could be know which one will be used.
So it was decided to stick on_change behaviour to the default behaviour
of the client which means for One2Many: create, update and delete and
for ManyMany: add/remove.

> >Here is the code:
> >
> >class Ticketsale(ModelSQL, ModelView):
> > """
> >Ticket sale
> >"""
> > __name__ = 'ticket.sale'
> > receipt_number = fields.Char('Receipt number', readonly=True,
> >select=True)
> > pos_create_date = fields.DateTime('Create date', readonly=True)
> > reservation = fields.Many2One('ticket.reservation', 'Reservation')
> > voucher = fields.Many2One('ticket.voucher', 'Voucher')
> > tickets = fields.One2Many('ticket.ticket', 'sale', "Tickets")
> > @fields.depends('reservation','tickets')
> > def on_change_reservation(self):
> > if self.reservation:
> > tkts = list(self.tickets)
> > for t in self.reservation.tickets:
> > tkts.append(t)
> > self.tickets = tuple(tkts)
> >
> >I already found another solution with the use of a button. Just wanted
> >to know (btw pokoli too) if the behaviour of tryton is correct in that
> >(indeed very special and uncommon) case.

I think the behaviour of Tryton shows you that there is a design issue
in this code. The tickers should be a Many2Many even if you would like
to have ticket linked to only one sale. I said that because nothing
prevent the user to select a reservation that is already selected on
another sale so you will re-link the tickets from one sale to another.
I think it is not what you want.
If you are using a Many2Many (with a unique constraint), this case will
raise an error and so the user could correct it.

-- 
Cédric Krier - B2CK SPRL
Email/Jabber: cedric.kr...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

-- 
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/20160506085535.GV13326%40tetsuo.