From 54887ed1419a37fdf4e02fd90370af8828b2c388 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Sat, 11 Jun 2022 12:09:06 +0200 Subject: [PATCH 1/3] [IMP] rma: prevent the creation of zero qty moves --- rma/models/stock_rule.py | 1 + rma/tests/test_rma.py | 15 +++++++++++++++ rma/wizards/rma_make_picking.py | 9 +++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) 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 5de02d4e..d3768252 100644 --- a/rma/tests/test_rma.py +++ b/rma/tests/test_rma.py @@ -1058,3 +1058,18 @@ class TestRma(common.SavepointCase): ).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 960e3361..c6ec5fcf 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: From 471be04eb27b93383aa8fdfe86695cfce23ef997 Mon Sep 17 00:00:00 2001 From: DavidJForgeFlow Date: Mon, 11 Jul 2022 09:41:26 +0200 Subject: [PATCH 2/3] [14.0][FIX]rma_account: fixup of procurement --- rma_account/models/procurement.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rma_account/models/procurement.py b/rma_account/models/procurement.py index 9404d1c2..7a3ae703 100644 --- a/rma_account/models/procurement.py +++ b/rma_account/models/procurement.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]) move = line.reference_move_id if move and move.stock_valuation_layer_ids: cost = move.stock_valuation_layer_ids[-1].unit_cost From 8623acedd9bcf8799376d71e17d40452f5ce951f Mon Sep 17 00:00:00 2001 From: DavidJForgeFlow Date: Mon, 11 Jul 2022 09:56:03 +0200 Subject: [PATCH 3/3] [14.0][FIX] rma_purchase: fixup of procurements --- rma_purchase/models/procurement.py | 1 + rma_sale/models/procurement.py | 1 + 2 files changed, 2 insertions(+) diff --git a/rma_purchase/models/procurement.py b/rma_purchase/models/procurement.py index 63993911..b551873e 100644 --- a/rma_purchase/models/procurement.py +++ b/rma_purchase/models/procurement.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]) if line.reference_move_id: return res if line.purchase_order_line_id: diff --git a/rma_sale/models/procurement.py b/rma_sale/models/procurement.py index 1b3248ee..f4a21038 100644 --- a/rma_sale/models/procurement.py +++ b/rma_sale/models/procurement.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]) if line.reference_move_id: return res if line.sale_line_id: