From da226e3078d2bb0a577b3d93dd7c35c9a1f3192e Mon Sep 17 00:00:00 2001 From: "ksa (Open ERP)" Date: Wed, 17 Mar 2010 16:13:25 +0530 Subject: [PATCH] [IMP]: lunch: code optimization and apply csv file and doc string bzr revid: ksa@tinyerp.co.in-20100317104325-184sxsqphab0q84y --- addons/lunch/__terp__.py | 15 ++- addons/lunch/lunch.py | 135 ++++++++++++++------- addons/lunch/lunch_view.xml | 38 ++++-- addons/lunch/security/ir.model.access.csv | 15 ++- addons/lunch/wizard/__init__.py | 6 +- addons/lunch/wizard/lunch_cashbox_clean.py | 6 + addons/lunch/wizard/lunch_order_confirm.py | 2 + 7 files changed, 152 insertions(+), 65 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 (). # @@ -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 . +# along with this program. If not, see . # ############################################################################## @@ -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): - cr.execute("SELECT box,sum(amount) from lunch_cashmove where active = 't' group by box") - r = dict(cr.fetchall()) - for i in ids: - r.setdefault(i,0) - return r - _columns={ - 'manager': fields.many2one('res.users','Manager'), - 'name': fields.char('Name',size=30,required=True, unique = True), + """ 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") + amount = dict(cr.fetchall()) + for i in ids: + amount.setdefault(i, 0) + return amount + + _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 @@ - + Order @@ -38,6 +38,8 @@ + + Order lunch.order @@ -55,17 +57,18 @@ - + Lunch Orders lunch.order tree,form + - + CashBox @@ -78,6 +81,8 @@ + + CashBox lunch.cashbox @@ -91,6 +96,8 @@ + + CashBox lunch.cashbox @@ -101,7 +108,7 @@ id="menu_lunch_cashbox_form" action="action_lunch_cashbox_form" /> - + CashMove @@ -118,6 +125,8 @@ + + CashMove lunch.cashmove @@ -133,6 +142,8 @@ + + CashMove lunch.cashmove @@ -142,7 +153,7 @@ id="menu_lunch_cashmove_form" action="action_lunch_cashmove_form" /> - + Category of product @@ -155,6 +166,8 @@ + + Category lunch.category @@ -166,12 +179,14 @@ + + Category of product lunch.category - + Products @@ -188,6 +203,8 @@ + + Products lunch.product @@ -202,6 +219,8 @@ + + Product lunch.product @@ -221,7 +240,8 @@ id="menu_lunch_category_form" action="action_lunch_category_form" sequence="1" /> - + + Lunch amount @@ -236,6 +256,8 @@ + + Lunch amount report.lunch.amount @@ -249,6 +271,8 @@ + + Lunch amount report.lunch.amount 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 (). # @@ -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 . +# along with this program. If not, see . # ############################################################################## + 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 . # ############################################################################## + 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 {}