Skip to Content
Menu
This question has been flagged
2443 Views

Hi everyone!

I'm trying to achieve a feature and i have some problems.. I created two transient models, lets call them 'transient_model' and 'transient_model_line'.

A transient_model_line has a many2many field called "invoice_ids", amongst other fields.

On the Invoice tree form, i created an action. It group the invoices by partner_id, and for each partner, creates a transient_model_line. This is how i populate the lines:


@api.model

def default_get(self, fields):

rec = super(transient_model, self).default_get(fields)

line_obj = self.env['transient_model_line']

active_ids = self._context.get('active_ids', [])

active_invoices = self.env['account.invoice'].browse(active_ids)

line_ids = []

invoice_partners = active_invoices.mapped('partner_id')

for partner in invoice_partners:

    partner_invoices = active_invoices.filtered( lambda invoice: invoice.partner_id == partner)

    line = line_obj.create({ 'invoice_ids': [(6, 0, partner_invoices.ids)], })

    line_ids.append(line.id)

    rec['transient_model_line_ids'] = [(6, 0, line_ids)]

return rec


Using this code, my transient is well filled with the invoices, grouped by partner. Everything seems to be fine when the transient model is displayed..

But i when i click on a button displayed in the form, that should do something on the invoices, my field 'transient_model_line_ids' seems to be empty. The previously created lines are not linked anymore to my transient model..


Does anyone have any idea how i can retrieve the displayed lines when i click on that button?.

Thank you!

Avatar
Discard