From f4c33e407b5ad3c54d65ae23b10db77e62ab9029 Mon Sep 17 00:00:00 2001
From: Benjamin <benjamin@le-filament.com>
Date: Thu, 18 Mar 2021 15:02:07 +0100
Subject: [PATCH] [add] tab on payment.order for SDD file download

---
 __manifest__.py                 |  1 +
 models/__init__.py              |  1 +
 models/account_payment_order.py | 22 +++++++++++++++++
 views/account_payment_order.xml | 44 +++++++++++++++++++++++++++++++++
 4 files changed, 68 insertions(+)
 create mode 100644 models/account_payment_order.py
 create mode 100644 views/account_payment_order.xml

diff --git a/__manifest__.py b/__manifest__.py
index f5f616f..9063489 100755
--- a/__manifest__.py
+++ b/__manifest__.py
@@ -19,6 +19,7 @@
         "security/ir.model.access.csv",
         "views/account_invoice.xml",
         "views/account_payment_term.xml",
+        "views/account_payment_order.xml",
         "views/res_config_settings.xml",
         "views/scop_cotisation_task.xml",
     ],
diff --git a/models/__init__.py b/models/__init__.py
index 4db72cb..796e1a9 100755
--- a/models/__init__.py
+++ b/models/__init__.py
@@ -2,6 +2,7 @@
 # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
 
 from . import account_invoice
+from . import account_payment_order
 from . import account_payment_term
 from . import chart_template
 from . import res_company
diff --git a/models/account_payment_order.py b/models/account_payment_order.py
new file mode 100644
index 0000000..7b8b401
--- /dev/null
+++ b/models/account_payment_order.py
@@ -0,0 +1,22 @@
+# Copyright 2020 Le Filament
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
+
+from odoo import fields, models, api
+
+
+class ModelName(models.Model):
+    _inherit = 'account.payment.order'
+
+    attachment_ids = fields.One2many(
+        comodel_name='ir.attachment',
+        compute='_compute_attachment_ids'
+    )
+
+    @api.multi
+    def _compute_attachment_ids(self):
+        Attachment = self.env['ir.attachment']
+        for po in self:
+           po.attachment_ids = Attachment.search([
+               ('res_model', '=', 'account.payment.order'),
+               ('res_id', '=', po.id)
+           ])
diff --git a/views/account_payment_order.xml b/views/account_payment_order.xml
new file mode 100644
index 0000000..c04eb59
--- /dev/null
+++ b/views/account_payment_order.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+    <!--  Copyright 2020 Le Filament
+          License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).  -->
+    <data>
+
+        <record id="account_payment_order_form" model="ir.ui.view">
+            <field name="name">account.payment.order.form</field>
+            <field name="model">account.payment.order</field>
+            <field name="inherit_id" ref="account_payment_order.account_payment_order_form"/>
+            <field name="arch" type="xml">
+                <xpath expr="//notebook" position="inside">
+                    <page name="attachments" string="Fichiers de prélèvements">
+                        <field name="attachment_ids">
+                            <tree>
+                                <field name="create_date"/>
+                                <field name="name"/>
+                                <field name="type"/>
+                                <field name="datas" filename="datas_fname"/>
+                                <field name="create_uid"/>
+                            </tree>
+                            <form>
+                                <h1><field name="name"/></h1>
+                                <group>
+                                    <group>
+                                        <field name="datas" filename="datas_fname" attrs="{'invisible':[('type','=','url')]}" string="Télécharger le fichier"/>
+                                        <field name="datas_fname" invisible="1" attrs="{'invisible':[('type','=','url')]}" class="oe_inline oe_right"/>
+                                        <field name="url" widget="url" attrs="{'invisible':[('type','=','binary')]}"/>
+                                        <field name="mimetype" groups="base.group_no_one"/>
+                                        <field name="type"/>
+                                    </group>
+                                    <group>
+                                        <field name="create_uid"/>
+                                        <field name="create_date"/>
+                                    </group>
+                                </group>
+                            </form>
+                        </field>
+                    </page>
+                </xpath>
+            </field>
+        </record>
+    </data>
+</odoo>
\ No newline at end of file
-- 
GitLab