Skip to content

Commit 4cb77f6

Browse files
[OU-ADD] stock
1 parent e7e2180 commit 4cb77f6

4 files changed

Lines changed: 314 additions & 1 deletion

File tree

docsource/modules170-180.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ Module coverage 17.0 -> 18.0
10241024
+---------------------------------------------------+----------------------+-------------------------------------------------+
10251025
| spreadsheet_dashboard_website_sale_slides | | |
10261026
+---------------------------------------------------+----------------------+-------------------------------------------------+
1027-
| stock | | |
1027+
| stock | Done | |
10281028
+---------------------------------------------------+----------------------+-------------------------------------------------+
10291029
| stock_account | | |
10301030
+---------------------------------------------------+----------------------+-------------------------------------------------+
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from openupgradelib import openupgrade, openupgrade_180
4+
5+
6+
def convert_company_dependent(env):
7+
openupgrade_180.convert_company_dependent(
8+
env, "product.template", "property_stock_inventory"
9+
)
10+
openupgrade_180.convert_company_dependent(
11+
env, "product.template", "property_stock_production"
12+
)
13+
openupgrade_180.convert_company_dependent(env, "product.template", "responsible_id")
14+
openupgrade_180.convert_company_dependent(
15+
env, "res.partner", "property_stock_customer"
16+
)
17+
openupgrade_180.convert_company_dependent(
18+
env, "res.partner", "property_stock_supplier"
19+
)
20+
21+
22+
def _create_default_new_types_for_all_warehouses(env):
23+
# method mainly based on _create_or_update_sequences_and_picking_types()
24+
all_warehouses = env["stock.warehouse"].with_context(active_test=False).search([])
25+
for wh in all_warehouses:
26+
sequence_data = wh._get_sequence_values()
27+
for field in ["qc_type_id", "store_type_id", "xdock_type_id"]:
28+
# choose the next available color for the operation types of this warehouse
29+
all_used_colors = [
30+
res["color"]
31+
for res in env["stock.picking.type"]
32+
.with_context(active_test=False)
33+
.search_read(
34+
[("warehouse_id", "!=", False), ("color", "!=", False)],
35+
["color"],
36+
order="color",
37+
)
38+
]
39+
available_colors = [
40+
zef for zef in range(0, 12) if zef not in all_used_colors
41+
]
42+
color = available_colors[0] if available_colors else 0
43+
# suit for each warehouse: reception, internal, pick, pack, ship
44+
max_sequence = (
45+
env["stock.picking.type"]
46+
.with_context(active_test=False)
47+
.search_read(
48+
[("sequence", "!=", False)],
49+
["sequence"],
50+
limit=1,
51+
order="sequence desc",
52+
)
53+
)
54+
max_sequence = max_sequence and max_sequence[0]["sequence"] or 0
55+
values = wh._get_picking_type_update_values()[field]
56+
create_data, _ = wh._get_picking_type_create_values(max_sequence)
57+
values.update(create_data[field])
58+
sequence = env["ir.sequence"].create(sequence_data[field])
59+
values.update(
60+
warehouse_id=wh.id,
61+
color=color,
62+
sequence_id=sequence.id,
63+
sequence=max_sequence + 1,
64+
company_id=wh.company_id.id,
65+
active=wh.active,
66+
)
67+
# create return picking type
68+
picking_type_id = env["stock.picking.type"].create(values).id
69+
# update return picking type for warehouse
70+
wh.write({field: picking_type_id})
71+
72+
73+
def _set_inter_company_locations(env):
74+
"""See https://github.com/odoo/odoo/commit/08536d687880ca6d9ad5c37b639c0ad4c2599d74"""
75+
companies = env["res.company"].search([])
76+
if companies > 1:
77+
inter_company_location = env.ref("stock.stock_location_inter_company")
78+
if not inter_company_location.active:
79+
inter_company_location.sudo().write({"active": True})
80+
for company in companies:
81+
company.sudo()._set_per_company_inter_company_locations(
82+
inter_company_location
83+
)
84+
85+
86+
@openupgrade.migrate()
87+
def migrate(env, version):
88+
convert_company_dependent(env)
89+
_create_default_new_types_for_all_warehouses(env)
90+
_set_inter_company_locations(env)
91+
openupgrade.load_data(env, "stock", "18.0.1.1/noupdate_changes.xml")
92+
openupgrade.delete_records_safely_by_xml_id(
93+
env, ["stock.property_stock_customer", "stock.property_stock_supplier"]
94+
)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from openupgradelib import openupgrade
4+
5+
_field_renames = [
6+
("stock.move", "stock_move", "location_dest_id", "location_final_id"),
7+
(
8+
"stock.warehouse.orderpoint",
9+
"stock_warehouse_orderpoint",
10+
"qty_to_order",
11+
"qty_to_order_manual",
12+
),
13+
]
14+
15+
_xmlid_renames = [
16+
("stock.stock_location_inter_wh", "stock.stock_location_inter_company"),
17+
]
18+
19+
_new_columns = [
20+
("product.template", "is_storable", "boolean", False),
21+
("stock.move", "location_dest_id", "many2one"),
22+
("stock.rule", "location_dest_from_rule", "boolean", False),
23+
("stock.picking.type", "move_type", "selection", "direct"),
24+
("stock.putaway.rule", "sublocation", "selection", "no"),
25+
]
26+
27+
28+
def fill_product_template_is_storable(env):
29+
openupgrade.logged_query(
30+
env.cr,
31+
"""
32+
UPDATE product_template
33+
SET is_storable = TRUE, type = 'consu'
34+
WHERE type = 'product'""",
35+
)
36+
37+
38+
def fill_stock_move_location_dest_id(env):
39+
openupgrade.logged_query(
40+
env.cr,
41+
"""
42+
UPDATE stock_move sm2
43+
SET location_dest_id = COALESCE(sp.location_dest_id,
44+
spt.default_location_dest_id, sm.location_final_id)
45+
FROM stock_move sm
46+
LEFT JOIN stock_picking sp ON sm.picking_id = sp.id
47+
LEFT JOIN stock_picking_type spt ON sm.picking_type_id = spt.id
48+
WHERE sm2.id = sm.id
49+
""",
50+
)
51+
openupgrade.logged_query(
52+
env.cr,
53+
"""
54+
UPDATE stock_rule sr
55+
SET location_dest_from_rule = TRUE
56+
FROM stock_move sm
57+
WHERE sm.rule_id = sr.id
58+
AND sm.location_dest_id != sm.location_final_id
59+
AND sr.action IN ('pull', 'pull_push')
60+
""",
61+
)
62+
63+
64+
def fill_stock_putaway_rule_sublocation(env):
65+
openupgrade.logged_query(
66+
env.cr,
67+
"""
68+
UPDATE stock_putaway_rule
69+
SET sublocation = 'closest_location'
70+
WHERE storage_category_id is not null""",
71+
)
72+
73+
74+
@openupgrade.migrate()
75+
def migrate(env, version=None):
76+
openupgrade.rename_fields(env, _field_renames)
77+
openupgrade.rename_xmlids(env.cr, _xmlid_renames)
78+
openupgrade.add_columns(env, _new_columns)
79+
fill_product_template_is_storable(env)
80+
fill_stock_move_location_dest_id(env)
81+
fill_stock_putaway_rule_sublocation(env)
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
---Models in module 'stock'---
2+
obsolete model stock.assign.serial [transient]
3+
obsolete model stock.scheduler.compute [transient]
4+
new model stock.lot.report [sql_view]
5+
new model stock.replenish.mixin [abstract]
6+
new model stock.scrap.reason.tag
7+
# NOTHING TO DO
8+
9+
---Fields in module 'stock'---
10+
stock / product.template / detailed_type (False) : DEL selection_keys: ['consu', 'product', 'service'], mode: modify
11+
stock / product.template / type (False) : DEL selection_keys: ['consu', 'product', 'service'], mode: modify
12+
stock / product.template / is_storable (boolean) : NEW hasdefault: default
13+
# DONE: pre-migration:: pre-create and fill is_storable and move 'product' to 'consu'
14+
15+
stock / product.template / route_from_categ_ids (many2many): table is now 'False' ('stock.route')
16+
# NOTHING TO DO: related field
17+
18+
stock / product.template / property_stock_inventory (many2one): needs conversion to v18-style company dependent
19+
stock / product.template / property_stock_production (many2one): needs conversion to v18-style company dependent
20+
stock / product.template / responsible_id (many2one) : needs conversion to v18-style company dependent
21+
stock / res.partner / property_stock_customer (many2one): needs conversion to v18-style company dependent
22+
stock / res.partner / property_stock_supplier (many2one): needs conversion to v18-style company dependent
23+
# DONE: post-migration: used openupgrade_180.convert_company_dependent
24+
25+
stock / stock.location / return_location (boolean) : DEL
26+
stock / stock.picking.type / default_location_return_id (many2one): DEL relation: stock.location
27+
# NOTHING TO DO: now is using _can_return() method instead
28+
29+
stock / stock.move / location_dest_id (many2one) : now a function
30+
stock / stock.move / location_final_id (many2one) : NEW relation: stock.location
31+
stock / stock.rule / location_dest_from_rule (boolean): NEW hasdefault: default
32+
# DONE: pre-migration: rename location_dest_id to location_final_id, pre-create and fill location_dest_id and location_dest_from_rule
33+
34+
stock / stock.move / never_product_template_attribute_value_ids (many2many): NEW relation: product.template.attribute.value
35+
# NOTHING TO DO: new technical feature
36+
37+
stock / stock.move.line / product_category_name (char) : not stored anymore
38+
# NOTHING TO DO
39+
40+
stock / stock.picking / search_date_category (selection): NEW selection_keys: ['after', 'before', 'day_1', 'day_2', 'today', 'yesterday']
41+
stock / stock.picking / shipping_weight (float) : previously in module stock_delivery
42+
stock / stock.picking / weight_bulk (float) : previously in module stock_delivery
43+
# NOTHING TO DO: not stored
44+
45+
stock / stock.picking.type / _order : _order is now 'is_favorite desc, sequence, id' ('sequence, id')
46+
# NOTHING TO DO: is_favorite is not stored
47+
48+
stock / stock.picking.type / default_location_dest_id (many2one): now required
49+
stock / stock.picking.type / default_location_src_id (many2one): now required
50+
# NOTHING TO DO? (not sure if we can assure it someway)
51+
52+
stock / stock.picking.type / favorite_user_ids (many2many) : NEW relation: res.users
53+
# NOTHING TO DO: new feature
54+
55+
stock / stock.picking.type / move_type (selection) : NEW required, selection_keys: ['direct', 'one'], hasdefault: default
56+
# DONE: pre-migration: pre-create and fill it with default 'direct'
57+
58+
stock / stock.picking.type / show_reserved (boolean) : DEL
59+
# NOTHING TO DO: obsolete, see https://github.com/odoo/odoo/commit/54a795bf11d1ef5d791e587b0c9e4d260b97a79d
60+
61+
stock / stock.putaway.rule / sublocation (selection) : NEW selection_keys: ['closest_location', 'last_used', 'no'], hasdefault: default
62+
# DONE: pre-migration: pre-create and fill it ('no' by default, 'closest_location' if storage_category_id is not null)
63+
64+
stock / stock.quant.package / location_id (many2one) : not a function anymore
65+
# NOTHING TO DO: not sure why marked this way, it's the same in both v17 and v18
66+
67+
stock / stock.quant.package / shipping_weight (float) : previously in module stock_delivery
68+
# NOTHING TO DO
69+
70+
stock / stock.rule / push_domain (char) : NEW
71+
# NOTHING TO DO: new feature
72+
73+
stock / stock.scrap / scrap_reason_tag_ids (many2many): NEW relation: stock.scrap.reason.tag
74+
stock / stock.scrap.reason.tag / color (char) : NEW hasdefault: default
75+
stock / stock.scrap.reason.tag / name (char) : NEW required
76+
stock / stock.scrap.reason.tag / sequence (integer) : NEW hasdefault: default
77+
# NOTHING TO DO: new feature
78+
79+
stock / stock.warehouse / qc_type_id (many2one) : NEW relation: stock.picking.type
80+
stock / stock.warehouse / store_type_id (many2one) : NEW relation: stock.picking.type
81+
stock / stock.warehouse / xdock_type_id (many2one) : NEW relation: stock.picking.type
82+
# DONE: post-migration: created / updated default return type for all warehouses
83+
84+
stock / stock.warehouse.orderpoint / qty_to_order (float) : not stored anymore
85+
stock / stock.warehouse.orderpoint / qty_to_order (float) : now a function
86+
stock / stock.warehouse.orderpoint / qty_to_order_manual (float) : NEW
87+
# DONE: pre-migration: rename qty_to_order to qty_to_order_manual
88+
89+
---XML records in module 'stock'---
90+
NEW digest.tip: stock.digest_tip_stock_1
91+
NEW ir.actions.act_window: stock.action_get_picking_type_ready_moves
92+
NEW ir.actions.act_window: stock.action_inventory_at_date
93+
NEW ir.actions.act_window: stock.action_lot_report
94+
NEW ir.actions.act_window: stock.action_picking_tree_graph
95+
# NOTHING TO DO
96+
97+
ir.actions.act_window: stock.stock_picking_action_picking_type (deleted domain)
98+
# NOTHING TO DO: domain was already empty
99+
100+
DEL ir.actions.act_window: stock.act_assign_serial_numbers
101+
DEL ir.actions.act_window: stock.action_procurement_compute
102+
NEW ir.actions.server: stock.action_install_barcode
103+
NEW ir.actions.server: stock.action_print_labels
104+
NEW ir.actions.server: stock.click_dashboard_graph
105+
NEW ir.actions.server: stock.method_action_picking_tree_incoming
106+
NEW ir.actions.server: stock.method_action_picking_tree_internal
107+
NEW ir.actions.server: stock.method_action_picking_tree_outgoing
108+
NEW ir.actions.server: stock.stock_split_picking
109+
NEW ir.config_parameter: stock.barcode_separator (noupdate)
110+
NEW ir.model.access: stock.access_stock_inventory_adjustment_name_manager
111+
NEW ir.model.access: stock.access_stock_inventory_adjustment_name_user
112+
NEW ir.model.access: stock.access_stock_location_all_user
113+
NEW ir.model.access: stock.access_stock_lot_report
114+
NEW ir.model.access: stock.access_stock_scrap_reason_tag_manager
115+
NEW ir.model.access: stock.access_stock_scrap_reason_tag_user
116+
NEW ir.model.access: stock.access_update_product_attribute_value_stock_manager
117+
DEL ir.model.access: stock.access_stock_assign_serial
118+
DEL ir.model.access: stock.access_stock_inventory_adjustment_name
119+
DEL ir.model.access: stock.access_stock_scheduler_compute
120+
NEW ir.model.constraint: stock.constraint_stock_scrap_reason_tag_name_uniq
121+
DEL ir.ui.menu: stock.menu_reordering_rules_config
122+
NEW ir.ui.view: stock.help_message_template
123+
NEW ir.ui.view: stock.product_template_search_view_inherit_stock
124+
NEW ir.ui.view: stock.search_customer_lot_filter
125+
NEW ir.ui.view: stock.stock_lot_customer_report_view_list
126+
DEL ir.ui.view: stock.view_assign_serial_numbers
127+
DEL ir.ui.view: stock.view_procurement_compute_wizard
128+
DEL res.groups: stock.group_stock_picking_wave
129+
DEL res.groups: stock.group_stock_storage_categories
130+
# NOTHING TO DO
131+
132+
DEL ir.property: stock.property_stock_customer (noupdate)
133+
DEL ir.property: stock.property_stock_supplier (noupdate)
134+
# DONE: post-migration: safely delete records
135+
136+
NEW stock.location: stock.stock_location_inter_company (noupdate)
137+
DEL stock.location: stock.stock_location_inter_wh (noupdate)
138+
# DONE: pre-migration: rename xmlid

0 commit comments

Comments
 (0)