From ed53202f701535223241ce5ddf369c3b806e81fd Mon Sep 17 00:00:00 2001 From: Thomas Binsfeld Date: Wed, 10 Apr 2019 14:05:02 +0200 Subject: [PATCH] [REF] Payment Order: move all move preparation code in _prepare_move --- .../models/account_payment_order.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/account_payment_order/models/account_payment_order.py b/account_payment_order/models/account_payment_order.py index 6377838b9..aae3b870f 100644 --- a/account_payment_order/models/account_payment_order.py +++ b/account_payment_order/models/account_payment_order.py @@ -380,6 +380,15 @@ class AccountPaymentOrder(models.Model): 'payment_order_id': self.id, 'line_ids': [], } + total_company_currency = total_payment_currency = 0 + for bline in bank_lines: + total_company_currency += bline.amount_company_currency + total_payment_currency += bline.amount_currency + partner_ml_vals = self._prepare_move_line_partner_account(bline) + vals['line_ids'].append((0, 0, partner_ml_vals)) + trf_ml_vals = self._prepare_move_line_offsetting_account( + total_company_currency, total_payment_currency, bank_lines) + vals['line_ids'].append((0, 0, trf_ml_vals)) return vals @api.multi @@ -466,16 +475,6 @@ class AccountPaymentOrder(models.Model): post_move = self.payment_mode_id.post_move am_obj = self.env['account.move'] mvals = self._prepare_move(blines) - total_company_currency = total_payment_currency = 0 - for bline in blines: - total_company_currency += bline.amount_company_currency - total_payment_currency += bline.amount_currency - partner_ml_vals = self._prepare_move_line_partner_account( - bline) - mvals['line_ids'].append((0, 0, partner_ml_vals)) - trf_ml_vals = self._prepare_move_line_offsetting_account( - total_company_currency, total_payment_currency, blines) - mvals['line_ids'].append((0, 0, trf_ml_vals)) move = am_obj.create(mvals) blines.reconcile_payment_lines() if post_move: