Browse Source

Feb 18: [FIX] Bug Fixed 'table_reservation_on_website'

pull/317/merge
Cybrosys Technologies 2 months ago
parent
commit
85ba09cc1e
  1. 2
      table_reservation_on_website/__manifest__.py
  2. 1
      table_reservation_on_website/controllers/__init__.py
  3. 31
      table_reservation_on_website/controllers/pos_config.py
  4. 18
      table_reservation_on_website/controllers/table_reservation_on_website.py
  5. 5
      table_reservation_on_website/doc/RELEASE_NOTES.md
  6. 30
      table_reservation_on_website/models/pos_config.py
  7. 36
      table_reservation_on_website/models/res_config_settings.py
  8. BIN
      table_reservation_on_website/static/description/assets/screenshots/1.png
  9. BIN
      table_reservation_on_website/static/description/assets/screenshots/17.png
  10. BIN
      table_reservation_on_website/static/description/assets/screenshots/22.png
  11. BIN
      table_reservation_on_website/static/description/assets/screenshots/4.png
  12. 1477
      table_reservation_on_website/static/description/index.html
  13. 2
      table_reservation_on_website/static/src/app/screens/floor_screen/floor_screen.js
  14. 1
      table_reservation_on_website/static/src/app/screens/product_screen/product_screen.js
  15. 119
      table_reservation_on_website/static/src/js/reservation.js
  16. 19
      table_reservation_on_website/views/res_config_settings_views.xml
  17. 30
      table_reservation_on_website/views/table_reservation_templates.xml

2
table_reservation_on_website/__manifest__.py

@ -21,7 +21,7 @@
############################################################################### ###############################################################################
{ {
'name': 'Table Reservation On POS And Website', 'name': 'Table Reservation On POS And Website',
'version': '17.0.1.1.3', 'version': '17.0.1.2.3',
'category': 'eCommerce,Point of Sale', 'category': 'eCommerce,Point of Sale',
'summary': 'Reserve tables in POS from website', 'summary': 'Reserve tables in POS from website',
'description': """This module enables to reserve tables in POS from website. 'description': """This module enables to reserve tables in POS from website.

1
table_reservation_on_website/controllers/__init__.py

@ -21,3 +21,4 @@
############################################################################### ###############################################################################
from . import table_reservation_on_website_website_sale from . import table_reservation_on_website_website_sale
from . import table_reservation_on_website from . import table_reservation_on_website
from . import pos_config

31
table_reservation_on_website/controllers/pos_config.py

@ -0,0 +1,31 @@
from datetime import datetime
from odoo import http
from odoo.http import request, _logger
class ResConfigSettingsController(http.Controller):
@http.route('/pos/get_opening_closing_hours', type='json', auth='public', methods=['POST'])
def get_opening_closing_hours(self):
res_config = request.env['res.config.settings'].sudo().search([], limit=1)
# Ensure proper time format
try:
opening_hour = self.float_to_time(float(res_config.pos_opening_hour))
closing_hour = self.float_to_time(float(res_config.pos_closing_hour))
except ValueError:
opening_hour = "00:00"
closing_hour = "23:59"
if res_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}"

18
table_reservation_on_website/controllers/table_reservation_on_website.py

@ -30,8 +30,24 @@ class TableReservation(http.Controller):
@http.route(['/table_reservation'], type='http', auth='user', website=True) @http.route(['/table_reservation'], type='http', auth='user', website=True)
def table_reservation(self): def table_reservation(self):
""" For rendering table reservation template """ """ For rendering table reservation template """
pos_config = request.env['res.config.settings'].sudo().search([],
limit=1)
try:
opening_hour = self.float_to_time(float(pos_config.pos_opening_hour))
closing_hour = self.float_to_time(float(pos_config.pos_closing_hour))
except ValueError:
opening_hour = "00:00"
closing_hour = "23:59"
return http.request.render( return http.request.render(
"table_reservation_on_website.table_reservation", {}) "table_reservation_on_website.table_reservation", {'opening_hour': opening_hour,
'closing_hour': closing_hour})
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}"
@http.route(['/restaurant/floors'], type='http', auth='user', website=True) @http.route(['/restaurant/floors'], type='http', auth='user', website=True)
def restaurant_floors(self, **kwargs): def restaurant_floors(self, **kwargs):

5
table_reservation_on_website/doc/RELEASE_NOTES.md

@ -19,3 +19,8 @@
#### Version 17.0.1.1.3 #### Version 17.0.1.1.3
##### BUGFIX ##### BUGFIX
- Updated the module work flow. - Updated the module work flow.
#### 18.02.2025
#### Version 17.0.1.2.3
##### BUGFIX
- Updated module to set opening and closing hours.

30
table_reservation_on_website/models/pos_config.py

@ -19,7 +19,7 @@
# If not, see <http://www.gnu.org/licenses/>. # If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################### ###############################################################################
from odoo import fields, models from odoo import api, fields, models
class PosConfig(models.Model): class PosConfig(models.Model):
@ -38,7 +38,33 @@ class PosConfig(models.Model):
help="Enable to apply charge for reservations.") help="Enable to apply charge for reservations.")
is_paid = fields.Boolean(string="Is paid reservation", is_paid = fields.Boolean(string="Is paid reservation",
help="To identify if the reservation is already paid") help="To identify if the reservation is already paid")
set_opening_hours = fields.Boolean(
string="Set Opening and Closing Hours",
help="Enable to configure restaurant opening and closing hours.")
opening_hour = fields.Float(
string="Opening Hour",
compute="_compute_opening_hour",
store=True
)
closing_hour = fields.Float(
string="Closing Hour",
compute="_compute_closing_hour",
store=True
)
def _compute_opening_hour(self):
""" Fetch opening hour from system parameters """
for record in self:
record.opening_hour = float(
self.env['ir.config_parameter'].sudo().get_param(
'table_reservation_on_website.opening_hour', default=0.0))
def _compute_closing_hour(self):
""" Fetch closing hour from system parameters """
for record in self:
record.closing_hour = float(
self.env['ir.config_parameter'].sudo().get_param(
'table_reservation_on_website.closing_hour', default=23.99))
def _compute_has_lead_time(self): def _compute_has_lead_time(self):
""" To check whether lead time is enabled from settings """ """ To check whether lead time is enabled from settings """
if self.env['ir.config_parameter'].sudo().get_param( if self.env['ir.config_parameter'].sudo().get_param(
@ -54,3 +80,5 @@ class PosConfig(models.Model):
self.has_reservation_charge = True self.has_reservation_charge = True
else: else:
self.has_reservation_charge = False self.has_reservation_charge = False

36
table_reservation_on_website/models/res_config_settings.py

@ -42,6 +42,21 @@ class ResConfigSettings(models.TransientModel):
string="Reservation Lead Time", string="Reservation Lead Time",
help="The order should be reserved hours" help="The order should be reserved hours"
"before the booking start time.") "before the booking start time.")
pos_set_opening_hours = fields.Boolean(
related='pos_config_id.set_opening_hours',
readonly=False,
help="Enable to configure restaurant opening and closing hours."
)
pos_opening_hour = fields.Float(
related='pos_config_id.opening_hour',
readonly=False,
help="Restaurant opening hour in 24-hour format."
)
pos_closing_hour = fields.Float(
related='pos_config_id.closing_hour',
readonly=False,
help="Restaurant closing hour in 24-hour format."
)
def set_values(self): def set_values(self):
""" To set the value for fields in config setting """ """ To set the value for fields in config setting """
@ -53,6 +68,15 @@ class ResConfigSettings(models.TransientModel):
self.env['ir.config_parameter'].sudo().set_param( self.env['ir.config_parameter'].sudo().set_param(
'table_reservation_on_website.reservation_lead_time', 'table_reservation_on_website.reservation_lead_time',
self.reservation_lead_time) self.reservation_lead_time)
self.env['ir.config_parameter'].sudo().set_param(
'table_reservation_on_website.set_opening_hours',
self.pos_set_opening_hours)
self.env['ir.config_parameter'].sudo().set_param(
'table_reservation_on_website.opening_hour',
self.pos_opening_hour)
self.env['ir.config_parameter'].sudo().set_param(
'table_reservation_on_website.closing_hour',
self.pos_closing_hour)
return res return res
def get_values(self): def get_values(self):
@ -69,4 +93,16 @@ class ResConfigSettings(models.TransientModel):
res.update( res.update(
reservation_lead_time=reservation_lead_time if reservation_lead_time reservation_lead_time=reservation_lead_time if reservation_lead_time
else 0.0) else 0.0)
set_opening_hours = self.env['ir.config_parameter'].sudo().get_param(
'table_reservation_on_website.set_opening_hours')
res.update(pos_set_opening_hours=bool(set_opening_hours))
opening_hour = self.env['ir.config_parameter'].sudo().get_param(
'table_reservation_on_website.opening_hour')
res.update(
pos_opening_hour=float(opening_hour) if opening_hour else 0.0)
closing_hour = self.env[
'ir.config_parameter'].sudo().get_param(
'table_reservation_on_website.closing_hour')
res.update(
pos_closing_hour=float(closing_hour) if opening_hour else 0.0)
return res return res

BIN
table_reservation_on_website/static/description/assets/screenshots/1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 KiB

After

Width:  |  Height:  |  Size: 84 KiB

BIN
table_reservation_on_website/static/description/assets/screenshots/17.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

After

Width:  |  Height:  |  Size: 84 KiB

BIN
table_reservation_on_website/static/description/assets/screenshots/22.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
table_reservation_on_website/static/description/assets/screenshots/4.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 78 KiB

1477
table_reservation_on_website/static/description/index.html

File diff suppressed because it is too large

2
table_reservation_on_website/static/src/app/screens/floor_screen/floor_screen.js

@ -35,10 +35,8 @@ patch(FloorScreen.prototype, {
}, },
async onSelectTable(table, ev) { async onSelectTable(table, ev) {
// if (table['reserved'] == true){ // if (table['reserved'] == true){
// console.log("hello welcome", this.env.services.pos)
// var data = await this.orm.call('table.reservation', 'add_payment', [table.id, table.floor.id]) // var data = await this.orm.call('table.reservation', 'add_payment', [table.id, table.floor.id])
// const current_order = this.pos.get_order(); // const current_order = this.pos.get_order();
// console.log("prod", current_order)
// if (this.pos.get_order){ // if (this.pos.get_order){
// } // }
// this.pos.get_order().add_product(product, { // this.pos.get_order().add_product(product, {

1
table_reservation_on_website/static/src/app/screens/product_screen/product_screen.js

@ -22,7 +22,6 @@ patch(ProductScreen.prototype, {
var product = this.pos.db.product_by_id[productDetails[0].product_id] var product = this.pos.db.product_by_id[productDetails[0].product_id]
product['lst_price'] = productDetails[0].rate product['lst_price'] = productDetails[0].rate
if (current_order.orderlines.length == 0){ if (current_order.orderlines.length == 0){
console.log('prodsss', product['lst_price'])
this.pos.get_order().add_product(product, { this.pos.get_order().add_product(product, {
quantity: 1, quantity: 1,
}); });

119
table_reservation_on_website/static/src/js/reservation.js

@ -1,5 +1,6 @@
/** @odoo-module */ /** @odoo-module */
import publicWidget from "@web/legacy/js/public/public_widget"; import publicWidget from "@web/legacy/js/public/public_widget";
import { jsonrpc } from "@web/core/network/rpc_service";
publicWidget.registry.reservation = publicWidget.Widget.extend({ publicWidget.registry.reservation = publicWidget.Widget.extend({
selector: '.container', selector: '.container',
@ -10,6 +11,24 @@ publicWidget.registry.reservation = publicWidget.Widget.extend({
'click .close_btn_alert_modal': '_onClickCloseBtn', 'click .close_btn_alert_modal': '_onClickCloseBtn',
'click .close_btn_time_alert_modal': '_onClickCloseAlertBtn', 'click .close_btn_time_alert_modal': '_onClickCloseAlertBtn',
}, },
async start() {
this.openingHour = null;
this.closingHour = null;
await this._fetchOpeningClosingHours();
},
async _fetchOpeningClosingHours() {
try {
const result = await jsonrpc('/pos/get_opening_closing_hours', {});
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);
}
},
// To ensure booking date is a valid one. // To ensure booking date is a valid one.
_onChangeDate: function (ev) { _onChangeDate: function (ev) {
var selectedDate = new Date(this.$el.find("#date").val()) var selectedDate = new Date(this.$el.find("#date").val())
@ -26,45 +45,73 @@ publicWidget.registry.reservation = publicWidget.Widget.extend({
}, },
// Display a modal if invalid start time and end is chosen. // Display a modal if invalid start time and end is chosen.
_onChangeTime: function() { _onChangeTime: function() {
var start_time = this.$el.find("#start_time") var start_time = this.$el.find("#start_time");
var end_time = this.$el.find("#end_time") var end_time = this.$el.find("#end_time");
let now = new Date();
// Get the current time let now = new Date();
let currentHours = now.getHours().toString().padStart(2, '0'); let currentHours = now.getHours().toString().padStart(2, '0');
let currentMinutes = now.getMinutes().toString().padStart(2, '0'); let currentMinutes = now.getMinutes().toString().padStart(2, '0');
let currentTime = `${currentHours}:${currentMinutes}`; let currentTime = `${currentHours}:${currentMinutes}`;
// Get the current date
const currentDate = new Date(); const currentDate = new Date();
const year = currentDate.getFullYear(); const year = currentDate.getFullYear();
const month = String(currentDate.getMonth() + 1).padStart(2, '0'); // Months are zero-based const month = String(currentDate.getMonth() + 1).padStart(2, '0');
const day = String(currentDate.getDate()).padStart(2, '0'); const day = String(currentDate.getDate()).padStart(2, '0');
// Format the date as YYYY-MM-DD const formattedDate = `${year}-${month}-${day}`;
const formattedDate = `${year}-${month}-${day}`;
if (start_time.val() && end_time.val()) { if (start_time.val() && end_time.val()) {
if (start_time.val() > end_time.val()) { if (start_time.val() > end_time.val()) {
this.$el.find("#time_alert_modal").show() this.$el.find("#time_alert_modal").show();
start_time.val('') start_time.val('');
end_time.val('') end_time.val('');
} return;
} }
if (start_time.val() && end_time.val() && (start_time.val() == end_time.val())) { if (start_time.val() == end_time.val()) {
this.$el.find("#time_alert_modal").show() this.$el.find("#time_alert_modal").show();
start_time.val('') start_time.val('');
end_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() // Ensure opening and closing hours are available
start_time.val('') if (!this.openingHour || !this.closingHour) {
end_time.val('') console.warn("Opening and closing hours are not set.");
} return;
if (end_time.val() && end_time.val() < currentTime) { }
this.$el.find("#time_alert_modal").show()
start_time.val('') // Validate start and end time against opening and closing time
end_time.val('') 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)) {
var e = this.$el.find("#time_alert_modal").show();
start_time.val('');
end_time.val('');
return;
}
// Ensure the time is not in the past for the current day
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;
}
}
},
// To close the alert modal if invalid booking start and end time is chosen. // To close the alert modal if invalid booking start and end time is chosen.
_onClickCloseAlertBtn: function() { _onClickCloseAlertBtn: function() {
this.$el.find("#time_alert_modal").hide() this.$el.find("#time_alert_modal").hide()

19
table_reservation_on_website/views/res_config_settings_views.xml

@ -41,6 +41,25 @@
<field name="reservation_lead_time"/> <field name="reservation_lead_time"/>
</div> </div>
</div> </div>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="pos_set_opening_hours"/>
</div>
<div class="o_setting_right_pane">
<label for="pos_set_opening_hours"/>
<div class="text-muted">
Set opening and closing hours for restaurant reservation
</div>
</div>
<div class="o_setting_right_pane" style="display:flex;"
invisible="not pos_set_opening_hours">
<field name="pos_opening_hour"/>
</div>
<div class="o_setting_right_pane" style="display:flex;"
invisible="not pos_set_opening_hours">
<field name="pos_closing_hour"/>
</div>
</div>
</xpath> </xpath>
</field> </field>
</record> </record>

30
table_reservation_on_website/views/table_reservation_templates.xml

@ -17,6 +17,9 @@
<b>Table Reservation</b> <b>Table Reservation</b>
</h1> </h1>
<br/> <br/>
<t t-if="opening_hour and closing_hour">
<h4>Opening Hours: <t t-esc="opening_hour"/> - <t t-esc="closing_hour"/></h4>
</t>
<br/> <br/>
<div> <div>
<div class="form-group row" <div class="form-group row"
@ -119,6 +122,33 @@
</div> </div>
</div> </div>
</center> </center>
<center>
<div class="modal" tabindex="-1"
id="open_hours_alert_modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Invalid
Time
</h5>
</div>
<hr class="m-0"/>
<div class="modal-body">
<p>Select a time between the opening and closing hours
</p>
</div>
<hr class="m-0"/>
<div class="modal-footer">
<button type="button"
class="btn btn-secondary close_btn_time_alert_modal"
data-bs-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
</center>
<br/> <br/>
<div class="row" data-name="Submit Button"> <div class="row" data-name="Submit Button">
<div class="col-sm-2" style="padding-left:45%;"> <div class="col-sm-2" style="padding-left:45%;">

Loading…
Cancel
Save