account-payment-team team mailing list archive
-
account-payment-team team
-
Mailing list archive
-
Message #00108
[Merge] lp:~pedro.baeza/account-payment/7.0-improvements into lp:account-payment/7.0
Pedro Manuel Baeza has proposed merging lp:~pedro.baeza/account-payment/7.0-improvements into lp:account-payment/7.0.
Requested reviews:
Guewen Baconnier @ Camptocamp (gbaconnier-c2c)
For more details, see:
https://code.launchpad.net/~pedro.baeza/account-payment/7.0-improvements/+merge/164400
[IMP] account_payment_extension: Removed all line2bank in search_entries that is not used.
[FIX] account_payment_extension: Changed value of t variable (payment mode) in the create_payment method to get account bank numbers in payments.
[IMP] account_payment_extension: Refactorization of set_done method to improve perfomance in the creation of the account move for large entries.
Let me explain the last one a bit more: in set_done method, currency retrieval was done on each payment line, and model objects were retrieved also on each line from the pool (with self.pool.get method). I have improved both of them. And there was one part that is particularly inefficient: for each account move line addition, a check for validity was done, increasing the time exponentially when having large entries. I have changed code to avoid this check on intermediate steps.
--
https://code.launchpad.net/~pedro.baeza/account-payment/7.0-improvements/+merge/164400
Your team Account Payment is subscribed to branch lp:account-payment/7.0.
=== modified file 'account_payment_extension/payment.py'
--- account_payment_extension/payment.py 2012-11-01 21:49:33 +0000
+++ account_payment_extension/payment.py 2013-05-17 13:37:28 +0000
@@ -200,7 +200,13 @@
def set_done(self, cr, uid, ids, context=None):
result = super(payment_order, self).set_done(cr, uid, ids, context)
- company_currency_id = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.currency_id.id
+ move_obj = self.pool.get('account.move')
+ move_line_obj = self.pool.get('account.move.line')
+ currency_obj = self.pool.get('res.currency')
+ payment_line_obj = self.pool.get('payment.line')
+
+ currency = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.currency_id
+ company_currency_id = currency.id
for order in self.browse(cr, uid, ids, context):
if order.create_account_moves != 'direct-payment':
@@ -209,12 +215,12 @@
# This process creates a simple account move with bank and line accounts and line's amount. At the end
# it will reconcile or partial reconcile both entries if that is possible.
- move_id = self.pool.get('account.move').create(cr, uid, {
+ move_id = move_obj.create(cr, uid, {
'name': '/',
'journal_id': order.mode.journal.id,
'period_id': order.period_id.id,
}, context)
-
+
for line in order.line_ids:
if not line.amount:
continue
@@ -237,7 +243,7 @@
ctx = context.copy()
ctx['res.currency.compute.account'] = acc_cur
- amount = self.pool.get('res.currency').compute(cr, uid, currency_id, company_currency_id, line_amount, context=ctx)
+ amount = currency_obj.compute(cr, uid, currency_id, company_currency_id, line_amount, context=ctx)
val = {
'name': line.move_line_id and line.move_line_id.name or '/',
@@ -251,11 +257,11 @@
'journal_id': order.mode.journal.id,
'period_id': order.period_id.id,
'currency_id': currency_id,
+ 'state': 'valid',
}
- amount = self.pool.get('res.currency').compute(cr, uid, currency_id, company_currency_id, line_amount, context=ctx)
if currency_id <> company_currency_id:
- amount_cur = self.pool.get('res.currency').compute(cr, uid, company_currency_id, currency_id, amount, context=ctx)
+ amount_cur = currency_obj.compute(cr, uid, company_currency_id, currency_id, amount, context=ctx)
val['amount_currency'] = -amount_cur
if line.account_id and line.account_id.currency_id and line.account_id.currency_id.id <> company_currency_id:
@@ -263,10 +269,10 @@
if company_currency_id == line.account_id.currency_id.id:
amount_cur = line_amount
else:
- amount_cur = self.pool.get('res.currency').compute(cr, uid, company_currency_id, line.account_id.currency_id.id, amount, context=ctx)
+ amount_cur = currency_obj.compute(cr, uid, company_currency_id, line.account_id.currency_id.id, amount, context=ctx)
val['amount_currency'] = amount_cur
- partner_line_id = self.pool.get('account.move.line').create(cr, uid, val, context, check=False)
+ partner_line_id = move_line_obj.create(cr, uid, val, context, check=False)
# Fill the secondary amount/currency
# if currency is not the same than the company
@@ -277,7 +283,7 @@
amount_currency = False
move_currency_id = False
- self.pool.get('account.move.line').create(cr, uid, {
+ move_line_obj.create(cr, uid, {
'name': line.move_line_id and line.move_line_id.name or '/',
'move_id': move_id,
'date': order.date_done,
@@ -290,45 +296,37 @@
'period_id': order.period_id.id,
'amount_currency': amount_currency,
'currency_id': move_currency_id,
- }, context)
-
- aml_ids = [x.id for x in self.pool.get('account.move').browse(cr, uid, move_id, context).line_id]
- for x in self.pool.get('account.move.line').browse(cr, uid, aml_ids, context):
- if x.state <> 'valid':
- raise osv.except_osv(_('Error !'), _('Account move line "%s" is not valid') % x.name)
+ 'state': 'valid',
+ }, context, check=False)
if line.move_line_id and not line.move_line_id.reconcile_id:
# If payment line has a related move line, we try to reconcile it with the move we just created.
lines_to_reconcile = [
partner_line_id,
]
-
# Check if payment line move is already partially reconciled and use those moves in that case.
if line.move_line_id.reconcile_partial_id:
for rline in line.move_line_id.reconcile_partial_id.line_partial_ids:
lines_to_reconcile.append( rline.id )
else:
lines_to_reconcile.append( line.move_line_id.id )
-
amount = 0.0
- for rline in self.pool.get('account.move.line').browse(cr, uid, lines_to_reconcile, context):
+ for rline in move_line_obj.browse(cr, uid, lines_to_reconcile, context):
amount += rline.debit - rline.credit
-
- currency = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.currency_id
-
- if self.pool.get('res.currency').is_zero(cr, uid, currency, amount):
- self.pool.get('account.move.line').reconcile(cr, uid, lines_to_reconcile, 'payment', context=context)
+
+ if currency_obj.is_zero(cr, uid, currency, amount):
+ move_line_obj.reconcile(cr, uid, lines_to_reconcile, 'payment', context=context)
else:
- self.pool.get('account.move.line').reconcile_partial(cr, uid, lines_to_reconcile, 'payment', context)
-
- if order.mode.journal.entry_posted:
- self.pool.get('account.move').write(cr, uid, [move_id], {
- 'state':'posted',
- }, context)
-
- self.pool.get('payment.line').write(cr, uid, [line.id], {
+ move_line_obj.reconcile_partial(cr, uid, lines_to_reconcile, 'payment', context)
+ # Annotate the move id
+ payment_line_obj.write(cr, uid, [line.id], {
'payment_move_id': move_id,
}, context)
+ # Post the move
+ if order.mode.journal.entry_posted:
+ move_obj.write(cr, uid, [move_id], {
+ 'state':'posted',
+ }, context)
return result
=== modified file 'account_payment_extension/wizard/account_payment_order.py'
--- account_payment_extension/wizard/account_payment_order.py 2013-04-11 13:40:25 +0000
+++ account_payment_extension/wizard/account_payment_order.py 2013-05-17 13:37:28 +0000
@@ -103,10 +103,6 @@
selected_ids = []
if amount > 0.0:
- if payment.mode and payment.mode.require_bank_account:
- line2bank = pool.get('account.move.line').line2bank(cr, uid, line_ids, payment.mode.id, context)
- else:
- line2bank = None
# If user specified an amount, search what moves match the criteria taking into account
# if payment mode allows bank account to be null.
for line in pool.get('account.move.line').browse(cr, uid, line_ids, context):
@@ -141,7 +137,7 @@
return {'type': 'ir.actions.act_window_close'}
payment = order_obj.browse(cr, uid, context['active_id'], context=context)
- t = None
+ t = payment.mode and payment.mode.id or None
line2bank = line_obj.line2bank(cr, uid, line_ids, t, context)
## Finally populate the current payment with new lines:
for line in line_obj.browse(cr, uid, line_ids, context=context):
Follow ups