-
-
Notifications
You must be signed in to change notification settings - Fork 705
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
Showing
5 changed files
with
162 additions
and
11 deletions.
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
33 changes: 31 additions & 2 deletions
33
openupgrade_scripts/scripts/stock/17.0.1.1/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 |
---|---|---|
@@ -1,14 +1,43 @@ | ||
# Copyright 2024 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from openupgradelib import openupgrade | ||
|
||
_field_renames = [ | ||
("stock.move", "stock_move", "quantity_done", "quantity"), | ||
("stock.move.line", "stock_move_line", "qty_done", "quantity"), | ||
] | ||
|
||
_column_copies = { | ||
"stock_move_line": [ | ||
("qty_done", "quantity", None), | ||
] | ||
} | ||
|
||
|
||
def fix_move_line_quantity(env): | ||
""" | ||
v17 combines what used to be reserved_qty and qty_done. | ||
We assume that we shouldn't touch an original qty_done on | ||
done moves, but that we can best reflect the v16 state of | ||
lines being worked on by adding reserved_qty to the new | ||
quantity column, which was qty_done in v16 | ||
In post-migration, we'll recompute the quantity field of | ||
moves affected. | ||
""" | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE stock_move_line | ||
SET quantity = quantity + reserved_qty | ||
WHERE | ||
state IN ('assigned', 'partially_available') | ||
AND reserved_qty <> 0 | ||
""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
openupgrade.rename_fields(env, _field_renames) | ||
openupgrade.copy_columns(env.cr, _column_copies) | ||
fix_move_line_quantity(env) |
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
16 changes: 16 additions & 0 deletions
16
openupgrade_scripts/scripts/stock/tests/data_stock_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,16 @@ | ||
env = locals().get("env") | ||
# return a picking so that we have something to migrate | ||
picking = env.ref("stock.outgoing_shipment_main_warehouse1") | ||
return_wizard = ( | ||
env["stock.return.picking"] | ||
.with_context( | ||
active_id=picking.id, | ||
active_ids=picking.ids, | ||
active_model=picking._name, | ||
) | ||
.create({}) | ||
) | ||
return_wizard._onchange_picking_id() | ||
return_wizard._create_returns() | ||
|
||
env.cr.commit() |
31 changes: 31 additions & 0 deletions
31
openupgrade_scripts/scripts/stock/tests/test_stock_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,31 @@ | ||
from odoo.tests import TransactionCase | ||
|
||
from odoo.addons.openupgrade_framework import openupgrade_test | ||
|
||
|
||
@openupgrade_test | ||
class TestStockMigration(TransactionCase): | ||
def test_move_quantity(self): | ||
""" | ||
Test that we add reserved_qty to quantity for assigned moves | ||
""" | ||
picking = self.env.ref("stock.outgoing_shipment_main_warehouse4") | ||
self.assertEqual(picking.move_ids.quantity, 16) | ||
picking = self.env.ref("stock.incomming_shipment2") | ||
self.assertEqual(picking.move_ids.quantity, 125) | ||
|
||
def test_returned_picking(self): | ||
""" | ||
Test that we correctly link returned pickings to their origin picking | ||
""" | ||
returned_picking = self.env.ref("stock.outgoing_shipment_main_warehouse1") | ||
self.assertTrue(returned_picking.return_ids) | ||
|
||
def test_return_location(self): | ||
""" | ||
Test that we set the default return location for pickings from the warehouse's | ||
return picking type from v16 | ||
""" | ||
picking_type = self.env.ref("stock.picking_type_in") | ||
stock_location = self.env.ref("stock.stock_location_stock") | ||
self.assertEqual(picking_type.default_location_return_id, stock_location) |