Hi everyone,I’m trying to create a new backorder by code, where 43717 is my stock.picking id:
bo = env["stock.backorder.confirmation"].create({"pick_ids”:[(4,43717)]})
bo.process()
But I get this error:
'It is not possible to unreserve more products of PRODUCTNAME than you have in stock.'Do you have any idea how can achieve the creation of the backorder?
If I click the Validate button in the web interface and confirm the wizard, it works as expected.
I really appreciate your help and hints!
Hi everyone,I’m trying to create a new backorder by code, where 43717 is my stock.picking id:
bo = env["stock.backorder.confirmation"].create({"pick_ids”:[(4,43717)]})
bo.process()
But I get this error:
'It is not possible to unreserve more products of PRODUCTNAME than you have in stock.'
Do you have any idea how can achieve the creation of the backorder?
If I click the Validate button in the web interface and confirm the wizard, it works as expected.
I really appreciate your help and hints!
Update:
After reading this thread: https://www.odoo.com/de_DE/forum/hilfe-1/question/it-is-not-possible-to-unreserve-more-products-of-than-you-have-in-stock-138783
and applying this gist: https://gist.githubusercontent.com/amoyaux/20d50f3368ef2f552071f718dc65cad4/raw/8e3a0151e8f9ccb42e907dfbfcac08068019bd91/gistfile1.txt
I get this error:
InternalError: SAVEPOINT can only be used in transaction blocks
Here is the complete Traceback:
---------------------------------------------------------------------------
InternalError Traceback (most recent call last)
<ipython-input-3-28ad7838efd6> in <module>
----> 1 bo.process()
~/src/odoo/addons/stock/wizard/stock_backorder_confirmation.py in process(self)
29
30 def process(self):
---> 31 self._process()
32
33 def process_cancel_backorder(self):
<decorator-gen-322> in _process(self, cancel_backorder)
~/src/odoo/odoo/api.py in loop(method, self, *args, **kwargs)
380 """
381 def loop(method, self, *args, **kwargs):
--> 382 result = [method(rec, *args, **kwargs) for rec in self]
383 return aggregate(method, result, self)
384
~/src/odoo/odoo/api.py in <listcomp>(.0)
380 """
381 def loop(method, self, *args, **kwargs):
--> 382 result = [method(rec, *args, **kwargs) for rec in self]
383 return aggregate(method, result, self)
384
~/src/odoo/addons/stock/wizard/stock_backorder_confirmation.py in _process(self, cancel_backorder)
21 moves_to_log[move] = (move.quantity_done, move.product_uom_qty)
22 pick_id._log_less_quantities_than_expected(moves_to_log)
---> 23 self.pick_ids.action_done()
24 if cancel_backorder:
25 for pick_id in self.pick_ids:
~/src/user/user/dhl_paket_shipping_ept/models/stock_picking_ept.py in action_done(self)
25 def action_done(self):
26 '''added by Emipro Technologies Pvt Ltd'''
---> 27 res = super(BaseStockPicking, self).action_done()
28 for id in self:
29 if id.carrier_id and id.carrier_id.delivery_type not in ['dhl_de_ept'] and id.carrier_id.integration_level == 'rate_and_ship':
~/src/odoo/addons/stock/models/stock_picking.py in action_done(self)
629 todo_moves |= new_move
630 #'qty_done': ops.qty_done})
--> 631 todo_moves._action_done()
632 self.write({'date_done': fields.Datetime.now()})
633 return True
~/src/odoo/addons/purchase_stock/models/stock.py in _action_done(self)
94
95 def _action_done(self):
---> 96 res = super(StockMove, self)._action_done()
97 self.mapped('purchase_line_id').sudo()._update_received_qty()
98 return res
~/src/odoo/addons/stock_account/models/stock.py in _action_done(self)
398 def _action_done(self):
399 self.product_price_update_before_done()
--> 400 res = super(StockMove, self)._action_done()
401 for move in res:
402 # Apply restrictions on the stock move to be able to make
~/src/odoo/addons/stock/models/stock_move.py in _action_done(self)
1139 pass
1140 move._unreserve_initial_demand(new_move)
-> 1141 moves_todo.mapped('move_line_ids')._action_done()
1142 # Check the consistency of the result packages; there should be an unique location across
1143 # the contained quants.
~/src/odoo/addons/stock/models/stock_move_line.py in _action_done(self)
435 # move what's been actually done
436 quantity = ml.product_uom_id._compute_quantity(ml.qty_done, ml.move_id.product_id.uom_id, rounding_method='HALF-UP')
--> 437 available_qty, in_date = Quant._update_available_quantity(ml.product_id, ml.location_id, -quantity, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id)
438 if available_qty < 0 and ml.lot_id:
439 # see if we can compensate the negative quants with some untracked quants
~/src/odoo/addons/stock/models/stock_quant.py in _update_available_quantity(self, product_id, location_id, quantity, lot_id, package_id, owner_id, in_date)
213 for quant in quants:
214 try:
--> 215 with self._cr.savepoint():
216 self._cr.execute("SELECT 1 FROM stock_quant WHERE id = %s FOR UPDATE NOWAIT", [quant.id], log_exceptions=False)
217 quant.write({
/usr/lib/python3.6/contextlib.py in __enter__(self)
79 def __enter__(self):
80 try:
---> 81 return next(self.gen)
82 except StopIteration:
83 raise RuntimeError("generator didn't yield") from None
~/src/odoo/odoo/sql_db.py in savepoint(self)
406 """context manager entering in a new savepoint"""
407 name = uuid.uuid1().hex
--> 408 self.execute('SAVEPOINT "%s"' % name)
409 try:
410 yield
~/src/odoo/odoo/sql_db.py in wrapper(self, *args, **kwargs)
146 msg += ' It was closed at %s, line %s' % self.__closer
147 raise psycopg2.OperationalError(msg)
--> 148 return f(self, *args, **kwargs)
149 return wrapper
150
~/src/odoo/odoo/sql_db.py in execute(self, query, params, log_exceptions)
223 try:
224 params = params or None
--> 225 res = self._obj.execute(query, params)
226 except Exception as e:
227 if self._default_log_exceptions if log_exceptions is None else log_exceptions:
InternalError: SAVEPOINT can only be used in transaction blocks