Skip to content

Commit

Permalink
[OU-FIX] rma: Improve migration script to create picking types (only …
Browse files Browse the repository at this point in the history
…if not set)

Fixes OCA#395
  • Loading branch information
victoralmau committed Jun 20, 2024
1 parent 6713de3 commit 75d7bf1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
5 changes: 4 additions & 1 deletion rma/migrations/16.0.1.4.0/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

@openupgrade.migrate()
def migrate(env, version):
"""Similar behavior to create_rma_routes of post_init_hook."""
"""Similar behavior to cread all data of post_init_hook."""
warehouses = env["stock.warehouse"].search([])
warehouses = warehouses.with_context(rma_post_init_hook=True)
for wh in warehouses:
if not wh.rma_in_type_id or not wh.rma_out_type_id:
data = wh._create_or_update_sequences_and_picking_types()
wh.write(data)
route_vals = wh._create_or_update_route()
wh.write(route_vals)
13 changes: 7 additions & 6 deletions rma/models/stock_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ def _get_picking_type_create_values(self, max_sequence):

def _get_picking_type_update_values(self):
data = super()._get_picking_type_update_values()
data.update(
{
"rma_in_type_id": {"default_location_dest_id": self.rma_loc_id.id},
"rma_out_type_id": {"default_location_src_id": self.rma_loc_id.id},
}
)
picking_types = {
"rma_in_type_id": {"default_location_dest_id": self.rma_loc_id.id},
"rma_out_type_id": {"default_location_src_id": self.rma_loc_id.id},
}
if self.env.context.get("rma_post_init_hook"):
return picking_types
data.update(picking_types)
return data

def _create_or_update_sequences_and_picking_types(self):
Expand Down
24 changes: 24 additions & 0 deletions rma/tests/test_rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from odoo.exceptions import UserError, ValidationError
from odoo.tests import Form, TransactionCase, new_test_user, users
from odoo.tools import mute_logger

from .. import hooks

Expand Down Expand Up @@ -155,6 +156,28 @@ def test_post_init_hook(self):
self.assertTrue(warehouse.rma_in_route_id)
self.assertTrue(warehouse.rma_out_route_id)

@mute_logger("odoo.models.unlink")
def test_migration_160140(self):
warehouses = self.env["stock.warehouse"].search([])
warehouses = warehouses.with_context(rma_post_init_hook=True)
for wh in warehouses:
wh.rma_in_route_id.unlink()
wh.rma_out_route_id.unlink()
wh.rma_loc_id.unlink()
wh.rma_in_type_id.unlink()
wh.rma_out_type_id.unlink()
data = wh._create_or_update_sequences_and_picking_types()
wh.write(data)
self.assertTrue(wh.rma_in_type_id)
self.assertTrue(wh.rma_out_type_id)
self.assertTrue(wh.rma_loc_id)
self.assertFalse(wh.rma_in_route_id)
self.assertFalse(wh.rma_out_route_id)
route_vals = wh._create_or_update_route()
wh.write(route_vals)
self.assertTrue(wh.rma_in_route_id)
self.assertTrue(wh.rma_out_route_id)

def test_rma_replace_pick_ship(self):
self.warehouse.write({"delivery_steps": "pick_ship"})
rma = self._create_rma(self.partner, self.product, 1, self.rma_loc)
Expand Down Expand Up @@ -761,6 +784,7 @@ def test_split(self):
self.assertEqual(new_rma.move_id.quantity_done, 10)
self.assertEqual(new_rma.reception_move_id.quantity_done, 10)

@mute_logger("odoo.models.unlink")
def test_rma_to_receive_on_delete_invoice(self):
rma = self._create_confirm_receive(self.partner, self.product, 10, self.rma_loc)
rma.action_refund()
Expand Down

0 comments on commit 75d7bf1

Please sign in to comment.