mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[9.0][IMP] stock_cycle_count: fix accuracy computation and store it
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
"name": "Stock Cycle Count",
|
||||
"summary": "Adds the capability to schedule cycle counts in a "
|
||||
"warehouse through different rules defined by the user",
|
||||
"version": "9.0.1.1.0",
|
||||
"version": "9.0.1.2.0",
|
||||
"author": "Eficent, "
|
||||
"Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||
|
||||
@@ -12,23 +12,27 @@ PERCENT = 100.0
|
||||
class StockInventory(models.Model):
|
||||
_inherit = 'stock.inventory'
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
@api.depends("state", "line_ids")
|
||||
def _compute_inventory_accuracy(self):
|
||||
total_qty = sum(self.line_ids.mapped('theoretical_qty'))
|
||||
abs_discrepancy = sum(self.line_ids.mapped(
|
||||
lambda x: abs(x.discrepancy_qty)))
|
||||
if total_qty:
|
||||
self.inventory_accuracy = PERCENT * (
|
||||
total_qty - abs_discrepancy) / total_qty
|
||||
if not self.line_ids and self.state == 'done':
|
||||
self.inventory_accuracy = 100.0
|
||||
for inv in self:
|
||||
theoretical = sum(inv.line_ids.mapped(
|
||||
lambda x: abs(x.theoretical_qty)))
|
||||
abs_discrepancy = sum(inv.line_ids.mapped(
|
||||
lambda x: abs(x.discrepancy_qty)))
|
||||
if theoretical:
|
||||
inv.inventory_accuracy = max(
|
||||
PERCENT * (theoretical - abs_discrepancy) / theoretical,
|
||||
0.0)
|
||||
if not inv.line_ids and inv.state == 'done':
|
||||
inv.inventory_accuracy = PERCENT
|
||||
|
||||
cycle_count_id = fields.Many2one(
|
||||
comodel_name='stock.cycle.count', string='Stock Cycle Count',
|
||||
ondelete='cascade', readonly=True)
|
||||
inventory_accuracy = fields.Float(string='Accuracy',
|
||||
compute=_compute_inventory_accuracy,
|
||||
digits=(3, 2))
|
||||
inventory_accuracy = fields.Float(
|
||||
string='Accuracy', compute=_compute_inventory_accuracy,
|
||||
digits=(3, 2), store=True)
|
||||
|
||||
@api.multi
|
||||
def action_done(self):
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
|
||||
<record model="ir.actions.act_window" id="act_accuracy_stats">
|
||||
<field name="domain">[('location_id', '=', active_ids),
|
||||
('exclude_sublocation', '=', True),
|
||||
('state', '=', 'done')]</field>
|
||||
<field name="name">Accuracy Stats</field>
|
||||
<field name="res_model">stock.inventory</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_mode">tree,form,pivot</field>
|
||||
</record>
|
||||
|
||||
<record id="view_location_form" model="ir.ui.view">
|
||||
|
||||
Reference in New Issue
Block a user