Merge lp:~pedro.baeza/account-payment/6.1-account_payment_extension_store into lp:~account-payment-team/account-payment/6.1

Proposed by Pedro Manuel Baeza on 2014-01-28
Status: Merged
Approved by: mikel on 2014-05-13
Approved revision: 115
Merged at revision: 115
Proposed branch: lp:~pedro.baeza/account-payment/6.1-account_payment_extension_store
Merge into: lp:~account-payment-team/account-payment/6.1
Diff against target: 82 lines (+40/-20)
1 file modified
account_payment_extension/account_move_line.py (+40/-20)
To merge this branch: bzr merge lp:~pedro.baeza/account-payment/6.1-account_payment_extension_store
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp Needs Fixing on 2014-03-21
Yannick Vaucher @ Camptocamp code review 2014-01-28 Approve on 2014-03-17
Review via email: mp+203596@code.launchpad.net

Description of the change

Methods for storing correctly the value amount_to_pay, that in 6.1 is stored, but not recomputed whenever its conditions changes, and for 7.0 is directly not stored, impacting on the performance on some operations.

Same for 7.0: https://code.launchpad.net/~pedro.baeza/account-payment/7.0-account_payment_extension_store/+merge/203594.

To post a comment you must log in.
114. By Pedro Manuel Baeza on 2014-01-30

[IMP] account_payment_extension: Store methods for saving correctly amount_to_pay field.

review: Approve (code review)

Same remarks than for the 7.0 version: set() instead of using keys of a dict and mutable default argument to remove.
Thanks

review: Needs Fixing
115. By Pedro Manuel Baeza on 2014-03-21

[IMP] account_payment_extension: dicts replaced by sets on store functions an mutable argument removed.

Pedro Manuel Baeza (pedro.baeza) wrote :

Done!

Thanks.

Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Guewen, can you please check my changes?

Regards.

Pedro Manuel Baeza (pedro.baeza) wrote :

Can you please check status of this MP?

Regards.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_payment_extension/account_move_line.py'
2--- account_payment_extension/account_move_line.py 2013-09-12 11:01:19 +0000
3+++ account_payment_extension/account_move_line.py 2014-03-21 14:47:19 +0000
4@@ -127,24 +127,6 @@
5 result[id] = debt
6 return result
7
8- def _to_pay_search(self, cr, uid, obj, name, args, context=None):
9- context = context or {}
10- if not len(args):
11- return []
12- currency = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.currency_id
13-
14- # For searching we first discard reconciled moves because the filter is fast and discards most records
15- # quickly.
16- ids = self.pool.get('account.move.line').search(cr, uid, [('reconcile_id','=',False)], context=context)
17- records = self.pool.get('account.move.line').read(cr, uid, ids, ['id', 'amount_to_pay'], context)
18- ids = []
19- for record in records:
20- if not self.pool.get('res.currency').is_zero( cr, uid, currency, record['amount_to_pay'] ):
21- ids.append( record['id'] )
22- if not ids:
23- return [('id','=',False)]
24- return [('id','in',ids)]
25-
26 def _payment_type_get(self, cr, uid, ids, field_name, arg, context=None):
27 context = context or {}
28 result = {}
29@@ -183,13 +165,51 @@
30 return [('id', 'in', [x[0] for x in res])]
31 return [('id','=','0')]
32
33+ def _get_move_lines(self, cr, uid, ids, context=None):
34+ result = set()
35+ line_obj = self.pool['payment.line']
36+ for line in line_obj.browse(cr, uid, ids, context=context):
37+ result.add(line.move_line_id.id)
38+ result.add(line.payment_move_id.id)
39+ return list(result)
40+
41+ def _get_move_lines_order(self, cr, uid, ids, context=None):
42+ result = set()
43+ order_obj = self.pool['payment.order']
44+ for order in order_obj.browse(cr, uid, ids, context=context):
45+ for line in order.line_ids:
46+ result.add(line.move_line_id.id)
47+ result.add(line.payment_move_id.id)
48+ return list(result)
49+
50+ def _get_reconcile(self, cr, uid, ids, context=None):
51+ result = set()
52+ reconcile_obj = self.pool['account.move.reconcile']
53+ for reconcile in reconcile_obj.browse(cr, uid, ids, context=context):
54+ for line in reconcile.line_id:
55+ result.add(line.id)
56+ for line in reconcile.line_partial_ids:
57+ result.add(line.id)
58+ return list(result)
59+
60 _columns = {
61 'invoice': fields.function(_invoice, method=True, string='Invoice',
62 type='many2one', relation='account.invoice', fnct_search=_invoice_search),
63 'received_check': fields.boolean('Received check', help="To write down that a check in paper support has been received, for example."),
64 'partner_bank_id': fields.many2one('res.partner.bank','Bank Account'),
65- 'amount_to_pay' : fields.function(amount_to_pay, method=True, type='float', string='Amount to pay', fnct_search=_to_pay_search, store=True),
66- 'payment_type': fields.function(_payment_type_get, fnct_search=_payment_type_search, method=True, type="many2one", relation="payment.type", string="Payment type"),
67+ 'amount_to_pay' : fields.function(amount_to_pay, method=True,
68+ type='float', string='Amount to pay',
69+ store={
70+ 'account.move.line': (lambda self, cr, uid, ids,
71+ context=None: ids, None, 20),
72+ 'payment.order': (_get_move_lines_order, ['line_ids'], 20),
73+ 'payment.line': (_get_move_lines,
74+ ['type', 'move_line_id', 'payment_move_id'], 20),
75+ 'account.move.reconcile': (_get_reconcile,
76+ ['line_id', 'line_partial_ids'], 20)
77+ }),
78+ 'payment_type': fields.function(_payment_type_get, fnct_search=_payment_type_search, method=True, type="many2one", relation="payment.type", string="Payment type")
79+
80 }
81
82 def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):

Subscribers

People subscribed via source and target branches