-
-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IMP] rma: custom route for replace action #434
Open
sbejaoui
wants to merge
1
commit into
OCA:16.0
Choose a base branch
from
acsone:16.0-rma_custom_replace_route-sbj
base: 16.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
# Copyright 2023 Michael Tietz (MT Software) <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import Command | ||
from odoo.exceptions import UserError, ValidationError | ||
from odoo.tests import Form, TransactionCase, new_test_user, users | ||
from odoo.tools import mute_logger | ||
|
@@ -108,6 +109,20 @@ def _create_confirm_receive( | |
rma.reception_move_id.picking_id._action_done() | ||
return rma | ||
|
||
def _receive_and_replace(self, partner, product, qty, location): | ||
rma = self._create_confirm_receive(partner, product, qty, location) | ||
delivery_form = Form( | ||
self.env["rma.delivery.wizard"].with_context( | ||
active_ids=rma.ids, | ||
rma_delivery_type="replace", | ||
) | ||
) | ||
delivery_form.product_id = rma.product_id | ||
delivery_form.product_uom_qty = qty | ||
delivery_wizard = delivery_form.save() | ||
delivery_wizard.action_deliver() | ||
return rma | ||
|
||
def _create_delivery(self): | ||
picking_type = self.env["stock.picking.type"].search( | ||
[ | ||
|
@@ -848,3 +863,53 @@ def test_autoconfirm_email(self): | |
) | ||
self.assertTrue(rma.name in mail_receipt.subject) | ||
self.assertTrue("products received" in mail_receipt.subject) | ||
|
||
def test_replace_picking_type(self): | ||
""" | ||
Test that by default, the replace operation uses the default delivery route, | ||
meaning the warehouse's default delivery picking type is applied. | ||
|
||
RMA replacement orders are not separated from regular deliveries, and both use | ||
the same picking type. | ||
""" | ||
rma = self._receive_and_replace(self.partner, self.product, 2, self.rma_loc) | ||
rma_in_type = self.warehouse.rma_in_type_id | ||
out_type = self.warehouse.out_type_id | ||
self.assertEqual(rma.reception_move_id.picking_type_id, rma_in_type) | ||
self.assertEqual(rma.delivery_move_ids.picking_type_id, out_type) | ||
|
||
def test_replace_picking_type_custom_picking_type(self): | ||
""" | ||
Test that when configured to use a custom route, the replace operation uses a | ||
custom picking type, separating RMA replacement orders from regular deliveries. | ||
|
||
The custom picking type is applied specifically for RMA replacements, instead | ||
of the default delivery picking type. | ||
""" | ||
rma_in_type = self.warehouse.rma_in_type_id | ||
rma_out_type = self.warehouse.rma_out_type_id | ||
route = self.env["stock.route"].create( | ||
{ | ||
"name": "RMA OUT replace", | ||
"active": True, | ||
"sequence": 100, | ||
"product_selectable": True, | ||
"rule_ids": [ | ||
Command.create( | ||
{ | ||
"name": "RMA OUT", | ||
"action": "pull", | ||
"picking_type_id": rma_out_type.id, | ||
"location_src_id": self.warehouse.lot_stock_id.id, | ||
"location_dest_id": self.env.ref( | ||
"stock.stock_location_customers" | ||
).id, | ||
}, | ||
) | ||
], | ||
} | ||
) | ||
self.warehouse.rma_out_replace_route_id = route | ||
rma = self._receive_and_replace(self.partner, self.product, 2, self.rma_loc) | ||
self.assertEqual(rma.reception_move_id.picking_type_id, rma_in_type) | ||
self.assertEqual(rma.delivery_move_ids.picking_type_id, rma_out_type) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbejaoui Should'nt we use the mechanisms to create that route (see
_get_route_values()
) ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the common use case is to use the default delivery route, which is why I didn't create or assign a custom route to the warehouse. If more people feel that having a custom route for RMA delivery by default is necessary, I will make the change.