2010-01-18 12:52:11 +00:00
|
|
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
|
##############################################################################
|
2010-03-16 14:03:02 +00:00
|
|
|
|
#
|
2010-01-18 12:52:11 +00:00
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
|
|
|
|
#
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-03-16 14:03:02 +00:00
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-18 12:52:11 +00:00
|
|
|
|
#
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
|
|
from osv import osv, fields
|
|
|
|
|
|
|
|
|
|
class lunch_category(osv.osv):
|
2010-03-16 14:03:02 +00:00
|
|
|
|
""" Lunch category """
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
2010-01-18 12:52:11 +00:00
|
|
|
|
_name = 'lunch.category'
|
|
|
|
|
_description = "Category"
|
|
|
|
|
|
|
|
|
|
_columns = {
|
|
|
|
|
'name': fields.char('Name', required=True, size=50),
|
|
|
|
|
}
|
|
|
|
|
_order = 'name'
|
|
|
|
|
|
|
|
|
|
lunch_category()
|
|
|
|
|
|
2010-03-16 14:03:02 +00:00
|
|
|
|
|
2010-01-18 12:52:11 +00:00
|
|
|
|
class lunch_product(osv.osv):
|
2010-03-16 14:03:02 +00:00
|
|
|
|
""" Lunch Product """
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
2010-01-18 12:52:11 +00:00
|
|
|
|
_name = 'lunch.product'
|
2010-03-16 14:03:02 +00:00
|
|
|
|
_description = "Lunch Product"
|
2010-01-18 12:52:11 +00:00
|
|
|
|
|
|
|
|
|
_columns = {
|
|
|
|
|
'name': fields.char('Name', size=50, required=True),
|
2010-04-21 14:27:13 +00:00
|
|
|
|
'category_id': fields.many2one('lunch.category', 'Category'),
|
2011-06-20 11:34:20 +00:00
|
|
|
|
'description': fields.text('Description', size=128, required=False),
|
2010-01-18 12:52:11 +00:00
|
|
|
|
'price': fields.float('Price', digits=(16,2)),
|
|
|
|
|
'active': fields.boolean('Active'),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_defaults = {
|
|
|
|
|
'active': lambda *a : True,
|
2010-08-13 12:20:05 +00:00
|
|
|
|
}
|
2010-01-18 12:52:11 +00:00
|
|
|
|
|
|
|
|
|
lunch_product()
|
|
|
|
|
|
2010-03-16 14:03:02 +00:00
|
|
|
|
|
2010-01-18 12:52:11 +00:00
|
|
|
|
class lunch_cashbox(osv.osv):
|
2010-03-16 14:03:02 +00:00
|
|
|
|
""" cashbox for Lunch """
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
|
|
|
|
_name = 'lunch.cashbox'
|
2010-03-16 14:03:02 +00:00
|
|
|
|
_description = "Cashbox for Lunch "
|
|
|
|
|
|
2010-01-18 12:52:11 +00:00
|
|
|
|
|
2010-11-19 13:48:01 +00:00
|
|
|
|
def amount_available(self, cr, uid, ids, field_name, arg, context=None):
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
|
|
|
|
""" count available amount
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
2010-03-17 11:50:40 +00:00
|
|
|
|
@param ids: List of create menu’s IDs
|
|
|
|
|
@param context: A standard dictionary for contextual values """
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
2010-01-18 12:52:11 +00:00
|
|
|
|
cr.execute("SELECT box,sum(amount) from lunch_cashmove where active = 't' group by box")
|
2010-03-17 10:43:25 +00:00
|
|
|
|
amount = dict(cr.fetchall())
|
2010-03-16 14:03:02 +00:00
|
|
|
|
for i in ids:
|
2010-03-17 10:43:25 +00:00
|
|
|
|
amount.setdefault(i, 0)
|
|
|
|
|
return amount
|
2010-01-18 12:52:11 +00:00
|
|
|
|
|
2010-03-17 10:43:25 +00:00
|
|
|
|
_columns = {
|
|
|
|
|
'manager': fields.many2one('res.users', 'Manager'),
|
|
|
|
|
'name': fields.char('Name', size=30, required=True, unique = True),
|
2011-07-01 23:41:24 +00:00
|
|
|
|
'sum_remain': fields.function(amount_available, string='Total Remaining'),
|
2010-08-13 12:20:05 +00:00
|
|
|
|
}
|
2010-01-18 12:52:11 +00:00
|
|
|
|
|
|
|
|
|
lunch_cashbox()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class lunch_cashmove(osv.osv):
|
2010-03-17 11:50:40 +00:00
|
|
|
|
""" Move cash """
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
|
|
|
|
_name = 'lunch.cashmove'
|
2010-05-19 18:32:32 +00:00
|
|
|
|
_description = "Cash Move"
|
2010-01-18 12:52:11 +00:00
|
|
|
|
|
2010-03-17 10:43:25 +00:00
|
|
|
|
_columns = {
|
2010-08-17 05:05:59 +00:00
|
|
|
|
'name': fields.char('Description', size=128),
|
2010-03-17 10:43:25 +00:00
|
|
|
|
'user_cashmove': fields.many2one('res.users', 'User Name', required=True),
|
|
|
|
|
'amount': fields.float('Amount', digits=(16, 2)),
|
|
|
|
|
'box': fields.many2one('lunch.cashbox', 'Box Name', size=30, required=True),
|
2010-03-16 14:03:02 +00:00
|
|
|
|
'active': fields.boolean('Active'),
|
2010-09-28 13:16:15 +00:00
|
|
|
|
'create_date': fields.datetime('Creation Date', readonly=True),
|
2010-08-13 12:20:05 +00:00
|
|
|
|
}
|
2010-01-18 12:52:11 +00:00
|
|
|
|
|
2010-03-17 10:43:25 +00:00
|
|
|
|
_defaults = {
|
2010-08-13 12:20:05 +00:00
|
|
|
|
'active': lambda *a: True,
|
2010-01-18 12:52:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lunch_cashmove()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class lunch_order(osv.osv):
|
2010-03-16 14:03:02 +00:00
|
|
|
|
""" Apply lunch order """
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
|
|
|
|
_name = 'lunch.order'
|
2010-03-16 14:03:02 +00:00
|
|
|
|
_description = "Lunch Order"
|
2010-03-17 10:43:25 +00:00
|
|
|
|
_rec_name = "user_id"
|
2010-01-18 12:52:11 +00:00
|
|
|
|
|
|
|
|
|
def _price_get(self, cr, uid, ids, name, args, context=None):
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
|
|
|
|
""" Get Price of Product
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
2010-03-17 11:50:40 +00:00
|
|
|
|
@param ids: List of Lunch order’s IDs
|
|
|
|
|
@param context: A standard dictionary for contextual values """
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
2010-01-18 12:52:11 +00:00
|
|
|
|
res = {}
|
2010-11-19 13:48:01 +00:00
|
|
|
|
for price in self.browse(cr, uid, ids, context=context):
|
2010-03-17 10:43:25 +00:00
|
|
|
|
res[price.id] = price.product.price
|
2010-01-18 12:52:11 +00:00
|
|
|
|
return res
|
|
|
|
|
|
2010-03-17 10:43:25 +00:00
|
|
|
|
_columns = {
|
|
|
|
|
'user_id': fields.many2one('res.users', 'User Name', required=True, \
|
|
|
|
|
readonly=True, states={'draft':[('readonly', False)]}),
|
|
|
|
|
'product': fields.many2one('lunch.product', 'Product', required=True, \
|
|
|
|
|
readonly=True, states={'draft':[('readonly', False)]}, change_default=True),
|
|
|
|
|
'date': fields.date('Date', readonly=True, states={'draft':[('readonly', False)]}),
|
|
|
|
|
'cashmove': fields.many2one('lunch.cashmove', 'CashMove' , readonly=True),
|
2010-08-25 13:20:23 +00:00
|
|
|
|
'descript': fields.char('Description Order', readonly=True, size=250, \
|
2010-03-17 10:43:25 +00:00
|
|
|
|
states = {'draft':[('readonly', False)]}),
|
2011-09-14 13:11:11 +00:00
|
|
|
|
'state': fields.selection([('draft', 'New'), ('confirmed', 'Confirmed'), ], \
|
2010-01-18 12:52:11 +00:00
|
|
|
|
'State', readonly=True, select=True),
|
2011-07-01 23:41:24 +00:00
|
|
|
|
'price': fields.function(_price_get, string="Price"),
|
2010-09-28 13:16:15 +00:00
|
|
|
|
'category': fields.many2one('lunch.category','Category'),
|
2010-01-18 12:52:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-17 10:43:25 +00:00
|
|
|
|
_defaults = {
|
2010-06-16 11:51:39 +00:00
|
|
|
|
'user_id': lambda self, cr, uid, context: uid,
|
2012-02-13 18:07:41 +00:00
|
|
|
|
'date': fields.date.context_today,
|
2010-06-16 11:51:39 +00:00
|
|
|
|
'state': lambda self, cr, uid, context: 'draft',
|
2010-01-18 12:52:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-19 13:48:01 +00:00
|
|
|
|
def confirm(self, cr, uid, ids, box, context=None):
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
|
|
|
|
""" confirm order
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
2010-03-17 11:50:40 +00:00
|
|
|
|
@param ids: List of confirm order’s IDs
|
|
|
|
|
@param context: A standard dictionary for contextual values """
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
|
|
|
|
cashmove_ref = self.pool.get('lunch.cashmove')
|
2010-11-19 13:48:01 +00:00
|
|
|
|
for order in self.browse(cr, uid, ids, context=context):
|
2010-01-18 12:52:11 +00:00
|
|
|
|
if order.state == 'confirmed':
|
|
|
|
|
continue
|
2010-03-17 11:33:47 +00:00
|
|
|
|
new_id = cashmove_ref.create(cr, uid, {'name': order.product.name+' order',
|
2010-01-18 12:52:11 +00:00
|
|
|
|
'amount':-order.product.price,
|
|
|
|
|
'user_cashmove':order.user_id.id,
|
|
|
|
|
'box':box,
|
|
|
|
|
'active':True,
|
2010-03-17 11:33:47 +00:00
|
|
|
|
})
|
2010-03-17 10:43:25 +00:00
|
|
|
|
self.write(cr, uid, [order.id], {'cashmove': new_id, 'state': 'confirmed'})
|
2010-01-18 12:52:11 +00:00
|
|
|
|
return {}
|
|
|
|
|
|
2010-11-19 13:48:01 +00:00
|
|
|
|
def lunch_order_cancel(self, cr, uid, ids, context=None):
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
|
|
|
|
"""" cancel order
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
2010-03-17 11:50:40 +00:00
|
|
|
|
@param ids: List of create menu’s IDs
|
|
|
|
|
@param context: A standard dictionary for contextual values """
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
2010-11-19 13:48:01 +00:00
|
|
|
|
orders = self.browse(cr, uid, ids, context=context)
|
2010-01-18 12:52:11 +00:00
|
|
|
|
for order in orders:
|
|
|
|
|
if not order.cashmove:
|
|
|
|
|
continue
|
2010-03-17 11:33:47 +00:00
|
|
|
|
if order.cashmove.id:
|
|
|
|
|
self.pool.get('lunch.cashmove').unlink(cr, uid, [order.cashmove.id])
|
2010-03-17 10:43:25 +00:00
|
|
|
|
self.write(cr, uid, ids, {'state':'draft'})
|
2010-01-18 12:52:11 +00:00
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
def onchange_product(self, cr, uid, ids, product):
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
|
|
|
|
""" Get price for Product
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
2010-03-17 11:50:40 +00:00
|
|
|
|
@param ids: List of create menu’s IDs
|
|
|
|
|
@product: Product To Ordered """
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
2010-01-18 12:52:11 +00:00
|
|
|
|
if not product:
|
|
|
|
|
return {'value': {'price': 0.0}}
|
|
|
|
|
price = self.pool.get('lunch.product').read(cr, uid, product, ['price'])['price']
|
2010-08-17 10:09:52 +00:00
|
|
|
|
categ_id = self.pool.get('lunch.product').browse(cr, uid, product).category_id.id
|
|
|
|
|
return {'value': {'price': price,'category':categ_id}}
|
2010-01-18 12:52:11 +00:00
|
|
|
|
|
|
|
|
|
lunch_order()
|
|
|
|
|
|
2010-03-16 14:03:02 +00:00
|
|
|
|
|
2010-01-18 12:52:11 +00:00
|
|
|
|
class report_lunch_amount(osv.osv):
|
2010-03-16 14:03:02 +00:00
|
|
|
|
""" Lunch Amount Report """
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
|
|
|
|
_name = 'report.lunch.amount'
|
2010-01-18 12:52:11 +00:00
|
|
|
|
_description = "Amount available by user and box"
|
|
|
|
|
_auto = False
|
2010-03-17 10:43:25 +00:00
|
|
|
|
_rec_name = "user"
|
2010-01-18 12:52:11 +00:00
|
|
|
|
|
|
|
|
|
_columns = {
|
2010-03-17 10:43:25 +00:00
|
|
|
|
'user_id': fields.many2one('res.users', 'User Name', readonly=True),
|
|
|
|
|
'amount': fields.float('Amount', readonly=True, digits=(16, 2)),
|
|
|
|
|
'box': fields.many2one('lunch.cashbox', 'Box Name', size=30, readonly=True),
|
2010-08-25 13:20:23 +00:00
|
|
|
|
'year': fields.char('Year', size=4, readonly=True),
|
|
|
|
|
'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'),
|
|
|
|
|
('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'),
|
|
|
|
|
('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True),
|
|
|
|
|
'day': fields.char('Day', size=128, readonly=True),
|
|
|
|
|
'date': fields.date('Created Date', readonly=True),
|
2010-08-13 12:20:05 +00:00
|
|
|
|
}
|
2010-01-18 12:52:11 +00:00
|
|
|
|
|
|
|
|
|
def init(self, cr):
|
2010-03-17 10:43:25 +00:00
|
|
|
|
|
|
|
|
|
""" @param cr: the current row, from the database cursor"""
|
|
|
|
|
|
2010-01-18 12:52:11 +00:00
|
|
|
|
cr.execute("""
|
|
|
|
|
create or replace view report_lunch_amount as (
|
|
|
|
|
select
|
|
|
|
|
min(lc.id) as id,
|
2010-08-25 13:20:23 +00:00
|
|
|
|
to_date(to_char(lc.create_date, 'dd-MM-YYYY'),'dd-MM-YYYY') as date,
|
|
|
|
|
to_char(lc.create_date, 'YYYY') as year,
|
|
|
|
|
to_char(lc.create_date, 'MM') as month,
|
|
|
|
|
to_char(lc.create_date, 'YYYY-MM-DD') as day,
|
2010-01-18 12:52:11 +00:00
|
|
|
|
lc.user_cashmove as user_id,
|
|
|
|
|
sum(amount) as amount,
|
|
|
|
|
lc.box as box
|
|
|
|
|
from
|
|
|
|
|
lunch_cashmove lc
|
|
|
|
|
where
|
|
|
|
|
active = 't'
|
2010-08-25 13:20:23 +00:00
|
|
|
|
group by lc.user_cashmove, lc.box, lc.create_date
|
2010-01-18 12:52:11 +00:00
|
|
|
|
)""")
|
|
|
|
|
|
|
|
|
|
report_lunch_amount()
|
2010-03-16 14:03:02 +00:00
|
|
|
|
|
2010-01-18 12:52:11 +00:00
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|
|