-
-
Notifications
You must be signed in to change notification settings - Fork 699
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6dda98
commit 55d01dd
Showing
4 changed files
with
241 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
openupgrade_scripts/scripts/sale/16.0.1.2/post-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from openupgradelib import openupgrade | ||
|
||
|
||
def try_delete_noupdate_records(env): | ||
openupgrade.delete_records_safely_by_xml_id( | ||
env, | ||
[ | ||
"sale.mail_notification_paynow_online", | ||
"sale.sale_payment_acquirer_onboarding_wizard_rule", | ||
], | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
openupgrade.load_data(env.cr, "sale", "16.0.1.2/noupdate_changes.xml") | ||
try_delete_noupdate_records(env) |
126 changes: 126 additions & 0 deletions
126
openupgrade_scripts/scripts/sale/16.0.1.2/pre-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
from openupgradelib import openupgrade | ||
|
||
_models_renames = [ | ||
( | ||
"sale.payment.acquirer.onboarding.wizard", | ||
"sale.payment.provider.onboarding.wizard", | ||
), | ||
] | ||
|
||
_tables_renames = [ | ||
( | ||
"sale_payment_acquirer_onboarding_wizard", | ||
"sale_payment_provider_onboarding_wizard", | ||
), | ||
] | ||
|
||
_renames_xmlids = [ | ||
( | ||
"sale_management.menu_product_attribute_action", | ||
"sale.menu_product_attribute_action", | ||
), | ||
] | ||
|
||
|
||
def _noupdate_switch(env): | ||
openupgrade.set_xml_ids_noupdate_value( | ||
env, "sale", ["model_sale_order_action_share"], False | ||
) | ||
|
||
|
||
def _remove_table_constraints(env): | ||
openupgrade.delete_sql_constraint_safely( | ||
env, "sale", "sale_order", "date_order_conditional_required" | ||
) | ||
|
||
|
||
def _drop_sql_views(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
DROP VIEW IF EXISTS report_all_channels_sales | ||
""", | ||
) | ||
|
||
|
||
def _fast_fill_analytic_distribution_on_sale_order_line(env): | ||
""" | ||
Dynamically fill analytic_distribution for model that inherit from analytic.mixin | ||
Hmmm this method should be placed in the library | ||
Take a look with example of account.move.line | ||
The idea is to take all the distribution of an account.move.line | ||
which has analytic.tag then form it as a jsonb like {'1': 100, '2': 50} | ||
and also check if the table has analytic_account_column then check if it | ||
exist in the analytic_account of all the analytic_distribution of the analytic tags | ||
then take it as the 100%, which mean an account.move.line both specify '2' as the | ||
analytic.account.id and it has 1 analytic.tag also have that analytic.account then | ||
the value will sum together | ||
""" | ||
if not openupgrade.column_exists( | ||
env.cr, "sale_order_line", "analytic_distribution" | ||
): | ||
openupgrade.logged_query( | ||
env.cr, | ||
f""" | ||
ALTER TABLE sale_order_line | ||
ADD COLUMN IF NOT EXISTS analytic_distribution jsonb; | ||
""", | ||
) | ||
|
||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
WITH distribution_data AS ( | ||
WITH sub AS ( | ||
SELECT | ||
all_line_data.sale_order_line_id, | ||
all_line_data.analytic_account_id, | ||
SUM(all_line_data.percentage) AS percentage | ||
FROM ( | ||
SELECT | ||
so_line.id AS sale_order_line_id, | ||
account.id AS analytic_account_id, | ||
100 AS percentage | ||
FROM sale_order_line so_line | ||
JOIN sale_order so ON so.id = so_line.order_id | ||
JOIN account_analytic_account account | ||
ON account.id = so.analytic_account_id | ||
WHERE so.analytic_account_id IS NOT NULL | ||
UNION ALL | ||
SELECT | ||
so_line.id AS sale_order_line_id, | ||
dist.account_id AS analytic_account_id, | ||
dist.percentage AS percentage | ||
FROM sale_order_line so_line | ||
JOIN account_analytic_tag_sale_order_line_rel tag_rel | ||
ON tag_rel.sale_order_line_id = so_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.sale_order_line_id, all_line_data.analytic_account_id | ||
) | ||
SELECT | ||
sub.sale_order_line_id, | ||
jsonb_object_agg(sub.analytic_account_id::text, sub.percentage) | ||
AS analytic_distribution | ||
FROM sub | ||
GROUP BY sub.sale_order_line_id | ||
) | ||
UPDATE sale_order_line so_line SET analytic_distribution = dist.analytic_distribution | ||
FROM distribution_data dist WHERE so_line.id = dist.sale_order_line_id | ||
""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
openupgrade.rename_models(env.cr, _models_renames) | ||
openupgrade.rename_tables(env.cr, _tables_renames) | ||
openupgrade.rename_xmlids(env.cr, _renames_xmlids) | ||
_drop_sql_views(env) | ||
_noupdate_switch(env) | ||
_remove_table_constraints(env) | ||
_fast_fill_analytic_distribution_on_sale_order_line(env) |
97 changes: 97 additions & 0 deletions
97
openupgrade_scripts/scripts/sale/16.0.1.2/upgrade_analysis_work.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
---Models in module 'sale'--- | ||
obsolete model report.all.channels.sales [sql_view] | ||
# DONE: pre-migration: drop view | ||
|
||
obsolete model report.sale.report_saleproforma [abstract] | ||
# NOTHING TO DO: obsolete model, does not exist in the database | ||
|
||
obsolete model sale.payment.acquirer.onboarding.wizard [transient] | ||
new model sale.payment.provider.onboarding.wizard [transient] | ||
# DONE: pre-migration: renamed model sale.payment.acquirer.onboarding.wizard to sale.payment.provider.onboarding.wizard | ||
|
||
---Fields in module 'sale'--- | ||
sale / account.analytic.applicability / business_domain (False) : NEW selection_keys: ['bill', 'expense', 'general', 'invoice', 'purchase_order', 'sale_order'], mode: modify | ||
# NOTHING TO DO | ||
|
||
sale / account.bank.statement.line / partner_shipping_id (many2one): module is now 'account' ('sale') | ||
sale / account.move / partner_shipping_id (many2one): module is now 'account' ('sale') | ||
sale / account.move.line / is_downpayment (boolean) : NEW | ||
sale / account.payment / partner_shipping_id (many2one): module is now 'account' ('sale') | ||
# NOTHING TO DO | ||
|
||
sale / payment.acquirer / so_reference_type (selection) : DEL selection_keys: ['partner', 'so_name'] | ||
sale / payment.provider / so_reference_type (selection) : NEW selection_keys: ['partner', 'so_name'], hasdefault: default | ||
# NOTHING TO DO | ||
|
||
sale / sale.order / show_update_fpos (boolean) : NEW | ||
sale / sale.order / show_update_pricelist (boolean): not stored anymore | ||
# NOTHING TO DO: handle by ORM | ||
|
||
sale / sale.order.line / analytic_distribution_stored_char (char): NEW isfunction: function, stored | ||
# NOTHING TO DO: handle by ORM | ||
|
||
sale / sale.order.line / analytic_tag_ids (many2many) : DEL relation: account.analytic.tag | ||
# DONE: fast fill analytic_distribution in pre-migration | ||
|
||
sale / sale.order.line / product_type (selection) : previously in module sale_stock | ||
# NOTHING TO DO: handle by ORM | ||
|
||
sale / sale.order.line / qty_delivered (float) : not a function anymore | ||
# NOTHING TO DO: only the inverse compute function was removed | ||
|
||
sale / sale.order.line / qty_delivered_manual (float) : DEL | ||
# NOTHING TO DO: not used any more, this field is useless since the new compute method from 13.0 | ||
|
||
---XML records in module 'sale'--- | ||
NEW ir.actions.act_window: sale.action_open_sale_payment_provider_onboarding_wizard | ||
DEL ir.actions.act_window: sale.action_open_sale_onboarding_payment_acquirer_wizard | ||
DEL ir.actions.act_window: sale.action_sale_order_form_view | ||
# NOTHING TO DO: noupdate="0" records | ||
|
||
ir.actions.server: sale.model_sale_order_action_share (noupdate switched) | ||
# DONE: pre-migration: noupdate switched to 0 | ||
|
||
NEW ir.config_parameter: sale.default_invoice_email_template (noupdate) | ||
# NOTHING TODO | ||
|
||
NEW ir.model.access: sale.access_product_product_attribute_custom_value_sale_user | ||
NEW ir.model.access: sale.access_product_tag_sale_manager | ||
NEW ir.model.access: sale.access_sale_payment_provider_onboarding_wizard | ||
DEL ir.model.access: sale.access_account_account_sale_manager | ||
DEL ir.model.access: sale.access_account_account_type_sale_salesman | ||
DEL ir.model.access: sale.access_account_analytic_tag_sale_salesman | ||
DEL ir.model.access: sale.access_account_move_manager | ||
DEL ir.model.access: sale.access_account_tax_sale_manager | ||
DEL ir.model.access: sale.access_product_product_attribute_custom_value_sale_manager | ||
DEL ir.model.access: sale.access_report_all_channels_sales | ||
DEL ir.model.access: sale.access_sale_payment_acquirer_onboarding_wizard | ||
DEL ir.model.access: sale.access_sale_report_manager | ||
# NOTHING TO DO | ||
|
||
ir.model.constraint: sale.constraint_sale_order_date_order_conditional_required (changed definition: is now 'check((state in('sale','done') and date_order is not null) or state not in('sale','done'))' ('check((state in('sale','done') and date_order is not null) or state not in('sale','done') )')) | ||
# DONE: pre-migration: dropped constraint and let ORM add it again with the new definition | ||
|
||
NEW ir.rule: sale.sale_payment_provider_onboarding_wizard_rule (noupdate) | ||
DEL ir.rule: sale.sale_payment_acquirer_onboarding_wizard_rule (noupdate) | ||
# DONE: post-migration: delete record noupdate="1" | ||
|
||
NEW ir.ui.menu: sale.menu_product_attribute_action [renamed from sale_management module] | ||
# DONE: pre-migration: renamed xmlids | ||
|
||
DEL ir.ui.menu: sale.menu_product | ||
NEW ir.ui.view: sale.payment_provider_form | ||
DEL ir.ui.view: sale.acquirer_form_inherit_sale | ||
# NOTHING TO DO | ||
|
||
DEL ir.ui.view: sale.mail_notification_paynow_online (noupdate) | ||
# DONE: post-migration: delete record noupdate="1" | ||
|
||
DEL ir.ui.view: sale.product_template_form_view_invoice_policy | ||
DEL ir.ui.view: sale.product_template_sale_form_view | ||
DEL ir.ui.view: sale.report_invoice_document_inherit_sale | ||
DEL ir.ui.view: sale.sale_onboarding_order_confirmation_form | ||
NEW mail.template: sale.mail_template_sale_cancellation (noupdate) | ||
# NOTHING TO DO | ||
|
||
DEL res.groups: sale.group_delivery_invoice_address [renamed to account module] | ||
# NOTHING TO DO: handle in migration script of 'account' module |