Issues when writing one2one relationship

125 views
Skip to first unread message

Pedro Moretto Rodriguez

unread,
May 24, 2016, 12:50:04 PM5/24/16
to tryton
Hello I am trying to get a one2one relationship to work. Here are my classes:

class Formulario(ModelSQL,ModelView):
    'Formulario'
    _name = 'cefiro.formulario'
    _description = __doc__

    formVivTrabajo = fields.One2One('cefiro.formvivtrabajo','formularioid','formvivtrabajoid','Vivienda y Trabajo', required=True)

Formulario()


class Formvivtrabtarget(ModelSQL,ModelView):
    'Formvivtrabtarget'
    _name = 'cefiro.formvivtrabtarget.target'
    _description = __doc__

    tipoVivienda = fields.Selection([('casa','La casa'),('calle','La calle'),('inst',u'Institución protectora'),('car','Privado de libertad')],'Vive en',required=True)

Formvivtrabtarget()

class Formviviendatrabajo(ModelSQL,ModelView):
    'Formvivtrabajo'
    _name = 'cefiro.formvivtrabajo'
    _description = __doc__
   
    formvivtrabajoid = fields.Many2One('cefiro.formvivtrabtarget.target', 'Formvivtrabtarget')
    formularioid = fields.Many2One('cefiro.formulario', 'Formulario')
   
    def __init__(self):

        super(Formviviendatrabajo, self).__init__()

        self._sql_constraints += [
            ('origin_unique', 'UNIQUE(formularioid)','Origin must be unique'),
            ('target_unique', 'UNIQUE(formvivtrabajoid)','Target must be unique'),
        ]

Formviviendatrabajo()

You can see that I already have formvivtrabjoid as a Formviviendatrabajo's field but I am getting the following error when saving it:

Traceback (most recent call last):
  File "/trytond/protocols/jsonrpc.py", line 123, in _marshaled_dispatch
    response['result'] = dispatch_method(method, params)
  File "/trytond/protocols/jsonrpc.py", line 156, in _dispatch
    res = dispatch(*args)
  File "/trytond/protocols/dispatcher.py", line 156, in dispatch
    res = getattr(obj, method)(*args_without_context, **kargs)
  File "/trytond/model/modelsql.py", line 925, in write
    self._columns[field].set(ids, self, field, values[field])
  File "/trytond/model/fields/one2many.py", line 130, in set
    model.create(act[1])
  File "/trytond/model/modelsql.py", line 423, in create
    self._validate([id_new])
  File "/trytond/model/modelsql.py", line 2207, in _validate
    super(ModelSQL, self)._validate(ids)
  File "/trytond/model/modelstorage.py", line 1090, in _validate
    if (isinstance(record[field_name], (BrowseRecordNull,
  File "/trytond/model/browse.py", line 174, in __getitem__
    for data in self._model.read(ids, ffields.keys()):
  File "/trytond/model/modelsql.py", line 622, in read
    res2 = self._columns[field].get(ids, self, field, values=res)
  File "/trytond/model/fields/one2one.py", line 24, in get
    res = super(One2One, self).get(ids, model, name, values=values)
  File "/trytond/model/fields/many2many.py", line 78, in get
    ], order=order))
  File "/trytond/model/modelsql.py", line 1168, in search
    order_by2, tables2, tables2_args = self._order_calc(field, otype)
  File "/trytond/model/modelsql.py", line 2058, in _order_calc
    (field, self._name))
Exception: ('Error', 'Wrong field name (formvivtrabajoid) for cefiro.formvivtrabajo in order!')

I based on the following links but didn't work as you can see:
 
[1] http://doc.tryton.org/2.0/trytond/doc/ref/models/fields.html#one2one,
[2] http://hg.tryton.org/trytond/file/14a0a4d4e03b/trytond/test/test.py#l359
[3] http://hg.tryton.org/trytond/file/14a0a4d4e03b/trytond/tests/test_fields.py#l2083

Thank you in advance

Cédric Krier

unread,
May 25, 2016, 11:55:04 AM5/25/16
to tryton
Release 2.2 is almost 5 years old, it is no more supported since 2.5
years. I think the first thing to do is to work on recent/supported version.
Many improvement and especially the ordering stuffs have been improved
thanks to python-sql.

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

Pedro Moretto Rodriguez

unread,
May 25, 2016, 3:30:05 PM5/25/16
to tryton
Well, I am using Tryton 2.4.0 and now tried to upgrade it to 4.0.

But now it's not possible to load my module, I created a tryton.cfg file and edited __init.py__ on the folder's module. I don't know exactly what I need to upgrade it and get the module work properly.

Pedro Moretto Rodriguez

unread,
May 26, 2016, 7:20:04 AM5/26/16
to tryton
I mean, I have the module almost finished, I just need to make this one2one relation to work. I am trying to run it on a newer tryton server version without success.

Sergi Almacellas Abellana

unread,
May 26, 2016, 7:22:12 AM5/26/16
to try...@googlegroups.com
El 26/05/16 a les 12:52, Pedro Moretto Rodriguez ha escrit:
> I mean, I have the module almost finished, I just need to make this
> one2one relation to work. I am trying to run it on a newer tryton server
> version without success.
>
> El miércoles, 25 de mayo de 2016, 16:30:05 (UTC-3), Pedro Moretto
> Rodriguez escribió:
>
> Well, I am using Tryton 2.4.0 and now tried to upgrade it to 4.0.
>
> But now it's not possible to load my module, I created a tryton.cfg
> file and edited __init.py__ on the folder's module. I don't know
> exactly what I need to upgrade it and get the module work properly.
Can not give any guidance without the source code, so maybe you can
upload it somewhere so we can review it.


PS: Please don't top-post on this mailing list, see
http://groups.tryton.org/netiquette

--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Pedro Moretto Rodriguez

unread,
May 26, 2016, 1:10:04 PM5/26/16
to tryton


Hi, I uploaded it to https://github.com/guzmanico23/cefiro

I changed the names of the clases but the logic is the same:

1) At formulario.py: within Formulario class I have the One2One field "formularioViviendaTrabajo"
2) At formVivTrabajo.py: I have two classes "FormularioViviendaTrabajo" and "AuxFormVivTrabajo" (similar to Formviviendatrabajo and Formvivtrabtarget)

The views involved are hc.xml and hcVivTrab.xml

I also post here the error message when trying to opening a new "Formulario" (now it can be saved but not properly shown)

Sergi Almacellas Abellana

unread,
May 27, 2016, 3:10:39 AM5/27/16
to try...@googlegroups.com
El 26/05/16 a les 17:55, Pedro Moretto Rodriguez ha escrit:
>
> Hi, I uploaded it to https://github.com/guzmanico23/cefiro
>
> I changed the names of the clases but the logic is the same:
>
> 1) At formulario.py: within Formulario class I have the One2One field
> "formularioViviendaTrabajo"
> 2) At formVivTrabajo.py: I have two classes "FormularioViviendaTrabajo"
> and "AuxFormVivTrabajo" (similar to Formviviendatrabajo and
> Formvivtrabtarget)
>
> The views involved are hc.xml and hcVivTrab.xml
>
> I also post here the error message when trying to opening a new
> "Formulario" (now it can be saved but not properly shown)

Module is still on an unsupported version, so I can not give any tips if
iy is not migrated to a supported version.

Sorry.
>
> <https://lh3.googleusercontent.com/-y0mX2eMPI8Y/V0cbmPP97WI/AAAAAAAAA4g/qaPUT5cnrO4p6t9apnGXlrIJTl30Bch4wCLcB/s1600/one2one%2BError%2Bwhen%2Bopening%2Bregister.jpg>
>
>
>
> El jueves, 26 de mayo de 2016, 8:22:12 (UTC-3), Sergi Almacellas
> Abellana escribió:
>
> El 26/05/16 a les 12:52, Pedro Moretto Rodriguez ha escrit:
> > I mean, I have the module almost finished, I just need to make this
> > one2one relation to work. I am trying to run it on a newer tryton
> server
> > version without success.
> >
> > El miércoles, 25 de mayo de 2016, 16:30:05 (UTC-3), Pedro Moretto
> > Rodriguez escribió:
> >
> > Well, I am using Tryton 2.4.0 and now tried to upgrade it to
> 4.0.
> >
> > But now it's not possible to load my module, I created a
> tryton.cfg
> > file and edited __init.py__ on the folder's module. I don't know
> > exactly what I need to upgrade it and get the module work
> properly.
> Can not give any guidance without the source code, so maybe you can
> upload it somewhere so we can review it.
>
>
> PS: Please don't top-post on this mailing list, see
> http://groups.tryton.org/netiquette
> <http://groups.tryton.org/netiquette>
>
> --
> Sergi Almacellas Abellana
> www.koolpi.com <http://www.koolpi.com>
> Twitter: @pokoli_srk
>
> --
> 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/9129d982-fa07-4d5b-91c4-f606dc60f157%40googlegroups.com
> <https://groups.google.com/d/msgid/tryton/9129d982-fa07-4d5b-91c4-f606dc60f157%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages