Skip to content
Open
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
22 changes: 10 additions & 12 deletions addons/stock/migrations/10.0.1.1/openupgrade_analysis_work.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ stock / barcode.rule / type (False) : NEW se
# NOTHING TO DO

stock / procurement.rule / picking_type_id (many2one) : now required
# TODO: pre-migration. Default to some value, guessing by looking at source
# Done: post-migration. Default to some value, guessing by looking at source
# and destination locations, and warehouse.

stock / procurement.rule / route_sequence (float) : type is now 'integer' ('float')
# TODO: pre-migration: copy column
# TODO: post-migration: move values from old column
# Done: pre-migration: copy column and then convert float to integer

stock / product.product / stock_move_ids (one2many) : NEW relation: stock.move
stock / product.product / stock_quant_ids (one2many) : NEW relation: stock.quant
# NOTHING TO DO

stock / product.template / location_id (many2one) : not a function anymore
stock / product.template / warehouse_id (many2one) : not a function anymore
# TODO: ??? IN V9 were defined as fields.dummy
# NOTHING TO DO as in v9 were dummy fields (existed only for backwards compatibility)

stock / product.template / type (False) : NEW selection_keys: ['consu', 'product', 'service'], mode: modify
# NOTHING TO DO
Expand All @@ -29,17 +29,16 @@ stock / stock.inventory.line / state (char) : type i
# NOTHING TO DO

stock / stock.location.path / auto (selection) : selection_keys is now '['manual', 'transparent']' ('['auto', 'manual', 'transparent']')
# TODO: pre-migration. copy column
# TODO: post-migration. Move 'auto' to some other value
# Done: post-migration. move values 'auto' to 'manual'

stock / stock.location.path / route_sequence (float) : type is now 'integer' ('float')
# TODO: pre-migration. copy column
# TODO: post-migration. copy values to new field converting to integer
# Done: pre-migration: copy column and then convert float to integer

stock / stock.move / ordered_qty (float) : NEW
# TODO: post-migration. Default to product_uom_qty
# Done: post-migration. Default to product_uom_qty

stock / stock.pack.operation / ordered_qty (float) : NEW
# TODO: post-migration. Default to product_uom_qty
# Done: post-migration. Default to product_qty

stock / stock.pack.operation / processed_boolean (boolean) : was renamed to is_done [nothing to do]
# NOTHING TO DO
Expand Down Expand Up @@ -69,8 +68,7 @@ stock / stock.scrap / product_uom_id (many2one) : NEW re
stock / stock.scrap / scrap_location_id (many2one) : NEW relation: stock.location
stock / stock.scrap / scrap_qty (float) : NEW required: required, req_default: function
stock / stock.scrap / state (selection) : NEW selection_keys: ['done', 'draft']
# TODO: Create one record for each move that had as destionation a scrap
# location
# Done: post-migration: Create one record for each move linked to a scrap location

stock / stock.warehouse / active (boolean) : NEW
stock / stock.warehouse / resupply_from_wh (boolean) : DEL
Expand Down
132 changes: 132 additions & 0 deletions addons/stock/migrations/10.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Trescloud <http://trescloud.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade


def map_location_auto(cr):
openupgrade.map_values(
cr,
openupgrade.get_legacy_name('auto'), 'auto',
[('auto', 'manual')],
table='stock_location_path', write='sql')


def update_picking_type_id(env):
"""Updates picking_type_id, defaulting to some value, guessing by looking
at source and destination locations, and warehouse.
:param env: environment variable (self)
"""
# load xml data to be used for filling in missing info
xml_stock_picking_type_int = env.ref("stock.picking_type_internal", False)
xml_stock_picking_type_out = env.ref("stock.picking_type_out", False)
xml_stock_picking_type_in = env.ref("stock.picking_type_in", False)
xml_stock_picking_type_manufacturing = env.ref(
"mrp.picking_type_manufacturing", False
)
# verify for each procurement rule to set
procurement_rules_to_set = env['procurement.rule'].search([])
for procurement_rule in procurement_rules_to_set:
if not procurement_rule.picking_type_id:
picking_type_id = False
env.cr.execute(
"""
SELECT id from stock_picking_type
WHERE warehouse_id = %s AND
default_location_dest_id = %s AND
default_location_src_id = %s""" % (
procurement_rule.warehouse_id,
procurement_rule.location_id,
procurement_rule.location_src_id,
)
)
picking_type_ids = env.cr.fetchone()
if picking_type_ids:
picking_type_id = picking_type_ids[0]

# fallback values when everything else fails
if not picking_type_id:
if procurement_rule.action == 'buy':
# location_src_id is not considered
# (as is not mandatory in this case)
if xml_stock_picking_type_in:
picking_type_id = xml_stock_picking_type_in.id
elif procurement_rule.action == 'move':
if procurement_rule.location_id and procurement_rule.\
location_id.usage == 'customer':
# delivery case to a customer location
if xml_stock_picking_type_out:
picking_type_id = xml_stock_picking_type_out.id
else:
if xml_stock_picking_type_int:
picking_type_id = xml_stock_picking_type_int.id

# special case for mrp module put here for not repeating the logic.
# If mrp not installed won't break
elif procurement_rule.action == 'manufacture':
if xml_stock_picking_type_manufacturing:
picking_type_id = xml_stock_picking_type_manufacturing.id

procurement_rule.write({'picking_type_id': picking_type_id})


def update_ordered_qty(cr):
""" Set the value of new field ordered_qty as:
- for stock moves the value of field product_uom_qty
- for stock_pack_operation the value of product_qty
:param cr: cursor variable (self.env)
"""

cr.execute(
"UPDATE stock_move SET ordered_qty = product_uom_qty")
cr.execute(
"UPDATE stock_pack_operation SET ordered_qty = product_qty")


def populate_stock_scrap(cr):
"""
Fills up new object "stock.scrap" based on moves linked to scrap location
:param cr: cursor variable (self.env)
"""
cr.execute(
"""
SELECT id from stock_location
WHERE scrap_location is True
"""
)
scrap_location_ids = cr.fetchone()
# Use SQL instead of ORM, otherwise stock_scrap.create() will create a
# duplicated stock move
cr.execute(
"""
INSERT INTO stock_scrap
(date_expected,create_date,location_id,lot_id,move_id,
name,origin,owner_id,package_id,picking_id,product_id,
product_uom_id,scrap_location_id,scrap_qty,state)
WITH Q1 as (SELECT DISTINCT sq.package_id,sr.move_id
FROM stock_quant_move_rel sr
INNER JOIN stock_quant as sq ON sq.id = sr.quant_id),
Q2 as (SELECT COUNT(Q1.package_id) as n,Q1.move_id
FROM Q1
GROUP BY Q1.move_id),
Q3 as (SELECT DISTINCT Q2.move_id,sq.package_id
FROM Q2
LEFT JOIN stock_quant_move_rel sr ON sr.move_id = Q2.move_id
LEFT JOIN stock_quant as sq ON sq.id = sr.quant_id
WHERE Q2.n = 1)
SELECT date_expected,create_date,location_id,restrict_lot_id,id,
name,origin,restrict_partner_id,Q3.package_id,picking_id,
product_id,product_uom,location_dest_id,product_uom_qty,state
FROM stock_move sm
LEFT JOIN Q3 ON sm.id = Q3.move_id
WHERE location_dest_id IN %s AND state = 'done'
""", (scrap_location_ids,))


@openupgrade.migrate(use_env=True)
def migrate(env, version):
cr = env.cr
map_location_auto(cr)
update_picking_type_id(env)
update_ordered_qty(cr)
populate_stock_scrap(cr)
22 changes: 22 additions & 0 deletions addons/stock/migrations/10.0.1.1/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Trescloud <http://trescloud.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade

column_copies = {
'procurement_rule': [
('route_sequence', None, None),
],
'stock_location_path': [
('auto', None, None),
('route_sequence', None, None),
],
}


@openupgrade.migrate(use_env=True)
def migrate(env, version):
cr = env.cr
openupgrade.copy_columns(cr, column_copies)
openupgrade.float_to_integer(cr, 'procurement_rule', 'route_sequence')
openupgrade.float_to_integer(cr, 'stock_location_path', 'route_sequence')
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 @@ -453,7 +453,7 @@ missing in the new release are marked with |del|.
+-----------------------------------+-----------------------------------+
|sales_team | Done |
+-----------------------------------+-----------------------------------+
|stock | |
|stock | Done |
+-----------------------------------+-----------------------------------+
|stock_account | Nothing to do |
+-----------------------------------+-----------------------------------+
Expand Down