Bypass availability checks for rental products as per request and update inquiry text in templates
This commit is contained in:
parent
d4a8113c79
commit
0467bcc6f6
Binary file not shown.
@ -124,14 +124,14 @@ class EventRentalController(http.Controller):
|
||||
if not product:
|
||||
raise ValueError(_("Invalid rental product selected."))
|
||||
|
||||
# Availability checking
|
||||
dummy_request = request.env['event.rental.request'].sudo()
|
||||
available_qty = dummy_request.check_availability(start_date, end_date, product)
|
||||
|
||||
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.") % (
|
||||
product.name, quantity, available_qty
|
||||
))
|
||||
# Availability checking bypassed per request
|
||||
# dummy_request = request.env['event.rental.request'].sudo()
|
||||
# available_qty = dummy_request.check_availability(start_date, end_date, product)
|
||||
#
|
||||
# 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.") % (
|
||||
# product.name, quantity, available_qty
|
||||
# ))
|
||||
|
||||
# Find or create partner
|
||||
partner = request.env['res.partner'].sudo().search([('email', '=', customer_email)], limit=1)
|
||||
|
||||
Binary file not shown.
@ -112,34 +112,10 @@ class EventRentalRequest(models.Model):
|
||||
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.
|
||||
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
|
||||
|
||||
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):
|
||||
product = self.env['product.product'].search([('default_code', '=', default_code)], limit=1)
|
||||
if not product:
|
||||
@ -161,13 +137,13 @@ class EventRentalRequest(models.Model):
|
||||
if not self.line_ids:
|
||||
raise UserError(_("Please add at least one rental product line."))
|
||||
|
||||
# Re-check availability before approving
|
||||
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)
|
||||
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.") % (
|
||||
line.product_id.display_name, line.quantity, available_qty
|
||||
))
|
||||
# Re-check availability bypassed per request
|
||||
# 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)
|
||||
# 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.") % (
|
||||
# line.product_id.display_name, line.quantity, available_qty
|
||||
# ))
|
||||
|
||||
# Check/create partner
|
||||
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')
|
||||
def _compute_is_available(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
|
||||
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):
|
||||
|
||||
@ -323,7 +323,7 @@
|
||||
<div class="text-center mb-5">
|
||||
<span class="aakriti-cursive d-block" style="font-size: 1.8rem;">Let's Design Together</span>
|
||||
<h2 class="display-5" style="font-size: 2rem;">Inquire About Your Event</h2>
|
||||
<p class="text-muted" style="max-width: 600px; margin: 8px auto 0; font-size: 0.95rem;">Enter details below. Our reservations engine will instantly check stock availability and generate an itemized quote.</p>
|
||||
<p class="text-muted" style="max-width: 600px; margin: 8px auto 0; font-size: 0.95rem;">Enter details below to submit your inquiry. Our reservations engine will instantly generate an itemized quote.</p>
|
||||
</div>
|
||||
|
||||
<!-- Error Alert -->
|
||||
@ -399,7 +399,7 @@
|
||||
<!-- Product Details -->
|
||||
<h5 class="section-header mb-4">3. Rental Item Selected</h5>
|
||||
<div class="row">
|
||||
<div class="form-group col-md-8 mb-3">
|
||||
<div class="form-group col-md-12 mb-3">
|
||||
<label for="product_id">Selected Product / Service <span class="text-danger">*</span></label>
|
||||
<select name="product_id" id="product_id" class="form-control" required="1">
|
||||
<t t-foreach="all_products" t-as="prod">
|
||||
@ -409,10 +409,6 @@
|
||||
</t>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group col-md-4 mb-3">
|
||||
<label for="quantity">Quantity Required <span class="text-danger">*</span></label>
|
||||
<input type="number" name="quantity" id="quantity" class="form-control" min="1" step="1" required="1" t-att-value="post.get('quantity', '1')"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="my-4" style="border-top: 1px solid #eef2f7;"/>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user