From eb339a328ce81891d24dfa056f53ea6e0dd8ab50 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20-=20Le=20Filament?= <remi@le-filament.com>
Date: Thu, 21 Dec 2023 19:29:14 +0100
Subject: [PATCH] [UPD] portal and values

---
 controllers/main.py                    | 39 ++++----------------------
 templates/operation_templates_page.xml | 12 ++++----
 2 files changed, 10 insertions(+), 41 deletions(-)

diff --git a/controllers/main.py b/controllers/main.py
index 5c0f494..496274d 100644
--- a/controllers/main.py
+++ b/controllers/main.py
@@ -10,7 +10,7 @@ from odoo.addons.http_routing.models.ir_http import slug
 
 
 class PortalAccount(PortalAccount):
-    def _prepare_invoice_surplus_portal_values(self, operation, domain, order):
+    def _prepare_invoice_surplus_portal_values(self, operation, order):
         """
         Get all surplus invoices matching domain
         """
@@ -18,7 +18,6 @@ class PortalAccount(PortalAccount):
         values.update(self._get_role(operation))
         domain = expression.AND(
             [
-                domain,
                 [("acc_operation_id", "=", operation.id)],
                 [("acc_delivery_id", "=", False)],
                 [
@@ -65,16 +64,6 @@ class PortalAccount(PortalAccount):
         values["invoices_surplus"] = request.env["account.move"].sudo().search(domain)
         return values
 
-    def _get_operation_values(self, operation):
-        render_values = super()._get_operation_values(operation)
-        if operation.is_surplus_active:
-            render_values[
-                "ope_invoices_surplus"
-            ] = self._prepare_invoice_surplus_portal_values(
-                operation=operation, domain=[], order="name desc"
-            )["invoices_surplus"]
-        return render_values
-
     @http.route(
         [
             '/operation/<model("acc.operation"):operation>/invoices-surplus',
@@ -89,26 +78,14 @@ class PortalAccount(PortalAccount):
         """
         List all surplus invoices
         """
-        render_values = self._get_operation_values(operation)
-        searchbar_sortings = self._get_account_searchbar_sortings()
-        # default sort by order
-        if not sortby:
-            sortby = "date"
-        order = searchbar_sortings[sortby]["order"]
 
-        domain = []
-        searchbar_filters = self._get_account_searchbar_filters()
-        # default filter by value
-        if not filterby:
-            filterby = "all"
-        domain += searchbar_filters[filterby]["domain"]
+        render_values = {}
+        render_values.update(self._get_role(operation))
 
-        searchbar_inputs = self._get_account_searchbar_inputs()
-        if search and search_in:
-            domain += self._get_account_search_domain(search_in, search)
+        order = "state, name desc, start_date desc, partner_id"
 
         render_values["invoices_surplus"] = self._prepare_invoice_surplus_portal_values(
-            operation, domain, order
+            operation, order
         )["invoices_surplus"]
 
         render_values.update(
@@ -116,12 +93,6 @@ class PortalAccount(PortalAccount):
                 "default_url": "/operation/" + slug(operation) + "/invoices-surplus",
                 "page_name": "invoice-surplus",
                 "page_breadcrumbs": "Factures Surplus",
-                "search_in": search_in,
-                "search": search,
-                "sortby": sortby,
-                "filterby": filterby,
-                "searchbar_inputs": searchbar_inputs,
-                "searchbar_filters": searchbar_filters,
             }
         )
 
diff --git a/templates/operation_templates_page.xml b/templates/operation_templates_page.xml
index 9fbcf48..93cfd2d 100644
--- a/templates/operation_templates_page.xml
+++ b/templates/operation_templates_page.xml
@@ -4,7 +4,7 @@
         <xpath expr="//li[@id='menu-contact']" position="before">
             <li
                 class="nav-item"
-                t-if="operation.is_surplus_active and ope_invoices_surplus"
+                t-if="operation.is_surplus_active and (isProductor or isAdmin or isSuperAdmin)"
             >
                 <a
                     t-attf-href="/operation/#{slug(operation)}/invoices-surplus"
@@ -17,7 +17,6 @@
     </template>
 
     <!-- Operation Document template -->
-    <!-- TODO: reuse same template as for consumer invoices -->
     <template id='operation_invoice_surplus' name="Operation Factures Surplus">
         <t t-call="oacc_portal.layout_op">
             <div class="col-12 bg-white">
@@ -25,14 +24,13 @@
                     class="text-center mt-2 text-uppercase"
                 >Mes Factures Surplus</h3>
                 <t t-if="invoices_surplus">
-                    <t
-                        t-set="invoices"
-                        t-value="invoices_surplus"
-                    />
+                    <t t-set="invoices" t-value="invoices_surplus" />
                     <t t-call="oacc_portal_account.operation_invoice_table" />
                 </t>
                 <t t-else="">
-                    <p class="pt-5">Il n'y a actuellement aucune facture de surplus sur cette opération.</p>
+                    <p
+                        class="pt-5"
+                    >Il n'y a actuellement aucune facture de surplus sur cette opération.</p>
                 </t>
             </div>
         </t>
-- 
GitLab