From 677e89381b97fd5a4785af99f569eb8d46ab93a2 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Sat, 11 Jun 2022 12:09:06 +0200 Subject: [PATCH] [IMP] rma: prevent the creation of zero qty moves --- rma/tests/test_rma.py | 13 +++++++++++++ rma/wizards/rma_make_picking.py | 12 +++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/rma/tests/test_rma.py b/rma/tests/test_rma.py index 4ce48bbe..b277695e 100644 --- a/rma/tests/test_rma.py +++ b/rma/tests/test_rma.py @@ -645,3 +645,16 @@ class TestRma(common.SavepointCase): self.assertTrue(new_line.product_id.categ_id.rma_customer_operation_id) new_line._onchange_product_id() self.assertEqual(new_line.operation_id, rma_operation) + + def test_06_no_zero_qty_moves(self): + rma_lines = self.rma_customer_id.rma_line_ids + rma_lines.write({"receipt_policy": "delivered"}) + self.assertEqual(sum(rma_lines.mapped("qty_to_receive")), 0) + wizard = self.rma_make_picking.with_context({ + 'active_ids': rma_lines.ids, + 'active_model': 'rma.order.line', + 'picking_type': 'incoming', + 'active_id': 1 + }).create({}) + with self.assertRaisesRegex(ValidationError, "No quantity to transfer"): + wizard._create_picking() diff --git a/rma/wizards/rma_make_picking.py b/rma/wizards/rma_make_picking.py index 8e5170b5..2048b7b9 100644 --- a/rma/wizards/rma_make_picking.py +++ b/rma/wizards/rma_make_picking.py @@ -4,7 +4,7 @@ import time from odoo import models, fields, api, _ from odoo.exceptions import UserError, ValidationError -from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT as DT_FORMAT +from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT as DT_FORMAT, float_compare import odoo.addons.decimal_precision as dp @@ -149,12 +149,18 @@ class RmaMakePicking(models.TransientModel): else: qty = item.qty_to_deliver values = self._get_procurement_data(item, group, qty, picking_type) + product = item.line_id.product_id + if float_compare(qty, 0, product.uom_id.rounding) != 1: + raise ValidationError( + _("No quantity to transfer on %s shipment of product %s.") % + (_(picking_type), product.default_code or product.name) + ) # create picking try: self.env['procurement.group'].run( - item.line_id.product_id, + product, qty, - item.line_id.product_id.product_tmpl_id.uom_id, + product.uom_id, values.get('location_id'), values.get('origin'), values.get('origin'),