
from odoo import api, fields, models


class StockQuant(models.Model):
    _inherit = "stock.quant"

    contains_unreserved = fields.Boolean(
        string="Contains unreserved products",
        compute="_compute_contains_unreserved",
        store=True,
    )

    @api.depends("product_id", "location_id", "quantity", "reserved_quantity")
    def _compute_contains_unreserved(self):
        for record in self:
            available = record._get_available_quantity(
                record.product_id, record.location_id
            )
            record.contains_unreserved = True if available > 0 else False


from odoo import api, fields, models


class StockQuant(models.Model):
    _inherit = "stock.quant"

    contains_unreserved = fields.Boolean(
        string="Contains unreserved products",
        compute="_compute_contains_unreserved",
        store=True,
    )

    @api.depends("product_id", "location_id", "quantity", "reserved_quantity")
    def _compute_contains_unreserved(self):
        for record in self:
            # Avoid error when adding a new line on manually Update Quantity
            if isinstance(record.id, models.NewId):
                record.contains_unreserved = False
                continue
            available = record._get_available_quantity(
                record.product_id, record.location_id
            )
            record.contains_unreserved = True if available > 0 else False

Fix compute contains_unreserved on NewId records
[FIX] Fix compute contains_unreserved on NewId records

  
  from odoo import api, fields, models
  
  
  class StockQuant(models.Model):
      _inherit = "stock.quant"
  
      contains_unreserved = fields.Boolean(
          string="Contains unreserved products",
          compute="_compute_contains_unreserved",
          store=True,
      )
  
      @api.depends("product_id", "location_id", "quantity", "reserved_quantity")
      def _compute_contains_unreserved(self):
          for record in self:
+             # Avoid error when adding a new line on manually Update Quantity
+             if isinstance(record.id, models.NewId):
+                 record.contains_unreserved = False
+                 continue
              available = record._get_available_quantity(
                  record.product_id, record.location_id
              )
              record.contains_unreserved = True if available > 0 else False
  
Fix compute contains_unreserved on NewId records
## Code Before:

from odoo import api, fields, models


class StockQuant(models.Model):
    _inherit = "stock.quant"

    contains_unreserved = fields.Boolean(
        string="Contains unreserved products",
        compute="_compute_contains_unreserved",
        store=True,
    )

    @api.depends("product_id", "location_id", "quantity", "reserved_quantity")
    def _compute_contains_unreserved(self):
        for record in self:
            available = record._get_available_quantity(
                record.product_id, record.location_id
            )
            record.contains_unreserved = True if available > 0 else False

## Instruction:
Fix compute contains_unreserved on NewId records
## Code After:

from odoo import api, fields, models


class StockQuant(models.Model):
    _inherit = "stock.quant"

    contains_unreserved = fields.Boolean(
        string="Contains unreserved products",
        compute="_compute_contains_unreserved",
        store=True,
    )

    @api.depends("product_id", "location_id", "quantity", "reserved_quantity")
    def _compute_contains_unreserved(self):
        for record in self:
            # Avoid error when adding a new line on manually Update Quantity
            if isinstance(record.id, models.NewId):
                record.contains_unreserved = False
                continue
            available = record._get_available_quantity(
                record.product_id, record.location_id
            )
            record.contains_unreserved = True if available > 0 else False
