-
-
Notifications
You must be signed in to change notification settings - Fork 723
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] stock_cycle_count: line_accuracy in stock move lines
- Loading branch information
1 parent
3b235bd
commit 09edb8a
Showing
5 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 Quantity", store=True) | ||
counted_qty = fields.Float(string="Counted Quantity", store=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# 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: | ||
if rec.discrepancy_percent > 100: | ||
line_accuracy = 0 | ||
else: | ||
line_accuracy = 1 - (rec.discrepancy_percent / 100) | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2017 ForgeFlow S.L. | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<record id="view_stock_move_line_tree" model="ir.ui.view"> | ||
<field name="name">Stock Move Line Tree - cycle count extension</field> | ||
<field name="model">stock.move.line</field> | ||
<field | ||
name="inherit_id" | ||
ref="stock_inventory.view_stock_move_line_inventory_tree" | ||
/> | ||
<field name="arch" type="xml"> | ||
<field name="product_id" position="after"> | ||
<field name="is_inventory" invisible="1" /> | ||
<field | ||
name="theoretical_qty" | ||
attrs="{'invisible': [('is_inventory', '=', False)]}" | ||
/> | ||
<field | ||
name="counted_qty" | ||
attrs="{'invisible': [('is_inventory', '=', False)]}" | ||
/> | ||
<field | ||
name="line_accuracy" | ||
attrs="{'invisible': [('is_inventory', '=', False)]}" | ||
widget="percentage" | ||
/> | ||
</field> | ||
</field> | ||
</record> | ||
<record id="view_stock_move_line_form" model="ir.ui.view"> | ||
<field name="name">Stock Move Line Form - cycle count extension</field> | ||
<field name="model">stock.move.line</field> | ||
<field name="inherit_id" ref="stock.view_move_line_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="lot_id" position="after"> | ||
<field name="is_inventory" invisible="1" /> | ||
<field | ||
name="theoretical_qty" | ||
attrs="{'invisible': [('is_inventory', '=', False)]}" | ||
/> | ||
<field | ||
name="counted_qty" | ||
attrs="{'invisible': [('is_inventory', '=', False)]}" | ||
/> | ||
<field | ||
name="line_accuracy" | ||
attrs="{'invisible': [('is_inventory', '=', False)]}" | ||
class="oe_inline" | ||
widget="percentage" | ||
/> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |