Skip to content

Commit

Permalink
[IMP] stock_picking_return_restricted_qty: add restrict_return_qty se…
Browse files Browse the repository at this point in the history
…tting to stock.picking.type
  • Loading branch information
ced-adhoc committed Oct 4, 2024
1 parent c8bf812 commit 17bd110
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
3 changes: 3 additions & 0 deletions stock_picking_return_restricted_qty/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
"author": "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-workflow",
"depends": ["stock"],
"data": [
"views/stock_picking_type_views.xml",
],
}
1 change: 1 addition & 0 deletions stock_picking_return_restricted_qty/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_picking_type
16 changes: 16 additions & 0 deletions stock_picking_return_restricted_qty/models/stock_picking_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class StockPickingType(models.Model):
_inherit = "stock.picking.type"

restrict_return_qty = fields.Boolean(
string="Restrict Return Quantity",
help=(
"Enable this option to restrict returning more quantities "
"than delivered."
),
default=False,
)
5 changes: 5 additions & 0 deletions stock_picking_return_restricted_qty/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To manage analytic account tags using this module, you need to:

#. Navigate to **Inventory > Configuration > Operations Types**.
#. Select the Operation Type for which you want to enable the restriction.
#. Check the box "Restrict Return Quantity" and save.
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,28 @@ def get_return_picking_wizard(self, picking):
def test_return_not_allowed(self):
"""On this test we create a return picking with more quantity
than the quantity that client have on his hand"""
self.picking.picking_type_id.restrict_return_qty = True
return_picking = self.get_return_picking_wizard(self.picking)
self.assertEqual(return_picking.product_return_moves.quantity, 20)
return_picking.product_return_moves.quantity = 30
with self.assertRaises(UserError):
return_picking._create_returns()

def test_return_without_restriction(self):
"""On this test we create a return picking with more quantity
than the quantity that client have on his hand
without the quantity restriction"""
self.picking.picking_type_id.restrict_return_qty = False
return_picking = self.get_return_picking_wizard(self.picking)
self.assertEqual(return_picking.product_return_moves.quantity, 20)
return_picking.product_return_moves.quantity = 30
return_picking._create_returns()
self.assertEqual(return_picking.product_return_moves.quantity, 30)

def test_multiple_return(self):
"""On this test we are going to follow a sequence that a client
can follow if he tries to return a product"""
self.picking.picking_type_id.restrict_return_qty = True
wiz = self.get_return_picking_wizard(self.picking)
wiz.product_return_moves.quantity = 10
picking_returned_id = wiz._create_returns()[0]
Expand All @@ -90,3 +103,24 @@ def test_multiple_return(self):
wiz.product_return_moves.quantity = 80
with self.assertRaises(UserError):
wiz.product_return_moves._onchange_quantity()

def test_multiple_return_without_restriction(self):
"""On this test we are going to follow a sequence that a client
can follow if he tries to return a product
without the quantity restriction"""
self.picking.picking_type_id.restrict_return_qty = False
wiz = self.get_return_picking_wizard(self.picking)
wiz.product_return_moves.quantity = 10
picking_returned_id = wiz._create_returns()[0]
picking_returned = self.env["stock.picking"].browse(picking_returned_id)

wiz = self.get_return_picking_wizard(self.picking)
self.assertEqual(wiz.product_return_moves.quantity, 10)

picking_returned._action_done()
wiz = self.get_return_picking_wizard(self.picking)
self.assertEqual(wiz.product_return_moves.quantity, 10)

wiz.product_return_moves.quantity = 80
wiz.product_return_moves._onchange_quantity()
self.assertEqual(wiz.product_return_moves.quantity, 80)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_picking_type_form" model="ir.ui.view">
<field name="name">stock.picking.type.restrict.return</field>
<field name="model">stock.picking.type</field>
<field name="inherit_id" ref="stock.view_picking_type_form" />
<field name="arch" type="xml">
<field name="return_picking_type_id" position="after">
<field name="restrict_return_qty" />
</field>
</field>
</record>
</odoo>

0 comments on commit 17bd110

Please sign in to comment.