46affe5d397939d5635753ec73069ec94f5a13d4
[odoo/odoo.git] / addons / pos_restaurant / restaurant.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 import logging
23
24 import openerp
25 from openerp import tools
26 from openerp.osv import fields, osv
27 from openerp.tools.translate import _
28
29 _logger = logging.getLogger(__name__)
30
31 class restaurant_floor(osv.osv):
32     _name = 'restaurant.floor'
33     _columns = {
34         'name':             fields.char('Floor Name', size=32, required=True, help='An internal identification of the restaurant floor'),
35         'pos_config_id':    fields.many2one('pos.config','Point of Sale'),
36         'background_image': fields.binary('Background Image', help='A background image used to display a floor layout in the point of sale interface'),  
37         'table_ids':        fields.one2many('restaurant.table','floor_id','Tables', help='The list of tables in this floor'),
38         'sequence':         fields.integer('Sequence',help='Used to sort Floors'),
39     }
40
41     _defaults = {
42         'sequence': 1,
43     }
44
45 class restaurant_table(osv.osv):
46     _name = 'restaurant.table'
47     _columns = {
48         'name':         fields.char('Table Name', size=32, required=True, help='An internal identification of a table'),
49         'floor_id':     fields.many2one('restaurant.floor','Floor'),
50         'shape':        fields.selection([('square','Square'),('round','Round')],'Shape', required=True),
51         'position_h':   fields.float('Horizontal Position', help="The table's horizontal position from the left side to the table's center, in percentage of the floor's width"),
52         'position_v':   fields.float('Vertical Position', help="The table's vertical position from the top to the table's center, in percentage of the floor's height"),
53         'width':        fields.float('Width', help="The table's width in percentage of the floor's width"),
54         'height':       fields.float('Height', help="The table's height in percentage of the floor's height"),
55         'color':        fields.char('Color', size=32, help="The table's color"),
56         'active':       fields.boolean('Active',help='If false, the table is deactivated and will not be available in the point of sale'),
57         'pos_order_ids':fields.one2many('pos.order','table_id','Pos Orders', help='The orders served at this table'),
58     }
59
60     _defaults = {
61         'shape': 'square',
62         'position_h': 10,
63         'position_v': 10,
64         'height': 50,
65         'width':  50,
66         'active': True,
67     }
68
69     def create_from_ui(self, cr, uid, table, context=None):
70         """ create or modify a table from the point of sale UI.
71             table contains the table's fields. If it contains an
72             id, it will modify the existing table. It then 
73             returns the id of the table.  """
74
75         if table.get('floor_id',False):
76             floor_id = table['floor_id'][0]
77             table['floor_id'] = floor_id
78
79         if table.get('id',False):   # Modifiy existing table
80             table_id = table['id']
81             del table['id']
82             self.write(cr, uid, [table_id], table, context=context)
83         else:
84             table_id = self.create(cr, uid, table, context=context)
85
86         return table_id
87
88 class restaurant_printer(osv.osv):
89     _name = 'restaurant.printer'
90
91     _columns = {
92         'name' : fields.char('Printer Name', size=32, required=True, help='An internal identification of the printer'),
93         'proxy_ip': fields.char('Proxy IP Address', size=32, help="The IP Address or hostname of the Printer's hardware proxy"),
94         'product_categories_ids': fields.many2many('pos.category','printer_category_rel', 'printer_id','category_id',string='Printed Product Categories'),
95     }
96
97     _defaults = {
98         'name' : 'Printer',
99     }
100
101 class pos_config(osv.osv):
102     _inherit = 'pos.config'
103     _columns = {
104         'iface_splitbill': fields.boolean('Bill Splitting', help='Enables Bill Splitting in the Point of Sale'),
105         'iface_printbill': fields.boolean('Bill Printing', help='Allows to print the Bill before payment'),
106         'iface_floorplan': fields.boolean('Floor Plan', help='Enable Floor and Tables in the Point of Sale'),
107         'floor_ids':       fields.one2many('restaurant.floor','pos_config_id','Restaurant Floors', help='The restaurant floors served by this point of sale'),
108         'printer_ids':     fields.many2many('restaurant.printer','pos_config_printer_rel', 'config_id','printer_id',string='Order Printers'),
109     }
110     _defaults = {
111         'iface_splitbill': False,
112         'iface_printbill': False,
113         'iface_floorplan': False,
114     }
115             
116 class pos_order(osv.osv):
117     _inherit = 'pos.order'
118     _columns = {
119         'table_id': fields.many2one('restaurant.table','Table', help='The table where this order was served'),
120     }
121