Skip to content

Commit

Permalink
[MIG] stock_picking_progress: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
natuan9 committed Jan 6, 2025
1 parent 2bcca1c commit abdd289
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 110 deletions.
16 changes: 11 additions & 5 deletions stock_picking_progress/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ Stock Picking Progress

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

This module adds a new progress field on stock.picking, stock.move and
stock.move.line.
This module adds a new progress field on stock.picking, stock.move.

On stock.move and stock.move.line, this field represents the percentage
of qty_done compared to the product_uom_qty. On stock.picking, this
field is the average progress of all moves.
On stock.move, this field represents the percentage of quantity compared
to the product_uom_qty. On stock.picking, this field is the average
progress of all moves.

**Table of contents**

Expand Down Expand Up @@ -65,6 +64,13 @@ Contributors
- Juan Miguel Sánchez Arce <juan.sanchez@camptocamp.com>
- Souheil Bejaoui <souheil.bejaoui@acsone.eu>
- Denis Roussel <denis.roussel@acsone.eu>
- Tuan Nguyen <tuanna@trobz.com>

Other credits
-------------

The migration of this module from 17.0 to 18.0 has been financially
supported by Camptocamp

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion stock_picking_progress/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Stock Picking Progress",
"summary": "Compute the stock.picking progression",
"version": "16.0.1.0.0",
"version": "18.0.1.0.0",
"category": "Inventory",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "Camptocamp SA, Odoo Community Association (OCA)",
Expand Down
52 changes: 10 additions & 42 deletions stock_picking_progress/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,15 @@
logger = logging.getLogger(__name__)


def setup_move_line_progress(cr):
"""Update the 'progress' column for move lines."""
table = "stock_move_line"
column = "progress"
if column_exists(cr, table, column):
logger.info("%s already exists on %s, skipping setup", column, table)
return
env = api.Environment(cr, SUPERUSER_ID, {})
logger.info("creating %s on table %s", column, table)
field_spec = [
(
"progress",
"stock.move.line",
"stock_move_line",
"float",
"float",
"stock_picking_progress",
100.0,
)
]
openupgrade.add_fields(env, field_spec)
logger.info("filling up %s on %s", column, table)
cr.execute("""UPDATE stock_move_line SET progress =0 WHERE state = 'cancel'""")
cr.execute(
"""
UPDATE stock_move_line SET progress =(qty_done / reserved_qty) * 100
WHERE state not in ('done', 'cancel') AND reserved_qty > 0.0
"""
)


def setup_move_progress(cr):
"""Update the 'progress' column for not-started or already done moves."""
table = "stock_move"
column = "progress"
if column_exists(cr, table, column):
logger.info("%s already exists on %s, skipping setup", column, table)
logger.info(f"{column} already exists on {table}, skipping setup")
return

Check warning on line 20 in stock_picking_progress/hooks.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_progress/hooks.py#L19-L20

Added lines #L19 - L20 were not covered by tests
env = api.Environment(cr, SUPERUSER_ID, {})
logger.info("creating %s on table %s", column, table)
logger.info(f"creating {column} on table {table}")
field_spec = [
(
"progress",
Expand All @@ -63,11 +32,11 @@ def setup_move_progress(cr):
)
]
openupgrade.add_fields(env, field_spec)
logger.info("filling up %s on %s", column, table)
logger.info(f"filling up {column} on {table}")
cr.execute("""UPDATE stock_move SET progress =0 WHERE state = 'cancel'""")
cr.execute(
"""
UPDATE stock_move SET progress =(quantity_done / product_uom_qty) * 100
UPDATE stock_move SET progress =(quantity / product_uom_qty) * 100
WHERE state not in ('done', 'cancel') AND product_uom_qty > 0.0
"""
)
Expand All @@ -78,9 +47,9 @@ def setup_picking_progress(cr):
column = "progress"
_type = "float"
if column_exists(cr, table, column):
logger.info("%s already exists on %s, skipping setup", column, table)
logger.info(f"{column} already exists on {table}, skipping setup")
return

Check warning on line 51 in stock_picking_progress/hooks.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_progress/hooks.py#L50-L51

Added lines #L50 - L51 were not covered by tests
logger.info("creating %s on table %s", column, table)
logger.info(f"creating {column} on table {table}")
create_column(cr, table, column, _type)
fill_column_query = """
UPDATE stock_picking p
Expand All @@ -92,11 +61,10 @@ def setup_picking_progress(cr):
) as subquery
WHERE p.id = subquery.picking_id;
"""
logger.info("filling up %s on %s", column, table)
logger.info(f"filling up {column} on {table}")
cr.execute(fill_column_query)


def pre_init_hook(cr):
setup_move_line_progress(cr)
setup_move_progress(cr)
setup_picking_progress(cr)
def pre_init_hook(env):
setup_move_progress(env.cr)
setup_picking_progress(env.cr)
1 change: 0 additions & 1 deletion stock_picking_progress/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from . import stock_move_line
from . import stock_move
from . import stock_picking
8 changes: 3 additions & 5 deletions stock_picking_progress/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
class StockMove(models.Model):
_inherit = "stock.move"

progress = fields.Float(
compute="_compute_progress", store=True, group_operator="avg"
)
progress = fields.Float(compute="_compute_progress", store=True, aggregator="avg")

@api.depends(
"product_uom_qty",
"product_uom",
"quantity_done",
"quantity",
"state",
)
def _compute_progress(self):
Expand All @@ -27,4 +25,4 @@ def _compute_progress(self):
if float_is_zero(record.product_uom_qty, precision_rounding=rounding):
record.progress = 100

Check warning on line 26 in stock_picking_progress/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_progress/models/stock_move.py#L26

Added line #L26 was not covered by tests
else:
record.progress = (record.quantity_done / record.product_uom_qty) * 100
record.progress = (record.quantity / record.product_uom_qty) * 100
30 changes: 0 additions & 30 deletions stock_picking_progress/models/stock_move_line.py

This file was deleted.

4 changes: 1 addition & 3 deletions stock_picking_progress/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
class StockPicking(models.Model):
_inherit = "stock.picking"

progress = fields.Float(
compute="_compute_progress", store=True, group_operator="avg"
)
progress = fields.Float(compute="_compute_progress", store=True, aggregator="avg")

@api.depends("move_ids", "move_ids.progress")
def _compute_progress(self):
Expand Down
1 change: 1 addition & 0 deletions stock_picking_progress/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
- Juan Miguel Sánchez Arce \<<juan.sanchez@camptocamp.com>\>
- Souheil Bejaoui \<<souheil.bejaoui@acsone.eu>\>
- Denis Roussel \<<denis.roussel@acsone.eu>\>
- Tuan Nguyen \<<tuanna@trobz.com>\>
1 change: 1 addition & 0 deletions stock_picking_progress/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The migration of this module from 17.0 to 18.0 has been financially supported by Camptocamp
7 changes: 3 additions & 4 deletions stock_picking_progress/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
This module adds a new progress field on stock.picking, stock.move and
stock.move.line.
This module adds a new progress field on stock.picking, stock.move.

On stock.move and stock.move.line, this field represents the percentage
of qty_done compared to the product_uom_qty. On stock.picking, this
On stock.move, this field represents the percentage
of quantity compared to the product_uom_qty. On stock.picking, this
field is the average progress of all moves.
20 changes: 13 additions & 7 deletions stock_picking_progress/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,19 +370,19 @@ <h1 class="title">Stock Picking Progress</h1>
!! source digest: sha256:dd993305dde76b31c94efff5c8e9a2d7ea6c9c1e33bdb77751615ef486a7990a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/18.0/stock_picking_progress"><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-18-0/stock-logistics-workflow-18-0-stock_picking_progress"><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=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds a new progress field on stock.picking, stock.move and
stock.move.line.</p>
<p>On stock.move and stock.move.line, this field represents the percentage
of qty_done compared to the product_uom_qty. On stock.picking, this
field is the average progress of all moves.</p>
<p>This module adds a new progress field on stock.picking, stock.move.</p>
<p>On stock.move, this field represents the percentage of quantity compared
to the product_uom_qty. On stock.picking, this field is the average
progress of all moves.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-5">Maintainers</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-5">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -410,10 +410,16 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<li>Juan Miguel Sánchez Arce &lt;<a class="reference external" href="mailto:juan.sanchez&#64;camptocamp.com">juan.sanchez&#64;camptocamp.com</a>&gt;</li>
<li>Souheil Bejaoui &lt;<a class="reference external" href="mailto:souheil.bejaoui&#64;acsone.eu">souheil.bejaoui&#64;acsone.eu</a>&gt;</li>
<li>Denis Roussel &lt;<a class="reference external" href="mailto:denis.roussel&#64;acsone.eu">denis.roussel&#64;acsone.eu</a>&gt;</li>
<li>Tuan Nguyen &lt;<a class="reference external" href="mailto:tuanna&#64;trobz.com">tuanna&#64;trobz.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-5">Other credits</a></h2>
<p>The migration of this module from 17.0 to 18.0 has been financially
supported by Camptocamp</p>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">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" />
Expand Down
24 changes: 12 additions & 12 deletions stock_picking_progress/tests/test_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ def add_move(self, name):
}
return self.env["stock.move"].create(data)

def set_quantity_done(self, moves, qty=None):
def set_quantity(self, moves, qty=None):
for move in moves:
if qty is None:
quantity_done = move.product_uom_qty
quantity = move.product_uom_qty
else:
quantity_done = qty
move.quantity_done = quantity_done
quantity = qty
move.quantity = quantity

def test_progress(self):
# No move, progress is 100%
self.assertEqual(self.picking.progress, 100.0)
# Add a new move, no qty done: progress 0%
move1 = self.add_move("Move 1")
self.assertEqual(self.picking.progress, 0.0)
# Set quantity_done to 5.0 (half done), both move and picking are 50% done
self.set_quantity_done(move1, 5.0)
# Set quantity to 5.0 (half done), both move and picking are 50% done
self.set_quantity(move1, 5.0)
self.assertEqual(self.picking.progress, 50.0)
self.assertEqual(move1.progress, 50.0)
# Add a new move:
Expand All @@ -55,25 +55,25 @@ def test_progress(self):
self.assertEqual(self.picking.progress, 25.0)
self.assertEqual(move1.progress, 50.0)
self.assertEqual(move2.progress, 0.0)
# Set quantity_done = 10.0 on move 2
# Set quantity = 10.0 on move 2
# move1 progress is still 50%
# move2 progress is 100%
# picking progress is 75%
self.set_quantity_done(move2)
self.set_quantity(move2)
self.assertEqual(self.picking.progress, 75.0)
self.assertEqual(move2.progress, 100.0)
# Set quantity_done = 10.0 on move 1
# Set quantity = 10.0 on move 1
# move1 progress is 100%
# move2 progress is still 100%
# picking progress is 100%
self.set_quantity_done(move1)
self.set_quantity(move1)
self.assertEqual(self.picking.progress, 100.0)
self.assertEqual(move1.progress, 100.0)
# Set quantity_done = 0.0 on both move
# Set quantity = 0.0 on both move
# move1 progress is 0%
# move2 progress is still 0%
# picking progress is 0%
self.set_quantity_done(self.picking.move_ids, 0.0)
self.set_quantity(self.picking.move_ids, 0.0)
self.assertEqual(move1.progress, 0.0)
self.assertEqual(move2.progress, 0.0)
self.assertEqual(self.picking.progress, 0.0)

0 comments on commit abdd289

Please sign in to comment.