Skip to content

Commit

Permalink
[ADD] stock_cycle_count: line_accuracy in stock move lines
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanSForgeFlow authored and ArnauCForgeFlow committed May 2, 2024
1 parent 3b235bd commit ff64074
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
1 change: 1 addition & 0 deletions stock_cycle_count/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions stock_cycle_count/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions stock_cycle_count/models/stock_move_line.py
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)
47 changes: 47 additions & 0 deletions stock_cycle_count/models/stock_quant.py
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
58 changes: 58 additions & 0 deletions stock_cycle_count/views/stock_move_line_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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>

0 comments on commit ff64074

Please sign in to comment.