14 changed files with 530 additions and 30 deletions
@ -0,0 +1,29 @@ |
|||
from odoo import http |
|||
from odoo.http import request |
|||
|
|||
|
|||
class ResConfigSettingsController(http.Controller): |
|||
|
|||
@http.route('/pos/get_opening_closing_hours', type='json', auth='public', methods=['POST']) |
|||
def get_opening_closing_hours(self): |
|||
pos_config = request.env['pos.config'].sudo().search([], limit=1, order="id desc") |
|||
# Ensure proper time format |
|||
try: |
|||
opening_hour = self.float_to_time(float(pos_config.opening_hour)) |
|||
closing_hour = self.float_to_time(float(pos_config.closing_hour)) |
|||
except ValueError: |
|||
opening_hour = "00:00" |
|||
closing_hour = "23:59" |
|||
|
|||
if pos_config: |
|||
return { |
|||
'opening_hour': opening_hour, |
|||
'closing_hour': closing_hour |
|||
} |
|||
return {'error': 'POS configuration not found'} |
|||
|
|||
def float_to_time(self, hour_float): |
|||
""" Convert float hours (e.g., 8.5 → 08:30) to HH:MM format """ |
|||
hours = int(hour_float) |
|||
minutes = int((hour_float - hours) * 60) |
|||
return f"{hours:02d}:{minutes:02d}" |
After Width: | Height: | Size: 84 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 37 KiB |
@ -0,0 +1,108 @@ |
|||
/** @odoo-module **/ |
|||
import publicWidget from 'web.public.widget'; |
|||
import { registry } from '@web/core/registry'; |
|||
import { rpc } from "@web/core/network/rpc_service"; |
|||
import ajax from "web.ajax"; |
|||
|
|||
publicWidget.registry.reservation = publicWidget.Widget.extend({ |
|||
selector: '.container', |
|||
events: { |
|||
'change #date': '_onChangeDate', |
|||
'change #start_time': '_onChangeTime', |
|||
'change #end_time': '_onChangeTime', |
|||
'click .close_btn_alert_modal': '_onClickCloseBtn', |
|||
'click .close_btn_time_alert_modal': '_onClickCloseAlertBtn', |
|||
}, |
|||
async start() { |
|||
this.openingHour = null; |
|||
this.closingHour = null; |
|||
await this._fetchOpeningClosingHours(); |
|||
}, |
|||
async _fetchOpeningClosingHours() { |
|||
try { |
|||
const result = await ajax.jsonRpc("/pos/get_opening_closing_hours", "call", {}); |
|||
if (result && !result.error) { |
|||
this.openingHour = result.opening_hour; |
|||
this.closingHour = result.closing_hour; |
|||
} else { |
|||
console.error("Error: ", result.error); |
|||
} |
|||
} catch (error) { |
|||
console.error("Failed to fetch opening and closing hours:", error); |
|||
} |
|||
}, |
|||
|
|||
_onChangeDate: function (ev) { |
|||
let selectedDate = new Date(this.$el.find("#date").val()); |
|||
const currentDate = new Date(); |
|||
if (selectedDate.setHours(0, 0, 0, 0) < currentDate.setHours(0, 0, 0, 0)) { |
|||
this.$el.find("#alert_modal").show(); |
|||
this.$el.find("#date").val(''); |
|||
} |
|||
this._onChangeTime(); |
|||
}, |
|||
|
|||
_onClickCloseBtn: function() { |
|||
this.$el.find("#alert_modal").hide(); |
|||
}, |
|||
|
|||
_onChangeTime: function() { |
|||
let start_time = this.$el.find("#start_time"); |
|||
let end_time = this.$el.find("#end_time"); |
|||
|
|||
let now = new Date(); |
|||
let currentHours = now.getHours().toString().padStart(2, '0'); |
|||
let currentMinutes = now.getMinutes().toString().padStart(2, '0'); |
|||
let currentTime = `${currentHours}:${currentMinutes}`; |
|||
|
|||
const currentDate = new Date(); |
|||
const formattedDate = currentDate.toISOString().split('T')[0]; |
|||
|
|||
if (start_time.val() && end_time.val()) { |
|||
if (start_time.val() > end_time.val() || start_time.val() == end_time.val()) { |
|||
this.$el.find("#time_alert_modal").show(); |
|||
start_time.val(''); |
|||
end_time.val(''); |
|||
return; |
|||
} |
|||
} |
|||
|
|||
if (!this.openingHour || !this.closingHour) { |
|||
console.warn("Opening and closing hours are not set."); |
|||
return; |
|||
} |
|||
|
|||
if (start_time.val() && (start_time.val() < this.openingHour || start_time.val() > this.closingHour)) { |
|||
this.$el.find("#time_alert_modal").show(); |
|||
start_time.val(''); |
|||
end_time.val(''); |
|||
return; |
|||
} |
|||
|
|||
if (end_time.val() && (end_time.val() < this.openingHour || end_time.val() > this.closingHour)) { |
|||
this.$el.find("#time_alert_modal").show(); |
|||
start_time.val(''); |
|||
end_time.val(''); |
|||
return; |
|||
} |
|||
|
|||
if (formattedDate == this.$el.find("#date").val()) { |
|||
if (start_time.val() && start_time.val() < currentTime) { |
|||
this.$el.find("#time_alert_modal").show(); |
|||
start_time.val(''); |
|||
end_time.val(''); |
|||
return; |
|||
} |
|||
if (end_time.val() && end_time.val() < currentTime) { |
|||
this.$el.find("#time_alert_modal").show(); |
|||
start_time.val(''); |
|||
end_time.val(''); |
|||
return; |
|||
} |
|||
} |
|||
}, |
|||
|
|||
_onClickCloseAlertBtn: function() { |
|||
this.$el.find("#time_alert_modal").hide(); |
|||
} |
|||
}); |
Loading…
Reference in new issue