diff options
| author | Laurent Smet <las@odoo.com> | 2019-10-29 12:21:27 +0000 |
|---|---|---|
| committer | qdp-odoo <qdp@odoo.com> | 2020-04-10 09:47:24 +0000 |
| commit | caeb782841fc5a7ad71a196e2c9ee67644ef9074 (patch) | |
| tree | 28103bc29ab4f0d98162095f607c4c6ab1433f25 /addons/payment/models | |
| parent | b4d1360ed1d71c8fda44ca0c3b1a80d5a112b93f (diff) | |
[IMP] account,*: Improve bank statements/payments workflow
- Create journal entries as soon as bank/cash statement lines are created, temporary booked on a suspense account set on the journal.
- Simplify the management of "blue" lines in the reconciliation widget. A "blue" line is now a journal item using a temporary liquidity account (outstanding payment/receipt accounts, set on the journal).
- Adapt and simplify the bank reconciliation report.
- Remove the bank reconciliation threshold date. The reconciliation report will show the not already reconciled journal entries using a liquidity account and the not already reconciled journal entries using a temporary liquidity account. Without accounting, an account.payment will involve directly the liquidity account and then, will be considered as a statement line directly.
- Remove the post_at bank reconciliation feature. The "paid" state will be set on the invoices only if reconciled with a journal entry involving the journal's liquidity account.
With invoicing, the payment will do that so the "in_payment" state should never be shown up.
With accounting, only the statement lines have the power to move an invoice to the "paid" state.
- Fix various corner cases about the management of multi-currency in bank statement lines.
- Fix the conversion dates in multi-currency: Since the bank/cash is always used on the statement lines, it will use always the real "bank" date instead of the fictive payment one.
- Ensure the 'reconcile' method will raise an error if the involved moves are not posted.
related enterprise PR odoo/enterprise#7019
closes odoo/odoo#41301
--task: 2092096
Related: odoo/upgrade#1018
Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
Diffstat (limited to 'addons/payment/models')
| -rw-r--r-- | addons/payment/models/account_payment.py | 4 | ||||
| -rw-r--r-- | addons/payment/models/payment_acquirer.py | 40 |
2 files changed, 27 insertions, 17 deletions
diff --git a/addons/payment/models/account_payment.py b/addons/payment/models/account_payment.py index 5c398c8f634..e324b033ce8 100644 --- a/addons/payment/models/account_payment.py +++ b/addons/payment/models/account_payment.py @@ -88,7 +88,7 @@ class AccountPayment(models.Model): self.mapped('payment_transaction_id').filtered(lambda x: x.state == 'done' and not x.is_processed)._post_process_after_done() return res - def post(self): + def action_post(self): # Post the payments "normally" if no transactions are needed. # If not, let the acquirer updates the state. # __________ ______________ @@ -109,7 +109,7 @@ class AccountPayment(models.Model): payments_need_trans = self.filtered(lambda pay: pay.payment_token_id and not pay.payment_transaction_id) transactions = payments_need_trans._create_payment_transaction() - res = super(AccountPayment, self - payments_need_trans).post() + res = super(AccountPayment, self - payments_need_trans).action_post() transactions.s2s_do_transaction() diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index f09951061f4..704b53c7c65 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -639,22 +639,42 @@ class PaymentTransaction(models.Model): for trans in self: trans.invoice_ids_nbr = len(trans.invoice_ids) - def _prepare_account_payment_vals(self): + def _create_payment(self, add_payment_vals={}): + ''' Create an account.payment record for the current payment.transaction. + If the transaction is linked to some invoices, the reconciliation will be done automatically. + :param add_payment_vals: Optional additional values to be passed to the account.payment.create method. + :return: An account.payment record. + ''' self.ensure_one() - return { + + payment_vals = { 'amount': self.amount, 'payment_type': 'inbound' if self.amount > 0 else 'outbound', 'currency_id': self.currency_id.id, 'partner_id': self.partner_id.id, 'partner_type': 'customer', - 'invoice_ids': [(6, 0, self.invoice_ids.ids)], 'journal_id': self.acquirer_id.journal_id.id, 'company_id': self.acquirer_id.company_id.id, 'payment_method_id': self.env.ref('payment.account_payment_method_electronic_in').id, 'payment_token_id': self.payment_token_id and self.payment_token_id.id or None, 'payment_transaction_id': self.id, - 'communication': self.reference, + 'ref': self.reference, + **add_payment_vals, } + payment = self.env['account.payment'].create(payment_vals) + payment.action_post() + + # Track the payment to make a one2one. + self.payment_id = payment + + if self.invoice_ids: + self.invoice_ids.filtered(lambda move: move.state == 'draft').post() + + (payment.line_ids + self.invoice_ids.line_ids)\ + .filtered(lambda line: line.account_id == payment.destination_account_id and not line.reconciled)\ + .reconcile() + + return payment def get_last_transaction(self): transactions = self.filtered(lambda t: t.state != 'draft') @@ -791,21 +811,11 @@ class PaymentTransaction(models.Model): invoices.post() # Create & Post the payments. - payments = defaultdict(lambda: self.env['account.payment']) for trans in self: if trans.payment_id: - payments[trans.acquirer_id.company_id.id] += trans.payment_id continue - payment_vals = trans._prepare_account_payment_vals() - payment = self.env['account.payment'].create(payment_vals) - payments[trans.acquirer_id.company_id.id] += payment - - # Track the payment to make a one2one. - trans.payment_id = payment - - for company in payments: - payments[company].with_company(company).with_context(company_id=company).post() + trans._create_payment() def _set_transaction_cancel(self): '''Move the transaction's payment to the cancel state(e.g. Paypal).''' |
