[IMP]: lunch: code optimization and apply csv file and doc string

bzr revid: ksa@tinyerp.co.in-20100317104325-184sxsqphab0q84y
This commit is contained in:
ksa (Open ERP) 2010-03-17 16:13:25 +05:30
parent c759fe8400
commit da226e3078
7 changed files with 152 additions and 65 deletions

View File

@ -25,6 +25,12 @@
"version": "0.1",
"depends": ["base"],
"category" : "Generic Modules/Others",
'description': """
The base module to manage lunch
keep track for the Lunch Order ,Cash Moves ,CashBox ,Product.
Apply Different Category for the product.
""",
"init_xml": [],
"update_xml": [
'security/ir.model.access.csv',
@ -38,5 +44,6 @@
"demo_xml": ['lunch_demo.xml'],
"installable": True,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -24,6 +24,7 @@ import time
class lunch_category(osv.osv):
""" Lunch category """
_name = 'lunch.category'
_description = "Category"
@ -37,11 +38,16 @@ lunch_category()
class lunch_product(osv.osv):
""" Lunch Product """
_name = 'lunch.product'
_description = "Lunch Product"
def _category_name_get(self, cr, uid, context={}):
""" Get category name """
""" Get category name
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,"""
obj = self.pool.get('lunch.category')
cat_ids = obj.search(cr,uid,[])
res = obj.read(cr, uid, cat_ids, ['name', 'category'])
@ -64,16 +70,23 @@ lunch_product()
class lunch_cashbox(osv.osv):
""" cashbox for Lunch """
_name = 'lunch.cashbox'
_description = "Cashbox for Lunch "
def amount_available(self, cr, uid, ids, field_name, arg, context):
""" count available amount
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of create menus IDs """
cr.execute("SELECT box,sum(amount) from lunch_cashmove where active = 't' group by box")
r = dict(cr.fetchall())
amount = dict(cr.fetchall())
for i in ids:
r.setdefault(i,0)
return r
amount.setdefault(i, 0)
return amount
_columns = {
'manager': fields.many2one('res.users', 'Manager'),
@ -86,6 +99,7 @@ lunch_cashbox()
class lunch_cashmove(osv.osv):
""" Move cah """
_name = 'lunch.cashmove'
_description = "Move cash"
@ -107,14 +121,21 @@ lunch_cashmove()
class lunch_order(osv.osv):
""" Apply lunch order """
_name = 'lunch.order'
_description = "Lunch Order"
_rec_name = "user_id"
def _price_get(self, cr, uid, ids, name, args, context=None):
""" Get Price of Product
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of Lunch orders IDs"""
res = {}
for o in self.browse(cr, uid, ids):
res[o.id] = o.product.price
for price in self.browse(cr, uid, ids):
res[price.id] = price.product.price
return res
_columns = {
@ -138,20 +159,32 @@ class lunch_order(osv.osv):
}
def confirm(self,cr,uid,ids,box,context):
""" confirm order
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of confirm orders IDs """
cashmove_ref = self.pool.get('lunch.cashmove')
for order in self.browse(cr, uid, ids):
if order.state == 'confirmed':
continue
new_id= cashmove_ref.create(cr,uid,{'name': order.product.name+' order',
new_id = cashmove_ref.createcr, uid, {'name': order.product.name+' order',
'amount':-order.product.price,
'user_cashmove':order.user_id.id,
'box':box,
'active':True,
})
}
self.write(cr, uid, [order.id], {'cashmove': new_id, 'state': 'confirmed'})
return {}
def lunch_order_cancel(self, cr, uid, ids, context):
"""" cancel order
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of create menus IDs """
orders = self.browse(cr, uid, ids)
for order in orders:
if not order.cashmove:
@ -161,6 +194,12 @@ class lunch_order(osv.osv):
return {}
def onchange_product(self, cr, uid, ids, product):
""" Get price for Product
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of create menus IDs """
if not product:
return {'value': {'price': 0.0}}
price = self.pool.get('lunch.product').read(cr, uid, product, ['price'])['price']
@ -171,6 +210,7 @@ lunch_order()
class report_lunch_amount(osv.osv):
""" Lunch Amount Report """
_name = 'report.lunch.amount'
_description = "Amount available by user and box"
_auto = False
@ -183,6 +223,9 @@ class report_lunch_amount(osv.osv):
}
def init(self, cr):
""" @param cr: the current row, from the database cursor"""
cr.execute("""
create or replace view report_lunch_amount as (
select

View File

@ -18,7 +18,7 @@
<menuitem name="Lunch" parent="base.menu_lunch_survey_root"
id="menu_lunch_category_root_configuration" sequence="1" />
<!-- Lunch order -->
<!-- Lunch order Form view -->
<record model="ir.ui.view" id="view_lunch_order_form">
<field name="name">Order</field>
@ -38,6 +38,8 @@
</field>
</record>
<!-- Lunch order Tree view -->
<record model="ir.ui.view" id="view_lunch_order_tree">
<field name="name">Order</field>
<field name="model">lunch.order</field>
@ -55,17 +57,18 @@
</field>
</record>
<!-- Lunch order Action -->
<record model="ir.actions.act_window" id="action_lunch_order_form">
<field name="name">Lunch Orders</field>
<field name="res_model">lunch.order</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="Lunch Order" parent="menu_lunch"
id="menu_lunch_order_form" action="action_lunch_order_form" />
<!-- Cash Box -->
<!-- Cash Box Form view -->
<record model="ir.ui.view" id="view_lunch_cashbox_form">
<field name="name">CashBox</field>
@ -78,6 +81,8 @@
</field>
</record>
<!-- Cash Box Tree view -->
<record model="ir.ui.view" id="view_lunch_cashbox_tree">
<field name="name">CashBox</field>
<field name="model">lunch.cashbox</field>
@ -91,6 +96,8 @@
</field>
</record>
<!-- Cash Box Action -->
<record model="ir.actions.act_window" id="action_lunch_cashbox_form">
<field name="name"> CashBox </field>
<field name="res_model">lunch.cashbox</field>
@ -101,7 +108,7 @@
id="menu_lunch_cashbox_form"
action="action_lunch_cashbox_form" />
<!-- Cash Move -->
<!-- Cash Move Form view -->
<record model="ir.ui.view" id="view_lunch_cashmove_form">
<field name="name">CashMove</field>
@ -118,6 +125,8 @@
</field>
</record>
<!-- Cash Move Tree view -->
<record model="ir.ui.view" id="view_lunch_cashmove_tree">
<field name="name">CashMove</field>
<field name="model">lunch.cashmove</field>
@ -133,6 +142,8 @@
</field>
</record>
<!-- Cash Move Action -->
<record model="ir.actions.act_window" id="action_lunch_cashmove_form">
<field name="name">CashMove</field>
<field name="res_model">lunch.cashmove</field>
@ -142,7 +153,7 @@
id="menu_lunch_cashmove_form"
action="action_lunch_cashmove_form" />
<!-- Lunch Category -->
<!-- Lunch Category Form view -->
<record model="ir.ui.view" id="view_lunch_category_form">
<field name="name"> Category of product </field>
@ -155,6 +166,8 @@
</field>
</record>
<!-- Lunch Category Tree view -->
<record model="ir.ui.view" id="view_lunch_category_tree">
<field name="name">Category</field>
<field name="model">lunch.category</field>
@ -166,12 +179,14 @@
</field>
</record>
<!-- Lunch Category Action -->
<record model="ir.actions.act_window" id="action_lunch_category_form">
<field name="name"> Category of product </field>
<field name="res_model">lunch.category</field>
</record>
<!-- Lunch Product -->
<!-- Lunch Product Form view -->
<record model="ir.ui.view" id="view_lunch_product_form">
<field name="name">Products</field>
@ -188,6 +203,8 @@
</field>
</record>
<!-- Lunch Product Tree view -->
<record model="ir.ui.view" id="view_lunch_product_tree">
<field name="name">Products</field>
<field name="model">lunch.product</field>
@ -202,6 +219,8 @@
</field>
</record>
<!-- Lunch Product Action -->
<record model="ir.actions.act_window" id="action_lunch_product_form">
<field name="name">Product</field>
<field name="res_model">lunch.product</field>
@ -221,7 +240,8 @@
id="menu_lunch_category_form"
action="action_lunch_category_form" sequence="1" />
<!-- Lunch Amount -->
<!-- Lunch Amount Tree view -->
<record model="ir.ui.view" id="view_report_lunch_amount_tree">
<field name="name">Lunch amount</field>
@ -236,6 +256,8 @@
</field>
</record>
<!-- Lunch Amount Form view -->
<record model="ir.ui.view" id="view_report_lunch_amount_form">
<field name="name">Lunch amount</field>
<field name="model">report.lunch.amount</field>
@ -249,6 +271,8 @@
</field>
</record>
<!-- Lunch Amount Action -->
<record model="ir.actions.act_window" id="action_report_lunch_amount_tree">
<field name="name">Lunch amount</field>
<field name="res_model">report.lunch.amount</field>

View File

@ -1,7 +1,10 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_lunch_category","lunch.category","model_lunch_category",base.group_user,1,1,1,1
"access_lunch_product","lunch.product","model_lunch_product",base.group_user,1,1,1,1
"access_lunch_cashbox","lunch.cashbox","model_lunch_cashbox",base.group_user,1,1,1,1
"access_lunch_cashmove","lunch.cashmove","model_lunch_cashmove",base.group_user,1,1,1,1
"access_lunch_order","lunch.order","model_lunch_order",base.group_user,1,1,1,1
"access_report_lunch_amount","report.lunch.amount","model_report_lunch_amount",base.group_user,1,1,1,1
"access_lunch_category","lunch.category","model_lunch_category","base.group_user",1,1,1,1
"access_lunch_product","lunch.product","model_lunch_product","base.group_user",1,1,1,1
"access_lunch_cashbox","lunch.cashbox","model_lunch_cashbox","base.group_user",1,1,1,1
"access_lunch_cashmove","lunch.cashmove","model_lunch_cashmove","base.group_user",1,1,1,1
"access_lunch_order","lunch.order","model_lunch_order","base.group_user",1,1,1,1
"access_report_lunch_amount","report.lunch.amount","model_report_lunch_amount","base.group_user",1,1,1,1
"lunch_order_confirm ","lunch.order.confirm","model_lunch_order_confirm","base.group_user",1,1,1,1
"lunch_order_cancel","lunch.order.cancel","model_lunch_order_cancel","base.group_user",1,1,1,1
"lunch_cashbox_clean","lunch.cashbox.clean","model_lunch_cashbox_clean","base.group_user",1,1,1,1

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_lunch_category lunch.category model_lunch_category base.group_user 1 1 1 1
3 access_lunch_product lunch.product model_lunch_product base.group_user 1 1 1 1
4 access_lunch_cashbox lunch.cashbox model_lunch_cashbox base.group_user 1 1 1 1
5 access_lunch_cashmove lunch.cashmove model_lunch_cashmove base.group_user 1 1 1 1
6 access_lunch_order lunch.order model_lunch_order base.group_user 1 1 1 1
7 access_report_lunch_amount report.lunch.amount model_report_lunch_amount base.group_user 1 1 1 1
8 lunch_order_confirm lunch.order.confirm model_lunch_order_confirm base.group_user 1 1 1 1
9 lunch_order_cancel lunch.order.cancel model_lunch_order_cancel base.group_user 1 1 1 1
10 lunch_cashbox_clean lunch.cashbox.clean model_lunch_cashbox_clean base.group_user 1 1 1 1

View File

@ -18,8 +18,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import lunch_order_confirm
import lunch_order_cancel
import lunch_cashbox_clean
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import fields, osv
class lunch_cashbox_clean(osv.osv_memory):
@ -26,6 +27,7 @@ class lunch_cashbox_clean(osv.osv_memory):
_description = "clean cashbox"
def set_to_zero(self, cr, uid, ids, context):
"""
clean Cashbox. set active fields False.
@param cr: the current row, from the database cursor,
@ -33,14 +35,18 @@ class lunch_cashbox_clean(osv.osv_memory):
@param ids: List Lunch cashbox Cleans IDs
@return:Dictionary {}.
"""
data = context and context.get('active_ids', []) or []
cashmove_ref = self.pool.get('lunch.cashmove')
cr.execute("select user_cashmove, box,sum(amount) from lunch_cashmove \
where active = 't' and box in (%s) group by user_cashmove, \
box" % ','.join(map(str, data)))
res = cr.fetchall()
cr.execute("update lunch_cashmove set active = 'f' where active= 't' \
and box in (%s)" % ','.join(map(str, data)))
for (user_id, box_id, amount) in res:
cashmove_ref.create(cr, uid, {'name': 'Summary for user' + str(user_id),
'amount': amount,

View File

@ -27,6 +27,7 @@ class lunch_order_confirm(osv.osv_memory):
"""
_name = "lunch.order.confirm"
_description = "confirm Order"
_columns = {
'confirm_cashbox':fields.many2one('lunch.cashbox', 'Name of box', required=True),
}
@ -42,6 +43,7 @@ class lunch_order_confirm(osv.osv_memory):
"""
data = context and context.get('active_ids', []) or []
order_ref = self.pool.get('lunch.order')
for confirm_obj in self.read(cr, uid, ids):
order_ref.confirm(cr, uid, data, confirm_obj['confirm_cashbox'], context)
return {}