This is the problem, which happens to everyone who needs to use active_id
: https://github.com/odoo/odoo/issues/39070
In summary, in a customized stock.production.lot
view, I have this:
<field name="outgoing_moves" context="{'default_lot_id': active_id}"/>
Where outgoing_moves
is a One2many field. I only want to fill in automatically the field lot_id
with the current opened lot each time the user adds a new outgoing move.
The problem is that if I open this lot view from other model view (through a shortcut button for example), the active_id
is not updated, and brings me the ID of the previous model.
Example, I open the lot 61 after clicking on a button in the customer 133. When I try to add a new outgoing move in the One2many field, I get the error "The lot with ID 133 does not exist". This is an Odoo bug of the 13.0 version, currently not fixed yet.
The solution they propose in the GitHub thread is to use active_ids[0]
instead of active_id
:
Notice that is does use active_ids[0], which works even in the example you provided.
<field name="outgoing_moves" context="{'default_lot_id': active_ids[0]}"/>
Well, everyone seems to be happy with that solution, but it is not working in my case. I am pretty sure that my code is right updated and that I am using active_ids[0]
, but I always get the wrong ID.
Another solution I've read is to use the realiable ID, which means, the ID of the record (lot in my case) itself. I've tried and worked, but sometimes, after restarting Odoo, I get a JavaScript error each time I click on whatever in Odoo. And the error disappears when I remove the context of outgoing_moves
:
<field name="id" invisible="1"/>
<field name="outgoing_moves" context="{'default_lot_id': id}"/>
Does anyone experienced this problem and found a workaround?