From a9cdc1bd5beb0e3a791c90a9775c3c43679e971d Mon Sep 17 00:00:00 2001
From: jordan <jordan@le-filament.com>
Date: Wed, 10 Feb 2021 10:01:51 +0100
Subject: [PATCH] [update] scop_cotisation_task in scop_cotisation parent

---
 __manifest__.py                |  2 ++
 models/__init__.py             |  1 +
 models/res_config_settings.py  |  4 ++++
 models/scop_cotisation_task.py | 24 ++++++++++++++++++++
 security/ir.model.access.csv   |  2 ++
 security/security_rules.xml    | 19 ++++++++++++++++
 views/scop_cotisation_task.xml | 40 ++++++++++++++++++++++++++++++++++
 7 files changed, 92 insertions(+)
 create mode 100644 models/scop_cotisation_task.py
 create mode 100644 security/security_rules.xml
 create mode 100644 views/scop_cotisation_task.xml

diff --git a/__manifest__.py b/__manifest__.py
index 383dc02..058b54f 100755
--- a/__manifest__.py
+++ b/__manifest__.py
@@ -15,9 +15,11 @@
         "multi_company_menu",
     ],
     "data": [
+        "security/security_rules.xml",
         "security/ir.model.access.csv",
         "views/account_invoice.xml",
         "views/res_config_settings.xml",
+        "views/scop_cotisation_task.xml",
     ],
     'post_init_hook': '_configure_journals',
 }
diff --git a/models/__init__.py b/models/__init__.py
index e635914..048e4e9 100755
--- a/models/__init__.py
+++ b/models/__init__.py
@@ -7,3 +7,4 @@ from . import res_company
 from . import res_config_settings
 from . import scop_contribution
 from . import scop_cotisation
+from . import scop_cotisation_task
diff --git a/models/res_config_settings.py b/models/res_config_settings.py
index 78f240d..8214d9c 100644
--- a/models/res_config_settings.py
+++ b/models/res_config_settings.py
@@ -46,7 +46,11 @@ class CotisationsConfigSettings(models.TransientModel):
 
         menu_cotiz = self.env.ref(
             'cgscop_cotisation.menu_scop_cotisation')
+        menu_cotiz_task_create = self.env.ref(
+            'cgscop_cotisation.menu_scop_cotisation_list_task')
+
         bool_condition = self.is_contribution
 
         self.add_company_to_menu(menu_cotiz, bool_condition)
+        self.add_company_to_menu(menu_cotiz_task_create, bool_condition)
         return res
diff --git a/models/scop_cotisation_task.py b/models/scop_cotisation_task.py
new file mode 100644
index 0000000..9cf5fd7
--- /dev/null
+++ b/models/scop_cotisation_task.py
@@ -0,0 +1,24 @@
+# © 2021 Le Filament (<http://www.le-filament.com>)
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+from odoo import fields, models
+
+
+class CotisationTask(models.Model):
+    _name = 'scop.cotisation.task'
+    _description = 'Gestion des créations des cotisations'
+
+    year = fields.Integer('Année')
+    message = fields.Char("Message")
+    cotiz_created = fields.Integer("Appels de cotisation créés")
+    cotiz_to_create = fields.Integer("Appels de cotisation à créer")
+    is_error = fields.Boolean('En erreur', default=False)
+    status = fields.Selection([
+        ('in_process', 'En cours'),
+        ('done', 'Terminé')
+    ], string='Statut')
+    company_id = fields.Many2one(
+        comodel_name='res.company',
+        string='Company', change_default=True,
+        required=True, readonly=True,
+        default=lambda self: self.env.user.company_id)
diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv
index 97dd8b9..e20c830 100755
--- a/security/ir.model.access.csv
+++ b/security/ir.model.access.csv
@@ -1 +1,3 @@
 id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_scop_cotisation_task,access_scop_cotisation_task,model_scop_cotisation_task,account.group_account_manager,1,1,1,0
+admin_access_scop_cotisation_task,admin_access_scop_cotisation_task,model_scop_cotisation_task,cgscop_partner.group_cg_administrator,1,1,1,1
diff --git a/security/security_rules.xml b/security/security_rules.xml
new file mode 100644
index 0000000..e449804
--- /dev/null
+++ b/security/security_rules.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2020 Le Filament
+     License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
+
+<odoo>
+    <data noupdate="0">
+
+        <record id="cg_cotisation_task_rule" model="ir.rule">
+            <field name="name">Tâches créations cotisations consultables que pour sa société</field>
+            <field name="model_id" ref="cgscop_cotisation.model_scop_cotisation_task"/>
+            <field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
+            <field name="perm_read" eval="True"/>
+            <field name="perm_write" eval="True"/>
+            <field name="perm_create" eval="True"/>
+            <field name="perm_unlink" eval="True"/>
+        </record>
+
+    </data>
+</odoo>
\ No newline at end of file
diff --git a/views/scop_cotisation_task.xml b/views/scop_cotisation_task.xml
new file mode 100644
index 0000000..08280db
--- /dev/null
+++ b/views/scop_cotisation_task.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<!-- Copyright 2021 Le Filament
+     License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
+
+<odoo>
+    <data>
+
+        <!-- TREE VIEW -->
+        <record model="ir.ui.view" id="view_scop_cotisation_task_tree">
+            <field name="name">scop.cotisation.task.tree</field>
+            <field name="model">scop.cotisation.task</field>
+            <field name="arch" type="xml">
+                <tree create="false" string="Taches création cotisations">
+                    <field name="create_date"/>
+                    <field name="year"/>
+                    <field name='status'/>
+                    <field name='cotiz_created'/>
+                    <field name='cotiz_to_create'/>
+                    <field name='is_error'/>
+                    <field name="message"/>
+                </tree>
+            </field>
+        </record>
+
+        <!-- ACTIONS VIEWS-->
+        <record model="ir.actions.act_window" id="action_scop_cotisation_task">
+            <field name="name">Taches cotisation</field>
+            <field name="res_model">scop.cotisation.task</field>
+            <field name="view_mode">tree,form</field>
+        </record>
+
+        <!-- MENU -->
+        <menuitem id="menu_scop_cotisation_list_task"
+                  parent="account.menu_finance_configuration"
+                  name="Taches création cotisations"
+                  sequence="50"
+                  action="action_scop_cotisation_task"/>
+
+    </data>
+</odoo>
\ No newline at end of file
-- 
GitLab