Skip to content

Conversation

ltabis
Copy link

@ltabis ltabis commented Aug 8, 2025

Adds a new model to create a procurement that takes available stock at the targeted location into account when creating pickings.

@ltabis ltabis force-pushed the 14.0-add-stock_resupply_order branch from f703e5c to e06d1c2 Compare August 11, 2025 16:10
@ltabis ltabis changed the title feat: stock_resupply_order [14.0][ADD] stock_resupply_order Aug 12, 2025
@ltabis ltabis force-pushed the 14.0-add-stock_resupply_order branch from e06d1c2 to 27e2ff7 Compare August 12, 2025 14:10
@ltabis ltabis force-pushed the 14.0-add-stock_resupply_order branch from 27e2ff7 to d1ffd9c Compare August 12, 2025 14:18
@ltabis ltabis marked this pull request as ready for review August 13, 2025 12:29
@ltabis ltabis force-pushed the 14.0-add-stock_resupply_order branch from 03329ca to a9c6661 Compare August 25, 2025 10:08
Copy link

@alexandregaldeano alexandregaldeano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ltabis ltabis force-pushed the 14.0-add-stock_resupply_order branch from a9c6661 to 54a9ecc Compare August 25, 2025 14:53
Comment on lines +150 to +185
def _get_existing_quants(self):
"""
Get stock quants at the targeted location. Override if you need to
apply specific constraints.
"""

self.ensure_one()

return (
self.env["stock.quant"]
.sudo()
.read_group(
domain=[
("location_id", "=", self.location_id.id),
(
"product_id",
"in",
self.stock_resupply_order_lines.product_id.ids,
),
],
# Cant aggregate available_quantity here.
fields=["product_id", "quantity:sum", "reserved_quantity:sum"],
groupby=["product_id"],
orderby="product_id",
lazy=False,
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose other part of the source code would be easier to read if this return a dict (using a default dict) some thing likes:

available_quantities: dict[int, int] = defaultdict(int)
for group in ...read_group():
   product_id = group...
   available_quantity = physic - reserved
   available_quantities[product_id] = available_quantity
``
   

@ltabis ltabis force-pushed the 14.0-add-stock_resupply_order branch 3 times, most recently from 8da3ceb to 9e12e98 Compare September 10, 2025 15:50
Copy link

@StephaneMangin StephaneMangin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. just some nitpick regarding naming and code structure

"stock.picking",
compute="_compute_picking_ids",
string="Generated stock pickings",
readonly=True,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
readonly=True,

By default for a simple compute

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

            # by default, computed fields are not stored, computed in superuser
            # mode if stored, not copied (unless stored and explicitly not
            # readonly), and readonly (unless inversible)

)

picking_count = fields.Integer(
string="Picking count", compute="_compute_picking_ids", readonly=True

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
string="Picking count", compute="_compute_picking_ids", readonly=True
string="Picking count", compute="_compute_picking_ids"

Same

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

1 similar comment
@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@ltabis ltabis force-pushed the 14.0-add-stock_resupply_order branch 2 times, most recently from 2221a40 to 7be62d4 Compare September 17, 2025 13:33
@ltabis ltabis force-pushed the 14.0-add-stock_resupply_order branch from 7be62d4 to 71ece6a Compare September 17, 2025 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants