Skip to content

Commit

Permalink
[10.0] cycle_count: fix acurracy computation
Browse files Browse the repository at this point in the history
  • Loading branch information
LoisRForgeFlow committed Aug 24, 2017
1 parent 71b84c2 commit d055950
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions stock_cycle_count/models/stock_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
class StockInventory(models.Model):
_inherit = 'stock.inventory'

@api.one
@api.multi
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 = 100.0

cycle_count_id = fields.Many2one(
comodel_name='stock.cycle.count', string='Stock Cycle Count',
Expand Down

0 comments on commit d055950

Please sign in to comment.