[ADD] pos_hr_restaurant: link between pos_hr and pos_restaurant

Moved the cross behaviors and logics in a new link module. This avoid having to
create hook methods in the `point_of_sale` that needs to be overridden.

closes odoo/odoo#92256

Signed-off-by: Masereel Pierre <pim@odoo.com>
This commit is contained in:
Jacky (trj)
2022-05-31 11:07:08 +02:00
parent 48f340d885
commit 0e2840aa87
12 changed files with 82 additions and 41 deletions
-4
View File
@@ -104,10 +104,6 @@ class PosOrder(models.Model):
return new_session
def _get_fields_for_draft_order(self):
"""This method is here to be overridden in order to add fields that are required for draft orders."""
return []
@api.model
def _process_order(self, order, draft, existing_order):
"""Create or update an pos.order from a given dictionary.
@@ -546,9 +546,6 @@ odoo.define('point_of_sale.Chrome', function(require) {
console.error('Unknown error. Unable to show information about this error.', errorToHandle);
}
}
_shouldResetIdleTimer() {
return true;
}
}
Chrome.template = 'Chrome';
Object.defineProperty(Chrome, "components", {
-5
View File
@@ -28,8 +28,3 @@ class PosOrder(models.Model):
'employee_id': order.employee_id.id,
})
return result
def _get_fields_for_draft_order(self):
fields = super(PosOrder, self)._get_fields_for_draft_order()
fields.append('employee_id')
return fields
-3
View File
@@ -22,9 +22,6 @@ odoo.define('pos_hr.chrome', function (require) {
}
return super.shouldShowCashControl();
}
_shouldResetIdleTimer() {
return super._shouldResetIdleTimer() && this.tempScreen.name !== 'LoginScreen';
}
};
Registries.Component.extend(Chrome, PosHrChrome);
+4
View File
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
+21
View File
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'PoS HR Restaurant',
'version': '1.0',
'category': 'Hidden',
'summary': 'Link module between pos_hr and pos_restaurant',
'description': """
This module adapts the behavior of the PoS when the pos_hr and pos_restaurant are installed.
""",
'depends': ['pos_hr', 'pos_restaurant'],
'auto_install': True,
'assets': {
'point_of_sale.assets': [
'pos_hr_restaurant/static/src/js/**/*.js',
],
},
'license': 'LGPL-3',
}
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import pos_order
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, api
class PosOrder(models.Model):
_inherit = "pos.order"
def _get_fields_for_draft_order(self):
fields = super()._get_fields_for_draft_order()
fields.append('employee_id')
return fields
@api.model
def get_table_draft_orders(self, table_id):
table_orders = super().get_table_draft_orders(table_id)
for order in table_orders:
if order['employee_id']:
order['employee_id'] = order['employee_id'][0] if order['employee_id'] else False
return table_orders
@@ -0,0 +1,14 @@
/* @odoo-module alias=pos_restaurant_hr.chrome */
import Chrome from 'point_of_sale.Chrome';
import Registries from 'point_of_sale.Registries';
export const PosHrRestaurantChrome = (Chrome) => class extends Chrome {
//@override
_shouldResetIdleTimer() {
return super._shouldResetIdleTimer() && this.tempScreen.name !== 'LoginScreen';
}
}
Registries.Component.extend(Chrome, PosHrRestaurantChrome);
+15 -19
View File
@@ -132,23 +132,21 @@ class PosOrder(models.Model):
next(order for order in orders if order['id'] == order_id[0])['statement_ids'] = list(payment_lines)
def _get_fields_for_draft_order(self):
fields = super(PosOrder, self)._get_fields_for_draft_order()
fields.extend([
'id',
'pricelist_id',
'partner_id',
'sequence_number',
'session_id',
'pos_reference',
'create_uid',
'create_date',
'customer_count',
'fiscal_position_id',
'table_id',
'to_invoice',
'multiprint_resume',
])
return fields
return [
'id',
'pricelist_id',
'partner_id',
'sequence_number',
'session_id',
'pos_reference',
'create_uid',
'create_date',
'customer_count',
'fiscal_position_id',
'table_id',
'to_invoice',
'multiprint_resume',
]
@api.model
def get_table_draft_orders(self, table_id):
@@ -182,8 +180,6 @@ class PosOrder(models.Model):
order['partner_id'] = order['partner_id'][0]
if order['table_id']:
order['table_id'] = order['table_id'][0]
if 'employee_id' in order:
order['employee_id'] = order['employee_id'][0] if order['employee_id'] else False
if not 'lines' in order:
order['lines'] = []
@@ -45,18 +45,14 @@ odoo.define('pos_restaurant.chrome', function (require) {
}
}
_setIdleTimer() {
clearTimeout(this.idleTimer);
if (this._shouldResetIdleTimer()) {
clearTimeout(this.idleTimer);
this.idleTimer = setTimeout(() => {
this._actionAfterIdle();
}, 60000);
}
}
_actionAfterIdle() {
// We also need to check if the action still need to be triggered
if (!this._shouldResetIdleTimer()) {
return;
}
if (this.tempScreen.isShown) {
this.trigger('close-temp-screen');
}
@@ -70,7 +66,7 @@ odoo.define('pos_restaurant.chrome', function (require) {
this.showScreen('FloorScreen', { floor: table ? table.floor : null });
}
_shouldResetIdleTimer() {
return super._shouldResetIdleTimer() && this.env.pos.config.iface_floorplan && this.mainScreen.name !== 'FloorScreen';
return this.env.pos.config.iface_floorplan && this.mainScreen.name !== 'FloorScreen';
}
__showScreen() {
super.__showScreen(...arguments);
@@ -152,7 +152,6 @@ odoo.define('pos_restaurant.FloorScreen', function (require) {
).length;
table_obj.order_count = table.orders + unsynced_orders;
});
this.render();
} catch (error) {
if (isConnectionError(error)) {
await this.showPopup('OfflineErrorPopup', {