Skip to content

[5217][ADD] stock_revaluation_fifo_lot #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stock_revaluation_fifo_lot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions stock_revaluation_fifo_lot/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2025 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock Revaluation FIFO Lot",
"version": "16.0.1.0.0",
"author": "Quartile",
"website": "https://www.quartile.co",
"category": "Warehouse",
"license": "AGPL-3",
"depends": ["stock_account"],
"data": [
"security/ir.model.access.csv",
],
"installable": True,
}
2 changes: 2 additions & 0 deletions stock_revaluation_fifo_lot/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import stock_product_revaluation
from . import stock_product_revaluation_line
46 changes: 46 additions & 0 deletions stock_revaluation_fifo_lot/models/stock_product_revaluation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2025 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo.exceptions import UserError


class StockProductRevaluation(models.Model):
_name = 'stock.product.revaluation'
_description = 'Stock Product Revaluation'
_order = 'date desc'

name = fields.Char(string='Reference', required=True, copy=False, readonly=True,
default=lambda self: self.env['ir.sequence'].next_by_code('stock.product.revaluation'))
date = fields.Date(string='Date', required=True, default=fields.Date.context_today)
journal_id = fields.Many2one('account.journal', string='Journal', required=True)
company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company)
line_ids = fields.One2many('stock.product.revaluation.line', 'revaluation_id', string='Revaluation Lines')
valuation_adjustment_ids = fields.One2many('stock.revaluation.adjustment.line', 'revaluation_id', string='Valuation Adjustments')
state = fields.Selection([
('draft', 'Draft'),
('posted', 'Posted'),
('cancelled', 'Cancelled')
], default='draft', tracking=True)

def action_post(self):
for record in self:
if not record.line_ids:
raise UserError("Please add at least one revaluation line.")

# Example placeholder for valuation calculation logic
for line in record.line_ids:
# Simulate retrieving old valuation and calculating new one
original_value = 100 # Placeholder
new_value = original_value + line.amount

self.env['stock.product.revaluation.valuation'].create({
'revaluation_id': record.id,
'product_id': line.product_id.id,
'lot_id': line.lot_id.id,
'original_value': original_value,
'new_value': new_value,
'difference': new_value - original_value,
})

record.state = 'posted'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2025 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class StockProductRevaluationLine(models.Model):
_name = 'stock.product.revaluation.line'
_description = 'Stock Product Revaluation Line'

revaluation_id = fields.Many2one('stock.product.revaluation', required=True, ondelete='cascade')
product_id = fields.Many2one('product.product', string='Product', required=True)
lot_id = fields.Many2one('stock.production.lot', string='Lot/Serial Number')
account_id = fields.Many2one('account.account', string='Account')
amount = fields.Float(string='Cost Adjustment')
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2025 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo.exceptions import UserError


class StockRevaluationAdjustmentLine(models.Model):
_name = 'stock.product.revaluation.valuation'
_description = 'Stock Product Revaluation Valuation'

revaluation_id = fields.Many2one('stock.product.revaluation', required=True, ondelete='cascade')
product_id = fields.Many2one('product.product', string='Product')
lot_id = fields.Many2one('stock.production.lot', string='Lot/Serial Number')
original_value = fields.Float(string='Original Value')
new_value = fields.Float(string='New Value')
difference = fields.Float(string='Difference', compute='_compute_difference', store=True)

@api.depends('original_value', 'new_value')
def _compute_difference(self):
for rec in self:
rec.difference = rec.new_value - rec.original_value
4 changes: 4 additions & 0 deletions stock_revaluation_fifo_lot/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_stock_product_revaluation,stock.product.revaluation,model_stock_product_revaluationstock.group_stock_user,1,1,1,1
access_stock_product_revaluation_line,stock.product.revaluation.line,model_stock_product_revaluation_linestock.group_stock_user,1,1,1,1
access_stock_product_revaluation_valuation,stock.product.revaluation.valuation,model_stock_product_revaluation_valuationstock.group_stock_user,1,1,1,1
Loading