From fe4e5cd735723aa1cab120438759f37d0d8eacb1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20=28Le=20Filament=29?= <remi@le-filament.com>
Date: Mon, 6 May 2024 09:02:46 +0200
Subject: [PATCH] [MIG] migration scripts for keeping fields on account.move

---
 __manifest__.py                               |  6 +++---
 migrations/13.0.1.0.1/post-migration.py       | 19 +++++++++++++++++++
 models/__init__.py                            |  5 +----
 .../{account_invoice.py => account_move.py}   |  2 +-
 4 files changed, 24 insertions(+), 8 deletions(-)
 create mode 100644 migrations/13.0.1.0.1/post-migration.py
 rename models/{account_invoice.py => account_move.py} (89%)

diff --git a/__manifest__.py b/__manifest__.py
index 2d05fee..5436c6d 100755
--- a/__manifest__.py
+++ b/__manifest__.py
@@ -1,7 +1,7 @@
 {
     "name": "3A Dentaire - Account Invoice Online",
     "summary": "Option de paiement en ligne",
-    "version": "12.0.1.0.1",
+    "version": "13.0.1.0.1",
     "author": "Le Filament",
     "license": "AGPL-3",
     "application": False,
@@ -11,7 +11,7 @@
         "account_payment",
     ],
     "data": [
-        "views/account_invoice.xml",
-        "templates/account_portal_templates.xml"
+        #"views/account_invoice.xml",
+        #"templates/account_portal_templates.xml"
     ]
 }
diff --git a/migrations/13.0.1.0.1/post-migration.py b/migrations/13.0.1.0.1/post-migration.py
new file mode 100644
index 0000000..24027b5
--- /dev/null
+++ b/migrations/13.0.1.0.1/post-migration.py
@@ -0,0 +1,19 @@
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+from openupgradelib import openupgrade
+
+
+def update_account_move_is_payment_online(cr):
+    openupgrade.logged_query(
+        cr, """
+            UPDATE account_move am
+            SET is_payment_online = ai.is_payment_online
+            FROM account_invoice ai
+            WHERE am.old_invoice_id = ai.id
+            """
+    )
+
+
+@openupgrade.migrate(use_env=True)
+def migrate(env, version):
+    update_account_move_is_payment_online(env.cr)
diff --git a/models/__init__.py b/models/__init__.py
index 353259f..9c0a421 100644
--- a/models/__init__.py
+++ b/models/__init__.py
@@ -1,4 +1 @@
-# © 2020 Le Filament (<http://www.le-filament.com>)
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-
-from . import account_invoice
+from . import account_move
diff --git a/models/account_invoice.py b/models/account_move.py
similarity index 89%
rename from models/account_invoice.py
rename to models/account_move.py
index 5590629..20ebb02 100644
--- a/models/account_invoice.py
+++ b/models/account_move.py
@@ -5,6 +5,6 @@ from odoo import fields, models
 
 
 class AccountInvoiceOnline(models.Model):
-    _inherit = 'account.invoice'
+    _inherit = 'account.move'
 
     is_payment_online = fields.Boolean("Paiement en ligne", default=True)
-- 
GitLab