How related origin reference field with One2Many fields

21 views
Skip to first unread message

Oscar Alvarez

unread,
Jun 28, 2018, 4:15:07 AM6/28/18
to tryto...@googlegroups.com

Hi Devs


It is possible to use field reference (origin) instead of Many2One? for example in this case:

class A(...):

    name = fields.Char(......)

    documents = field.One2Many('document.notification', 'origin', '???')


class B(...):

    name = fields.Char(......)

    documents = field.One2Many('document.notification', 'origin', '???')




class DocumentNotification(...):
  anotherfields = .....
  origin = fields.Reference('Origin', selection='get_origin') --> this field keep reference to records from A model or B model or C model, etc.



Or some type of Mixing is the best solution?

Thanks for advance.


-- Best regards / Atentamente, Oscar Andrés Alvarez M. CEO, Presik SAS Cel. 301 245 7967 www.presik.com < Empresas Inteligentes >

Cédric Krier

unread,
Jun 28, 2018, 4:30:06 AM6/28/18
to tryto...@googlegroups.com
Hi,

On 2018-06-27 18:53, Oscar Alvarez wrote:
> It is possible to use field reference (origin) instead of Many2One?

Yes: http://doc.tryton.org/4.8/trytond/doc/ref/models/fields.html#trytond.model.fields.One2Many

> for example in this case:
>
> class A(...):
>
>     name = fields.Char(......)
>
>     documents = field.One2Many('document.notification', 'origin', '???')
>
> class B(...):
>
>     name = fields.Char(......)
>
>     documents = field.One2Many('document.notification', 'origin', '???')
>
>
>
>
> class DocumentNotification(...):
>   anotherfields = .....
>   origin = fields.Reference('Origin', selection='get_origin') --> this
> field keep reference to records from A model or B model or C model, etc.
>

That's all you have to do. The '???' should be the string of the field.

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

Nicolas Évrard

unread,
Jun 28, 2018, 4:37:45 AM6/28/18
to tryto...@googlegroups.com
* Oscar Alvarez [2018-06-28 01:53:28]:
> Hi Devs

Hello,

> It is possible to use field reference (origin) instead of Many2One? for
> example in this case:
>
> class A(...):
>
> name = fields.Char(......)
>
> documents = field.One2Many('document.notification', 'origin',
> '???')
>
> class B(...):
>
> name = fields.Char(......)
>
> documents = field.One2Many('document.notification', 'origin',
> '???')
> class DocumentNotification(...):
> anotherfields = .....
> origin = fields.Reference('Origin', selection='get_origin') --> this
> field keep reference to records from A model or B model or C model,
> etc.
> Or some type of Mixing is the best solution?
> Thanks for advance.

Yes.

For example the shipment on the stock.move is a reference field yet
it's used as the origin of the corresponding One2Many in the different
shipments kind.

BTW this question should rather go to tryton instead of tryton-dev

--
Nicolas Évrard - B2CK SPRL
E-mail/Jabber: nicolas...@b2ck.com

Oscar Alvarez

unread,
Jun 28, 2018, 7:55:07 AM6/28/18
to tryto...@googlegroups.com
Thanks works!
Reply all
Reply to author
Forward
0 new messages