How to insert data from my module to sales order?

Sorry, I don’t understand the ideology of the system.
I developed a module with a table that holds some items that are owned by my clients.
My company sells services. These services are related to items (so, actually items — are serviceable items own by clients.)
Hence, the invoice should look like:

  1. item A1 - service B $10
  2. item A2 - service B $10
  3. item A3 - service C $10
    To pay: $30

Actually, Items connected to parties (clients) — so I know which party has which item.

To what class (in what module) I should connect One2Many/Many2One fields in my ‘items’ module to be able to add such strings to invoices??


Why not use the origin field to store this information when the invoice is created.

Cannot find where to add. I tried this but failed:
class Sale(metaclass=PoolMeta):
    __name__ = ''

    def _get_origin(cls):
        return super(Sale, cls)._get_origin() + ['my_module.item']

I added sale to tryton.cfg

Hope, I understand you right: is that correct, you recommended to put it in the following field:
-> Sale -> Other Info -> Origin:

Origin at Jul 28 20-24-46

Supposedly, I need to add to

sales = fields.One2Many('', 'origin', 'Sales')


I would have added to sale line origin as you seem to want to invoice multiple items at once.

  1. If that should be a Many2Many field? I think so because some items could be added to various invoices while the invoice could present several items in it. Am I correct?
    How it would look like?

My guess:

class item(ModelSQL, ModelView):
    __name__ = 'my_module.item'
    item_name = fields.Char(... 
    sales = fields.Many2Many(
        '', 'item_name', 'origin',
        help="The categories that the product is in.\n"
        "Used to group similar products together.")

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

def register():

that is why I didn’t find my module in the list of origins at the beginning. Just a note for future explorers :slight_smile:
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' my field
class Sale(metaclass=PoolMeta):
    __name__ = ''
   items = fields.Many2Many(
        relation_name = '',
        origin = 'sale', # because it is the Sale class
        target = 'item',
        string='Related sales')
#———— Connection class, 
#               builds a symmetrical behaviuor, mirroring One2Many
#               in both directions
class ItemServiceSales(ModelSQL):
    'Items - Sales relation'
    __name__ = ''
    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 sale.xml in tryton.cfg)
Now, I have my Items in the Sales module and may connect items (many of them) to any order.