From 00bbde79418b0732e1ad560f6a60adaeb40a6873 Mon Sep 17 00:00:00 2001
From: jordan <jordan@le-filament.com>
Date: Tue, 14 Dec 2021 15:04:37 +0100
Subject: [PATCH] [update] use has_outstanding to display reconcile widget

---
 models/scop_bordereau_cg.py | 59 +++++++------------------------------
 views/scop_bordereau_cg.xml | 19 +++++++-----
 2 files changed, 21 insertions(+), 57 deletions(-)

diff --git a/models/scop_bordereau_cg.py b/models/scop_bordereau_cg.py
index 0608d79..dcff4c4 100644
--- a/models/scop_bordereau_cg.py
+++ b/models/scop_bordereau_cg.py
@@ -172,10 +172,6 @@ class Bordereau(models.Model):
         comodel_name='scop.bordereau',
         string='Bordereau initial',
     )
-    move_reconciled = fields.Boolean(
-        'Paiements en cours',
-        compute='_compute_move_reconciled'
-    )
     # Emails management
     recipient_ids = fields.One2many(
         comodel_name='res.partner',
@@ -194,7 +190,6 @@ class Bordereau(models.Model):
         inverse_name='bordereau_id',
         string='Historique'
     )
-
     has_outstanding = fields.Boolean(
         string='Paiements en circulation',
         compute='_compute_has_outstanding')
@@ -307,20 +302,6 @@ class Bordereau(models.Model):
         if recs:
             return [('id', 'in', [x.id for x in recs])]
 
-    @api.multi
-    def _compute_move_reconciled(self):
-        self.ensure_one()
-        payments_ids = self.env['account.payment'].search([
-            ('partner_id', '=', self.partner_id.id)])
-        payments = list(
-            map(lambda p: self.get_move_reconciled(p), payments_ids))
-        if True in payments:
-            payments.remove(True)
-        if payments:
-            self.move_reconciled = False
-        else:
-            self.move_reconciled = True
-
     @api.multi
     def _compute_is_liasse_previ(self):
         for bordereau in self:
@@ -454,23 +435,17 @@ class Bordereau(models.Model):
 
     @api.multi
     def open_payment(self):
-        self.ensure_one()
-        payments_ids = self.env['account.payment'].search([
-            ('partner_id', '=', self.partner_id.id)])
-
-        payments = list(map(lambda p: self.get_move_reconciled(
-            p) if self.get_move_reconciled(p) != True else None, payments_ids))
-        if True in payments:
-            payments.remove(True)
-        # Return Action
-        action = {
-            'name': 'Liste des paiements en cours - ' + self.partner_id.name,
-            'type': 'ir.actions.act_window',
-            'res_model': 'account.payment',
-            'view_mode': 'tree,form',
-            'domain': [('id', 'in', payments)]
+        action_context = {
+            'company_ids': [self.company_id.id],
+            'partner_ids': [
+                self.partner_id.commercial_partner_id.id],
+            'mode': 'customers'
+        }
+        return {
+            'type': 'ir.actions.client',
+            'tag': 'manual_reconciliation_view',
+            'context': action_context,
         }
-        return action
 
     def action_show_cotiz(self):
         """
@@ -543,7 +518,6 @@ class Bordereau(models.Model):
             'version': self.version + 1,
             'date_regul': ongoing_version.date,
             'comment_regul': ongoing_version.comment,
-            'is_regul': True,
         })
         ongoing_version.write({
             'state': 'validated',
@@ -865,19 +839,6 @@ class Bordereau(models.Model):
             ['type_contribution_id', 'amount_total_signed'],
             ['type_contribution_id'])
 
-    def get_move_reconciled(self, payment):
-        """
-        Check if payment is reconciled
-        :param payment: account.payment object
-        :return: True or payment_id
-        """
-        rec = True
-        for aml in payment.move_line_ids.filtered(
-                lambda x: x.account_id.reconcile):
-            if not aml.reconciled:
-                rec = payment.id
-        return rec
-
     # Email
     def get_recipients(self):
         recipients = ','.join(map(lambda x: str(x), self.recipient_ids.ids))
diff --git a/views/scop_bordereau_cg.xml b/views/scop_bordereau_cg.xml
index 6745dc9..9a6683f 100644
--- a/views/scop_bordereau_cg.xml
+++ b/views/scop_bordereau_cg.xml
@@ -37,10 +37,6 @@
                                 type="action"
                                 states="cancel"/>
                     </header>
-                    <field name="has_outstanding" invisible="1"/>
-                    <div class="alert alert-info mt-3" role="alert" attrs="{'invisible': [('has_outstanding','=',False)]}">
-                        Vous avez des paiements en circulation pour ce bordereau.
-                    </div>
                     <sheet>
                         <div class="oe_button_box" name="button_box">
                             <button name="action_show_cotiz" type="object"
@@ -50,8 +46,7 @@
                             </button>
                             <button class="oe_stat_button" name="open_payment"
                                     string="Paiements en cours" type="object"
-                                    attrs="{'invisible':['|', ('move_reconciled','=',True), ('state', '!=', 'validated')]}" icon="fa-university"/>
-                            <field name="move_reconciled" invisible="1"/>
+                                    attrs="{'invisible':['|', ('has_outstanding','=',False), ('state', '!=', 'validated')]}" icon="fa-university"/>
                         </div>
                         <div class="oe_title">
                             <h1>
@@ -62,6 +57,14 @@
                             Adhérent : <field name="partner_id"/> <br/>
                             UR : <field name="partner_ur_id" readonly="True" options="{'no_open': True}"/>
                         </h4>
+                        <field name="has_outstanding" invisible="1"/>
+                        <div class="alert alert-info mt-3" role="alert"
+                             attrs="{'invisible': ['|', ('has_outstanding','=',False), ('state', '!=', 'validated')]}">
+                            Vous avez des paiements en circulation pour ce bordereau.
+                        </div>
+                        <div class="alert alert-warning" role="alert" attrs="{'invisible': [('state', '!=', 'ongoing')]}">
+                            <strong>Bordereau en cours de modification </strong>(Détails dans l'onglet "Historique")<br/>
+                        </div>
                         <field name="is_regul" invisible="1"/>
                         <div class="alert alert-warning" role="alert" attrs="{'invisible': [('is_regul', '!=', True)]}">
                             <strong>Bordereau annulé le : </strong><field name="date_regul" readonly="True"/><br/>
@@ -133,10 +136,10 @@
                             </page>
                             <page string="Historique">
                                 <field name="bordereau_version_ids" widget="one2many" class="mt-2">
-                                    <tree edit="false" create="false" delete="false" default_order="version desc">
+                                    <tree create="false" delete="false" default_order="version desc" editable="top">
                                         <field name="date"/>
                                         <field name="version"/>
-                                        <field name="comment"/>
+                                        <field name="comment" attrs="{'readonly':[('state','=','validated')]}"/>
                                         <field name="liasse_fiscale_id_old"/>
                                         <field name="type_assiette"/>
                                         <field name="montant_assiette"/>
-- 
GitLab