fix revaluation bug
This commit is contained in:
parent
e296df45d9
commit
479513d880
BIN
__pycache__/__init__.cpython-312.pyc
Executable file → Normal file
BIN
__pycache__/__init__.cpython-312.pyc
Executable file → Normal file
Binary file not shown.
BIN
models/__pycache__/__init__.cpython-312.pyc
Executable file → Normal file
BIN
models/__pycache__/__init__.cpython-312.pyc
Executable file → Normal file
Binary file not shown.
BIN
models/__pycache__/stock_inventory_revaluation.cpython-312.pyc
Executable file → Normal file
BIN
models/__pycache__/stock_inventory_revaluation.cpython-312.pyc
Executable file → Normal file
Binary file not shown.
@ -119,6 +119,41 @@ class StockInventoryRevaluation(models.Model):
|
|||||||
# Create Stock Valuation Layer
|
# Create Stock Valuation Layer
|
||||||
self._create_valuation_layer(move)
|
self._create_valuation_layer(move)
|
||||||
|
|
||||||
|
# AVCO/FIFO Logic: Update Standard Price and Distribute Value to Layers
|
||||||
|
# This fixes the issue where revaluation creates a layer but doesn't update the moving average cost
|
||||||
|
if self.product_id.categ_id.property_cost_method in ['average', 'fifo'] and self.quantity > 0:
|
||||||
|
# 1. Update Standard Price
|
||||||
|
# We use disable_auto_svl to prevent Odoo from creating an extra SVL for this price change
|
||||||
|
new_std_price = self.product_id.standard_price + (self.extra_cost / self.quantity)
|
||||||
|
self.product_id.with_context(disable_auto_svl=True).sudo().write({'standard_price': new_std_price})
|
||||||
|
|
||||||
|
# 2. Distribute Value to Remaining Layers (Crucial for correct COGS later)
|
||||||
|
remaining_svls = self.env['stock.valuation.layer'].search([
|
||||||
|
('product_id', '=', self.product_id.id),
|
||||||
|
('remaining_qty', '>', 0),
|
||||||
|
('company_id', '=', self.company_id.id),
|
||||||
|
])
|
||||||
|
|
||||||
|
if remaining_svls:
|
||||||
|
remaining_qty_total = sum(remaining_svls.mapped('remaining_qty'))
|
||||||
|
if remaining_qty_total > 0:
|
||||||
|
remaining_value_to_distribute = self.extra_cost
|
||||||
|
remaining_value_unit_cost = remaining_value_to_distribute / remaining_qty_total
|
||||||
|
|
||||||
|
for layer in remaining_svls:
|
||||||
|
if float_compare(layer.remaining_qty, remaining_qty_total, precision_rounding=self.product_id.uom_id.rounding) >= 0:
|
||||||
|
taken_remaining_value = remaining_value_to_distribute
|
||||||
|
else:
|
||||||
|
taken_remaining_value = remaining_value_unit_cost * layer.remaining_qty
|
||||||
|
|
||||||
|
# Rounding
|
||||||
|
taken_remaining_value = self.currency_id.round(taken_remaining_value)
|
||||||
|
|
||||||
|
layer.sudo().write({'remaining_value': layer.remaining_value + taken_remaining_value})
|
||||||
|
|
||||||
|
remaining_value_to_distribute -= taken_remaining_value
|
||||||
|
remaining_qty_total -= layer.remaining_qty
|
||||||
|
|
||||||
self.state = 'done'
|
self.state = 'done'
|
||||||
|
|
||||||
def _prepare_account_move_vals(self):
|
def _prepare_account_move_vals(self):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user