Skip to content

Commit 2bb3960

Browse files
committed
[FIX] stock_account: create journal item with correct total qty value
Steps to reproduce the bug: - Create a storable product “P1”: - Cost: $10 - UoM: Unit - Sales tab: - Packaging: Pack of 6 - Category: Goods - Costing Method: AVCO - Inventory Valuation: Perpetual (at invoicing) - Expense Account: 500000 Cost of Goods Sold - Stock Account: 110100 Stock Valuation - Create an invoice: - Customer: Azure Interior - Product: P1 - Quantity: 10 - UoM: Pack of 6 - Confirm Problem: The journal items created for Stock Valuation and Cost of Goods Sold are computed with an incorrect amount: $100 instead of $600. Explanation: In the `_stock_account_prepare_realtime_out_lines_vals` method, the unit price is first computed for a single unit, regardless of the costing method (AVCO, Standard, or FIFO), using the helper method `_get_cogs_value`: - https://github.com/odoo/odoo/blob/08b62a4bbcc6f9a391b2cc00a621ef4c76100229/addons/stock_account/models/account_move.py#L121 - https://github.com/odoo/odoo/blob/08b62a4bbcc6f9a391b2cc00a621ef4c76100229/addons/stock_account/models/account_move_line.py#L66-L67 In the FIFO case, the computation is based on the stock move value, but still returns the price per single unit: - https://github.com/odoo/odoo/blob/08b62a4bbcc6f9a391b2cc00a621ef4c76100229/addons/stock_account/models/account_move_line.py#L70-L71 opw-5215191 closes odoo#234976 X-original-commit: e8530d2 Signed-off-by: William Henrotin (whe) <whe@odoo.com> Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
1 parent 2d327a1 commit 2bb3960

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

addons/stock_account/models/account_move.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def _stock_account_prepare_realtime_out_lines_vals(self):
119119
# Compute accounting fields.
120120
sign = -1 if move.move_type == 'out_refund' else 1
121121
price_unit = line.with_context(anglo_saxon_price_ctx)._get_cogs_value()
122-
amount_currency = sign * line.quantity * price_unit
122+
amount_currency = sign * line.product_uom_id._compute_quantity(line.quantity, line.product_id.uom_id) * price_unit
123123

124124
if move.currency_id.is_zero(amount_currency) or float_is_zero(price_unit, precision_digits=price_unit_prec):
125125
continue

addons/stock_account/tests/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ def _create_account_move(self, move_type, product, quantity=1.0, price_unit=1.0,
2424
if kwargs.get('reversed_entry_id'):
2525
invoice_vals["reversed_entry_id"] = kwargs['reversed_entry_id']
2626
invoice = self.env["account.move"].create(invoice_vals)
27+
product_uom = kwargs.get('product_uom') or product.uom_id
2728
self.env["account.move.line"].create({
2829
"move_id": invoice.id,
2930
"display_type": "product",
3031
"name": "test line",
3132
"price_unit": price_unit,
3233
"quantity": quantity,
3334
"product_id": product.id,
34-
"product_uom_id": product.uom_id.id,
35+
"product_uom_id": product_uom.id,
3536
"tax_ids": [(5, 0, 0)],
3637
})
3738
if post:

addons/stock_account/tests/test_stockvaluation.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,3 +2846,20 @@ def test_journal_entry_created_with_given_accounting_date(self):
28462846
self._get_stock_valuation_move_lines().move_id.date,
28472847
past_accounting_date
28482848
)
2849+
2850+
def test_journal_entry_with_packaging_uom_cogs(self):
2851+
"""Test that journal entries for COGS and stock valuation are correctly computed
2852+
when selling a product using a different UoM (e.g., pack of 6).
2853+
The COGS amount should reflect the total quantity converted to the product's base UoM.
2854+
"""
2855+
invoice = self._create_invoice(self.product_avco_auto, quantity=10, price_unit=100, product_uom=self.env.ref('uom.product_uom_pack_6'))
2856+
self.assertEqual(self.product_avco_auto.standard_price, 10)
2857+
self.assertRecordValues(
2858+
invoice.journal_line_ids,
2859+
[
2860+
{'account_id': self.category_avco_auto.property_account_income_categ_id.id, 'credit': 1000.0, 'debit': 0.0},
2861+
{'account_id': self.account_receivable.id, 'credit': 0.0, 'debit': 1000.0},
2862+
{'account_id': self.account_stock_valuation.id, 'credit': 600.0, 'debit': 0.0},
2863+
{'account_id': self.account_expense.id, 'credit': 0.0, 'debit': 600.0},
2864+
]
2865+
)

0 commit comments

Comments
 (0)