Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ website_sale / product.image / product_tmpl_id (many2one) : NEW re


website_sale / product.pricelist / selectable (boolean) : NEW
# Imported values from old website_pricelist.selectable model
website_sale / product.pricelist / website_id (many2one) : NEW relation: website
# imported values from old website_pricelist_ids
# TODO: Add the default website

website_sale / product.template / availability (selection) : NEW selection_keys: ['empty', 'in_stock', 'warning']
Expand All @@ -20,10 +22,10 @@ website_sale / product.template / product_image_ids (one2many) : NEW re
# NOTHING TO DO

website_sale / res.country.group / website_pricelist_ids (many2many): DEL relation: website_pricelist
# NOTHING TO DO
# country is now taken out of this model and is managed on the pricelist itself, nothing to do

website_sale / website / website_pricelist_ids (one2many): DEL relation: website_pricelist
# NOTHING TO DO
# now is website_id on the pricelist.

---XML records in module 'website_sale'---
NEW crm.team: sales_team.salesteam_website_sales
Expand Down
25 changes: 25 additions & 0 deletions addons/website_sale/migrations/10.0.1.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
cr = env.cr
pl_model = env['product.pricelist']
sql = """
UPDATE product_pricelist pp
SET website_id = wp.website_id,
selectable = wp.selectable
FROM website_pricelist_openupgrade_10 wp
WHERE wp.pricelist_id = pp.id
"""
openupgrade.logged_query(cr, sql)
# all remaining pricelists will be assigned to default
sql = """select pricelist_id from
website_pricelist_openupgrade_10"""
cr.execute(sql)
pricelist_ids = cr.fetchall()
for pricelist in pl_model.search([('id', 'not in', pricelist_ids)]):
pricelist.write({'website_id': pricelist._default_website().id})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache the default website in a previous variable for avoiding successive calls to the method.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this in case the default calculation became more complex in a near future (e.g. per-pricelists default websites) , as things stand, you are right, but wouldn't you agree to sacrifice performance to increase modularity in a one-time run like a migration?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

12 changes: 12 additions & 0 deletions addons/website_sale/migrations/10.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade


@openupgrade.migrate(use_env=False)
def migrate(cr, version):
# keeping info in website pricelist table that would be dropped
sql = """create table website_pricelist_openupgrade_10 as select * from
website_pricelist"""
cr.execute(sql)
2 changes: 1 addition & 1 deletion odoo/openupgrade/doc/source/modules90-100.rst
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ missing in the new release are marked with |del|.
+-----------------------------------+-----------------------------------+
|website_rating_project_issue | |
+-----------------------------------+-----------------------------------+
|website_sale | |
|website_sale | Done |
+-----------------------------------+-----------------------------------+
|website_sale_delivery | |
+-----------------------------------+-----------------------------------+
Expand Down