|
3 | 3 | # Copyright 2023 Tecnativa - Pedro M. Baeza
|
4 | 4 | # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
5 | 5 |
|
| 6 | +from odoo.exceptions import ValidationError |
6 | 7 | from odoo.tests import Form, TransactionCase
|
7 | 8 | from odoo.tests.common import users
|
8 | 9 |
|
@@ -222,3 +223,57 @@ def test_report_rma(self):
|
222 | 223 | res = str(res[0])
|
223 | 224 | self.assertRegex(res, self.sale_order.name)
|
224 | 225 | self.assertRegex(res, operation.name)
|
| 226 | + |
| 227 | + def test_manual_refund_no_quantity_impact(self): |
| 228 | + """If the operation is meant for a manual refund, the delivered quantity |
| 229 | + should not be updated.""" |
| 230 | + self.operation.action_create_refund = "manual_after_receipt" |
| 231 | + order = self.sale_order |
| 232 | + order_line = order.order_line |
| 233 | + self.assertEqual(order_line.qty_delivered, 5) |
| 234 | + wizard = self._rma_sale_wizard(order) |
| 235 | + rma = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"]) |
| 236 | + self.assertEqual(rma.reception_move_id.sale_line_id, order_line) |
| 237 | + rma.action_confirm() |
| 238 | + rma.reception_move_id.quantity_done = rma.product_uom_qty |
| 239 | + rma.reception_move_id.picking_id._action_done() |
| 240 | + self.assertEqual(order.order_line.qty_delivered, 5) |
| 241 | + |
| 242 | + def test_no_manual_refund_quantity_impact(self): |
| 243 | + """If the operation is meant for a manual refund, the delivered quantity |
| 244 | + should not be updated.""" |
| 245 | + self.operation.action_create_refund = "update_quantity" |
| 246 | + order = self.sale_order |
| 247 | + order_line = order.order_line |
| 248 | + self.assertEqual(order_line.qty_delivered, 5) |
| 249 | + wizard = self._rma_sale_wizard(order) |
| 250 | + rma = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"]) |
| 251 | + self.assertEqual(rma.reception_move_id.sale_line_id, order_line) |
| 252 | + self.assertFalse(rma.can_be_refunded) |
| 253 | + rma.reception_move_id.quantity_done = rma.product_uom_qty |
| 254 | + rma.reception_move_id.picking_id._action_done() |
| 255 | + self.assertEqual(order.order_line.qty_delivered, 0) |
| 256 | + |
| 257 | + def test_return_different_product(self): |
| 258 | + self.operation.action_create_delivery = False |
| 259 | + self.operation.different_return_product = True |
| 260 | + self.operation.action_create_refund = "update_quantity" |
| 261 | + order = self.sale_order |
| 262 | + order_line = order.order_line |
| 263 | + self.assertEqual(order_line.qty_delivered, 5) |
| 264 | + wizard = self._rma_sale_wizard(order) |
| 265 | + with self.assertRaises( |
| 266 | + ValidationError, msg="Complete the replacement information" |
| 267 | + ): |
| 268 | + rma = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"]) |
| 269 | + return_product = self.product_product.create( |
| 270 | + {"name": "return Product test 1", "type": "product"} |
| 271 | + ) |
| 272 | + wizard.line_ids.return_product_id = return_product |
| 273 | + rma = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"]) |
| 274 | + self.assertEqual(rma.reception_move_id.sale_line_id, order_line) |
| 275 | + self.assertEqual(rma.reception_move_id.product_id, return_product) |
| 276 | + self.assertFalse(rma.can_be_refunded) |
| 277 | + rma.reception_move_id.quantity_done = rma.product_uom_qty |
| 278 | + rma.reception_move_id.picking_id._action_done() |
| 279 | + self.assertEqual(order.order_line.qty_delivered, 5) |
0 commit comments