How to retrieve lines from other model?

Hi Community
For example, after create a document with a number, put that number and retrieve lines added to that document from other model…

Thanks

You should get the module from the tryton pool and perform a search operation to retrieve the records from other model. For example:

from trytond.pool import Pool
...
pool = Pool()
Line = pool.get('sale.line')
lines = Line.search([])

lines will contain a list of all the existing lines.

You should use a domain to restrict the lines using a criteria.

On the other hand, if you need to create a new module, you can just use the active record pattern:

...
Sale = pool.get('sale.sale')
sale = Sale()
sale.number = '1'
sale.lines = lines
sale.save()

But if you need to create a lots of record, it’s more performant to create them in a bunch:


Sale = pool.get('sale.sale')
to_save = []
for i in range(1000):
    sale = Sale()
    sale.number = str(i)
    to_save.append(sale)
Sale.save(to_save)

Hope it helps!

Thanks for information @pokoli my idea is have a field in new module to put number and retrieve lines from other module . I will test this