summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorksa (Open ERP) <ksa@tinyerp.co.in>2010-03-17 16:13:25 +0530
committerksa (Open ERP) <ksa@tinyerp.co.in>2010-03-17 16:13:25 +0530
commitda226e3078d2bb0a577b3d93dd7c35c9a1f3192e (patch)
tree218742e5d853fe16146b8997d2eb84075db207c2
parentc759fe8400e169dbf8482cd6df452d5f690b59a4 (diff)
[IMP]: lunch: code optimization and apply csv file and doc string
bzr revid: ksa@tinyerp.co.in-20100317104325-184sxsqphab0q84y
-rw-r--r--addons/lunch/__terp__.py15
-rw-r--r--addons/lunch/lunch.py131
-rw-r--r--addons/lunch/lunch_view.xml38
-rw-r--r--addons/lunch/security/ir.model.access.csv15
-rw-r--r--addons/lunch/wizard/__init__.py6
-rw-r--r--addons/lunch/wizard/lunch_cashbox_clean.py6
-rw-r--r--addons/lunch/wizard/lunch_order_confirm.py2
7 files changed, 150 insertions, 63 deletions
diff --git a/addons/lunch/__terp__.py b/addons/lunch/__terp__.py
index b4fe451aac1..37a7ba4f452 100644
--- a/addons/lunch/__terp__.py
+++ b/addons/lunch/__terp__.py
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
##############################################################################
-#
+#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
@@ -15,7 +15,7 @@
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
@@ -25,18 +25,25 @@
"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',
'wizard/lunch_order_cancel_view.xml',
'wizard/lunch_order_confirm_view.xml',
- 'wizard/lunch_cashbox_clean_view.xml',
- 'lunch_view.xml',
+ 'wizard/lunch_cashbox_clean_view.xml',
+ 'lunch_view.xml',
'lunch_report.xml',
#'process/lunch_process.xml'
],
"demo_xml": ['lunch_demo.xml'],
"installable": True,
}
+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/lunch/lunch.py b/addons/lunch/lunch.py
index ba6f816169d..db7b6e53f59 100644
--- a/addons/lunch/lunch.py
+++ b/addons/lunch/lunch.py
@@ -24,6 +24,7 @@ import time
class lunch_category(osv.osv):
""" Lunch category """
+
_name = 'lunch.category'
_description = "Category"
@@ -37,13 +38,18 @@ 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 user’s ID for security checks,"""
+
obj = self.pool.get('lunch.category')
- cat_ids= obj.search(cr,uid,[])
+ cat_ids = obj.search(cr,uid,[])
res = obj.read(cr, uid, cat_ids, ['name', 'category'])
return [(str(r['id']), r['name']) for r in res]+ [('0','')]
@@ -64,20 +70,27 @@ lunch_product()
class lunch_cashbox(osv.osv):
""" cashbox for Lunch """
- _name='lunch.cashbox'
+
+ _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 user’s ID for security checks,
+ @param ids: List of create menu’s 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'),
- 'name': fields.char('Name',size=30,required=True, unique = True),
+ _columns = {
+ 'manager': fields.many2one('res.users', 'Manager'),
+ 'name': fields.char('Name', size=30, required=True, unique = True),
'sum_remain': fields.function(amount_available, method=True, string='Remained Total'),
}
@@ -86,19 +99,20 @@ lunch_cashbox()
class lunch_cashmove(osv.osv):
""" Move cah """
- _name= 'lunch.cashmove'
+
+ _name = 'lunch.cashmove'
_description = "Move cash"
- _columns={
- 'name': fields.char('Name',size=128),
- '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),
+ _columns = {
+ 'name': fields.char('Name', size=128),
+ '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),
'active': fields.boolean('Active'),
'create_date': fields.datetime('Created date', readonly=True),
}
- _defaults={
+ _defaults = {
'active': lambda *a: True,
}
@@ -107,60 +121,85 @@ lunch_cashmove()
class lunch_order(osv.osv):
""" Apply lunch order """
- _name='lunch.order'
+
+ _name = 'lunch.order'
_description = "Lunch Order"
- _rec_name= "user_id"
+ _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 user’s ID for security checks,
+ @param ids: List of Lunch order’s 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={
- '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 ),
- 'descript': fields.char('Description Order', readonly=True, size=50,\
- states={'draft':[('readonly',False)]}),
- 'state': fields.selection([('draft','Draft'), ('confirmed','Confirmed'),],\
+ _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),
+ 'descript': fields.char('Description Order', readonly=True, size=50, \
+ states = {'draft':[('readonly', False)]}),
+ 'state': fields.selection([('draft', 'Draft'), ('confirmed', 'Confirmed'), ], \
'State', readonly=True, select=True),
'price': fields.function(_price_get, method=True, string="Price"),
}
- _defaults={
+ _defaults = {
'user_id': lambda self,cr,uid,context: uid,
'date': lambda self,cr,uid,context: time.strftime('%Y-%m-%d'),
'state': lambda self,cr,uid,context: 'draft',
}
def confirm(self,cr,uid,ids,box,context):
- cashmove_ref= self.pool.get('lunch.cashmove')
- for order in self.browse(cr,uid,ids):
+
+ """ confirm order
+ @param cr: the current row, from the database cursor,
+ @param uid: the current user’s ID for security checks,
+ @param ids: List of confirm order’s 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'})
+ }
+ self.write(cr, uid, [order.id], {'cashmove': new_id, 'state': 'confirmed'})
return {}
- def lunch_order_cancel(self,cr,uid,ids,context):
- orders= self.browse(cr,uid,ids)
+ def lunch_order_cancel(self, cr, uid, ids, context):
+
+ """" cancel order
+ @param cr: the current row, from the database cursor,
+ @param uid: the current user’s ID for security checks,
+ @param ids: List of create menu’s IDs """
+
+ orders = self.browse(cr, uid, ids)
for order in orders:
if not order.cashmove:
continue
self.pool.get('lunch.cashmove').unlink(cr, uid, [order.cashmove.id])
- self.write(cr,uid,ids,{'state':'draft'})
+ self.write(cr, uid, ids, {'state':'draft'})
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 user’s ID for security checks,
+ @param ids: List of create menu’s IDs """
+
if not product:
return {'value': {'price': 0.0}}
price = self.pool.get('lunch.product').read(cr, uid, product, ['price'])['price']
@@ -171,18 +210,22 @@ lunch_order()
class report_lunch_amount(osv.osv):
""" Lunch Amount Report """
- _name='report.lunch.amount'
+
+ _name = 'report.lunch.amount'
_description = "Amount available by user and box"
_auto = False
- _rec_name= "user"
+ _rec_name = "user"
_columns = {
- '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),
+ '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),
}
def init(self, cr):
+
+ """ @param cr: the current row, from the database cursor"""
+
cr.execute("""
create or replace view report_lunch_amount as (
select
diff --git a/addons/lunch/lunch_view.xml b/addons/lunch/lunch_view.xml
index 87fff3cb273..eb24cdc53dc 100644
--- a/addons/lunch/lunch_view.xml
+++ b/addons/lunch/lunch_view.xml
@@ -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>
diff --git a/addons/lunch/security/ir.model.access.csv b/addons/lunch/security/ir.model.access.csv
index 43490780c36..5af63e329fd 100644
--- a/addons/lunch/security/ir.model.access.csv
+++ b/addons/lunch/security/ir.model.access.csv
@@ -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 \ No newline at end of file
+"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
diff --git a/addons/lunch/wizard/__init__.py b/addons/lunch/wizard/__init__.py
index 543ebdbf8dc..e6b34c215ac 100644
--- a/addons/lunch/wizard/__init__.py
+++ b/addons/lunch/wizard/__init__.py
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
##############################################################################
-#
+#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
@@ -15,11 +15,13 @@
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# 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:
diff --git a/addons/lunch/wizard/lunch_cashbox_clean.py b/addons/lunch/wizard/lunch_cashbox_clean.py
index b1a96556460..1956dc6d4b7 100644
--- a/addons/lunch/wizard/lunch_cashbox_clean.py
+++ b/addons/lunch/wizard/lunch_cashbox_clean.py
@@ -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 Clean’s 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,
diff --git a/addons/lunch/wizard/lunch_order_confirm.py b/addons/lunch/wizard/lunch_order_confirm.py
index f15f18b0867..1a84e25febb 100644
--- a/addons/lunch/wizard/lunch_order_confirm.py
+++ b/addons/lunch/wizard/lunch_order_confirm.py
@@ -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 {}