请帮我解决这个问题。 我正在使用OpenERP 6.0
目前我遇到了性能问题。 问题是,当我转到供应商或客户付款时,我选择 partner_id 让询问系统自动检索合作伙伴的未结帐单我选择付款(实际上有 150发票 ,这是未完成的。)
所以,当我选择它的时候,系统正在花费 2分30秒来检索这150张发票,这对我来说花了很多时间。
def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=None):
if context is None:
context = {}
if not journal_id:
return {}
context_multi_currency = context.copy()
if date:
context_multi_currency.update({'date': date})
line_pool = self.pool.get('account.voucher.line')
line_ids = ids and line_pool.search(cr, uid, [('voucher_id', '=', ids[0])]) or False
if line_ids:
line_pool.unlink(cr, uid, line_ids)
currency_pool = self.pool.get('res.currency')
move_line_pool = self.pool.get('account.move.line')
partner_pool = self.pool.get('res.partner')
journal_pool = self.pool.get('account.journal')
vals = self.onchange_journal(cr, uid, ids, journal_id, [], False, partner_id, context)
vals = vals.get('value')
currency_id = vals.get('currency_id', currency_id)
default = {
'value':{'line_ids':[], 'line_dr_ids':[], 'line_cr_ids':[], 'pre_line': False, 'currency_id':currency_id},
}
if not partner_id:
return default
if not partner_id and ids:
line_ids = line_pool.search(cr, uid, [('voucher_id', '=', ids[0])])
if line_ids:
line_pool.unlink(cr, uid, line_ids)
return default
journal = journal_pool.browse(cr, uid, journal_id, context=context)
partner = partner_pool.browse(cr, uid, partner_id, context=context)
account_id = False
if journal.type in ('sale','sale_refund'):
account_id = partner.property_account_receivable.id
elif journal.type in ('purchase', 'purchase_refund','expense'):
account_id = partner.property_account_payable.id
else:
account_id = journal.default_credit_account_id.id or journal.default_debit_account_id.id
default['value']['account_id'] = account_id
if journal.type not in ('cash', 'bank'):
return default
total_credit = 0.0
total_debit = 0.0
account_type = 'receivable'
if ttype == 'payment':
account_type = 'payable'
total_debit = price or 0.0
else:
total_credit = price or 0.0
account_type = 'receivable'
if not context.get('move_line_ids', False):
domain = [('state','=','valid'), ('account_id.type', '=', account_type), ('reconcile_id', '=', False), ('partner_id', '=', partner_id)]
if context.get('invoice_id', False):
domain.append(('invoice', '=', context['invoice_id']))
ids = move_line_pool.search(cr, uid, domain, context=context)
else:
ids = context['move_line_ids']
ids.reverse()
moves = move_line_pool.browse(cr, uid, ids, context=context)
company_currency = journal.company_id.currency_id.id
if company_currency != currency_id and ttype == 'payment':
total_debit = currency_pool.compute(cr, uid, currency_id, company_currency, total_debit, context=context_multi_currency)
elif company_currency != currency_id and ttype == 'receipt':
total_credit = currency_pool.compute(cr, uid, currency_id, company_currency, total_credit, context=context_multi_currency)
for line in moves:
if line.credit and line.reconcile_partial_id and ttype == 'receipt':
continue
if line.debit and line.reconcile_partial_id and ttype == 'payment':
continue
total_credit += line.credit or 0.0
total_debit += line.debit or 0.0
for line in moves:
if line.credit and line.reconcile_partial_id and ttype == 'receipt':
continue
if line.debit and line.reconcile_partial_id and ttype == 'payment':
continue
original_amount = line.credit or line.debit or 0.0
amount_unreconciled = currency_pool.compute(cr, uid, line.currency_id and line.currency_id.id or company_currency, currency_id, abs(line.amount_residual_currency), context=context_multi_currency)
rs = {
'name':line.move_id.name,
'type': line.credit and 'dr' or 'cr',
'move_line_id':line.id,
'account_id':line.account_id.id,
'amount_original': currency_pool.compute(cr, uid, line.currency_id and line.currency_id.id or company_currency, currency_id, line.currency_id and abs(line.amount_currency) or original_amount, context=context_multi_currency),
'date_original':line.date,
'date_due':line.date_maturity,
'amount_unreconciled': amount_unreconciled,
}
if line.credit:
amount = min(amount_unreconciled, currency_pool.compute(cr, uid, company_currency, currency_id, abs(total_debit), context=context_multi_currency))
rs['amount'] = amount
total_debit -= amount
else:
amount = min(amount_unreconciled, currency_pool.compute(cr, uid, company_currency, currency_id, abs(total_credit), context=context_multi_currency))
rs['amount'] = amount
total_credit -= amount
default['value']['line_ids'].append(rs)
if rs['type'] == 'cr':
default['value']['line_cr_ids'].append(rs)
else:
default['value']['line_dr_ids'].append(rs)
if ttype == 'payment' and len(default['value']['line_cr_ids']) > 0:
default['value']['pre_line'] = 1
elif ttype == 'receipt' and len(default['value']['line_dr_ids']) > 0:
default['value']['pre_line'] = 1
default['value']['writeoff_amount'] = self._compute_writeoff_amount(cr, uid, default['value']['line_dr_ids'], default['value']['line_cr_ids'], price)
return default
实际上我已经检查了使它变慢的代码在哪里。它是附加的,将值插入项目行。
default['value']['line_ids'].append(rs)
if rs['type'] == 'cr':
default['value']['line_cr_ids'].append(rs)
else:
default['value']['line_dr_ids'].append(rs)
您是否有任何想法可以通过修改代码解决此性能问题(使其更快)?
谢谢