[IMP] pos_restaurant: allow to change the floor plans's background color from the POS

This commit is contained in:
Frédéric van der Essen
2015-02-02 16:29:32 +01:00
parent bec4e70829
commit 386f5f99d6
4 changed files with 60 additions and 12 deletions
+6 -1
View File
@@ -31,17 +31,22 @@ _logger = logging.getLogger(__name__)
class restaurant_floor(osv.osv):
_name = 'restaurant.floor'
_columns = {
'name': fields.char('Floor Name', size=32, required=True, help='An internal identification of the restaurant floor'),
'name': fields.char('Floor Name', required=True, help='An internal identification of the restaurant floor'),
'pos_config_id': fields.many2one('pos.config','Point of Sale'),
'background_image': fields.binary('Background Image', help='A background image used to display a floor layout in the point of sale interface'),
'background_color': fields.char('Background Color', help='The background color of the floor layout, (must be specified in a html-compatible format)'),
'table_ids': fields.one2many('restaurant.table','floor_id','Tables', help='The list of tables in this floor'),
'sequence': fields.integer('Sequence',help='Used to sort Floors'),
}
_defaults = {
'sequence': 1,
'background_color': 'rgb(210, 210, 210)',
}
def set_background_color(self, cr, uid, id, background, context=None):
self.write(cr, uid, [id], {'background_color': background}, context=context)
class restaurant_table(osv.osv):
_name = 'restaurant.table'
_columns = {
@@ -14,6 +14,7 @@
<field name="name" />
<field name="pos_config_id" />
<field name="background_image" widget="image" />
<field name="background_color" />
</group>
<field name="table_ids">
<tree string='Tables'>
+30 -2
View File
@@ -5,7 +5,7 @@ openerp.pos_restaurant.load_floors = function(instance,module){
// At POS Startup, load the floors, and add them to the pos model
module.load_models({
model: 'restaurant.floor',
fields: ['name','background_image','table_ids','sequence'],
fields: ['name','background_color','table_ids','sequence'],
domain: function(self){ return [['pos_config_id','=',self.config.id]] },
loaded: function(self,floors){
self.floors = floors;
@@ -354,6 +354,29 @@ openerp.pos_restaurant.load_floors = function(instance,module){
background_image_url: function(floor) {
return '/web/binary/image?model=restaurant.floor&id='+floor.id+'&field=background_image';
},
get_floor_style: function() {
var style = "";
if (this.floor.background_image) {
style += "background-image: url(" + this.background_image_url(this.floor) + "); ";
}
if (this.floor.background_color) {
style += "background-color: " + _.escape(this.floor.background_color) + ";";
}
return style;
},
set_background_color: function(background) {
this.floor.background_color = background;
(new instance.web.Model('restaurant.floor'))
.call('set_background_color',[this.floor.id, background]).fail(function(err,event){
self.gui.show_popup('error',{
'title':_t('Changes could not be saved'),
'body': _t('Check your internet connection and access rights'),
});
event.stopPropagation();
event.preventDefault();
});
this.renderElement();
},
deselect_tables: function(){
for (var i = 0; i < this.table_widgets.length; i++) {
var table = this.table_widgets[i];
@@ -385,13 +408,18 @@ openerp.pos_restaurant.load_floors = function(instance,module){
}
},
tool_colorpicker_open: function(){
this.$('.color-picker').addClass('oe_hidden');
if (this.selected_table) {
this.$('.color-picker').removeClass('oe_hidden');
this.$('.color-picker.fg-picker').removeClass('oe_hidden');
} else {
this.$('.color-picker.bg-picker').removeClass('oe_hidden');
}
},
tool_colorpicker_pick: function(event,$el){
if (this.selected_table) {
this.selected_table.set_table_color($el[0].style['background-color']);
} else {
this.set_background_color($el[0].style['background-color']);
}
},
tool_colorpicker_close: function(){
@@ -70,7 +70,7 @@
</t>
</div>
</t>
<div class='floor-map' t-att-style='widget.floor.background_image ? ("background-image:url("+widget.background_image_url(widget.floor)+");") :"" '>
<div class='floor-map' t-att-style='widget.get_floor_style()' >
<span class='edit-button editing'><i class='fa fa-pencil'></i></span>
<div class='edit-bar oe_hidden'>
<span class='edit-button new-table'>
@@ -86,21 +86,35 @@
<span class='button-option square'><i class='fa fa-square-o'></i></span>
<span class='button-option round oe_hidden'><i class='fa fa-circle-o'></i></span>
</span>
<span class='edit-button color needs-selection'>
<span class='edit-button color'>
<i class='fa fa-tint'></i>
<div class='color-picker oe_hidden'>
<div class='color-picker fg-picker oe_hidden'>
<div class='close-picker'>
<i class='fa fa-times' />
</div>
<span class='color tl' style='background-color:#EB6D6D' />
<span class='color' style='background-color:#35D374' />
<span class='color tr' style='background-color:#6C6DEC' />
<span class='color tl' style='background-color:#EB6D6D' />
<span class='color' style='background-color:#35D374' />
<span class='color tr' style='background-color:#6C6DEC' />
<span class='color' style='background-color:#EBBF6D' />
<span class='color' style='background-color:#EBEC6D' />
<span class='color' style='background-color:#AC6DAD' />
<span class='color bl' style='background-color:#6C6D6D' />
<span class='color' style='background-color:#ACADAD' />
<span class='color br' style='background-color:#4ED2BE' />
<span class='color bl' style='background-color:#6C6D6D' />
<span class='color' style='background-color:#ACADAD' />
<span class='color br' style='background-color:#4ED2BE' />
</div>
<div class='color-picker bg-picker oe_hidden'>
<div class='close-picker'>
<i class='fa fa-times' />
</div>
<span class='color tl' style='background-color:rgb(244, 149, 149)' />
<span class='color' style='background-color:rgb(130, 233, 171)' />
<span class='color tr' style='background-color:rgb(136, 137, 242)' />
<span class='color' style='background-color:rgb(255, 214, 136)' />
<span class='color' style='background-color:rgb(254, 255, 154)' />
<span class='color' style='background-color:rgb(209, 171, 210)' />
<span class='color bl' style='background-color:rgb(75, 75, 75)' />
<span class='color' style='background-color:rgb(210, 210, 210)' />
<span class='color br' style='background-color:rgb(127, 221, 236)' />
</div>
</span>
<span class='edit-button trash needs-selection'>