Skip to content

Commit

Permalink
[OA-ADD] purchase: migration analytic distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
SonCrits committed Jul 20, 2023
1 parent e6dda98 commit be92f64
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docsource/modules150-160.rst
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ Module coverage 15.0 -> 16.0
+-------------------------------------------------+----------------------+-------------------------------------------------+
| project_timesheet_holidays |Nothing to do |No DB layout changes. |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| purchase | | |
| purchase | Done | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| purchase_mrp | | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
17 changes: 17 additions & 0 deletions openupgrade_scripts/scripts/purchase/16.0.1.2/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from openupgradelib import openupgrade


def _remove_safety_xml_record(env):
openupgrade.delete_records_safely_by_xml_id(
env, ["purchase.mail_notification_confirm"]
)


def _run_the_file_no_update_again(env):
openupgrade.load_data(env.cr, "purchase", "16.0.1.2/noupdate_changes.xml")


@openupgrade.migrate()
def migrate(env, version):
_remove_safety_xml_record(env)
_run_the_file_no_update_again(env)
57 changes: 57 additions & 0 deletions openupgrade_scripts/scripts/purchase/16.0.1.2/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from openupgradelib import openupgrade


def _fill_analytic_distribution(env):

openupgrade.logged_query(
env.cr,
"""
WITH distribution_data AS (
WITH sub AS (
SELECT
all_line_data.porder_line_id,
all_line_data.account_analytic_id,
SUM(all_line_data.percentage) AS percentage
FROM (
SELECT
porder_line.id AS porder_line_id,
account.id AS account_analytic_id,
100 AS percentage
FROM purchase_order_line porder_line
JOIN account_analytic_account account
ON account.id = porder_line.account_analytic_id
WHERE porder_line.account_analytic_id IS NOT NULL
UNION ALL
SELECT
porder_line.id AS porder_line_id,
dist.account_id AS account_analytic_id,
dist.percentage AS percentage
FROM purchase_order_line porder_line
JOIN account_analytic_tag_purchase_order_line_rel tag_rel
ON tag_rel.purchase_order_line_id = porder_line.id
JOIN account_analytic_distribution dist
ON dist.tag_id = tag_rel.account_analytic_tag_id
) AS all_line_data
GROUP BY all_line_data.porder_line_id, all_line_data.account_analytic_id
)
SELECT
sub.porder_line_id,
jsonb_object_agg(
sub.account_analytic_id::text, sub.percentage
) AS analytic_distribution
FROM sub
GROUP BY sub.porder_line_id
)
UPDATE purchase_order_line porder_line
SET analytic_distribution = dist.analytic_distribution
FROM distribution_data dist
WHERE porder_line.id = dist.porder_line_id;
""",
)


@openupgrade.migrate()
def migrate(env, version):
_fill_analytic_distribution(env)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---Models in module 'purchase'---
---Fields in module 'purchase'---
purchase / account.analytic.applicability / business_domain (False) : NEW selection_keys: ['bill', 'expense', 'general', 'invoice', 'purchase_order'], mode: modify
# NOTHING TO DO: business_domain field must have value, but this will be handled by the analytic and account module

purchase / product.category / property_account_creditor_price_difference_categ (many2one): module is now 'purchase_price_diff' ('purchase')
purchase / product.product / property_account_creditor_price_difference (many2one): module is now 'purchase_price_diff' ('purchase')
purchase / product.template / property_account_creditor_price_difference (many2one): module is now 'purchase_price_diff' ('purchase')
# DONE pre-migration: rename_fields

purchase / purchase.order.line / account_analytic_id (many2one): DEL relation: account.analytic.account
purchase / purchase.order.line / analytic_distribution (json) : NEW hasdefault: compute
purchase / purchase.order.line / analytic_distribution_search (json): NEW
purchase / purchase.order.line / analytic_precision (integer) : NEW hasdefault: default
purchase / purchase.order.line / analytic_tag_ids (many2many) : DEL relation: account.analytic.tag
# DONE pre-migration: https://github.com/Viindoo/OpenUpgrade/commit/ab42981e37f3978495eacd05428dba7d2515c957

---XML records in module 'purchase'---
NEW ir.actions.act_window: purchase.action_purchase_history
DEL ir.actions.act_window: purchase.purchase_action_dashboard_kanban
DEL ir.actions.act_window: purchase.purchase_action_dashboard_list
NEW ir.model.access: purchase.access_product_tag_purchase_manager
DEL ir.model.access: purchase.access_account_type
NEW ir.ui.view: purchase.purchase_history_tree
NEW ir.ui.view: purchase.purchase_order_view_kanban_without_dashboard
# NOTHING TO DO

DEL ir.ui.view: purchase.mail_notification_confirm (noupdate)
# DONE post-migration: remove safety

DEL ir.ui.view: purchase.product_template_form_view
DEL ir.ui.view: purchase.view_category_property_form
NEW mail.message.subtype: purchase.mt_rfq_sent (noupdate)
# NOTHING TO DO

0 comments on commit be92f64

Please sign in to comment.