diff --git a/rma/models/stock_rule.py b/rma/models/stock_rule.py index 6a042544..678d971e 100644 --- a/rma/models/stock_rule.py +++ b/rma/models/stock_rule.py @@ -30,6 +30,7 @@ class StockRule(models.Model): ) if "rma_line_id" in values: line = values.get("rma_line_id") + line = self.env["rma.order.line"].browse([line]) res["rma_line_id"] = line.id if line.delivery_address_id: res["partner_id"] = line.delivery_address_id.id diff --git a/rma/tests/test_rma.py b/rma/tests/test_rma.py index 2a742906..0a27fbf3 100644 --- a/rma/tests/test_rma.py +++ b/rma/tests/test_rma.py @@ -1049,3 +1049,18 @@ class TestRma(common.TransactionCase): ).create({}) with self.assertRaisesRegex(UserError, "No rule found"): wizard._create_picking() + + def test_07_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 f9cd84db..45924a7b 100644 --- a/rma/wizards/rma_make_picking.py +++ b/rma/wizards/rma_make_picking.py @@ -5,7 +5,7 @@ import time from odoo import _, api, fields, models 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 class RmaMakePicking(models.TransientModel): @@ -147,7 +147,12 @@ class RmaMakePicking(models.TransientModel): else: qty = item.qty_to_deliver values = self._get_procurement_data(item, group, qty, picking_type) - values = dict(values, rma_line_id=item.line_id, rma_id=item.line_id.rma_id) + 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 procurements = [] try: