Connect to a party module. / How to?

I am trying to connect my module to the Party module in Tryton.
And I am really puzzled about how to arrange all dependencies.
Would you point me to a manual or clear example of how to do that?
A party->items.
Items may not be connected to parties, but I need to have a way to link the ownership when it is known.

I need Many2One field:

party = fields.Many2One('', 'Party (owner)', required=False,
    ondelete='SET NULL', help="The party which holds the item.") 

but what I should have done around? I mean I will create a Party class, but how to search and populate it with parties from the Party module?
I explored the bank module, but it is rather complex to derive what exactly I should do.


I don’t understand.

When you’re creating a Many2One in SQL terms you’re creating a FOREIGN KEY referencing a record in another table. So in your python code you’re only manipulating the schema of the database.

It’s your users that will fill the data.

Of course you can programmatically fill some fields or propose default values for them but we need to understand better what you’d like to do in order to help.

Thank you, Nicolas,

Yes, I understand that I was not clear enough. So let me be more detailed:
I changed a schema since asked the question. I have two classes (i.e. tables, I skipped non-relevant declarations):

Class Owner(ModelSQL, ModelView):
    __name__ = 'my_module.owner'
    name = fields.Char(....)
    items = One2Many('my_module.item', ..., 'Items owned by this person')

Class Item(ModelSQL, ModelView):
    __name__ = 'my_module.item'
   item_name = fields.Char(...)
   owner = Many2One('my_module.owner',...,help = 'The owner of item')

What I want — I want to populate or someway to connect the Owner class to the Party class in the Party module (that delivers with standard Tryton setup), that resides in …/modules/party/ directory:

class Party(DeactivableMixin, ModelSQL, ModelView, MultiValueMixin):
    __name__ = ''

    name = fields.Char(
        "Name", select=True,
        help="The main identifier of the party.")

Since I have access to all modules, may be worth removing the Owner class and link the class Item to the class Party directly (May2One/One2Many). But I think that is a not good solution as it not a good programming style.

So, how to connect the Owner to the Party in party module?

I do not see why it would not be a good solution. We have such design in so many places in Tryton.

You can still set a Many2One from owner to party like we do for the Bank in the bank module.

1 Like

It depends how you want them connected :slight_smile:.

When your Owner model should be considered something different than a Party (like a Bank is not a Party but it is linked to a party because it has a name, some addresses, etc), then you should use a Many2One like in the bank module.

But if your Owner model extends the concept of Party (like adding some new fields to add extra functionnalities) then you should do the Tryton kind of inheritance. There are example of this kind of inheritance in the sale module but here’s a quick outline:

class Party(metaclass=PoolMeta):
   __name__ = ''
   your_new_field = fields.Type(…)

In both cases your tryton.cfg file must include party in its depends section.


I really appreciate your answers, Nicolas and CĂ©dric. You have saved a lot of time for me!
And especially want to say thank you for mentioning a party string in tryton.cfg — I would definitely forget to do that without your hint.

PS: It works now like a magic.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.