This question has been flagged
3 Replies
10304 Views

My example python code without success:

vals = {...}
record = self.env['my.model'].new(vals)
...
form_rec = self.env.ref('my_model.view_my_model_form')

return {
'view_id': [form_rec.id],
'res_model': 'my.model',
'res_id': record.id,
'type': 'ir.actions.act_window',
'view_mode': 'form',
'target': 'new',
'context': self.env.context,
}

Error:
psycopg2.DataError: Error:  invalid input syntax for integer: "<NewId 0x7f01f0948cc0>"
LINE 1: ...my_model" WHERE "my_model".id IN ('<NewId 0x...

Avatar
Discard
Best Answer

Check that

https://www.odoo.com/es_ES/forum/ayuda-1/obtain-the-id-of-a-self-onchange-odoo-101202

Avatar
Discard
Best Answer

Is there a reason you are using new rather than create? New only puts it in memory so doesn't give it an id until the end, while create will put it in the database and give it an id straight away.

Avatar
Discard
Author

I am building a structurally complicated record and cannot save it before it is approved.

Could you add an active flag and default it to false. This will allow you to save the record on the first step without it showing up in other views. Then only make it active once it's finished?

Author

Thx, it's always an idea :). However, I am surprised that I can move individual fields in context and I can't somehow pass the entire record

Best Answer

you could not pass virtual(NewId) record as res_id because a client could not read this virtual record.

 
why don't you pass default context instead of creating a new record?  you will get the same functionality by defualt context (if wizard create new record each time bother you then you can take transient/abstract model)
https://github.com/odoo/odoo/blob/12.0/addons/account/models/account_invoice.py#L662
 

Avatar
Discard
Author

I am building a structurally complicated record and cannot save it before it is approved. Generating a context of each field seems to me not very effective. I would like to transfer it entirely to form as a complete NewId record.

ok, same functionality implemented for as one2many field it handles virtual record at server-side so you can take reference from there

so I basic idea is

1) instead of return <NewID..> convert it to a unique string (client don't care about record id it can be a string)

2) when dialog open it makes a read request with this unique virtual id

3) override read and intercept this virtual id and instead of hitting ORM return read result from a new record (I am not sure how we get a new record in read method but I am sure it's feasible :))

4) on the wizard dialog button click client will try to save this record (here you need to form view to stop sending virtual id)

please post here you need any help on client-side changes. It would be fun :)

Author

Hmm... , interesting concept, I have to think about it