From f9a5020094cc8091e75d4996493ecb93d71ebf3f Mon Sep 17 00:00:00 2001 From: "Merel Geens (mege)" Date: Tue, 27 Dec 2022 16:25:57 +0000 Subject: [PATCH] [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) Signed-off-by: Merel Geens --- addons/point_of_sale/models/pos_session.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index 4e6580e3b74..0bebe549f71 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -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)