[FIX] stock_account: correct revaluation statement at general ledger report

Steps to reproduce:
- Install Sales, Accounting and Inventory apps.
- Go to Inventory > Configuration > Products > Product Categories.
- Open All / Saleable / Office Furniture and:
	- Set the Inventory Valuation as Automated
	- Set the Costing Method as First In First Out (FIFO)
- Go to Inventory > Reporting > Inventory Valuation
- Open the toggle header then Click on the plus button at the header.
- In the popup shown -Notice how the current value is 0-, set:
	- Added Value to 1000
	- Counterpart Account to 600000 Expenses
- Click on REVALUE, a new report appears.
- Open the newly created report > Other Info, open the Journal Entry
- In the Journal Items tab, notice the label says that `the valuation was changed from 1000 to 2000` while it should be `the valuation was changed from 0 to 2000`.

Investigation:
- the `current_value_svl` field is related to `product_id.value_svl` https://github.com/odoo/odoo/blob/7152fa4fb4a8b66ae72bbdc8177f2a787161f594/addons/stock_account/wizard/stock_valuation_layer_revaluation.py#L34
- Which get computend using `_compute_value_svl()` depending on `stock_valuation_layer_ids`
- When we revaluate, we trigger `action_validate_revaluation` that performs this line https://github.com/odoo/odoo/blob/7152fa4fb4a8b66ae72bbdc8177f2a787161f594/addons/stock_account/wizard/stock_valuation_layer_revaluation.py#L110 creating new stock.valuation.layer triggering the `_compute_value_svl()` method setting the product `value_svl` to the updated value (current + added) which then updates `current_value_svl` being a related field
- That's why now `current_value_svl` is the new value and not the old one.

opw-3715522

closes odoo/odoo#157450

X-original-commit: 065b6632b133d780543c9f40beb536c2ff37ff52
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Ali Hassan Youssef (alhy) <alhy@odoo.com>
This commit is contained in:
AH-Yussef
2024-03-13 04:07:29 +00:00
parent e330f345ff
commit 2f847c4629
2 changed files with 24 additions and 4 deletions
@@ -4048,3 +4048,22 @@ class TestStockValuation(TestStockValuationBase):
with self.assertRaises(UserError):
revaluation.action_validate_revaluation()
def test_manual_revaluation_statement(self):
self.product1.categ_id.property_cost_method = 'fifo'
self.product1.categ_id.property_valuation = 'real_time'
self._make_in_move(self.product1, 1, unit_cost=15)
revaluation_form = Form(self.env['stock.valuation.layer.revaluation'].with_context({
'default_product_id': self.product1.id,
'default_company_id': self.env.company.id,
}))
revaluation_form.added_value = 10.0
revaluation_form.account_id = self.stock_valuation_account
revaluation = revaluation_form.save()
revaluation.action_validate_revaluation()
account_move = self.env['account.move'].search([('journal_id', '=', revaluation.account_journal_id.id)])
self.assertEqual(account_move.line_ids[0].name, 'OdooBot changed stock valuation from 15.0 to 25.0 - [prda] Product A')
@@ -107,6 +107,7 @@ class StockValuationLayerRevaluation(models.TransientModel):
remaining_value -= taken_remaining_value
remaining_qty -= svl.remaining_qty
previous_value_svl = self.current_value_svl
revaluation_svl = self.env['stock.valuation.layer'].create(revaluation_svl_vals)
# Update the stardard price in case of AVCO/FIFO
@@ -136,8 +137,8 @@ class StockValuationLayerRevaluation(models.TransientModel):
'line_ids': [(0, 0, {
'name': _('%(user)s changed stock valuation from %(previous)s to %(new_value)s - %(product)s',
user=self.env.user.name,
previous=self.current_value_svl,
new_value=self.current_value_svl + self.added_value,
previous=previous_value_svl,
new_value=previous_value_svl + self.added_value,
product=product_id.display_name,
),
'account_id': debit_account_id,
@@ -147,8 +148,8 @@ class StockValuationLayerRevaluation(models.TransientModel):
}), (0, 0, {
'name': _('%(user)s changed stock valuation from %(previous)s to %(new_value)s - %(product)s',
user=self.env.user.name,
previous=self.current_value_svl,
new_value=self.current_value_svl + self.added_value,
previous=previous_value_svl,
new_value=previous_value_svl + self.added_value,
product=product_id.display_name,
),
'account_id': credit_account_id,