Skip to content

Commit

Permalink
[MIG] stock_picking_return_restricted_qty: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ced-adhoc committed Oct 1, 2024
1 parent 8897bfb commit 888dacb
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 34 deletions.
25 changes: 18 additions & 7 deletions stock_picking_return_restricted_qty/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,51 @@ Stock Picking Return Restricted Qty
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-workflow/tree/15.0/stock_picking_return_restricted_qty
:target: https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_picking_return_restricted_qty
:alt: OCA/stock-logistics-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-15-0/stock-logistics-workflow-15-0-stock_picking_return_restricted_qty
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-16-0/stock-logistics-workflow-16-0-stock_picking_return_restricted_qty
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&target_branch=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module don't allow you to return more quantity of products than the
This module doesn't allow you to return more quantity of products than the
delivered.

**Table of contents**

.. contents::
:local:

Configuration
=============

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.

Usage
=====

To use this module, you need to:

#. Create an outgoing or an internal picking.
#. Include one or more products with enough stock.
#. Validate the picking.
#. Try to return more products than the delivered and see the warning.
#. Attemp to return more products than the delivered and see the warning message.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_picking_return_restricted_qty%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_picking_return_restricted_qty%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -83,6 +94,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/15.0/stock_picking_return_restricted_qty>`_ project on GitHub.
This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_picking_return_restricted_qty>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions stock_picking_return_restricted_qty/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import wizard
from . import models
6 changes: 4 additions & 2 deletions stock_picking_return_restricted_qty/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
{
"name": "Stock Picking Return Restricted Qty",
"summary": "Restrict the return to delivered quantity",
"version": "15.0.1.0.1",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-workflow",
"depends": ["stock"],
"data": [],
"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
13 changes: 13 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,13 @@
# 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.
2 changes: 1 addition & 1 deletion stock_picking_return_restricted_qty/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
This module don't allow you to return more quantity of products than the
This module doesn't allow you to return more quantity of products than the
delivered.
4 changes: 3 additions & 1 deletion stock_picking_return_restricted_qty/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
To use this module, you need to:

#. Create an outgoing or an internal picking.
#. Include one or more products with enough stock.
#. Validate the picking.
#. Try to return more products than the delivered and see the warning.
#. Attemp to return more products than the delivered and see the warning message.
46 changes: 28 additions & 18 deletions stock_picking_return_restricted_qty/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -369,49 +368,60 @@ <h1 class="title">Stock Picking Return Restricted Qty</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:53be3c3c8c4c46df50af7083ad7ad918a59add0e68c12d41718a261a2d727a70
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/stock-logistics-workflow/tree/15.0/stock_picking_return_restricted_qty"><img alt="OCA/stock-logistics-workflow" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-workflow-15-0/stock-logistics-workflow-15-0-stock_picking_return_restricted_qty"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module don’t allow you to return more quantity of products than the
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_picking_return_restricted_qty"><img alt="OCA/stock-logistics-workflow" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-workflow-16-0/stock-logistics-workflow-16-0-stock_picking_return_restricted_qty"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module doesn’t allow you to return more quantity of products than the
delivered.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="toc-entry-1">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>To manage analytic account tags using this module, you need to:</p>
<ol class="arabic simple">
<li>Navigate to <strong>Inventory &gt; Configuration &gt; Operations Types</strong>.</li>
<li>Select the Operation Type for which you want to enable the restriction.</li>
<li>Check the box “Restrict Return Quantity” and save.</li>
</ol>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>To use this module, you need to:</p>
<ol class="arabic simple">
<li>Create an outgoing or an internal picking.</li>
<li>Include one or more products with enough stock.</li>
<li>Validate the picking.</li>
<li>Try to return more products than the delivered and see the warning.</li>
<li>Attemp to return more products than the delivered and see the warning message.</li>
</ol>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_picking_return_restricted_qty%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_picking_return_restricted_qty%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Carlos Roca</li>
Expand All @@ -421,13 +431,13 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/tree/15.0/stock_picking_return_restricted_qty">OCA/stock-logistics-workflow</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_picking_return_restricted_qty">OCA/stock-logistics-workflow</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def setUpClass(cls):
"picking_type_id": picking_type_out.id,
"location_id": stock_location.id,
"location_dest_id": customer_location.id,
"move_lines": [
"move_ids": [
(
0,
0,
Expand All @@ -50,7 +50,7 @@ def setUpClass(cls):
)
cls.picking.action_confirm()
cls.picking.action_assign()
cls.picking.move_lines[:1].quantity_done = 20
cls.picking.move_ids[:1].quantity_done = 20
cls.picking.button_validate()

def get_return_picking_wizard(self, picking):
Expand All @@ -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(wiz.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>
14 changes: 11 additions & 3 deletions stock_picking_return_restricted_qty/wizard/stock_picking_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ def _prepare_stock_return_picking_line_vals_from_move(self, stock_move):
return val

def _create_returns(self):
restrict_return_qty = self.picking_id.picking_type_id.restrict_return_qty

precision = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
for return_line in self.product_return_moves:
quantity = return_line.get_returned_restricted_quantity(return_line.move_id)
if (

if restrict_return_qty and (
float_compare(
return_line.quantity, quantity, precision_digits=precision
)
Expand All @@ -39,8 +42,13 @@ class ReturnPickingLine(models.TransientModel):

@api.onchange("quantity")
def _onchange_quantity(self):
restrict_return_qty = (
self.move_id.picking_id.picking_type_id.restrict_return_qty
)

qty = self.get_returned_restricted_quantity(self.move_id)
if self.quantity > qty:

if restrict_return_qty and self.quantity > qty:
raise UserError(_("Return more quantities than delivered is not allowed."))

def get_returned_restricted_quantity(self, stock_move):
Expand All @@ -55,7 +63,7 @@ def get_returned_restricted_quantity(self, stock_move):
):
continue
if line.state in {"partially_available", "assigned"}:
qty -= line.product_qty
qty -= line.reserved_qty
elif line.state == "done":
qty -= line.qty_done
return max(qty, 0.0)

0 comments on commit 888dacb

Please sign in to comment.