7 changed files with 388 additions and 239 deletions
@ -1,152 +0,0 @@ |
|||||
odoo.define('pos_kitchen_screen_odoo.dashboard_action', function(require) { |
|
||||
"use strict"; |
|
||||
var AbstractAction = require('web.AbstractAction'); |
|
||||
var core = require('web.core'); |
|
||||
document.write( |
|
||||
unescape("%3Cscript src='https://cdn.jsdelivr.net/npm/chart.js' type='text/javascript'%3E%3C/script%3E")); |
|
||||
const { |
|
||||
loadBundle |
|
||||
} = require("@web/core/assets"); |
|
||||
var QWeb = core.qweb; |
|
||||
var rpc = require('web.rpc'); |
|
||||
|
|
||||
//extending abstract actions for the dashboard
|
|
||||
var KitchenCustomDashBoard = AbstractAction.extend({ |
|
||||
template: 'KitchenCustomDashBoard', |
|
||||
events: { |
|
||||
'click .cancel_order': 'cancel_order', |
|
||||
'click .accept_order': 'accept_order', |
|
||||
'click .accept_order_line': 'accept_order_line', |
|
||||
'click .done_order': 'done_order', |
|
||||
'click .ready_stage': 'ready_stage', |
|
||||
'click .waiting_stage': 'waiting_stage', |
|
||||
'click .draft_stage': 'draft_stage', |
|
||||
}, |
|
||||
|
|
||||
//set up the dashboard template and fetch the data every 2 seconds from the backend for the dashboard
|
|
||||
init: function(parent, context) { |
|
||||
var self = this; |
|
||||
this._super(parent, context); |
|
||||
setInterval(function() { |
|
||||
self.fetch_data(); |
|
||||
}, 1000); |
|
||||
this.dashboards_templates = ['KitchenOrder']; |
|
||||
this.shop_id = context.context.default_lead_id; |
|
||||
}, |
|
||||
//returning the fetched data
|
|
||||
willStart: function() { |
|
||||
var self = this; |
|
||||
return Promise.all([loadBundle(this), this._super()]).then(function() { |
|
||||
return self.fetch_data(); |
|
||||
}); |
|
||||
}, |
|
||||
//rendering the dashboard every 2 seconds
|
|
||||
start: function() { |
|
||||
var self = this; |
|
||||
this.set("title", 'Dashboard'); |
|
||||
return this._super().then(function() { |
|
||||
self.render_dashboards(); |
|
||||
setInterval(function() { |
|
||||
self.render_dashboards(); |
|
||||
}, 1000); |
|
||||
}); |
|
||||
}, |
|
||||
//Used to render the dashboard
|
|
||||
render_dashboards: function() { |
|
||||
var self = this; |
|
||||
console.log('render_dashboards',self) |
|
||||
_.each(this.dashboards_templates, function(template) { |
|
||||
self.$('.o_pj_dashboard').html(QWeb.render(template, { |
|
||||
widget: self |
|
||||
})); |
|
||||
}); |
|
||||
}, |
|
||||
// fetch pos order details
|
|
||||
fetch_data: function() { |
|
||||
var self = this; |
|
||||
var def1 = self._rpc({ |
|
||||
model: 'pos.order', |
|
||||
method: 'get_details', |
|
||||
args: [ |
|
||||
[], self.shop_id, [] |
|
||||
], |
|
||||
}).then(function(result) { |
|
||||
self.total_room = result['orders']; |
|
||||
self.lines = result['order_lines']; |
|
||||
}); |
|
||||
return $.when(def1); |
|
||||
}, |
|
||||
// cancel the order from the kitchen
|
|
||||
cancel_order: function(e) { |
|
||||
var input_id = this.$("#" + e.target.id).val(); |
|
||||
rpc.query({ |
|
||||
model: 'pos.order', |
|
||||
method: 'order_progress_cancel', |
|
||||
args: [ |
|
||||
[], input_id |
|
||||
] |
|
||||
}) |
|
||||
}, |
|
||||
// accept the order from the kitchen
|
|
||||
accept_order: function(e) { |
|
||||
var input_id = this.$("#" + e.target.id).val(); |
|
||||
ScrollReveal().reveal("#" + e.target.id, { |
|
||||
delay: 1000, |
|
||||
duration: 2000, |
|
||||
opacity: 0, |
|
||||
distance: "50%", |
|
||||
origin: "top", |
|
||||
reset: true, |
|
||||
interval: 600, |
|
||||
}); |
|
||||
rpc.query({ |
|
||||
model: 'pos.order', |
|
||||
method: 'order_progress_draft', |
|
||||
args: [ |
|
||||
[], input_id |
|
||||
] |
|
||||
}) |
|
||||
}, |
|
||||
//set the stage is ready to see the completed stage orders
|
|
||||
ready_stage: function(e) { |
|
||||
var self = this; |
|
||||
self.stages = 'ready'; |
|
||||
}, |
|
||||
//set the stage is waiting to see the ready stage orders
|
|
||||
waiting_stage: function(e) { |
|
||||
var self = this; |
|
||||
self.stages = 'waiting'; |
|
||||
}, |
|
||||
//set the stage is draft to see the cooking stage orders
|
|
||||
draft_stage: function(e) { |
|
||||
var self = this; |
|
||||
self.stages = 'draft'; |
|
||||
}, |
|
||||
// change the status of the order from the kitchen
|
|
||||
done_order: function(e) { |
|
||||
var input_id = this.$("#" + e.target.id).val(); |
|
||||
rpc.query({ |
|
||||
model: 'pos.order', |
|
||||
method: 'order_progress_change', |
|
||||
args: [ |
|
||||
[], input_id |
|
||||
] |
|
||||
}); |
|
||||
}, |
|
||||
|
|
||||
// change the status of the product from the kitchen
|
|
||||
accept_order_line: function(e) { |
|
||||
var input_id = this.$("#" + e.target.id).val(); |
|
||||
rpc.query({ |
|
||||
model: 'pos.order.line', |
|
||||
method: 'order_progress_change', |
|
||||
args: [ |
|
||||
[], input_id |
|
||||
] |
|
||||
}) |
|
||||
}, |
|
||||
|
|
||||
}); |
|
||||
core.action_registry.add('kitchen_custom_dashboard_tags', KitchenCustomDashBoard); |
|
||||
return KitchenCustomDashBoard; |
|
||||
}); |
|
@ -0,0 +1,136 @@ |
|||||
|
/** @odoo-module */ |
||||
|
|
||||
|
import { registry } from "@web/core/registry"; |
||||
|
const { Component, useState } = owl; |
||||
|
import { useService } from "@web/core/utils/hooks"; |
||||
|
|
||||
|
|
||||
|
class kitchen_screen_dashboard extends Component { |
||||
|
|
||||
|
setup() { |
||||
|
this.busService = useService('bus_service') |
||||
|
this.busService.addChannel("pos_order_created"); |
||||
|
this.busService.addEventListener('notification', this.onPosOrderCreation.bind(this)); |
||||
|
|
||||
|
this.action = useService("action"); |
||||
|
this.rpc = useService("rpc"); |
||||
|
this.orm = useService("orm"); |
||||
|
var self=this |
||||
|
|
||||
|
this.state = useState({ |
||||
|
order_details: [], |
||||
|
shop_id:[], |
||||
|
stages: 'draft', |
||||
|
draft_count:[], |
||||
|
waiting_count:[], |
||||
|
ready_count:[], |
||||
|
lines:[] |
||||
|
}); |
||||
|
var session_shop_id; |
||||
|
//if refreshing the page then the last passed context (shop id)
|
||||
|
//save to the session storage
|
||||
|
if (this.props.action.context.default_shop_id) { |
||||
|
sessionStorage.setItem('shop_id', this.props.action.context.default_shop_id); |
||||
|
this.shop_id = this.props.action.context.default_shop_id; |
||||
|
session_shop_id = sessionStorage.getItem('shop_id'); |
||||
|
} else { |
||||
|
session_shop_id = sessionStorage.getItem('shop_id'); |
||||
|
this.shop_id = parseInt(session_shop_id, 10);; |
||||
|
} |
||||
|
self.orm.call("pos.order", "get_details", ["", self.shop_id,""]).then(function(result) { |
||||
|
self.state.order_details = result['orders'] |
||||
|
self.state.lines = result['order_lines'] |
||||
|
self.state.shop_id=self.shop_id |
||||
|
self.state.draft_count=self.state.order_details.filter((order) => order.order_status=='draft' && order.config_id[0]==self.state.shop_id).length |
||||
|
self.state.waiting_count=self.state.order_details.filter((order) => order.order_status=='waiting' && order.config_id[0]==self.state.shop_id).length |
||||
|
self.state.ready_count=self.state.order_details.filter((order) => order.order_status=='ready' && order.config_id[0]==self.state.shop_id).length |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
//Calling the onPosOrderCreation when an order is created or edited on the backend and return the notification
|
||||
|
onPosOrderCreation(message){ |
||||
|
let payload = message.detail[0].payload |
||||
|
var self=this |
||||
|
if(payload.message == "pos_order_created" && payload.res_model == "pos.order"){ |
||||
|
self.orm.call("pos.order", "get_details", ["", self.shop_id,""]).then(function(result) { |
||||
|
self.state.order_details = result['orders'] |
||||
|
self.state.lines = result['order_lines'] |
||||
|
self.state.shop_id=self.shop_id |
||||
|
self.state.draft_count=self.state.order_details.filter((order) => order.order_status=='draft' && order.config_id[0]==self.state.shop_id).length |
||||
|
self.state.waiting_count=self.state.order_details.filter((order) => order.order_status=='waiting' && order.config_id[0]==self.state.shop_id).length |
||||
|
self.state.ready_count=self.state.order_details.filter((order) => order.order_status=='ready' && order.config_id[0]==self.state.shop_id).length |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// cancel the order from the kitchen
|
||||
|
cancel_order(e) { |
||||
|
var input_id = $("#" + e.target.id).val(); |
||||
|
this.orm.call("pos.order", "order_progress_cancel", [Number(input_id)]) |
||||
|
var current_order = this.state.order_details.filter((order) => order.id==input_id) |
||||
|
if(current_order){ |
||||
|
current_order[0].order_status = 'cancel' |
||||
|
} |
||||
|
} |
||||
|
// accept the order from the kitchen
|
||||
|
accept_order(e) { |
||||
|
var input_id = $("#" + e.target.id).val(); |
||||
|
ScrollReveal().reveal("#" + e.target.id, { |
||||
|
delay: 1000, |
||||
|
duration: 2000, |
||||
|
opacity: 0, |
||||
|
distance: "50%", |
||||
|
origin: "top", |
||||
|
reset: true, |
||||
|
interval: 600, |
||||
|
}); |
||||
|
var self=this |
||||
|
this.orm.call("pos.order", "order_progress_draft", [Number(input_id)]) |
||||
|
var current_order = this.state.order_details.filter((order) => order.id==input_id) |
||||
|
if(current_order){ |
||||
|
current_order[0].order_status = 'waiting' |
||||
|
} |
||||
|
} |
||||
|
// set the stage is ready to see the completed stage orders
|
||||
|
ready_stage(e) { |
||||
|
var self = this; |
||||
|
self.state.stages = 'ready'; |
||||
|
} |
||||
|
//set the stage is waiting to see the ready stage orders
|
||||
|
waiting_stage(e) { |
||||
|
var self = this; |
||||
|
self.state.stages = 'waiting'; |
||||
|
} |
||||
|
//set the stage is draft to see the cooking stage orders
|
||||
|
draft_stage(e) { |
||||
|
var self = this; |
||||
|
self.state.stages = 'draft'; |
||||
|
} |
||||
|
// change the status of the order from the kitchen
|
||||
|
done_order(e) { |
||||
|
var self = this; |
||||
|
var input_id = $("#" + e.target.id).val(); |
||||
|
this.orm.call("pos.order", "order_progress_change", [Number(input_id)]) |
||||
|
var current_order = this.state.order_details.filter((order) => order.id==input_id) |
||||
|
if(current_order){ |
||||
|
current_order[0].order_status = 'ready' |
||||
|
} |
||||
|
} |
||||
|
// change the status of the product from the kitchen
|
||||
|
accept_order_line(e) { |
||||
|
var input_id = $("#" + e.target.id).val(); |
||||
|
this.orm.call("pos.order.line", "order_progress_change", [Number(input_id)]) |
||||
|
var current_order_line=this.state.lines.filter((order_line) => order_line.id==input_id) |
||||
|
if (current_order_line){ |
||||
|
if (current_order_line[0].order_status == 'ready'){ |
||||
|
current_order_line[0].order_status = 'waiting' |
||||
|
} |
||||
|
else{ |
||||
|
current_order_line[0].order_status = 'ready' |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
kitchen_screen_dashboard.template = 'KitchenCustomDashBoard'; |
||||
|
registry.category("actions").add("kitchen_custom_dashboard_tags", kitchen_screen_dashboard); |
Loading…
Reference in new issue