Skip to content

Commit

Permalink
[ADD] #688 use donation product&account for donation widget payment
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Sep 3, 2024
1 parent 9c96508 commit e81e809
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions bankayma_account/models/payment_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,36 @@ def _finalize_post_processing(self):
return super(
PaymentTransaction, self.with_company(self.provider_id.company_id)
)._finalize_post_processing()

def _create_payment(self, **extra_create_values):
payment_method_line = None
if self.is_donation and self.company_id.donation_account_id:
# poison the cache to have super create move line with configured account
payment_method_line = (
self.provider_id.journal_id.inbound_payment_method_line_ids.filtered(
lambda x, self=self: x.code == self.provider_id.code
)
)
payment_method_line._cache[
"payment_account_id"
] = self.company_id.donation_account_id.id
# pass donation product as default
result = super(
PaymentTransaction,
self.with_context(
default_product_id=self.company_id.donation_credit_transfer_product_id.id
),
)._create_payment(**extra_create_values)
if payment_method_line:
payment_method_line.invalidate_recordset(["payment_account_id"])
return result

def _to_sumit_vals(self):
result = super()._to_sumit_vals()
if self.is_donation and len(result.get("Items", [])) == 1:
result["Items"][0]["Item"]["Name"] = (
self.company_id.donation_credit_transfer_product_id.display_name
or self.company_id.donation_account_id.name
or result["Items"][0]["Item"]["Name"]
)
return result

0 comments on commit e81e809

Please sign in to comment.