Skip to content

Commit 8cc297a

Browse files
committed
[ADD] stock_picking_is_completed
1 parent 873f173 commit 8cc297a

File tree

16 files changed

+864
-0
lines changed

16 files changed

+864
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../stock_picking_is_completed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../stock_picking_is_ready
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
==========================
2+
Stock Picking Is Completed
3+
==========================
4+
5+
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6+
!! This file is generated by oca-gen-addon-readme !!
7+
!! changes will be overwritten. !!
8+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9+
10+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
11+
:target: https://odoo-community.org/page/development-status
12+
:alt: Beta
13+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
14+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
15+
:alt: License: LGPL-3
16+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github
17+
:target: https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_picking_is_completed
18+
:alt: OCA/stock-logistics-workflow
19+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20+
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-16-0/stock-logistics-workflow-16-0-stock_picking_is_completed
21+
:alt: Translate me on Weblate
22+
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23+
:target: https://runbot.odoo-community.org/runbot/154/16.0
24+
:alt: Try me on Runbot
25+
26+
|badge1| |badge2| |badge3| |badge4| |badge5|
27+
28+
This module adds a field on stock picking that will check if all movements have
29+
been filled in by stock operator.
30+
31+
This is helpful to see if at least all lines of the picking have been treated.
32+
The picking would not be marked as ready if some quantities stay at 0 (backorders) and
33+
quantities are < the reserved one.
34+
35+
**Table of contents**
36+
37+
.. contents::
38+
:local:
39+
40+
Usage
41+
=====
42+
43+
#. On a picking, do the stock operations as normally, filling in the done quantities.
44+
#. At least when the last operation is filled in with a quantity equal or greater
45+
than the demand quantity, the field 'is_completed' == True and a green banner
46+
is displayed on picking form side.
47+
48+
Bug Tracker
49+
===========
50+
51+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-workflow/issues>`_.
52+
In case of trouble, please check there if your issue has already been reported.
53+
If you spotted it first, help us smashing it by providing a detailed and welcomed
54+
`feedback <https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_picking_is_completed%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
55+
56+
Do not contact contributors directly about support or help with technical issues.
57+
58+
Credits
59+
=======
60+
61+
Authors
62+
~~~~~~~
63+
64+
* ACSONE SA/NV
65+
66+
Contributors
67+
~~~~~~~~~~~~
68+
69+
* Denis Roussel <[email protected]>
70+
71+
Maintainers
72+
~~~~~~~~~~~
73+
74+
This module is maintained by the OCA.
75+
76+
.. image:: https://odoo-community.org/logo.png
77+
:alt: Odoo Community Association
78+
:target: https://odoo-community.org
79+
80+
OCA, or the Odoo Community Association, is a nonprofit organization whose
81+
mission is to support the collaborative development of Odoo features and
82+
promote its widespread use.
83+
84+
.. |maintainer-rousseldenis| image:: https://github.com/rousseldenis.png?size=40px
85+
:target: https://github.com/rousseldenis
86+
:alt: rousseldenis
87+
88+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
89+
90+
|maintainer-rousseldenis|
91+
92+
This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_picking_is_completed>`_ project on GitHub.
93+
94+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2023 ACSONE SA/NV
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
3+
4+
{
5+
"name": "Stock Picking Is Completed",
6+
"summary": """
7+
This module adds a field on stock picking that will check if all movements
8+
have been filled in by stock operator""",
9+
"version": "16.0.1.0.0",
10+
"license": "LGPL-3",
11+
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
12+
"maintainers": ["rousseldenis"],
13+
"website": "https://github.com/OCA/stock-logistics-workflow",
14+
"depends": [
15+
"stock",
16+
],
17+
"data": [
18+
"views/stock_picking.xml",
19+
],
20+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import stock_picking
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Copyright 2023 ACSONE SA/NV
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
3+
from odoo import api, fields, models
4+
from odoo.osv.expression import NEGATIVE_TERM_OPERATORS
5+
from odoo.tools import float_compare, float_is_zero
6+
7+
8+
class StockPicking(models.Model):
9+
10+
_inherit = "stock.picking"
11+
12+
is_completed = fields.Boolean(
13+
compute="_compute_is_completed",
14+
search="_search_is_completed",
15+
help="This field means if all picking operations have been done (each quantity is > 0)",
16+
)
17+
18+
@api.depends(
19+
"state",
20+
"move_ids_without_package.quantity_done",
21+
"move_line_ids.qty_done",
22+
"move_ids.quantity_done",
23+
)
24+
def _compute_is_completed(self):
25+
"""
26+
We must implement several fields value retrieval to allow a good behaviour on
27+
form side as several fields can be filled in:
28+
- move_line_ids.qty_done
29+
- move_ids_without_package
30+
"""
31+
precision_digits = self.env["decimal.precision"].precision_get(
32+
"Product Unit of Measure"
33+
)
34+
# We must use recordset (and not ids) as web interface can trigger this
35+
# and record arrives here with NewId
36+
ready_pickings = self.browse()
37+
for picking in self.filtered(lambda picking: picking.state == "assigned"):
38+
if all(
39+
not float_is_zero(move_line.qty_done, precision_digits=precision_digits)
40+
and float_compare(
41+
move_line.qty_done,
42+
move_line.reserved_uom_qty,
43+
precision_digits=precision_digits,
44+
)
45+
>= 0
46+
for move_line in picking.move_line_ids.filtered(
47+
lambda m: m.state not in ("done", "cancel")
48+
)
49+
):
50+
ready_pickings |= picking
51+
elif all(
52+
not float_is_zero(
53+
move_id.quantity_done, precision_digits=precision_digits
54+
)
55+
and float_compare(
56+
move_id.quantity_done,
57+
move_id.product_uom_qty,
58+
precision_digits=precision_digits,
59+
)
60+
>= 0
61+
for move_id in picking.move_ids.filtered(
62+
lambda m: m.state not in ("done", "cancel")
63+
)
64+
):
65+
ready_pickings |= picking
66+
ready_pickings.update({"is_completed": True})
67+
(self - ready_pickings).update({"is_completed": False})
68+
69+
def _get_is_completed_domain(self):
70+
return [
71+
("move_ids.quantity_done", ">", 0),
72+
("state", "not in", ["done", "cancel"]),
73+
]
74+
75+
def _get_is_not_completed_domain(self):
76+
return [
77+
"|",
78+
("move_ids.quantity_done", "=", 0),
79+
("state", "in", ["done", "cancel"]),
80+
]
81+
82+
def _search_is_completed(self, operator, value):
83+
negative = operator in NEGATIVE_TERM_OPERATORS
84+
85+
if (value and negative) or (not value and not negative):
86+
pickings = self.search(self._get_is_not_completed_domain())
87+
returned_pickings = pickings.filtered_domain([("is_completed", "=", False)])
88+
else:
89+
pickings = self.search(self._get_is_completed_domain())
90+
returned_pickings = pickings.filtered_domain([("is_completed", "=", True)])
91+
92+
return [("id", "in", returned_pickings.ids)]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Denis Roussel <[email protected]>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This module adds a field on stock picking that will check if all movements have
2+
been filled in by stock operator.
3+
4+
This is helpful to see if at least all lines of the picking have been treated.
5+
The picking would not be marked as ready if some quantities stay at 0 (backorders) and
6+
quantities are < the reserved one.

0 commit comments

Comments
 (0)