Skip to content

Commit

Permalink
[UPD] Sale migration
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanRijnhart committed Jul 25, 2016
1 parent 48e9a8d commit 85f767c
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 75 deletions.
15 changes: 15 additions & 0 deletions addons/sale/migrations/9.0.1.0/noupdate_changes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version='1.0' encoding='utf-8'?>
<openerp>
<data>
<!--Changes in noupdate data-->
<record id="mt_salesteam_order_sent" model="mail.message.subtype">
<field name="relation_field">team_id</field>
<field name="res_model">crm.team</field>
</record>
<record id="mt_salesteam_order_confirmed" model="mail.message.subtype">
<field name="relation_field">team_id</field>
<field name="res_model">crm.team</field>
</record>
</data>
</openerp>

56 changes: 27 additions & 29 deletions addons/sale/migrations/9.0.1.0/openupgrade_analysis_work.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,25 @@ sale / account.analytic.line / so_line (many2one) : NEW re

sale / account.invoice / section_id (many2one) : DEL relation: crm.case.section
sale / account.invoice / team_id (many2one) : NEW relation: crm.team
#TODO : section_id is now team_id
#Done : renamed the column to new column team_id.

sale / account.invoice.line / sale_line_ids (many2many) : NEW relation: sale.order.line
#Nothing To Do : New Functionality added.

sale / crm.team / invoiced_target (integer) : NEW
#TODO : to get it from crm.case.section
#Done : In Sales Team migration script.
#Nothing to do: existing field on renamed crm.case.section model

sale / crm.team / use_invoices (boolean) : NEW
#Nothing To Do : New Functionality added.

sale / crm.team / use_quotations (boolean) : NEW
#TODO : to get it from crm.case.section
#Done : In Sales Team migration script.
#Nothing to do: existing field on renamed crm.case.section model

sale / product.template / invoice_policy (selection) : NEW selection_keys: ['cost', 'delivery', 'order']
#TODO : (used to generate the invoice, maybe we can set it to 'order')
#Done : Set all to 'order'. (Will invoiced the ordered qty.)
#Done: set to default policy as per sale.config.settings::default_order_policy from sale_stock in 8.0

sale / product.template / track_service (selection) : NEW selection_keys: ['manual']
#TODO : Set all records to manual.
#Done : Set all to 'manual'.
#Done : set to 'manual'. Timesheet and project modules add their own values and logic.

sale / sale.order / date_confirm (date) : DEL
#Nothing to do : Functionality removed so now no longer needed.
Expand All @@ -36,26 +31,24 @@ sale / sale.order / fiscal_position (many2one) : was re
#Nothing To Do : ORM will change the name automatically.

sale / sale.order / invoice_ids (many2many) : DEL relation: account.invoice
#Nothing to do : Functionality removed now no longer needed.
#Nothing to do: Odoo now relies on the existing mapping between sale lines and invoice lines

sale / sale.order / message_follower_ids (many2many): not a function anymore
sale / sale.order / message_follower_ids (many2many): relation is now 'mail.followers' ('res.partner')
sale / sale.order / message_follower_ids (many2many): type is now 'one2many' ('many2many')
# TODO : ??? # Concerns module Mail (has to be done in another migration script specifically for that module) ---> Nothing to do
# Covered in mail module

sale / sale.order / order_policy (selection) : DEL required: required, selection_keys: ['manual'], req_default: manual
#Nothing To Do : Functionality removed now no longer needed.
# Now on product level. To be covered in the stock module migration

sale / sale.order / payment_term (many2one) : was renamed to payment_term_id [nothing to to]
#Nothing To Do : ORM will change the name automatically.
#Nothing to do

sale / sale.order / section_id (many2one) : DEL relation: crm.case.section
sale / sale.order / team_id (many2one) : NEW relation: crm.team
#TODO : section_id is now team_id
#Done : renamed the column to new column team_id.

sale / sale.order / state (selection) : selection_keys is now '['cancel', 'done', 'draft', 'sale', 'sent']' ('['cancel', 'done', 'draft', 'invoice_except', 'manual', 'progress', 'sent', 'shipping_except', 'waiting_date']')
TODO : To map the state values as per new values.
#Done : Mapped the values as per new state values

sale / sale.order / validity_date (date) : NEW
Expand All @@ -65,30 +58,29 @@ sale / sale.order.line / address_allotment_id (many2one): DEL r
#Nothing To Do : Functionality removed now no longer needed.

sale / sale.order.line / delay (float) : was renamed to customer_lead [nothing to to]
#Nothing To Do : ORM will change the name automatically.
#Nothing to do

sale / sale.order.line / product_id (many2one) : now required
#TODO : Maybe To create product from description. (need more analysis on this)
#Done : Created Service type product and assigned sale.order.line where product_id is null

sale / sale.order.line / product_uos (many2one) : DEL relation: product.uom
#TODO : Moved to product_uos module (so saved it for later use.)

sale / sale.order.line / product_uos_qty (float) : DEL
#TODO : Moved to product_uos module (so saved it for later use.)
#Moved to product_uos module

sale / sale.order.line / qty_delivered (float) : NEW
#Nothing To Do : New Functionality added.

sale / sale.order.line / state (selection) : selection_keys is now 'function' ('['cancel', 'confirmed', 'done', 'draft', 'exception']')
TODO : To map the state values as per new values.
#Done : Mapped the values as per new state values
#Done : calculated related field to order state

sale / sale.order.line / th_weight (float) : DEL
#Nothing To Do : Functionality removed now no longer needed.

---XML records in module 'sale'---
DEL email.template: sale.email_template_edi_sale
NEW mail.template: sale.email_template_edi_sale
# Done: covered in mail module

NEW ir.actions.act_window: sale.action_orders_to_invoice
NEW ir.actions.act_window: sale.action_orders_to_invoice_salesteams
NEW ir.actions.act_window: sale.action_orders_upselling
Expand All @@ -115,7 +107,6 @@ DEL ir.model.access: sale.access_product_pricelist_version_sale_manager
DEL ir.model.access: sale.access_product_ul_sale_manager
DEL ir.model.access: sale.access_res_partner_bank_type_field_user
DEL ir.model.access: sale.access_res_partner_bank_type_user
DEL ir.sequence.type: sale.seq_type_sale_order
NEW ir.ui.menu: base.menu_sale_general_settings
NEW ir.ui.menu: base.menu_sales_config
NEW ir.ui.menu: sale.menu_sale_invoicing
Expand All @@ -139,14 +130,22 @@ DEL ir.ui.view: sale.view_sale_order_line_make_invoice
DEL ir.ui.view: sale.view_sale_order_make_invoice
DEL ir.ui.view: sale.view_sales_order_uninvoiced_line_filter
DEL ir.values: sale.sale_order_make_invoice
NEW web.tip: sale.sale_tip_1
NEW web.tip: sale.sale_tip_2
# Nothing to do: updated data elements

DEL ir.sequence.type: sale.seq_type_sale_order
# Nothing to do: obsolete concept to provide a value for the sequence' code field

NEW mail.message.subtype: sale.mt_salesteam_invoice_confirmed
NEW mail.message.subtype: sale.mt_salesteam_invoice_created
NEW mail.template: sale.email_template_edi_sale
# Done: as these are default subtypes, add to existing subscriptions at least on the sales teams (if not on existing invoices)

NEW res.groups: sale.group_display_incoterm
DEL res.groups: sale.group_invoice_so_lines
NEW web.tip: sale.sale_tip_1
NEW web.tip: sale.sale_tip_2
# Done: check if incoterms are used. If so, add implied group to Employee group as per res_config

DEL res.groups: sale.group_invoice_so_lines
# Nothing to do: every sale user can now access this data

DEL workflow: sale.wkf_sale
DEL workflow.activity: sale.act_cancel
Expand Down Expand Up @@ -195,5 +194,4 @@ DEL workflow.transition: sale.trans_wait_invoice_invoice_manual
DEL workflow.transition: sale.trans_wait_ship_cancel3
DEL workflow.transition: sale.trans_wait_ship_done
DEL workflow.transition: sale.trans_wait_ship_ship

#Done : THE WORKFLOW IS REMOVED WITH THE DELETE WORKFLOW FUNCTION
#Nothing to do. Workflow is left for further reference in other modules
91 changes: 58 additions & 33 deletions addons/sale/migrations/9.0.1.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,77 @@
# -*- coding: utf-8 -*-
# © 2015 Eficent Business and IT Consulting Services S.L. -
# © 2016 Eficent Business and IT Consulting Services S.L. -
# Jordi Ballester Alomar
# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# © 2016 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# © 2016 Opener B.V. - Stefan Rijnhart
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from openupgradelib import openupgrade
import logging
from openerp import api, pooler, SUPERUSER_ID
from datetime import datetime
from openerp import api, SUPERUSER_ID


def set_invoice_policy(cr):
# used to generate the invoice, set it to 'order' which will create the invoice as per ordered quantities.
openupgrade.logged_query(cr, """
UPDATE product_template
SET invoice_policy = 'order'
WHERE invoice_policy IS NULL;
""")
def set_invoice_policy(env):
value = env['ir.values'].get_default('sale.order', 'order_policy')
policy = 'delivery' if value == 'picking' else 'order'
env['ir.values'].set_default('product.template', 'invoice_policy', policy)
openupgrade.logged_query(
env.cr,
"""UPDATE product_template
SET invoice_policy = %s
WHERE invoice_policy IS NULL AND type != 'service';""",
(policy,))
openupgrade.logged_query(
env.cr,
"""UPDATE product_template
SET invoice_policy = 'order'
WHERE invoice_policy IS NULL""")


def set_track_service(cr):
# Set all records to manual.
""" Set all records to manual """
openupgrade.logged_query(cr, """
UPDATE product_template
SET track_service = 'manual'
WHERE track_service IS NULL;
UPDATE product_template
SET track_service = 'manual'
WHERE track_service IS NULL;
""")

def map_order_state(cr):
# Mapping values for state field in sale.order and sale.order.line
openupgrade.map_values(
cr, openupgrade.get_legacy_name('state'), 'state',
[('waiting_date', 'sale'), ('progress', 'sale'), ('manual', 'sale'), ('shipping_except', 'sale'), ('invoice_except', 'sale')],
table='sale_order')

openupgrade.map_values(
cr, openupgrade.get_legacy_name('state'), 'state',
[('confirmed', 'sale'), ('exception', 'sale')],
table='sale_order_line')
def set_dummy_product(env):
product = env['product.product'].create({
'name': 'Any product',
'type': 'service',
'order_policy': 'manual',
})
env.cr.execute(
"""UPDATE sale_order_line
SET product_id = %s WHERE product_id IS NULL""",
(product.id,))


def set_incoterm(env):
""" Set the new Incoterm configuration option if incoterms
are used at all in this database. """
env.cr.execute("SELECT incoterm FROM sale_order "
"WHERE incoterm IS NOT NULL")
if env.cr.fetchone():
env.ref('base.group_employee').write({
'implied_ids': [(4, env.ref('sale.group_display_incoterm').id)]})


def set_crm_team_message_types(env):
""" Add two new default message types to existing subscriptions """
env['mail.followers'].search([('res_model', '=', 'crm.team')]).write(
{'subtype_ids': [
(4, env.ref('sale.mt_salesteam_invoice_confirmed').id),
(4, env.ref('sale.mt_salesteam_invoice_created').id)]})

def product_id_env(env):
product = env['product.product'].create({'name': 'Service Product', 'type': 'service'})
env.cr.execute("""UPDATE sale_order_line SET product_id = %s WHERE product_id IS NULL""" % product.id)

@openupgrade.migrate()
def migrate(cr, version):
pool = pooler.get_pool(cr.dbname)
env = api.Environment(cr, SUPERUSER_ID, {})
product_id_env(env)
set_invoice_policy(cr)
set_dummy_product(env)
set_invoice_policy(env)
set_track_service(cr)
map_order_state(cr)
set_incoterm(env)
set_crm_team_message_types(env)
openupgrade.load_data(
cr, 'sale', 'migrations/9.0.1.0/noupdate_changes.xml')
37 changes: 25 additions & 12 deletions addons/sale/migrations/9.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
# -*- coding: utf-8 -*-
# © 2014 Microcom
# © 2015 Eficent Business and IT Consulting Services S.L. -
# © 2015 Microcom
# © 2016 Eficent Business and IT Consulting Services S.L. -
# Jordi Ballester Alomar
# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# © 2016 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# © 2016 Opener B.V. - Stefan Rijnhart
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from openupgradelib import openupgrade


column_renames = {
'sale_order': [
('section_id', 'team_id'),
],
'account_invoice': [
('section_id', 'team_id'),
],
# 'invoice_id' in 8.0 already referred to invoice lines
'sale_order_line_invoice_rel': [
('invoice_id', 'invoice_line_id'),
],
# These columns are moved to product_uos module so they are kept to be recovered later.
'sale_order_line': [
('product_uos', None),
],
'sale_order_line': [
('product_uos_qty', None),
]
}

column_copies = {
Expand All @@ -35,8 +30,26 @@
],
}


def map_order_state(cr):
""" Map values for state field in sale.order and sale.order.line.
Do this in the pre script because it influences the automatic calculation
of the computed fields wrt. invoicing """
openupgrade.map_values(
cr, openupgrade.get_legacy_name('state'), 'state', [
('waiting_date', 'sale'), ('progress', 'sale'),
('manual', 'sale'), ('shipping_except', 'sale'),
('invoice_except', 'sale')],
table='sale_order')
cr.execute("""
UPDATE sale_order_line sol
SET state = so.state
FROM sale_order so
WHERE sol.order_id = so.id""")


@openupgrade.migrate()
def migrate(cr, version):
openupgrade.delete_model_workflow(cr, 'sale.order')
openupgrade.rename_columns(cr, column_renames)
openupgrade.copy_columns(cr, column_copies)
map_order_state(cr)
2 changes: 1 addition & 1 deletion openerp/openupgrade/doc/source/modules80-90.rst
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ Status :
+-----------------------------------+-----------------------------------+
|resource | |
+-----------------------------------+-----------------------------------+
|sale | Partial |
|sale | Done |
+-----------------------------------+-----------------------------------+
|sale_crm | |
+-----------------------------------+-----------------------------------+
Expand Down

0 comments on commit 85f767c

Please sign in to comment.