-
-
Notifications
You must be signed in to change notification settings - Fork 695
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
base: 16.0
Are you sure you want to change the base?
Conversation
LGTM |
I been testing and LGTM! |
LGTM 🤗 |
Very useful addition. LGTM |
There was a problem hiding this 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" |
There was a problem hiding this comment.
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 = ( |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
@jaloxi @JHernandezConinpe @AitorRamosSantos @Aingeru21 To take into account your review, please use the github feature you find in 'Files changed' tab here. |
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.