summaryrefslogtreecommitdiff
path: root/addons/payment
diff options
context:
space:
mode:
Diffstat (limited to 'addons/payment')
-rw-r--r--addons/payment/models/account_payment.py4
-rw-r--r--addons/payment/models/payment_acquirer.py40
-rw-r--r--addons/payment/wizards/payment_link_wizard.py2
3 files changed, 28 insertions, 18 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).'''
diff --git a/addons/payment/wizards/payment_link_wizard.py b/addons/payment/wizards/payment_link_wizard.py
index fb6e02b9cf5..7dd543d997b 100644
--- a/addons/payment/wizards/payment_link_wizard.py
+++ b/addons/payment/wizards/payment_link_wizard.py
@@ -24,7 +24,7 @@ class PaymentLinkWizard(models.TransientModel):
if res_id and res_model == 'account.move':
record = self.env[res_model].browse(res_id)
res.update({
- 'description': record.invoice_payment_ref,
+ 'description': record.payment_reference,
'amount': record[amount_field],
'currency_id': record.currency_id.id,
'partner_id': record.partner_id.id,