From f5e80764cfea13c9a101585f449e776015844308 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Luis=20Zanotti?= <joseluiszanotti@gmail.com>
Date: Tue, 13 Jun 2023 09:39:50 -0300
Subject: [PATCH] [IMP] Change way to calculate old embargos

---
 models/embargo.py | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/models/embargo.py b/models/embargo.py
index 3bbb57c..b8f7573 100644
--- a/models/embargo.py
+++ b/models/embargo.py
@@ -52,11 +52,6 @@ class Impund(models.Model):
     bank = fields.Many2one('res.bank', string='Bank')  # a completar con res.bank
     branch_office_number = fields.Char(string='Branch Office Number')
     branch_office_destiny = fields.Char(string='Branch Office Destiny')
-    # state = fields.Selection(string='Impound State',
-    #                          selection=[('espera 1', 'Opcion 1'),
-    #                                     ('en curso ', 'Opcion 1'),
-    #                                     ('finalizado ', 'Opcion 2')]
-    #                          )
     account_number = fields.Char(string='Account Number')
     cbu = fields.Char(string='CBU', size=22)
     state = fields.Selection([
@@ -66,17 +61,17 @@ class Impund(models.Model):
         ('cancel', 'Cancel')
         ], default='draft')
     impound_novelties_ids = fields.One2many('impound.balance.lines', 'impounds_id', string='Impound Novelties')
-    unprocessed_impounds_qty = fields.Integer(string='Unprocessed Impounds',compute='_compute_unprocessed_impounds_qty', store=False)
-    extension_impound_id  = fields.Many2one('impound.impound', string='Extension Impound')
+    unprocessed_impounds_qty = fields.Integer(string='Unprocessed Impounds', compute='_compute_unprocessed_impounds_qty', store=False)
+    extension_impound_id = fields.Many2one('impound.impound', string='Extension Impound')
 
     def _compute_unprocessed_impounds_qty(self):
         for impound in self:
-            unfinished_impounds = self.env['impound.impound'].search_count([
-                ('employee', '=', impound.employee.id),
-                ('state', 'not in', ('done','cancel')),
+            unfinished_impounds = self.env['impound.impound'].search([
+                ('employee', '=', self.employee.id),
+                ('state', 'in', ('draft', 'in_progress')),
                 ('order', '<', impound.order)
-                ])
-            impound.unprocessed_impounds_qty = unfinished_impounds
+            ])
+            impound.unprocessed_impounds_qty = impound.order - len(unfinished_impounds)
 
     @api.onchange('employee')
     def _compute_file(self):
-- 
GitLab