Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] stock_inventory_non_stocked #2019

Open
wants to merge 3 commits into
base: 16.0
Choose a base branch
from
Open

Conversation

linuxivan
Copy link

This module adds a option to a create a 0 quantity quant for products without any stock and any quants in stock inventory groups.

In previous versions inventory adjustment lines were created, but nowadays the stock_inventory module works directly with quants, which means that no matter how many filters you use, if the product does not have a quant it will not appear in the adjustment.
This module creates a quant at 0 to solve this problem.

@jaloxi
Copy link

jaloxi commented May 6, 2024

LGTM

@JHernandezConinpe
Copy link
Contributor

I been testing and LGTM!

@AitorRamosSantos
Copy link

AitorRamosSantos commented May 6, 2024

LGTM 🤗

@Aingeru21
Copy link

Very useful addition. LGTM

@rousseldenis rousseldenis added this to the 16.0 milestone May 7, 2024
Copy link
Sponsor Contributor

@rousseldenis rousseldenis left a comment

Choose a reason for hiding this comment

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

@linuxivan Thanks for this.

Code review.



class StockQuant(models.Model):
_inherit = "stock.quant"
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Please put one model per file

@api.depends("qty_available", "incoming_qty", "outgoing_qty")
def _compute_has_quants(self):
for record in self:
record.has_quants = (
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

This is completely inefficient.

Please do either a read_group before loop, either use the 'stock_quant_ids' field to compute the value.

> 0
)

lot_ids = fields.One2many("stock.lot", "product_id", string="Lots", copy=False)
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Please put fields declarations on top. IMHO, declaring such field could maybe go into a dedicated module.

@api.model_create_multi
def create(self, vals_list):
res = super(StockQuant, self).create(vals_list)
res.product_id._compute_has_quants()
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Why doing that ? Maybe you want to use 'precompute=True' field attribute ?

("type", "=", "product"),
]
)
new_quants = self.create_zero_quants(product_ids)
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Maybe you can avoid some code doing one search depending the configuration by building a domain.

Then, with the result, call one 'create_zero_quants()'

# If the product is tracked but has no lots, we don't create any quant
if product.tracking == "lot" and product.lot_ids:
for lot in product.lot_ids:
new_quants |= self.env["stock.quant"].create(
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Create a list of values instead and call one create at the end.

# If the product is tracked by lot, we create a quant for each lot
# If the product is not tracked, we create a single quant
# If the product is tracked but has no lots, we don't create any quant
if product.tracking == "lot" and product.lot_ids:
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

And for the 'tracking == 'serial'' case ?

@@ -0,0 +1 @@
This module adds a option to a create a 0 quantity quant for products without any stock and any quants in stock inventory groups.
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Maybe you can add a 'CONTEXT.rst' that explain the 'why' of this module.

@rousseldenis
Copy link
Sponsor Contributor

@jaloxi @JHernandezConinpe @AitorRamosSantos @Aingeru21 To take into account your review, please use the github feature you find in 'Files changed' tab here.

image

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.

None yet

7 participants