Skip to content
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] OD-2049, rma: prevent the creation of zero qty moves #3

Open
wants to merge 2 commits into
base: OD-1276/vanmoof_rma/product_replacement
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions rma/tests/test_rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,19 @@ def test_02_customer_rma(self):
self.rma_customer_id.action_view_out_shipments()
self.rma_customer_id.action_view_lines()

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()

# DROPSHIP
def test_03_dropship(self):
for line in self.rma_droship_id.rma_line_ids:
Expand Down
19 changes: 13 additions & 6 deletions rma/wizards/rma_make_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -149,15 +149,22 @@ def _create_procurement(self, item, picking_type):
else:
qty = item.qty_to_deliver
values = self._get_procurement_data(item, group, qty, picking_type)
product = values.get('product_id') or item.line_id.product_id
uom = self.env['uom.uom'].browse(
values.get('product_uom') or
item.line_id.product_id.product_tmpl_id.uom_id.id
)
if float_compare(qty, 0, uom.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(
values.get('product_id') or item.line_id.product_id,
product,
qty,
self.env['uom.uom'].browse(
values.get('product_uom') or
item.line_id.product_id.product_tmpl_id.uom_id.id
),
uom,
values.get('location_id'),
values.get('origin'),
values.get('origin'),
Expand Down