Compare commits

...

4 Commits

8 changed files with 466 additions and 1960 deletions

View File

@ -124,14 +124,14 @@ class EventRentalController(http.Controller):
if not product: if not product:
raise ValueError(_("Invalid rental product selected.")) raise ValueError(_("Invalid rental product selected."))
# Availability checking # Availability checking bypassed per request
dummy_request = request.env['event.rental.request'].sudo() # dummy_request = request.env['event.rental.request'].sudo()
available_qty = dummy_request.check_availability(start_date, end_date, product) # available_qty = dummy_request.check_availability(start_date, end_date, product)
#
if available_qty < quantity: # if available_qty < quantity:
raise ValueError(_("Product '%s' is not available in the quantity requested (%s) for the selected dates. Only %s units are currently available.") % ( # raise ValueError(_("Product '%s' is not available in the quantity requested (%s) for the selected dates. Only %s units are currently available.") % (
product.name, quantity, available_qty # product.name, quantity, available_qty
)) # ))
# Find or create partner # Find or create partner
partner = request.env['res.partner'].sudo().search([('email', '=', customer_email)], limit=1) partner = request.env['res.partner'].sudo().search([('email', '=', customer_email)], limit=1)

View File

@ -112,34 +112,10 @@ class EventRentalRequest(models.Model):
def check_availability(self, start_date, end_date, product_id, exclude_request_id=None): def check_availability(self, start_date, end_date, product_id, exclude_request_id=None):
""" """
Check the available inventory of a product for the selected date range. Check the available inventory of a product for the selected date range.
Standard qty_available acts as total pool. Bypassed per request - returning infinite availability.
""" """
if not product_id or not start_date or not end_date:
return 0.0
# Non-storable products are assumed to have infinite quantity
if product_id.type != 'product':
return 999999.0 return 999999.0
total_capacity = product_id.qty_available
# Overlapping criteria:
# (Start1 < End2) AND (End1 > Start2)
# Statuses blocking inventory: approved, quotation_sent, confirmed, delivered, returned
domain = [
('product_id', '=', product_id.id),
('request_id.status', 'in', ['approved', 'quotation_sent', 'confirmed', 'delivered', 'returned']),
('request_id.start_date', '<', end_date),
('request_id.end_date', '>', start_date),
]
if exclude_request_id:
domain.append(('request_id', '!=', exclude_request_id))
overlapping_lines = self.env['event.rental.line'].search(domain)
reserved_qty = sum(overlapping_lines.mapped('quantity'))
return max(0.0, total_capacity - reserved_qty)
def _get_or_create_service_product(self, name, default_code): def _get_or_create_service_product(self, name, default_code):
product = self.env['product.product'].search([('default_code', '=', default_code)], limit=1) product = self.env['product.product'].search([('default_code', '=', default_code)], limit=1)
if not product: if not product:
@ -161,13 +137,13 @@ class EventRentalRequest(models.Model):
if not self.line_ids: if not self.line_ids:
raise UserError(_("Please add at least one rental product line.")) raise UserError(_("Please add at least one rental product line."))
# Re-check availability before approving # Re-check availability bypassed per request
for line in self.line_ids: # for line in self.line_ids:
available_qty = self.check_availability(self.start_date, self.end_date, line.product_id, exclude_request_id=self.id) # available_qty = self.check_availability(self.start_date, self.end_date, line.product_id, exclude_request_id=self.id)
if available_qty < line.quantity: # if available_qty < line.quantity:
raise UserError(_("Product '%s' is not available in the required quantity (%s) for the selected dates. Only %s units are available.") % ( # raise UserError(_("Product '%s' is not available in the required quantity (%s) for the selected dates. Only %s units are available.") % (
line.product_id.display_name, line.quantity, available_qty # line.product_id.display_name, line.quantity, available_qty
)) # ))
# Check/create partner # Check/create partner
partner = self.partner_id partner = self.partner_id
@ -335,16 +311,7 @@ class EventRentalLine(models.Model):
@api.depends('product_id', 'quantity', 'request_id.start_date', 'request_id.end_date') @api.depends('product_id', 'quantity', 'request_id.start_date', 'request_id.end_date')
def _compute_is_available(self): def _compute_is_available(self):
for line in self: for line in self:
if not line.product_id or not line.request_id.start_date or not line.request_id.end_date:
line.is_available = True line.is_available = True
continue
available_qty = line.request_id.check_availability(
line.request_id.start_date,
line.request_id.end_date,
line.product_id,
exclude_request_id=line.request_id.id
)
line.is_available = available_qty >= line.quantity
class EventDocument(models.Model): class EventDocument(models.Model):

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

File diff suppressed because it is too large Load Diff