[FIX] contract_payment_auto: transaction create must always get a token (#167)

When a contrat had no payment token but the corresponding partner had
one, the transaction was created without an acquirer, leading to an
integrity error in postgres.

This change makes sure the token used to test the ability to pay an
invoice is passed along to the transaction creation call.

Tests were also added to check the ability to use the contract token if
present, but the partner's in the opposite case.

This change fixes #165.
This commit is contained in:
fcayre
2018-05-28 17:46:32 +02:00
committed by Pedro M. Baeza
parent 9bf323fccf
commit caec4cf6f8
3 changed files with 35 additions and 7 deletions

View File

@@ -91,7 +91,7 @@ class AccountAnalyticAccount(models.Model):
return
transaction = self.env['payment.transaction'].create(
self._get_tx_vals(invoice),
self._get_tx_vals(invoice, token),
)
valid_states = ['authorized', 'done']
@@ -136,10 +136,9 @@ class AccountAnalyticAccount(models.Model):
return
@api.multi
def _get_tx_vals(self, invoice):
def _get_tx_vals(self, invoice, token):
""" Return values for create of payment.transaction for invoice."""
amount_due = invoice.residual
token = self.payment_token_id
partner = token.partner_id
reference = self.env['payment.transaction'].get_next_reference(
invoice.number,