[FIX] point_of_sale: random runbot error (20517)
When performing the picking action in the context of savepoint, the env inside the action can randomly change causing an AccessError which is caught as UserError (in the current point_of_sale code). Flushing before calling a method in a savepoint will deterministically avoid this issue. Note that the weakset used to store environments was modified in #121604 to avoid this kind of issue. When using a cr.savepoint, the transaction must be flushed but in we don't have any reference to the env that should be used on the cursor, meaning that the env is chosen in the list of existing env. This choice is random because Transaction.envs is using a Weakset. In some case, the chosen env does not have the correct access right because the context allowed_company_ids is corresponding to a company coming from another test, leading to an access error, hidden by the try except. Flushing the environment before creating the savepoint will help to prevent this issue by flushing on a well defined environment. Note that the weakset used to store environments was modified in #121604 (master) closes odoo/odoo#123048 X-original-commit: c7c268ed50c1f6fd6eebe7d8a01abdb9d4a32573 Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
This commit is contained in:
committed by
Xavier-Do
parent
2714a25621
commit
787223c4e7
@@ -44,6 +44,7 @@ class StockPicking(models.Model):
|
||||
)
|
||||
|
||||
positive_picking._create_move_from_pos_order_lines(positive_lines)
|
||||
self.env.flush_all()
|
||||
try:
|
||||
with self.env.cr.savepoint():
|
||||
positive_picking._action_done()
|
||||
@@ -63,6 +64,7 @@ class StockPicking(models.Model):
|
||||
self._prepare_picking_vals(partner, return_picking_type, location_dest_id, return_location_id)
|
||||
)
|
||||
negative_picking._create_move_from_pos_order_lines(negative_lines)
|
||||
self.env.flush_all()
|
||||
try:
|
||||
with self.env.cr.savepoint():
|
||||
negative_picking._action_done()
|
||||
|
||||
Reference in New Issue
Block a user