Compare commits
No commits in common. "d5342c73fb95b689f428812dcab7d28155ba226f" and "9d426ff17623d512025b4fa66f46a026e9c56f79" have entirely different histories.
d5342c73fb
...
9d426ff176
2 changed files with 10 additions and 35 deletions
|
|
@ -46,15 +46,6 @@ class StockMove(models.Model):
|
|||
else:
|
||||
price_updated = move.purchase_line_id.price_unit
|
||||
|
||||
# Convert price to product's base UoM if purchase UoM is different
|
||||
if (
|
||||
move.purchase_line_id
|
||||
and move.purchase_line_id.product_uom != move.product_id.uom_id
|
||||
):
|
||||
price_updated = move.purchase_line_id.product_uom._compute_price(
|
||||
price_updated, move.product_id.uom_id
|
||||
)
|
||||
|
||||
if float_compare(
|
||||
move.product_id.last_purchase_price_received,
|
||||
price_updated,
|
||||
|
|
|
|||
|
|
@ -44,9 +44,7 @@ class StockInventory(models.Model):
|
|||
|
||||
quants_to_create = []
|
||||
for location in locations:
|
||||
for product in products.filtered(
|
||||
lambda p: p.type == "product" and p.active
|
||||
):
|
||||
for product in products.filtered(lambda p: p.type == "product"):
|
||||
if (product.id, location.id) not in existing_combinations:
|
||||
_logger.debug(
|
||||
"Creating zero quant for product %s in location %s",
|
||||
|
|
@ -105,28 +103,14 @@ class StockQuant(models.Model):
|
|||
|
||||
@api.model
|
||||
def _unlink_zero_quants(self):
|
||||
"""Override to only unlink zero quants for archived products.
|
||||
"""Prevent automatic unlinking of zero quants.
|
||||
|
||||
This method modifies the default behavior to preserve zero quants
|
||||
for active products while still removing them for archived products.
|
||||
This is useful when using the 'Include Exhausted Products' feature.
|
||||
This method overrides the default behavior to prevent
|
||||
zero quants from being automatically removed.
|
||||
This may need review to ensure it doesn't conflict
|
||||
with standard Odoo behavior.
|
||||
"""
|
||||
precision_digits = max(
|
||||
6, self.sudo().env.ref("product.decimal_product_uom").digits * 2
|
||||
)
|
||||
# Use a select instead of ORM search for UoM robustness.
|
||||
# Join with product_product and product_template to check if product is active
|
||||
query = """SELECT sq.id FROM stock_quant sq
|
||||
INNER JOIN product_product pp ON sq.product_id = pp.id
|
||||
INNER JOIN product_template pt ON pp.product_tmpl_id = pt.id
|
||||
WHERE (round(sq.quantity::numeric, %s) = 0 OR sq.quantity IS NULL)
|
||||
AND round(sq.reserved_quantity::numeric, %s) = 0
|
||||
AND (round(sq.inventory_quantity::numeric, %s) = 0 OR sq.inventory_quantity IS NULL)
|
||||
AND sq.user_id IS NULL
|
||||
AND (pp.active = false OR pt.active = false);"""
|
||||
params = (precision_digits, precision_digits, precision_digits)
|
||||
self.env.cr.execute(query, params)
|
||||
quant_ids = self.env["stock.quant"].browse(
|
||||
[quant["id"] for quant in self.env.cr.dictfetchall()]
|
||||
)
|
||||
quant_ids.sudo().unlink()
|
||||
if self.product_tmpl_id.active:
|
||||
_logger.debug("Preventing automatic unlinking of zero quants")
|
||||
else:
|
||||
super()._unlink_zero_quants()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue