From 23617797f5cd2e917d04358785af8de297289bbe Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 22 Sep 2010 11:40:04 +0530 Subject: [PATCH 1/7] [REM] print statements from account/test/account_report.yml bzr revid: xmo@openerp.com-20100922061004-lv61ehfjflmnzben --- addons/account/test/account_report.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/addons/account/test/account_report.yml b/addons/account/test/account_report.yml index 0048de7af46..a02635d0fc1 100644 --- a/addons/account/test/account_report.yml +++ b/addons/account/test/account_report.yml @@ -143,7 +143,6 @@ (data, format) = netsvc.LocalService('report.account.account.balance').create(cr, uid, [ref('account.bal'),ref('account.gpf')], data_dict, {'periods': []}) if tools.config['test_report_directory']: file(os.path.join(tools.config['test_report_directory'], 'account-account_balance-normal.'+format), 'wb+').write(data) - print "Account Balance Report in Normal mode - From Menu" data_dict.update({'model': 'ir.ui.menu'}) data_dict['form'].update({'active_ids':[ref('account.bal'),ref('account.gpf')]}) @@ -174,7 +173,6 @@ if tools.config['test_report_directory']: file(os.path.join(tools.config['test_report_directory'], 'account-central_journal.'+format), 'wb+').write(data) - print "Central Journal Report - From Menu" data_dict.update({'model': 'ir.ui.menu'}) data_dict['form'].update({'active_ids':journal_period_ids}) @@ -226,7 +224,6 @@ if tools.config['test_report_directory']: file(os.path.join(tools.config['test_report_directory'], 'account-general_ledger.'+format), 'wb+').write(data) - print "GL report from menu" data_dict.update({'model': 'ir.ui.menu'}) data_dict['form'].update({'active_ids': acc_ids}) (data, format) = netsvc.LocalService('report.account.general.ledger').create(cr, uid, [], data_dict, {}) @@ -255,7 +252,6 @@ if tools.config['test_report_directory']: file(os.path.join(tools.config['test_report_directory'], 'account-general_ledger-landscape.'+format), 'wb+').write(data) - print "GL report landscape mode from menu" data_dict.update({'model': 'ir.ui.menu'}) data_dict['form'].update({'active_ids': acc_ids}) (data, format) = netsvc.LocalService('report.account.general.ledger_landscape').create(cr, uid, [], data_dict, {}) @@ -285,7 +281,6 @@ if tools.config['test_report_directory']: file(os.path.join(tools.config['test_report_directory'], 'account-print_journal.'+format), 'wb+').write(data) - print "Journal Report - From Menu" data_dict.update({'model': 'ir.ui.menu'}) data_dict['form'].update({'active_ids':journal_period_ids}) From c2a364bff058c818ac6c2a2ba114f01665e979e9 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 22 Sep 2010 11:42:09 +0530 Subject: [PATCH 2/7] [REM] print statement in change_currency accounting test bzr revid: xmo@openerp.com-20100922061209-s0p1ccf7k0f3t2va --- addons/account/test/account_change_currency.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/addons/account/test/account_change_currency.yml b/addons/account/test/account_change_currency.yml index d99c9002870..71a4ff6e301 100644 --- a/addons/account/test/account_change_currency.yml +++ b/addons/account/test/account_change_currency.yml @@ -41,17 +41,14 @@ I clicked on Change Currency button to change the currency - !python {model: account.change.currency}: | - try: - self.view_init(cr, uid, [ref("account_change_currency_0")], {"lang": 'en_US', + self.view_init(cr, uid, [ref("account_change_currency_0")], {"lang": 'en_US', "active_model": "account.invoice", "tz": False, "record_id": 4, "active_ids": [ref("account_invoice_currency")], "type": "out_invoice", "active_id": ref("account_invoice_currency"), - }) - self.change_currency(cr, uid, [ref("account_change_currency_0")], {"lang": 'en_US', + }) + self.change_currency(cr, uid, [ref("account_change_currency_0")], {"lang": 'en_US', "active_model": "account.invoice", "tz": False, "record_id": 4, "active_ids": [ref("account_invoice_currency")], "type": "out_invoice", "active_id": ref("account_invoice_currency"), - }) - except: - print "You can not change currency for Open Invoice !" + }) - I can't change the currency of invoice when it is not in draft state so i change the state to cancel - From e334e9db447a3acbfa3274895a6b59635a6dde61 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 22 Sep 2010 11:43:11 +0530 Subject: [PATCH 3/7] [REM] print statement in parent_structure accounting test bzr revid: xmo@openerp.com-20100922061311-0iwcxfh24h7hkewr --- addons/account/test/test_parent_structure.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/addons/account/test/test_parent_structure.py b/addons/account/test/test_parent_structure.py index ba27d91c87c..9c3dd2b4c47 100644 --- a/addons/account/test/test_parent_structure.py +++ b/addons/account/test/test_parent_structure.py @@ -47,8 +47,3 @@ for a in account_lists: (a2['parent_right']a['parent_left']) and (a2['parent_right'] Date: Wed, 22 Sep 2010 11:45:07 +0530 Subject: [PATCH 4/7] [IMP] remove commit from account/report/account_journal.py bzr revid: xmo@openerp.com-20100922061507-076xytzpvubfcdhw --- addons/account/report/account_journal.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/account/report/account_journal.py b/addons/account/report/account_journal.py index 9f050756a5e..9d62829ef93 100644 --- a/addons/account/report/account_journal.py +++ b/addons/account/report/account_journal.py @@ -114,8 +114,7 @@ class journal_print(report_sxw.rml_parse, common_report_header): journal_id = [journal_id] obj_mline = self.pool.get('account.move.line') self.cr.execute('update account_journal_period set state=%s where journal_id IN %s and period_id=%s and state=%s', ('printed', self.journal_ids, period_id, 'draft')) - self.cr.commit() - + move_state = ['draft','posted'] if self.target_move == 'posted': move_state = ['posted'] @@ -158,4 +157,4 @@ class journal_print(report_sxw.rml_parse, common_report_header): report_sxw.report_sxw('report.account.journal.period.print', 'account.journal.period', 'addons/account/report/account_journal.rml', parser=journal_print, header='internal') -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 627afe0258f24c7c16f3aa9d6a8df9f28b708999 Mon Sep 17 00:00:00 2001 From: "olt@tinyerp.com" <> Date: Wed, 22 Sep 2010 10:23:53 +0200 Subject: [PATCH 5/7] [IMP] hr_holidays: hr.holidays.status: performance improvement: move sql query outside the loop bzr revid: olt@tinyerp.com-20100922082353-kf95hdpfwzxtfoj6 --- addons/hr_holidays/hr_holidays.py | 39 +++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index b5f4534454f..487de83ebf4 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -23,11 +23,14 @@ import time import datetime +from itertools import groupby +from operator import itemgetter import netsvc from osv import fields, osv from tools.translate import _ + class hr_holidays_status(osv.osv): _name = "hr.holidays.status" _description = "Leave Type" @@ -35,39 +38,51 @@ class hr_holidays_status(osv.osv): def get_days_cat(self, cr, uid, ids, category_id, return_false, context=None): if context is None: context = {} + + cr.execute("""SELECT id, type, number_of_days, holiday_status_id FROM hr_holidays WHERE category_id = %s AND state='validate' AND holiday_status_id in %s""", + [category_id, tuple(ids)]) + result = sorted(cr.dictfetchall(), key=lambda x: x['holiday_status_id']) + + grouped_lines = dict((k, [v for v in itr]) for k, itr in groupby(result, itemgetter('holiday_status_id'))) + res = {} for record in self.browse(cr, uid, ids, context=context): res[record.id] = {} max_leaves = leaves_taken = 0 if not return_false: - cr.execute("""SELECT type, sum(number_of_days) FROM hr_holidays WHERE category_id = %s AND state='validate' AND holiday_status_id = %s GROUP BY type""", (str(category_id), str(record.id))) - for line in cr.fetchall(): - if line[0] =='remove': - leaves_taken = -line[1] - if line[0] =='add': - max_leaves = line[1] + if record.id in grouped_lines: + leaves_taken = -sum([item['number_of_days'] for item in grouped_lines[record.id] if item['type'] == 'remove']) + max_leaves = sum([item['number_of_days'] for item in grouped_lines[record.id] if item['type'] == 'add']) + res[record.id]['max_leaves'] = max_leaves res[record.id]['leaves_taken'] = leaves_taken res[record.id]['remaining_leaves'] = max_leaves - leaves_taken + return res def get_days(self, cr, uid, ids, employee_id, return_false, context=None): if context is None: context = {} + + cr.execute("""SELECT id, type, number_of_days, holiday_status_id FROM hr_holidays WHERE employee_id = %s AND state='validate' AND holiday_status_id in %s""", + [employee_id, tuple(ids)]) + result = sorted(cr.dictfetchall(), key=lambda x: x['holiday_status_id']) + + grouped_lines = dict((k, [v for v in itr]) for k, itr in groupby(result, itemgetter('holiday_status_id'))) + res = {} for record in self.browse(cr, uid, ids, context=context): res[record.id] = {} max_leaves = leaves_taken = 0 if not return_false: - cr.execute("""SELECT type, sum(number_of_days) FROM hr_holidays WHERE employee_id = %s AND state='validate' AND holiday_status_id = %s GROUP BY type""", (str(employee_id), str(record.id))) - for line in cr.fetchall(): - if line[0] =='remove': - leaves_taken = -line[1] - if line[0] =='add': - max_leaves = line[1] + if record.id in grouped_lines: + leaves_taken = -sum([item['number_of_days'] for item in grouped_lines[record.id] if item['type'] == 'remove']) + max_leaves = sum([item['number_of_days'] for item in grouped_lines[record.id] if item['type'] == 'add']) + res[record.id]['max_leaves'] = max_leaves res[record.id]['leaves_taken'] = leaves_taken res[record.id]['remaining_leaves'] = max_leaves - leaves_taken + return res def _user_left_days(self, cr, uid, ids, name, args, context=None): From 2a3ee6ed48f5c11cec12b162ff1535c2fe239eac Mon Sep 17 00:00:00 2001 From: "olt@tinyerp.com" <> Date: Wed, 22 Sep 2010 10:38:35 +0200 Subject: [PATCH 6/7] [FIX] decimal_precision: clear cache after calling parent write bzr revid: olt@tinyerp.com-20100922083835-kjhopzhopkp7fyau --- addons/decimal_precision/decimal_precision.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/decimal_precision/decimal_precision.py b/addons/decimal_precision/decimal_precision.py index 6a0f8ffa424..4077a019ee2 100644 --- a/addons/decimal_precision/decimal_precision.py +++ b/addons/decimal_precision/decimal_precision.py @@ -45,12 +45,12 @@ class decimal_precision(osv.osv): return res and res[0] or 2 def write(self, cr, uid, ids, data, *args, **argv): - self.precision_get.clear_cache(cr.dbname) res = super(decimal_precision, self).write(cr, uid, ids, data, *args, **argv) for obj in self.pool.obj_list(): for colname,col in self.pool.get(obj)._columns.items(): if isinstance(col, fields.float): col.digits_change(cr) + self.precision_get.clear_cache(cr.dbname) return res decimal_precision() From 6d1dedeee948d473dccea5fd0390fc25615998ad Mon Sep 17 00:00:00 2001 From: "olt@tinyerp.com" <> Date: Wed, 22 Sep 2010 10:38:38 +0200 Subject: [PATCH 7/7] [FIX] hr_timesheet_sheet, mrp: don't pass a dict or list to fromkeys second argument (it's only evaluated once) bzr revid: olt@tinyerp.com-20100922083838-80ikcizior7qkcic --- addons/hr_timesheet_sheet/hr_timesheet_sheet.py | 15 +++++++++------ addons/mrp/mrp.py | 8 ++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index a4049242c22..55e25e4001c 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -34,8 +34,6 @@ class one2many_mod2(fields.one2many): if values is None: values = {} - res = {}.fromkeys(ids, []) - # dict: # {idn: (date_current, user_id), ... # 1: ('2010-08-15', 1)} @@ -59,9 +57,13 @@ class one2many_mod2(fields.one2many): ids2 = obj.pool.get(self._obj).search(cr, user, dom, limit=self._limit) + res = {} + for i in ids: + res[i] = [] + for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'): if r[self._fields_id]: - res.setdefault(r[self._fields_id][0], []).append(r['id']) + res[r[self._fields_id][0]].append(r['id']) return res @@ -82,7 +84,6 @@ class one2many_mod(fields.one2many): if values is None: values = {} - res = {}.fromkeys(ids, []) res5 = obj.read(cr, user, ids, ['date_current', 'user_id'], context=context) res6 = {} @@ -96,11 +97,13 @@ class one2many_mod(fields.one2many): dom = [('date', '=', res6[id][0]), ('user_id', '=', res6[id][1])] ids2.extend(obj.pool.get(self._obj).search(cr, user, dom, limit=self._limit)) - + res = {} + for i in ids: + res[i] = [] for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'): if r[self._fields_id]: - res.setdefault(r[self._fields_id][0], []).append(r['id']) + res[r[self._fields_id][0]].append(r['id']) return res diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 87dfe8dd670..33828840eeb 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -357,7 +357,9 @@ class many2many_domain(fields.many2many): context = {} move_obj = obj.pool.get('stock.move') - res = {}.fromkeys(ids, []) + res = {} + for i in ids: + res[i] = [] valid_move_ids = move_obj.search(cr, user, self._domain) # move ids relative to domain argument cr.execute("SELECT production_id, move_id from mrp_production_move_ids where production_id in %s and move_id in %s", [tuple(ids), tuple(valid_move_ids)]) @@ -377,7 +379,9 @@ class one2many_domain(fields.one2many): context = {} move_obj = obj.pool.get('stock.move') - res = {}.fromkeys(ids, []) + res = {} + for i in ids: + res[i] = [] move_ids = move_obj.search(cr, user, self._domain+[('production_id', 'in', tuple(ids))], context=context) related_move_dict = dict([(o.production_id.id, [o.id]) for o in move_obj.browse(cr, user, move_ids, context=context)]) res.update(related_move_dict)