Skip to content

Commit

Permalink
point_of_sale: [IMP] add category filter on pos.config
Browse files Browse the repository at this point in the history
Use Case:

In a multi point of sale setup, I probably will not have the same offer on
every point of sale.
While limiting to the available products on the seved location would be appealing
it does not fit the make_to_order restaurant use case. Limiting (optionally)
certain product categories, however, can be considered as safe.

Signed-off-by: "David Arnold" <"dar@xoe.solutions">
  • Loading branch information
David Arnold committed Feb 22, 2018
1 parent 71c36f6 commit 3243710
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
13 changes: 13 additions & 0 deletions addons/point_of_sale/models/pos_config.py
Expand Up @@ -103,6 +103,8 @@ def _compute_default_customer_html(self):
iface_tax_included = fields.Selection([('subtotal', 'Tax-Excluded Prices'), ('total', 'Tax-Included Prices')], "Tax Display", default='subtotal', required=True)
iface_start_categ_id = fields.Many2one('pos.category', string='Initial Category',
help='The point of sale will display this product category by default. If no category is specified, all available products will be shown.')
iface_available_categ_ids = fields.Many2many('pos.category', string='Available Category Tree',
help='The point of sale will only display products which are within one of the selected category trees. If no category is specified, all available products will be shown')
iface_display_categ_images = fields.Boolean(string='Display Category Pictures',
help="The product categories will be displayed with pictures.")
restrict_price_control = fields.Boolean(string='Restrict Price Modifications to Managers',
Expand Down Expand Up @@ -160,6 +162,7 @@ def _compute_default_customer_html(self):
tax_regime_selection = fields.Boolean("Tax Regime Selection value")
barcode_scanner = fields.Boolean("Barcode Scanner")
start_category = fields.Boolean("Set Start Category")
limit_categories = fields.Boolean("Limit Available Categories")
module_pos_restaurant = fields.Boolean("Is a Bar/Restaurant")
module_pos_discount = fields.Boolean("Global Discounts")
module_pos_loyalty = fields.Boolean("Loyalty Program")
Expand Down Expand Up @@ -258,6 +261,11 @@ def _check_currencies(self):
def _onchange_iface_print_via_proxy(self):
self.iface_print_auto = self.iface_print_via_proxy

@api.onchange('iface_available_categ_ids')
def _onchange_iface_available_categ_ids(self):
if self.iface_start_categ_id not in self.iface_available_categ_ids:
self.iface_start_categ_id = False

@api.onchange('picking_type_id')
def _onchange_picking_type_id(self):
if self.picking_type_id.default_location_src_id.usage == 'internal' and self.picking_type_id.default_location_dest_id.usage == 'customer':
Expand Down Expand Up @@ -321,6 +329,11 @@ def _onchange_start_category(self):
if not self.start_category:
self.iface_start_categ_id = False

@api.onchange('limit_categories')
def _onchange_limit_categories(self):
if not self.limit_categories:
self.iface_available_categ_ids = [(5, 0, 0)]

@api.onchange('is_header_or_footer')
def _onchange_header_footer(self):
if not self.is_header_or_footer:
Expand Down
12 changes: 9 additions & 3 deletions addons/point_of_sale/static/src/js/db.js
Expand Up @@ -86,7 +86,7 @@ var PosDB = core.Class.extend({
/* adds categories definitions to the database. categories is a list of categories objects as
* returned by the openerp server. Categories must be inserted before the products or the
* product/ categories association may (will) not work properly */
add_categories: function(categories){
add_categories: function(categories, available_categ_ids){
var self = this;
if(!this.category_by_id[this.root_category_id]){
this.category_by_id[this.root_category_id] = {
Expand All @@ -95,12 +95,15 @@ var PosDB = core.Class.extend({
};
}
for(var i=0, len = categories.length; i < len; i++){
if (available_categ_ids.length && !available_categ_ids.includes(categories[i].id)){
categories[i].invisible = true;
}
this.category_by_id[categories[i].id] = categories[i];
}
len = categories.length;
for(i=0; i < len; i++){
var cat = categories[i];
var parent_id = cat.parent_id[0] || this.root_category_id;
var parent_id = this.category_by_id[cat.parent_id[0]] ? cat.parent_id[0] : this.root_category_id;
this.category_parent[cat.id] = cat.parent_id[0];
if(!this.category_childs[parent_id]){
this.category_childs[parent_id] = [];
Expand Down Expand Up @@ -167,7 +170,7 @@ var PosDB = core.Class.extend({
str = product.id + ':' + str.replace(/:/g,'') + '\n';
return str;
},
add_products: function(products){
add_products: function(products, available_categ_ids){
var stored_categories = this.product_by_category_id;

if(!products instanceof Array){
Expand Down Expand Up @@ -202,6 +205,9 @@ var PosDB = core.Class.extend({
}
this.category_search_string[ancestor] += search_string;
}
if (available_categ_ids.length && !available_categ_ids.includes(categ_id)){
product.invisible = true;
}
this.product_by_id[product.id] = product;
if(product.barcode){
this.product_by_barcode[product.barcode] = product;
Expand Down
2 changes: 1 addition & 1 deletion addons/point_of_sale/static/src/js/models.js
Expand Up @@ -343,7 +343,7 @@ exports.PosModel = Backbone.Model.extend({
fields: ['id', 'name', 'parent_id', 'child_id'],
domain: null,
loaded: function(self, categories){
self.db.add_categories(categories);
self.db.add_categories(categories, self.config.iface_available_categ_ids);
},
},{
model: 'product.product',
Expand Down
13 changes: 12 additions & 1 deletion addons/point_of_sale/static/src/js/screens.js
Expand Up @@ -689,7 +689,13 @@ var ProductCategoriesWidget = PosBaseWidget.extend({
if(this.category.id !== db.root_category_id){
this.breadcrumb.push(this.category);
}
this.subcategories = db.get_category_by_id(db.get_category_childs_ids(this.category.id));
var subcategories = db.get_category_by_id(db.get_category_childs_ids(this.category.id));
for (var i = subcategories.length - 1; i >= 0; i--){
if (subcategories[i].invisible){
subcategories.splice(i, 1);
}
}
this.subcategories = subcategories;
},

get_image_url: function(category){
Expand Down Expand Up @@ -846,6 +852,11 @@ var ProductListWidget = PosBaseWidget.extend({
}, this);
},
set_product_list: function(product_list){
for (var i = product_list.length - 1; i >= 0; i--){
if (product_list[i].invisible){
product_list.splice(i, 1);
}
}
this.product_list = product_list;
this.renderElement();
},
Expand Down
17 changes: 15 additions & 2 deletions addons/point_of_sale/views/pos_config_view.xml
Expand Up @@ -72,6 +72,20 @@
</div>
</div>
</div>
<div class="col-xs-12 col-md-6 o_setting_box" >
<div class="o_setting_left_pane">
<field name="limit_categories"/>
</div>
<div class="o_setting_right_pane">
<label for="limit_categories"/>
<div class="text-muted">
Explicitly set the available categories
</div>
<div class="content-group mt16" attrs="{'invisible': [('limit_categories', '=', False)]}">
<field name="iface_available_categ_ids"/>
</div>
</div>
</div>
<div class="col-xs-12 col-md-6 o_setting_box" >
<div class="o_setting_left_pane">
<field name="start_category"/>
Expand All @@ -82,7 +96,7 @@
Start selling from a default product category
</div>
<div class="content-group mt16" attrs="{'invisible': [('start_category', '=', False)]}">
<field name="iface_start_categ_id"/>
<field name="iface_start_categ_id" domain="[iface_available_categ_ids and ('id', '=', iface_available_categ_ids[0][2]) or (1, '=', 1)]"/>
</div>
</div>
</div>
Expand Down Expand Up @@ -488,7 +502,6 @@
</div>
</div>
</sheet>

</form>
</field>
</record>
Expand Down

0 comments on commit 3243710

Please sign in to comment.