From 3c540e5cb546ed2ed6eb50d76bd6bf1f402bc749 Mon Sep 17 00:00:00 2001
From: Alexis <acp@microcom.ca>
Date: Fri, 25 Oct 2024 12:57:29 -0400
Subject: [PATCH] [17.0][OU-ADD] purchase_stock: Migration to 17.0

---
 docsource/modules160-170.rst                  |  2 +-
 .../purchase_stock/17.0.1.2/post-migration.py | 22 ++++++++++++++++++
 .../17.0.1.2/upgrade_analysis_work.txt        | 23 +++++++++++++++++++
 3 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 openupgrade_scripts/scripts/purchase_stock/17.0.1.2/post-migration.py
 create mode 100644 openupgrade_scripts/scripts/purchase_stock/17.0.1.2/upgrade_analysis_work.txt

diff --git a/docsource/modules160-170.rst b/docsource/modules160-170.rst
index f1d925eea135..01528bc48708 100644
--- a/docsource/modules160-170.rst
+++ b/docsource/modules160-170.rst
@@ -738,7 +738,7 @@ Module coverage 16.0 -> 17.0
 +---------------------------------------------------+----------------------+-------------------------------------------------+
 | purchase_requisition_stock                        |                      |No DB layout changes.                            |
 +---------------------------------------------------+----------------------+-------------------------------------------------+
-| purchase_stock                                    |                      |                                                 |
+| purchase_stock                                    | Done                 |                                                 |
 +---------------------------------------------------+----------------------+-------------------------------------------------+
 | rating                                            |                      |                                                 |
 +---------------------------------------------------+----------------------+-------------------------------------------------+
diff --git a/openupgrade_scripts/scripts/purchase_stock/17.0.1.2/post-migration.py b/openupgrade_scripts/scripts/purchase_stock/17.0.1.2/post-migration.py
new file mode 100644
index 000000000000..2365a47bb2bf
--- /dev/null
+++ b/openupgrade_scripts/scripts/purchase_stock/17.0.1.2/post-migration.py
@@ -0,0 +1,22 @@
+# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+from openupgradelib import openupgrade
+
+
+def _purchase_stock_convert_created_purchase_line_id_m2o_to_m2m(env):
+    """
+    Convert m2o to m2m in 'purchase.stock'
+    """
+    openupgrade.m2o_to_x2m(
+        env.cr,
+        env["stock.move"],
+        "stock_move",
+        "created_purchase_line_ids",
+        "created_purchase_line_id",
+    )
+
+
+@openupgrade.migrate()
+def migrate(env, version):
+    _purchase_stock_convert_created_purchase_line_id_m2o_to_m2m(env)
diff --git a/openupgrade_scripts/scripts/purchase_stock/17.0.1.2/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/purchase_stock/17.0.1.2/upgrade_analysis_work.txt
new file mode 100644
index 000000000000..32bd49da0cbf
--- /dev/null
+++ b/openupgrade_scripts/scripts/purchase_stock/17.0.1.2/upgrade_analysis_work.txt
@@ -0,0 +1,23 @@
+---Models in module 'purchase_stock'---
+---Fields in module 'purchase_stock'---
+purchase_stock / product.category         / property_account_creditor_price_difference_categ (many2one): previously in module purchase_price_diff
+purchase_stock / product.product          / property_account_creditor_price_difference (many2one): previously in module purchase_price_diff
+purchase_stock / product.template         / property_account_creditor_price_difference (many2one): previously in module purchase_price_diff
+purchase_stock / purchase.order.line      / move_dest_ids (one2many)      : table is now 'stock_move_created_purchase_line_rel' ('False')
+purchase_stock / purchase.order.line      / move_dest_ids (one2many)      : type is now 'many2many' ('one2many')
+# NOTHING TO DO: handle by ORM
+
+purchase_stock / stock.move               / created_purchase_line_id (many2one): DEL relation: purchase.order.line
+purchase_stock / stock.move               / created_purchase_line_ids (many2many): NEW relation: purchase.order.line
+# DONE post-migration: convert from m2o to m2m
+
+---XML records in module 'purchase_stock'---
+NEW ir.ui.view: purchase_stock.product_template_form_view
+NEW ir.ui.view: purchase_stock.product_view_kanban_catalog_purchase_only
+NEW ir.ui.view: purchase_stock.stock_reorder_report_search_inherited_purchase_stock
+NEW ir.ui.view: purchase_stock.view_category_property_form
+NEW ir.ui.view: purchase_stock.view_product_replenish_form_inherit_stock
+# NOTHING TO DO: new feature
+
+DEL ir.ui.view: purchase_stock.purchase_report_product_product_replenishment
+# NOTHING TO DO
