From 81840a006cd6b7a80c6ca6c43efbc8fe536faa0e Mon Sep 17 00:00:00 2001 From: "ksa (Open ERP)" Date: Tue, 16 Mar 2010 19:33:02 +0530 Subject: [PATCH] [IMP]: lunch: code optimization and apply doc string bzr revid: ksa@tinyerp.co.in-20100316140302-sbjh3mot08dwdd0z --- addons/lunch/lunch.py | 48 +++++++---- addons/lunch/lunch_view.xml | 82 ++++++++++++------- addons/lunch/wizard/lunch_cashbox_clean.py | 30 +++---- .../lunch/wizard/lunch_cashbox_clean_view.xml | 11 ++- addons/lunch/wizard/lunch_order_cancel.py | 11 +-- .../lunch/wizard/lunch_order_cancel_view.xml | 11 ++- addons/lunch/wizard/lunch_order_confirm.py | 21 ++--- .../lunch/wizard/lunch_order_confirm_view.xml | 11 ++- 8 files changed, 137 insertions(+), 88 deletions(-) diff --git a/addons/lunch/lunch.py b/addons/lunch/lunch.py index 7eb6d858a3e..ba6f816169d 100644 --- a/addons/lunch/lunch.py +++ b/addons/lunch/lunch.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 . # ############################################################################## @@ -23,24 +23,28 @@ from osv import osv, fields import time class lunch_category(osv.osv): + """ Lunch category """ _name = 'lunch.category' _description = "Category" _columns = { 'name': fields.char('Name', required=True, size=50), } - _order = 'name' 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 """ obj = self.pool.get('lunch.category') cat_ids= obj.search(cr,uid,[]) - res = obj.read(cr,uid,cat_ids,['name', 'category']) + res = obj.read(cr, uid, cat_ids, ['name', 'category']) return [(str(r['id']), r['name']) for r in res]+ [('0','')] _columns = { @@ -57,36 +61,40 @@ class lunch_product(osv.osv): 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): cr.execute("SELECT box,sum(amount) from lunch_cashmove where active = 't' group by box") r = dict(cr.fetchall()) - for i in ids : + 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), + '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'), } lunch_cashbox() - - class lunch_cashmove(osv.osv): + """ Move cah """ _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), - 'active':fields.boolean('Active'), + 'box': fields.many2one('lunch.cashbox','Box Name',size=30,required=True), + 'active': fields.boolean('Active'), 'create_date': fields.datetime('Created date', readonly=True), } @@ -97,9 +105,10 @@ class lunch_cashmove(osv.osv): 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): @@ -109,15 +118,15 @@ class lunch_order(osv.osv): return res _columns={ - 'user_id': fields.many2one('res.users','User Name', required=True, + 'user_id': fields.many2one('res.users','User Name', required=True, \ readonly=True, states={'draft':[('readonly',False)]}), - 'product':fields.many2one('lunch.product','Product', required=True, + '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, + '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': fields.selection([('draft','Draft'), ('confirmed','Confirmed'),],\ 'State', readonly=True, select=True), 'price': fields.function(_price_get, method=True, string="Price"), } @@ -147,7 +156,7 @@ class lunch_order(osv.osv): for order in orders: if not order.cashmove: continue - self.pool.get('lunch.cashmove').unlink(cr, uid, [order.cashmove.id]) + self.pool.get('lunch.cashmove').unlink(cr, uid, [order.cashmove.id]) self.write(cr,uid,ids,{'state':'draft'}) return {} @@ -159,7 +168,9 @@ class lunch_order(osv.osv): lunch_order() + class report_lunch_amount(osv.osv): + """ Lunch Amount Report """ _name='report.lunch.amount' _description = "Amount available by user and box" _auto = False @@ -187,5 +198,6 @@ class report_lunch_amount(osv.osv): )""") report_lunch_amount() + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/lunch/lunch_view.xml b/addons/lunch/lunch_view.xml index 449c0400905..87fff3cb273 100644 --- a/addons/lunch/lunch_view.xml +++ b/addons/lunch/lunch_view.xml @@ -2,21 +2,25 @@ - + - - - - + + - - + + + + + + + Order lunch.order @@ -58,15 +62,10 @@ lunch.order tree,form - + - - - - - - - + CashBox @@ -96,7 +95,13 @@ CashBox lunch.cashbox - + + + + CashMove @@ -133,7 +138,11 @@ lunch.cashmove - + + + Category of product @@ -157,12 +166,13 @@ - Category of product lunch.category + + Products form @@ -178,7 +188,6 @@ - Products lunch.product @@ -198,10 +207,21 @@ lunch.product - - - + + + + + + Lunch amount @@ -229,14 +249,18 @@ - Lunch amount report.lunch.amount form tree,form - + + + diff --git a/addons/lunch/wizard/lunch_cashbox_clean.py b/addons/lunch/wizard/lunch_cashbox_clean.py index 5656ca92dbe..b1a96556460 100644 --- a/addons/lunch/wizard/lunch_cashbox_clean.py +++ b/addons/lunch/wizard/lunch_cashbox_clean.py @@ -1,6 +1,6 @@ # -*- encoding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). # @@ -15,16 +15,16 @@ # 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 . # ############################################################################## from osv import fields, osv class lunch_cashbox_clean(osv.osv_memory): - + _name = "lunch.cashbox.clean" _description = "clean cashbox" - + def set_to_zero(self, cr, uid, ids, context): """ clean Cashbox. set active fields False. @@ -33,22 +33,24 @@ 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, context['active_ids']))) + 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, context['active_ids']))) -## to_unactive= {}.fromkeys([r[0] for r in cr.fetchall]).keys() -## print to_unactive -## cashmove_ref.write(cr,uid,to_unactive,{'active':False}) + 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, - 'user_cashmove': user_id, - 'box': box_id, - 'active': True, + cashmove_ref.create(cr, uid, {'name': 'Summary for user' + str(user_id), + 'amount': amount, + 'user_cashmove': user_id, + 'box': box_id, + 'active': True, }) return {} lunch_cashbox_clean() + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/lunch/wizard/lunch_cashbox_clean_view.xml b/addons/lunch/wizard/lunch_cashbox_clean_view.xml index 6e151dc0484..20fb2416ade 100644 --- a/addons/lunch/wizard/lunch_cashbox_clean_view.xml +++ b/addons/lunch/wizard/lunch_cashbox_clean_view.xml @@ -1,6 +1,9 @@ + + + lunch.cashbox.clean.form lunch.cashbox.clean @@ -18,21 +21,21 @@ - + Set CashBox to Zero lunch.cashbox.clean form tree,form - + new {'record_id':active_id} - + - + diff --git a/addons/lunch/wizard/lunch_order_cancel.py b/addons/lunch/wizard/lunch_order_cancel.py index 91f25aa421a..c17c4e651ff 100644 --- a/addons/lunch/wizard/lunch_order_cancel.py +++ b/addons/lunch/wizard/lunch_order_cancel.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 . # ############################################################################## from osv import fields, osv @@ -26,7 +26,7 @@ class lunch_order_cancel(osv.osv_memory): """ _name = "lunch.order.cancel" _description = "Cancel Order" - + def cancel(self, cr, uid, ids, context): """ Cancel cashmove entry from cashmoves and update state to draft. @@ -34,8 +34,9 @@ class lunch_order_cancel(osv.osv_memory): @param uid: the current user’s ID for security checks, @param ids: List Lunch Order Cancel’s IDs """ - return self.pool.get('lunch.order').lunch_order_cancel(cr, uid, context['active_ids'], context) - + data = context and context.get('active_ids', []) or [] + return self.pool.get('lunch.order').lunch_order_cancel(cr, uid, data, context) + lunch_order_cancel() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/lunch/wizard/lunch_order_cancel_view.xml b/addons/lunch/wizard/lunch_order_cancel_view.xml index c69d321b938..dcfe412af48 100644 --- a/addons/lunch/wizard/lunch_order_cancel_view.xml +++ b/addons/lunch/wizard/lunch_order_cancel_view.xml @@ -1,6 +1,9 @@ + + + lunch.order.cancel.form lunch.order.cancel @@ -18,21 +21,21 @@ - + Cancel Order lunch.order.cancel form tree,form - + new {'record_id':active_id} - + - + diff --git a/addons/lunch/wizard/lunch_order_confirm.py b/addons/lunch/wizard/lunch_order_confirm.py index 9b7476f40e3..f15f18b0867 100644 --- a/addons/lunch/wizard/lunch_order_confirm.py +++ b/addons/lunch/wizard/lunch_order_confirm.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 . # ############################################################################## @@ -28,21 +28,22 @@ 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), + 'confirm_cashbox':fields.many2one('lunch.cashbox', 'Name of box', required=True), } - + def confirm(self, cr, uid, ids, context): """ - confirm Lunch Order.Create cashmoves in launch cashmoves when state is + confirm Lunch Order.Create cashmoves in launch cashmoves when state is confirm in lunch order. - @param cr: the current row, from the database cursor, - @param uid: the current user’s ID for security checks, + @param cr: the current row, from the database cursor, + @param uid: the current user’s ID for security checks, @param ids: List Lunch Order confirm’s IDs - @return: Dictionary {}. + @return: Dictionary {}. """ + data = context and context.get('active_ids', []) or [] order_ref = self.pool.get('lunch.order') - for data in self.read(cr, uid, ids): - order_ref.confirm(cr, uid, context['active_ids'], data['confirm_cashbox'], context) + for confirm_obj in self.read(cr, uid, ids): + order_ref.confirm(cr, uid, data, confirm_obj['confirm_cashbox'], context) return {} lunch_order_confirm() diff --git a/addons/lunch/wizard/lunch_order_confirm_view.xml b/addons/lunch/wizard/lunch_order_confirm_view.xml index 89ddd8f6153..8afd25c2307 100644 --- a/addons/lunch/wizard/lunch_order_confirm_view.xml +++ b/addons/lunch/wizard/lunch_order_confirm_view.xml @@ -1,6 +1,9 @@ + + + lunch.order.confirm.form lunch.order.confirm @@ -20,21 +23,21 @@ - + Confirm Order lunch.order.confirm form tree,form - + new {'record_id':active_id} - + - +