summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorJoseph Caburnay <jcb@odoo.com>2020-09-14 15:12:19 +0000
committerAntoine Prieels <anp@odoo.com>2020-10-08 14:18:18 +0000
commit0fd87bca3041e680deb628e1952e995e4a2dba54 (patch)
treeef352a7a8c3a74142278931642560de569ab1453 /addons
parent0a400313136ff7a7359d6105200522e859ce865d (diff)
[FIX] point_of_sale: include active orders in search results
When searching in the order management screen, we only include results from orders saved in the server, which excludes the orders currently saved locally. In this commit, we allow the search to include those locally-saved orders. closes odoo/odoo#57674 Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/point_of_sale/static/src/js/Screens/OrderManagementScreen/OrderFetcher.js39
1 files changed, 29 insertions, 10 deletions
diff --git a/addons/point_of_sale/static/src/js/Screens/OrderManagementScreen/OrderFetcher.js b/addons/point_of_sale/static/src/js/Screens/OrderManagementScreen/OrderFetcher.js
index 9af727717d9..57a0263567b 100644
--- a/addons/point_of_sale/static/src/js/Screens/OrderManagementScreen/OrderFetcher.js
+++ b/addons/point_of_sale/static/src/js/Screens/OrderManagementScreen/OrderFetcher.js
@@ -15,7 +15,34 @@ odoo.define('point_of_sale.OrderFetcher', function (require) {
this.totalCount = 0;
}
get activeOrders() {
- return this.searchDomain ? [] : this.comp.env.pos.get('orders').models;
+ const allActiveOrders = this.comp.env.pos.get('orders').models;
+ return this.searchDomain
+ ? allActiveOrders.filter(this._predicateBasedOnSearchDomain.bind(this))
+ : allActiveOrders;
+ }
+ _predicateBasedOnSearchDomain(order) {
+ function check(order, field, searchWord) {
+ searchWord = searchWord.toLowerCase();
+ switch (field) {
+ case 'pos_reference':
+ return order.name.toLowerCase().includes(searchWord);
+ case 'partner_id.display_name':
+ const client = order.get_client();
+ return client ? client.name.toLowerCase().includes(searchWord) : false;
+ case 'date_order':
+ return moment(order.creation_date).format('YYYY-MM-DD hh:mm A').includes(searchWord);
+ default:
+ return false;
+ }
+ }
+ for (let [field, _, searchWord] of (this.searchDomain || []).filter((item) => item !== '|')) {
+ // remove surrounding "%" from `searchWord`
+ searchWord = searchWord.substring(1, searchWord.length - 1);
+ if (check(order, field, searchWord)) {
+ return true;
+ }
+ }
+ return false;
}
get nActiveOrders() {
return this.activeOrders.length;
@@ -147,20 +174,12 @@ odoo.define('point_of_sale.OrderFetcher', function (require) {
}
}
/**
- * NOTE: If there is searchDomain, do not show the active orders.
- * Unless we want the searchDomain to be applicable to the active orders
- * as well. Don't we?
- *
* @param {integer|undefined} id id of the cached order
* @returns {Array<models.Order>}
*/
get(id) {
if (id) return this.cache[id];
- if (this.searchDomain) {
- return this.ordersToShow.filter((order) => order.locked);
- } else {
- return this.ordersToShow;
- }
+ return this.ordersToShow;
}
setSearchDomain(searchDomain) {
this.searchDomain = searchDomain;