From 2941be6cc10081e10113865aab4bba448d6b3e7b Mon Sep 17 00:00:00 2001
From: benjamin <benjamin@le-filament.com>
Date: Wed, 4 Jan 2023 16:57:08 +0100
Subject: [PATCH] [update] partner view + pre-commit clean

---
 __manifest__.py                            |  1 +
 models/account_invoice_employee_assign.py  | 15 +++---
 report/__init__.py                         |  0
 report/account_invoice_employee_report.py  | 21 +++++----
 report/account_invoice_employee_report.xml | 53 ++++++++++++++--------
 security/ir.model.access.csv               |  2 +-
 views/res_partner_views.xml                | 28 ++++++++++++
 7 files changed, 83 insertions(+), 37 deletions(-)
 mode change 100755 => 100644 report/__init__.py
 create mode 100644 views/res_partner_views.xml

diff --git a/__manifest__.py b/__manifest__.py
index c917ebb..e1b81f1 100644
--- a/__manifest__.py
+++ b/__manifest__.py
@@ -15,5 +15,6 @@
         "report/account_invoice_employee_report.xml",
         # views
         "views/account_invoice_views.xml",
+        "views/res_partner_views.xml",
     ],
 }
diff --git a/models/account_invoice_employee_assign.py b/models/account_invoice_employee_assign.py
index a1cb877..96ccb24 100644
--- a/models/account_invoice_employee_assign.py
+++ b/models/account_invoice_employee_assign.py
@@ -12,20 +12,19 @@ class AccountInvoiceEmployeeAssign(models.Model):
     @api.model
     def _get_partner_domain(self):
         partner_ids = self.env.ref("base.main_partner")
-        partner_ids += self.env["hr.employee"].search(
-            []).mapped("user_id").mapped("partner_id")
+        partner_ids += (
+            self.env["hr.employee"].search([]).mapped("user_id").mapped("partner_id")
+        )
         return [("id", "in", partner_ids.ids)]
 
     invoice_id = fields.Many2one(
-        comodel_name="account.invoice",
-        string="Facture",
-        required=True
+        comodel_name="account.invoice", string="Facture", required=True
     )
     partner_id = fields.Many2one(
         comodel_name="res.partner",
         string="Employé",
         domain=_get_partner_domain,
-        required=True
+        required=True,
     )
     percentage = fields.Float("Pourcentage", default=0.0, required=True)
 
@@ -36,6 +35,4 @@ class AccountInvoiceEmployeeAssign(models.Model):
     def _check_percentage(self):
         for record in self:
             if record.percentage < 0 or record.percentage > 100:
-                raise UserError(_(
-                    "Le pourcentage doit être entre 0 et 100"
-                ))
+                raise UserError(_("Le pourcentage doit être entre 0 et 100"))
diff --git a/report/__init__.py b/report/__init__.py
old mode 100755
new mode 100644
diff --git a/report/account_invoice_employee_report.py b/report/account_invoice_employee_report.py
index 481137a..29159f5 100644
--- a/report/account_invoice_employee_report.py
+++ b/report/account_invoice_employee_report.py
@@ -1,8 +1,7 @@
 # © 2022 Le Filament (<http://www.le-filament.com>)
 # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
 
-from odoo import tools
-from odoo import models, fields, api
+from odoo import api, fields, models, tools
 
 
 class AccountInvoiceEmployeeReport(models.Model):
@@ -32,7 +31,7 @@ class AccountInvoiceEmployeeReport(models.Model):
         string="Vendeur",
         readonly=True,
     )
-    currency_id = fields.Many2one("res.currency", string='Currency', readonly=True)
+    currency_id = fields.Many2one("res.currency", string="Currency", readonly=True)
     # employee fields
     partner_id = fields.Many2one(
         comodel_name="res.partner",
@@ -44,10 +43,14 @@ class AccountInvoiceEmployeeReport(models.Model):
 
     _depends = {
         "account.invoice": [
-            "state", "user_id", "amount_untaxed_signed", "date_invoice",
+            "state",
+            "user_id",
+            "amount_untaxed_signed",
+            "date_invoice",
         ],
         "account.invoice.employee.assign": [
-            "partner_id", "percentage",
+            "partner_id",
+            "percentage",
         ],
     }
 
@@ -81,10 +84,12 @@ class AccountInvoiceEmployeeReport(models.Model):
     @api.model_cr
     def init(self):
         tools.drop_view_if_exists(self.env.cr, self._table)
-        self.env.cr.execute("""CREATE or REPLACE VIEW %s as (
+        self.env.cr.execute(
+            """CREATE or REPLACE VIEW %s as (
             %s
-        )""" % (
-            self._table, self._query()))
+        )"""
+            % (self._table, self._query())
+        )
 
     # ------------------------------------------------------
     # Computed fields
diff --git a/report/account_invoice_employee_report.xml b/report/account_invoice_employee_report.xml
index d8599ea..493a282 100644
--- a/report/account_invoice_employee_report.xml
+++ b/report/account_invoice_employee_report.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8" ?>
 <odoo>
     <data>
         <!-- SEARCH VIEW -->
@@ -7,13 +7,25 @@
             <field name="model">account.invoice.employee.report</field>
             <field name="arch" type="xml">
                 <search string="Facturation par employé">
-                    <field name="partner_id"/>
-                    <field name="invoice_id"/>
-                    <field name="user_id"/>
+                    <field name="partner_id" />
+                    <field name="invoice_id" />
+                    <field name="user_id" />
                     <group expand="0" string="Group By">
-                        <filter name="group_by_date" string="Date de facturation" context="{'group_by':'date_invoice'}"/>
-                        <filter name="group_by_employee" string="Employé" context="{'group_by':'partner_id'}"/>
-                        <filter name="group_by_state" string="Statut" context="{'group_by':'state'}"/>
+                        <filter
+                            name="group_by_date"
+                            string="Date de facturation"
+                            context="{'group_by':'date_invoice'}"
+                        />
+                        <filter
+                            name="group_by_employee"
+                            string="Employé"
+                            context="{'group_by':'partner_id'}"
+                        />
+                        <filter
+                            name="group_by_state"
+                            string="Statut"
+                            context="{'group_by':'state'}"
+                        />
                     </group>
                 </search>
             </field>
@@ -26,14 +38,14 @@
             <field name="arch" type="xml">
                 <tree string="Facturation par employé">
                     <field name="currency_id" invisible="1" />
-                    <field name="date_invoice"/>
-                    <field name="partner_id"/>
-                    <field name="percentage"/>
+                    <field name="date_invoice" />
+                    <field name="partner_id" />
+                    <field name="percentage" />
                     <field name="revenue" widget="monetary" />
-                    <field name="user_id"/>
-                    <field name="invoice_id"/>
-                    <field name="amount_untaxed_signed"/>
-                    <field name="state"/>
+                    <field name="user_id" />
+                    <field name="invoice_id" />
+                    <field name="amount_untaxed_signed" />
+                    <field name="state" />
                 </tree>
             </field>
         </record>
@@ -45,9 +57,9 @@
             <field name="arch" type="xml">
                 <pivot string="Facturation par employé">
                     <field name="currency_id" invisible="1" />
-                    <field name="partner_id" type="row"/>
-                    <field name="date_invoice" type="col"/>
-                    <field name="revenue" type="measure"/>
+                    <field name="partner_id" type="row" />
+                    <field name="date_invoice" type="col" />
+                    <field name="revenue" type="measure" />
                 </pivot>
             </field>
         </record>
@@ -59,13 +71,16 @@
             <field name="arch" type="xml">
                 <graph string="Facturation par employé">
                     <field name="partner_id" />
-                    <field name="revenue" type="measure"/>
+                    <field name="revenue" type="measure" />
                 </graph>
             </field>
         </record>
 
         <!-- ACTION -->
-        <record id="account_invoice_employee_report_action" model="ir.actions.act_window">
+        <record
+            id="account_invoice_employee_report_action"
+            model="ir.actions.act_window"
+        >
             <field name="name">Rapports Legicoop</field>
             <field name="type">ir.actions.act_window</field>
             <field name="res_model">account.invoice.employee.report</field>
diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv
index 62f4e98..5abf484 100644
--- a/security/ir.model.access.csv
+++ b/security/ir.model.access.csv
@@ -1,3 +1,3 @@
 id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
 access_account_invoice_employee_assign,access_account_invoice_employee_assign,model_account_invoice_employee_assign,account.group_account_invoice,1,1,1,1
-access_account_invoice_employee_report,access_account_invoice_employee_report,model_account_invoice_employee_report,account.group_account_invoice,1,1,1,1
\ No newline at end of file
+access_account_invoice_employee_report,access_account_invoice_employee_report,model_account_invoice_employee_report,account.group_account_invoice,1,1,1,1
diff --git a/views/res_partner_views.xml b/views/res_partner_views.xml
new file mode 100644
index 0000000..ba54a63
--- /dev/null
+++ b/views/res_partner_views.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" ?>
+<!-- Copyright 2020 Le Filament
+     License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
+<odoo>
+    <data>
+        <record id="legicoop_account_view_partner_form" model="ir.ui.view">
+            <field name="name">legicoop.account.view.partner.form</field>
+            <field name="model">res.partner</field>
+            <field name="inherit_id" ref="base.view_partner_form" />
+            <field name="priority" eval="110" />
+            <field name="arch" type="xml">
+                <!-- no_edit sur les champs des comptes comptables  -->
+                <xpath
+                    expr="//field[@name='property_account_receivable_id']"
+                    position="attributes"
+                >
+                    <attribute name="options">{'no_open': 1}</attribute>
+                </xpath>
+                <xpath
+                    expr="//field[@name='property_account_payable_id']"
+                    position="attributes"
+                >
+                    <attribute name="options">{'no_open': 1}</attribute>
+-                </xpath>
+            </field>
+        </record>
+    </data>
+</odoo>
-- 
GitLab