diff --git a/stock_cycle_count/__manifest__.py b/stock_cycle_count/__manifest__.py index 456d3646699a..537370f7c629 100644 --- a/stock_cycle_count/__manifest__.py +++ b/stock_cycle_count/__manifest__.py @@ -17,6 +17,7 @@ "views/stock_warehouse_view.xml", "views/stock_inventory_view.xml", "views/stock_location_view.xml", + "views/stock_move_line_view.xml", "views/res_config_settings_view.xml", "data/cycle_count_sequence.xml", "data/cycle_count_ir_cron.xml", diff --git a/stock_cycle_count/models/__init__.py b/stock_cycle_count/models/__init__.py index e1320941dc81..9a1035894393 100644 --- a/stock_cycle_count/models/__init__.py +++ b/stock_cycle_count/models/__init__.py @@ -6,3 +6,5 @@ from . import stock_inventory from . import stock_warehouse from . import stock_move +from . import stock_move_line +from . import stock_quant diff --git a/stock_cycle_count/models/stock_move_line.py b/stock_cycle_count/models/stock_move_line.py new file mode 100644 index 000000000000..a5a6ed5d91a4 --- /dev/null +++ b/stock_cycle_count/models/stock_move_line.py @@ -0,0 +1,15 @@ +# Copyright 2024 ForgeFlow S.L. +# (http://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class StockMoveLine(models.Model): + _inherit = "stock.move.line" + + line_accuracy = fields.Float( + string="Accuracy", + store=True, + ) + theoretical_qty = fields.Float(string="Theoretical", store=True) + counted_qty = fields.Float(string="Counted", store=True) diff --git a/stock_cycle_count/models/stock_quant.py b/stock_cycle_count/models/stock_quant.py new file mode 100644 index 000000000000..5263cdc70d9f --- /dev/null +++ b/stock_cycle_count/models/stock_quant.py @@ -0,0 +1,44 @@ +# Copyright 2024 ForgeFlow S.L. +# (http://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) +from odoo import models + + +class StockQuant(models.Model): + _inherit = "stock.quant" + + def _apply_inventory(self): + accuracy_dict = {} + theoretical_dict = {} + counted_dict = {} + for rec in self: + line_accuracy = 100 - rec.discrepancy_percent + accuracy_dict[rec.id] = line_accuracy + theoretical_dict[rec.id] = rec.quantity + counted_dict[rec.id] = rec.inventory_quantity + res = super()._apply_inventory() + for rec in self: + record_moves = self.env["stock.move.line"] + moves = record_moves.search( + [ + ("product_id", "=", rec.product_id.id), + ("lot_id", "=", rec.lot_id.id), + "|", + ("location_id", "=", rec.location_id.id), + ("location_dest_id", "=", rec.location_id.id), + ], + order="create_date asc", + ).filtered( + lambda x: not x.company_id.id + or not rec.company_id.id + or rec.company_id.id == x.company_id.id + ) + move = moves[len(moves) - 1] + move.write( + { + "line_accuracy": accuracy_dict[rec.id], + "theoretical_qty": theoretical_dict[rec.id], + "counted_qty": counted_dict[rec.id], + } + ) + return res diff --git a/stock_cycle_count/views/stock_move_line_view.xml b/stock_cycle_count/views/stock_move_line_view.xml new file mode 100644 index 000000000000..70424bc05f27 --- /dev/null +++ b/stock_cycle_count/views/stock_move_line_view.xml @@ -0,0 +1,26 @@ + + + + + Stock Move Line Tree - cycle count extension + stock.move.line + + + + + + + + + +