2012-10-24 13:39:18 +00:00
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
#
##############################################################################
2012-10-26 11:39:01 +00:00
2012-10-31 14:24:48 +00:00
from xml . sax . saxutils import escape
2012-10-24 13:39:18 +00:00
import pytz
import time
2010-01-18 12:52:11 +00:00
from osv import osv , fields
2012-10-24 13:39:18 +00:00
from datetime import datetime , timedelta
from lxml import etree
2012-10-31 14:24:48 +00:00
from tools . translate import _
2012-10-25 14:44:57 +00:00
2012-10-24 13:39:18 +00:00
class lunch_order ( osv . Model ) :
""" lunch order """
2010-03-17 10:43:25 +00:00
_name = ' lunch.order '
2012-10-24 13:39:18 +00:00
_description = ' Lunch Order '
2010-01-18 12:52:11 +00:00
2012-10-25 14:44:57 +00:00
def _price_get ( self , cr , uid , ids , name , arg , context = None ) :
2012-10-26 11:39:01 +00:00
""" get and sum the order lines ' price """
2012-10-24 13:39:18 +00:00
result = { }
2012-10-26 11:39:01 +00:00
for order in self . browse ( cr , uid , ids , context = context ) :
2012-10-24 13:39:18 +00:00
value = 0.0
2012-10-30 08:47:01 +00:00
for orderline in order . order_line_ids :
2012-10-31 14:24:48 +00:00
value + = orderline . product_id . price
result [ order . id ] = value
2012-10-24 13:39:18 +00:00
return result
2012-10-26 12:58:08 +00:00
def _compute_total ( self , cr , uid , ids , name , context = None ) :
""" compute total """
result = { }
for order_line in self . browse ( cr , uid , ids , context = context ) :
2012-10-31 14:24:48 +00:00
result [ order_line . order_id . id ] = True
return result . keys ( )
2012-10-26 11:39:01 +00:00
def add_preference ( self , cr , uid , ids , pref_id , context = None ) :
""" create a new order line based on the preference selected (pref_id) """
2012-10-24 13:39:18 +00:00
orderline_ref = self . pool . get ( ' lunch.order.line ' )
2012-10-26 11:39:01 +00:00
prod_ref = self . pool . get ( ' lunch.product ' )
2012-10-24 13:39:18 +00:00
order = self . browse ( cr , uid , ids , context = context ) [ 0 ]
2012-11-02 08:15:48 +00:00
pref = orderline_ref . browse ( cr , uid , pref_id , context = context )
new_order_line = {
' date ' : order . date ,
' user_id ' : uid ,
' product_id ' : pref . product_id . id ,
' note ' : pref . note ,
' order_id ' : order . id ,
' price ' : pref . product_id . price ,
' supplier ' : pref . product_id . supplier . id
}
return orderline_ref . create ( cr , uid , new_order_line )
2012-10-24 13:39:18 +00:00
2012-10-26 11:39:01 +00:00
def _alerts_get ( self , cr , uid , ids , name , arg , context = None ) :
""" get the alerts to display on the order form """
2012-10-24 13:39:18 +00:00
orders = self . browse ( cr , uid , ids , context = context )
result = { }
2012-10-26 11:39:01 +00:00
alert_msg = self . _default_alerts_get ( cr , uid , arg , context = context )
2012-10-24 13:39:18 +00:00
for order in orders :
if order . state == ' new ' :
result [ order . id ] = alert_msg
return result
2012-10-26 11:39:01 +00:00
def check_day ( self , alert ) :
""" This method is used by can_display_alert to
to check if the alert day corresponds
to the current day
"""
2012-10-25 08:10:59 +00:00
today = datetime . now ( ) . isoweekday ( )
if today == 1 :
2012-11-02 08:15:48 +00:00
return alert . monday
2012-10-25 08:10:59 +00:00
if today == 2 :
2012-11-02 08:15:48 +00:00
return alert . tuesday
2012-10-25 08:10:59 +00:00
if today == 3 :
2012-11-02 08:15:48 +00:00
return alert . wednesday
2012-10-25 08:10:59 +00:00
if today == 4 :
2012-11-02 08:15:48 +00:00
return alert . thursday
2012-10-25 08:10:59 +00:00
if today == 5 :
2012-11-02 08:15:48 +00:00
return alert . friday
2012-10-25 08:10:59 +00:00
if today == 6 :
2012-11-02 08:15:48 +00:00
return alert . saturday
2012-10-25 08:10:59 +00:00
if today == 7 :
2012-11-02 08:15:48 +00:00
return alert . sunday
assert " today should be between 1 and 7 "
2012-10-25 08:10:59 +00:00
2012-10-26 11:39:01 +00:00
def can_display_alert ( self , alert ) :
""" This method check if the alert can be displayed today """
if alert . day == ' specific ' :
#the alert is only activated a specific day
2012-11-02 08:15:48 +00:00
return alert . specific == fields . datetime . now ( ) [ : 10 ]
2012-10-26 11:39:01 +00:00
elif alert . day == ' week ' :
#the alert is activated during some days of the week
return self . check_day ( alert )
2012-11-02 08:15:48 +00:00
return True
2012-10-26 11:39:01 +00:00
2012-11-02 08:15:48 +00:00
# code to improve
2012-10-24 13:39:18 +00:00
def _default_alerts_get ( self , cr , uid , arg , context = None ) :
2012-10-26 11:39:01 +00:00
""" get the alerts to display on the order form """
2012-10-24 13:39:18 +00:00
alert_ref = self . pool . get ( ' lunch.alert ' )
2012-10-26 12:58:08 +00:00
alert_ids = alert_ref . search ( cr , uid , [ ( ' lunch_active ' , ' = ' , True ) ] , context = context )
2012-10-31 10:23:07 +00:00
alert_msg = [ ]
2012-10-24 13:39:18 +00:00
for alert in alert_ref . browse ( cr , uid , alert_ids , context = context ) :
2012-10-26 11:39:01 +00:00
if self . can_display_alert ( alert ) :
2012-11-02 08:15:48 +00:00
#the alert is executing from ... to ...
now = datetime . utcnow ( )
user = self . pool . get ( ' res.users ' ) . browse ( cr , uid , uid , context = context )
tz = pytz . timezone ( user . tz ) if user . tz else pytz . utc
tzoffset = tz . utcoffset ( now )
mynow = now + tzoffset
hour_to = int ( alert . active_to )
min_to = int ( ( alert . active_to - hour_to ) * 60 )
to_alert = datetime . strptime ( str ( hour_to ) + " : " + str ( min_to ) , " % H: % M " )
hour_from = int ( alert . active_from )
min_from = int ( ( alert . active_from - hour_from ) * 60 )
from_alert = datetime . strptime ( str ( hour_from ) + " : " + str ( min_from ) , " % H: % M " )
if mynow . time ( ) > = from_alert . time ( ) and mynow . time ( ) < = to_alert . time ( ) :
2012-10-31 10:23:07 +00:00
alert_msg . append ( alert . message )
return ' \n ' . join ( alert_msg )
2012-10-24 13:39:18 +00:00
2012-10-26 12:58:08 +00:00
def onchange_price ( self , cr , uid , ids , order_line_ids , context = None ) :
2012-10-26 11:39:01 +00:00
""" Onchange methode that refresh the total price of order """
2012-10-24 13:39:18 +00:00
res = { ' value ' : { ' total ' : 0.0 } }
2012-10-30 14:02:44 +00:00
order_line_ids = self . resolve_o2m_commands_to_record_dicts ( cr , uid , " order_line_ids " , order_line_ids , [ " price " ] , context )
2012-10-26 12:58:08 +00:00
if order_line_ids :
2012-10-24 13:39:18 +00:00
tot = 0.0
2012-10-31 14:24:48 +00:00
product_ref = self . pool . get ( " lunch.product " )
2012-10-26 12:58:08 +00:00
for prod in order_line_ids :
2012-10-31 14:24:48 +00:00
if ' product_id ' in prod :
tot + = product_ref . browse ( cr , uid , prod [ ' product_id ' ] , context = context ) . price
else :
tot + = prod [ ' price ' ]
2012-10-26 11:39:01 +00:00
res = { ' value ' : { ' total ' : tot } }
2012-10-24 13:39:18 +00:00
return res
2010-03-17 10:43:25 +00:00
2012-10-24 13:39:18 +00:00
def __getattr__ ( self , attr ) :
2012-10-26 11:39:01 +00:00
""" this method catch unexisting method call and if starts with
add_preference_ ' n ' we execute the add_preference method with
' n ' as parameter """
2012-10-24 13:39:18 +00:00
if attr . startswith ( ' add_preference_ ' ) :
pref_id = int ( attr [ 15 : ] )
def specific_function ( cr , uid , ids , context = None ) :
return self . add_preference ( cr , uid , ids , pref_id , context = context )
return specific_function
return super ( lunch_order , self ) . __getattr__ ( self , attr )
def fields_view_get ( self , cr , uid , view_id = None , view_type = False , context = None , toolbar = False , submenu = False ) :
2012-10-31 14:24:48 +00:00
""" Add preferences in the form view of order.line """
2012-10-24 13:39:18 +00:00
res = super ( lunch_order , self ) . fields_view_get ( cr , uid , view_id = view_id , view_type = view_type , context = context , toolbar = toolbar , submenu = submenu )
2012-11-02 08:15:48 +00:00
line_ref = self . pool . get ( " lunch.order.line " )
2012-10-24 13:39:18 +00:00
if view_type == ' form ' :
2012-11-02 08:15:48 +00:00
pref_ids = line_ref . search ( cr , uid , [ ( ' user_id ' , ' = ' , uid ) ] , context = context )
2012-10-31 14:24:48 +00:00
text_xml = " <div> "
2012-11-02 08:15:48 +00:00
if len ( pref_ids ) == 0 :
2012-10-31 14:24:48 +00:00
text_xml + = """
< div class = " oe_inline oe_lunch_intro " >
2012-11-02 08:15:48 +00:00
< h3 > % s < / h3 >
< p class = " oe_grey " >
2012-10-31 14:24:48 +00:00
% s
2012-11-02 08:15:48 +00:00
< / p > < p class = " oe_grey " >
2012-10-31 14:24:48 +00:00
% s
2012-11-02 08:15:48 +00:00
< / p > < p class = " oe_grey " >
2012-10-31 14:24:48 +00:00
% s
2012-11-02 08:15:48 +00:00
< / p >
2012-10-31 14:24:48 +00:00
< / div >
""" % (_( " This is the first time you order a meal " ),
_ ( " Select a product and put your order comments on the note. " ) ,
_ ( " Your favorite meals will be created based on your last orders. " ) ,
_ ( " Don ' t forget the alerts displayed in the reddish area " ) )
else :
2012-11-02 08:15:48 +00:00
preferences = line_ref . browse ( cr , uid , pref_ids , context = context )
2012-10-26 11:39:01 +00:00
categories = { } #store the different categories of products in preference
for pref in preferences :
2012-11-02 08:15:48 +00:00
categories . setdefault ( pref . product_id . category_id . name , { } )
if pref . product_id . id not in categories [ pref . product_id . category_id . name ] :
categories [ pref . product_id . category_id . name ] [ pref . product_id . id ] = pref
currency = self . pool . get ( ' res.users ' ) . browse ( cr , uid , uid , context = context ) . company_id . currency_id
2012-10-26 11:39:01 +00:00
for key , value in categories . items ( ) :
2012-11-02 08:15:48 +00:00
value = value . values ( )
2012-10-26 11:39:01 +00:00
text_xml + = """
2012-10-31 14:24:48 +00:00
< div class = " oe_lunch_30pc " >
< h2 > % s < / h2 >
2012-10-26 11:39:01 +00:00
""" % (key,)
2012-10-30 14:02:44 +00:00
i = 0
2012-10-26 11:39:01 +00:00
for val in value :
2012-10-30 14:02:44 +00:00
if i == 5 : break
i + = 1
2012-10-26 11:39:01 +00:00
function_name = " add_preference_ " + str ( val . id )
text_xml + = '''
< div class = " oe_lunch_vignette " >
2012-10-31 10:23:07 +00:00
< span class = " oe_lunch_button " >
2012-10-31 14:24:48 +00:00
< button name = " %s " class = " oe_link oe_i oe_button_plus " type = " object " string = " + " > < / button > < button name = " %s " class = " oe_link oe_button_add " type = " object " string = " %s " > < / button >
2012-10-31 10:23:07 +00:00
< / span >
< div class = " oe_group_text_button " >
< div class = " oe_lunch_text " >
% s
< span class = " oe_tag " > % .2 f % s < / span >
< / div >
2012-10-26 11:39:01 +00:00
< / div >
2012-10-31 10:23:07 +00:00
< div class = " oe_grey " >
2012-10-30 08:47:01 +00:00
% s
< / div >
2012-10-26 11:39:01 +00:00
< / div >
2012-11-02 08:15:48 +00:00
''' % (function_name, function_name,_( " Add " ), escape(val.product_id.name), val.product_id.price or 0.0, currency.name or ' ' , escape(val.note or ' ' ))
2012-10-31 14:24:48 +00:00
text_xml + = ''' </div> '''
# ADD into ARCH xml
text_xml + = " </div> "
doc = etree . XML ( res [ ' arch ' ] )
node = doc . xpath ( " //div[@name= ' preferences ' ] " )
to_add = etree . fromstring ( text_xml )
node [ 0 ] . append ( to_add )
res [ ' arch ' ] = etree . tostring ( doc )
2010-01-18 12:52:11 +00:00
return res
2010-03-17 10:43:25 +00:00
_columns = {
2012-10-24 13:39:18 +00:00
' user_id ' : fields . many2one ( ' res.users ' , ' User Name ' , required = True , readonly = True , states = { ' new ' : [ ( ' readonly ' , False ) ] } ) ,
' date ' : fields . date ( ' Date ' , required = True , readonly = True , states = { ' new ' : [ ( ' readonly ' , False ) ] } ) ,
2012-10-26 12:58:08 +00:00
' order_line_ids ' : fields . one2many ( ' lunch.order.line ' , ' order_id ' , ' Products ' , ondelete = " cascade " , readonly = True , states = { ' new ' : [ ( ' readonly ' , False ) ] } ) , #TODO: a good naming convention is to finish your field names with `_ids´ for *2many fields. BTW, the field name should reflect more it's nature: `order_line_ids´ for example
' total ' : fields . function ( _price_get , string = " Total " , store = {
2012-10-31 14:24:48 +00:00
' lunch.order.line ' : ( _compute_total , [ ' product_id ' , ' order_id ' ] , 20 ) ,
2012-10-26 12:58:08 +00:00
} ) ,
2012-10-26 12:07:52 +00:00
' state ' : fields . selection ( [ ( ' new ' , ' New ' ) , ( ' confirmed ' , ' Confirmed ' ) , ( ' cancelled ' , ' Cancelled ' ) , ( ' partially ' , ' Partially Confirmed ' ) ] , ' Status ' , readonly = True , select = True ) , #TODO: parcially? #TODO: the labels are confusing. confirmed=='received' or 'delivered'...
2012-10-24 13:39:18 +00:00
' alerts ' : fields . function ( _alerts_get , string = " Alerts " , type = ' text ' ) ,
2012-10-26 11:39:01 +00:00
' company_id ' : fields . many2one ( ' res.company ' , ' Company ' , required = True ) ,
' currency_id ' : fields . related ( ' company_id ' , ' currency_id ' , string = " Currency " , readonly = True ) ,
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 ,
2012-10-26 11:39:01 +00:00
' state ' : ' new ' ,
2012-10-24 13:39:18 +00:00
' alerts ' : _default_alerts_get ,
2012-10-26 11:39:01 +00:00
' company_id ' : lambda self , cr , uid , context : self . pool . get ( ' res.company ' ) . _company_default_get ( cr , uid , ' lunch.order ' , context = context ) ,
2010-01-18 12:52:11 +00:00
}
2012-10-26 11:39:01 +00:00
class lunch_order_line ( osv . Model ) :
""" lunch order line : one lunch order can have many order lines """
2012-10-24 14:20:25 +00:00
_name = ' lunch.order.line '
_description = ' lunch order line '
2012-10-30 08:47:01 +00:00
def onchange_price ( self , cr , uid , ids , product_id , context = None ) :
if product_id :
price = self . pool . get ( ' lunch.product ' ) . read ( cr , uid , product_id , [ ' price ' ] ) [ ' price ' ]
2012-10-24 14:20:25 +00:00
return { ' value ' : { ' price ' : price } }
2012-10-30 08:47:01 +00:00
return { ' value ' : { ' price ' : 0.0 } }
2012-10-24 14:20:25 +00:00
2012-10-31 14:24:48 +00:00
def order ( self , cr , uid , ids , context = None ) :
for order_line in self . browse ( cr , uid , ids , context = context ) :
self . write ( cr , uid , [ order_line . id ] , { ' state ' : ' ordered ' } , context )
return { }
2012-10-24 14:20:25 +00:00
def confirm ( self , cr , uid , ids , context = None ) :
2012-10-26 11:39:01 +00:00
""" confirm one or more order line, update order status and create new cashmove """
2012-10-24 14:20:25 +00:00
cashmove_ref = self . pool . get ( ' lunch.cashmove ' )
orders_ref = self . pool . get ( ' lunch.order ' )
2012-10-26 11:39:01 +00:00
for order_line in self . browse ( cr , uid , ids , context = context ) :
if order_line . state != ' confirmed ' :
2012-11-02 08:15:48 +00:00
new_id = cashmove_ref . create ( cr , uid , { ' user_id ' : order_line . user_id . id , ' amount ' : - order_line . price , ' description ' : order_line . product_id . name , ' order_id ' : order_line . id , ' state ' : ' order ' , ' date ' : order_line . date } )
self . write ( cr , uid , [ order_line . id ] , { ' state ' : ' confirmed ' } , context )
return self . _update_order_lines ( cr , uid , ids , context )
def _update_order_lines ( self , cr , uid , ids , context = None ) :
for order in set ( self . browse ( cr , uid , ids , context = context ) . order_id ) :
2012-10-24 14:20:25 +00:00
isconfirmed = True
2012-11-02 08:15:48 +00:00
for orderline in order . order_line_ids :
2012-10-30 08:47:01 +00:00
if orderline . state == ' new ' :
2012-10-24 14:20:25 +00:00
isconfirmed = False
2012-10-30 08:47:01 +00:00
if orderline . state == ' cancelled ' :
2012-10-24 14:20:25 +00:00
isconfirmed = False
2012-11-02 08:15:48 +00:00
orders_ref . write ( cr , uid , [ order . id ] , { ' state ' : ' partially ' } , context = context )
if isconfirmed :
orders_ref . write ( cr , uid , [ order . id ] , { ' state ' : ' confirmed ' } , context = context )
2012-10-24 14:20:25 +00:00
return { }
def cancel ( self , cr , uid , ids , context = None ) :
2012-10-26 11:39:01 +00:00
""" confirm one or more order.line, update order status and create new cashmove """
2012-10-24 14:20:25 +00:00
cashmove_ref = self . pool . get ( ' lunch.cashmove ' )
orders_ref = self . pool . get ( ' lunch.order ' )
2012-10-26 11:39:01 +00:00
for order_line in self . browse ( cr , uid , ids , context = context ) :
self . write ( cr , uid , [ order_line . id ] , { ' state ' : ' cancelled ' } , context )
for cash in order_line . cashmove :
2012-10-24 14:20:25 +00:00
cashmove_ref . unlink ( cr , uid , cash . id , context )
2012-11-02 08:15:48 +00:00
return self . _update_order_lines ( cr , uid , ids , context )
2012-10-24 14:20:25 +00:00
_columns = {
2012-10-30 08:47:01 +00:00
' order_id ' : fields . many2one ( ' lunch.order ' , ' Order ' , ondelete = ' cascade ' ) ,
' product_id ' : fields . many2one ( ' lunch.product ' , ' Product ' , required = True ) ,
2012-10-26 11:39:01 +00:00
' date ' : fields . related ( ' order_id ' , ' date ' , type = ' date ' , string = " Date " , readonly = True , store = True ) ,
2012-10-30 08:47:01 +00:00
' supplier ' : fields . related ( ' product_id ' , ' supplier ' , type = ' many2one ' , relation = ' res.partner ' , string = " Supplier " , readonly = True , store = True ) ,
2012-10-26 11:39:01 +00:00
' user_id ' : fields . related ( ' order_id ' , ' user_id ' , type = ' many2one ' , relation = ' res.users ' , string = ' User ' , readonly = True , store = True ) ,
' note ' : fields . text ( ' Note ' , size = 256 , required = False ) ,
2012-11-02 08:15:48 +00:00
' price ' : fields . float ( " Price " ) ,
2012-10-31 14:24:48 +00:00
' state ' : fields . selection ( [ ( ' new ' , ' New ' ) , ( ' confirmed ' , ' Received ' ) , ( ' ordered ' , ' Ordered ' ) , ( ' cancelled ' , ' Cancelled ' ) ] , \
2012-10-26 11:39:01 +00:00
' Status ' , readonly = True , select = True ) , #new confirmed and cancelled are the convention
2012-10-24 14:20:25 +00:00
' cashmove ' : fields . one2many ( ' lunch.cashmove ' , ' order_id ' , ' Cash Move ' , ondelete = ' cascade ' ) ,
}
_defaults = {
2012-10-30 08:47:01 +00:00
' state ' : ' new ' ,
2012-10-24 14:20:25 +00:00
}
class lunch_product ( osv . Model ) :
""" lunch product """
_name = ' lunch.product '
_description = ' lunch product '
_columns = {
' name ' : fields . char ( ' Product ' , required = True , size = 64 ) ,
2012-11-02 08:15:48 +00:00
' category_id ' : fields . many2one ( ' lunch.product.category ' , ' Category ' , required = True ) ,
2012-10-24 14:20:25 +00:00
' description ' : fields . text ( ' Description ' , size = 256 , required = False ) ,
' price ' : fields . float ( ' Price ' , digits = ( 16 , 2 ) ) ,
' active ' : fields . boolean ( ' Active ' ) , #If this product isn't offered anymore, the active boolean is set to false. This will allow to keep trace of previous orders and cashmoves.
2012-11-02 08:15:48 +00:00
' supplier ' : fields . many2one ( ' res.partner ' , ' Supplier ' ) ,
2012-10-24 14:20:25 +00:00
}
class lunch_product_category ( osv . Model ) :
""" lunch product category """
_name = ' lunch.product.category '
_description = ' lunch product category '
_columns = {
2012-11-02 08:15:48 +00:00
' name ' : fields . char ( ' Category ' , required = True ) , #such as PIZZA, SANDWICH, PASTA, CHINESE, BURGER, ...
2012-10-24 14:20:25 +00:00
}
class lunch_cashmove ( osv . Model ) :
""" lunch cashmove => order or payment """
_name = ' lunch.cashmove '
_description = ' lunch cashmove '
_columns = {
' user_id ' : fields . many2one ( ' res.users ' , ' User Name ' , required = True ) ,
' date ' : fields . date ( ' Date ' , required = True ) ,
' amount ' : fields . float ( ' Amount ' , required = True ) , #depending on the kind of cashmove, the amount will be positive or negative
2012-11-02 08:15:48 +00:00
' description ' : fields . text ( ' Description ' ) , #the description can be an order or a payment
2012-10-24 14:20:25 +00:00
' order_id ' : fields . many2one ( ' lunch.order.line ' , ' Order ' , required = False , ondelete = ' cascade ' ) ,
' state ' : fields . selection ( [ ( ' order ' , ' Order ' ) , ( ' payment ' , ' Payment ' ) ] , ' Is an order or a Payment ' ) ,
}
_defaults = {
' user_id ' : lambda self , cr , uid , context : uid ,
' date ' : fields . date . context_today ,
' state ' : lambda self , cr , uid , context : ' payment ' ,
}
class lunch_alert ( osv . Model ) :
""" lunch alert """
_name = ' lunch.alert '
_description = ' lunch alert '
_columns = {
' message ' : fields . text ( ' Message ' , size = 256 , required = True ) ,
2012-10-26 12:58:08 +00:00
' lunch_active ' : fields . boolean ( ' Active ' ) ,
2012-11-02 08:15:48 +00:00
' day ' : fields . selection ( [ ( ' specific ' , ' Specific day ' ) , ( ' week ' , ' Every Week ' ) , ( ' days ' , ' Every Day ' ) ] , string = ' Recurrency ' , required = True , select = True ) ,
2012-10-24 14:20:25 +00:00
' specific ' : fields . date ( ' Day ' ) ,
' monday ' : fields . boolean ( ' Monday ' ) ,
' tuesday ' : fields . boolean ( ' Tuesday ' ) ,
' wednesday ' : fields . boolean ( ' Wednesday ' ) ,
' thursday ' : fields . boolean ( ' Thursday ' ) ,
' friday ' : fields . boolean ( ' Friday ' ) ,
' saturday ' : fields . boolean ( ' Saturday ' ) ,
' sunday ' : fields . boolean ( ' Sunday ' ) ,
' active_from ' : fields . float ( ' Between ' , required = True ) ,
' active_to ' : fields . float ( ' And ' , required = True ) ,
}
2012-11-02 08:15:48 +00:00
_defaults = {
' day ' : lambda self , cr , uid , context : ' specific ' ,
' specific ' : lambda self , cr , uid , context : time . strftime ( ' % Y- % m- %d ' ) ,
' active_from ' : 7 ,
' active_to ' : 23 ,
}