[MERGE] Merged Rifakat's branch for the fix of onchange call
authorJay Vora (OpenERP) <jvo@tinyerp.com>
Mon, 16 May 2011 14:18:07 +0000 (19:48 +0530)
committerJay Vora (OpenERP) <jvo@tinyerp.com>
Mon, 16 May 2011 14:18:07 +0000 (19:48 +0530)
bzr revid: jvo@tinyerp.com-20110516141807-5ktqh53nk8z8n3pu

addons/account_payment/wizard/account_payment_populate_statement.py

index 340ab4b..e7436d3 100644 (file)
@@ -75,45 +75,46 @@ class account_payment_populate_statement(osv.osv_memory):
             amount = currency_obj.compute(cr, uid, line.currency.id,
                     statement.currency.id, line.amount_currency, context=ctx)
 
+            if not line.move_line_id.id:
+                continue
             context.update({'move_line_ids': [line.move_line_id.id]})
-            result = voucher_obj.onchange_partner_id(cr, uid, [], partner_id=line.partner_id.id, journal_id=statement.journal_id.id, price=abs(amount), currency_id= statement.currency.id, ttype='payment', context=context)
+            result = voucher_obj.onchange_partner_id(cr, uid, [], partner_id=line.partner_id.id, journal_id=statement.journal_id.id, price=abs(amount), currency_id=statement.currency.id, ttype='payment', date=line.date, context=context)
 
-            if line.move_line_id:
-                voucher_res = {
-                        'type': 'payment',
-                        'name': line.name,
-                        'partner_id': line.partner_id.id,
-                        'journal_id': statement.journal_id.id,
-                        'account_id': result.get('account_id', statement.journal_id.default_credit_account_id.id),
-                        'company_id': statement.company_id.id,
-                        'currency_id': statement.currency.id,
-                        'date': line.date or time.strftime('%Y-%m-%d'),
-                        'amount': abs(amount),
-                        'period_id': statement.period_id.id
-                }
-                voucher_id = voucher_obj.create(cr, uid, voucher_res, context=context)
-                voucher_line_dict =  False
-                if result['value']['line_ids']:
-                    for line_dict in result['value']['line_ids']:
-                        move_line = move_line_obj.browse(cr, uid, line_dict['move_line_id'], context)
-                        if line.move_line_id.move_id.id == move_line.move_id.id:
-                            voucher_line_dict = line_dict
-                if voucher_line_dict:
-                    voucher_line_dict.update({'voucher_id': voucher_id})
-                    voucher_line_obj.create(cr, uid, voucher_line_dict, context=context)
-
-                st_line_id = statement_line_obj.create(cr, uid, {
-                    'name': line.order_id.reference or '?',
-                    'amount': - amount,
-                    'type': 'supplier',
+            voucher_res = {
+                    'type': 'payment',
+                    'name': line.name,
                     'partner_id': line.partner_id.id,
-                    'account_id': line.move_line_id.account_id.id,
-                    'statement_id': statement.id,
-                    'ref': line.communication,
-                    'voucher_id': voucher_id,
-                    }, context=context)
+                    'journal_id': statement.journal_id.id,
+                    'account_id': result.get('account_id', statement.journal_id.default_credit_account_id.id),
+                    'company_id': statement.company_id.id,
+                    'currency_id': statement.currency.id,
+                    'date': line.date or time.strftime('%Y-%m-%d'),
+                    'amount': abs(amount),
+                    'period_id': statement.period_id.id
+            }
+            voucher_id = voucher_obj.create(cr, uid, voucher_res, context=context)
+            voucher_line_dict =  {}
+            if result['value']['line_ids']:
+                for line_dict in result['value']['line_ids']:
+                    move_line = move_line_obj.browse(cr, uid, line_dict['move_line_id'], context)
+                    if line.move_line_id.move_id.id == move_line.move_id.id:
+                        voucher_line_dict = line_dict
+            if voucher_line_dict:
+                voucher_line_dict.update({'voucher_id': voucher_id})
+                voucher_line_obj.create(cr, uid, voucher_line_dict, context=context)
+
+            st_line_id = statement_line_obj.create(cr, uid, {
+                'name': line.order_id.reference or '?',
+                'amount': - amount,
+                'type': 'supplier',
+                'partner_id': line.partner_id.id,
+                'account_id': line.move_line_id.account_id.id,
+                'statement_id': statement.id,
+                'ref': line.communication,
+                'voucher_id': voucher_id,
+                }, context=context)
 
-                line_obj.write(cr, uid, [line.id], {'bank_statement_line_id': st_line_id})
+            line_obj.write(cr, uid, [line.id], {'bank_statement_line_id': st_line_id})
         return {'type': 'ir.actions.act_window_close'}
 
 account_payment_populate_statement()