Decided to share where I came to.
Goal: I need to indicate what items go under the service that is invoiced (the company sells services to Items that are owned by clients)
I started with adding
My_module to the Origin field in Sales, but I don’t like it (there is only one item that could be connected). And initially, I forgot to add override initialization to
that is why I didn’t find my module in the list of origins at the beginning. Just a note for future explorers
Next. I didn’t find that is good. It is not the ‘origin’ and the only one item from my module is on the list. I need many.
Eventually, I decided to forgo this way and switched to a more elaborate method to connect Service to Items.
Hence, I decided to use Many2Many fields.
from trytond.pool import PoolMeta
# ——— Add to original class 'Sale' sale.sale my field
__name__ = 'sale.sale'
items = fields.Many2Many(
relation_name = 'sale.sale-my_module.item',
origin = 'sale', # because it is the Sale class
target = 'item',
#———— Connection class,
# builds a symmetrical behaviuor, mirroring One2Many
# in both directions
'Items - Sales relation'
__name__ = 'sale.sale-my_module.item'
sale = fields.Many2One(
'Sales', # We are connected to ALL items (rows) in Sales class
item = fields.Many2One(
'Items', # We are connected to ALL items (rows) in that class
# —————— My class of my module
class Item(ModelSQL, ModelView):
__name__ = 'my_module.item'
item_sales = fields.Many2Many(
'item', # Origin is the 'item' because we are in the Item class
string='Sales for this item')
Also I wraped fields
sales / items in
<notebook> <page> tags both in sale_form.xml and items_form.xml, created sale.xml with links to that form in the root directory of my module (and added ‘sale’ to dependences & a file
Now, I have my Items in the Sales module and may connect items (many of them) to any order.