[FIX] point_of_sale: fallback to standard price

When creating the POS journal entry for a POS session (or one of its
orders when realtime inventory management is enabled), it's possible for
the stock picking to fail if a product requires a serial number or lot
id and none was provided. After the POS session is closed, this stock
picking can be corrected and the accompanying inventory valuation
entries will be created. However, when using anglo-saxon accounting, the
amount on the COGS line in the POS journal entry will be 0. That's
because the current implementation sums up the values from the stock
valuation layers to determine this amount. If the stock picking failed,
there will be no stock valuation layers so the result is 0.

In other workflows in Odoo like creating an invoice from a sales order
before the delivery is validated, the implementation deals with this
case by falling back to the standard price if no stock valuation layers
are available. This fix does the same for the POS journal entries.

opw-2988701

closes odoo/odoo#108966

X-original-commit: 4aeed49d86b0dfb8e2d1555384458eb6e3358d67
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Merel Geens <mege@odoo.com>
This commit is contained in:
Merel Geens (mege)
2023-01-03 07:58:52 +01:00
parent 7bb0f1f80f
commit f9a5020094
+2 -2
View File
@@ -757,7 +757,7 @@ class PosSession(models.Model):
for move in stock_moves:
exp_key = move.product_id._get_product_accounts()['expense']
out_key = move.product_id.categ_id.property_stock_account_output_categ_id
amount = -sum(move.sudo().stock_valuation_layer_ids.mapped('value'))
amount = move.product_qty * move.product_id._compute_average_price(0, move.product_qty, move)
stock_expense[exp_key] = self._update_amounts(stock_expense[exp_key], {'amount': amount}, move.picking_id.date, force_company_currency=True)
if move.location_id.usage == 'customer':
stock_return[out_key] = self._update_amounts(stock_return[out_key], {'amount': amount}, move.picking_id.date, force_company_currency=True)
@@ -783,7 +783,7 @@ class PosSession(models.Model):
for move in stock_moves:
exp_key = move.product_id._get_product_accounts()['expense']
out_key = move.product_id.categ_id.property_stock_account_output_categ_id
amount = -sum(move.stock_valuation_layer_ids.mapped('value'))
amount = move.product_qty * move.product_id._compute_average_price(0, move.product_qty, move)
stock_expense[exp_key] = self._update_amounts(stock_expense[exp_key], {'amount': amount}, move.picking_id.date, force_company_currency=True)
if move.location_id.usage == 'customer':
stock_return[out_key] = self._update_amounts(stock_return[out_key], {'amount': amount}, move.picking_id.date, force_company_currency=True)