mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[ADD] stock_cycle_count: line_accuracy in stock move lines
This commit is contained in:
committed by
ArnauCForgeFlow
parent
5c67fbb7c8
commit
7a06f33f0b
@@ -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",
|
||||
|
||||
@@ -6,3 +6,5 @@ from . import stock_location
|
||||
from . import stock_inventory
|
||||
from . import stock_warehouse
|
||||
from . import stock_move
|
||||
from . import stock_move_line
|
||||
from . import stock_quant
|
||||
|
||||
15
stock_cycle_count/models/stock_move_line.py
Normal file
15
stock_cycle_count/models/stock_move_line.py
Normal file
@@ -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
stock_cycle_count/models/stock_quant.py
Normal file
47
stock_cycle_count/models/stock_quant.py
Normal file
@@ -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
|
||||
55
stock_cycle_count/views/stock_move_line_view.xml
Normal file
55
stock_cycle_count/views/stock_move_line_view.xml
Normal file
@@ -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>
|
||||
Reference in New Issue
Block a user