Skip to content

Commit

Permalink
[FIX] Set recurring next date before generating the invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
tarteo committed Sep 11, 2024
1 parent 7445aab commit 5dfe6ef
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions sale_recurring_payment_mollie/models/sale_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,23 @@ def update_sale_subscription_payments(self, date_ref):
payment_transaction_obj = self.env["payment.transaction"]
mollie_client = mollie._api_mollie_get_client()
mollie_customer_id = self.partner_id.mollie_customer_id
if mollie_customer_id:
customer = mollie_client.customers.get(mollie_customer_id)
mandate = customer.mandates.get(self.payment_provider_mandate_id.reference)
if mandate:
invoices = self.invoice_ids.filtered(
lambda i: i.invoice_date == date_ref
)
unpaid_invoice = self.env["account.move"]
if not invoices:
if date_ref == self.recurring_next_date:
self.generate_invoice()
unpaid_invoice = self.invoice_ids.filtered(
lambda i: i.invoice_date == date_ref
and i.payment_state == "not_paid"
)
else:
unpaid_invoice = invoices.filtered(
lambda i: i.payment_state == "not_paid"
)
if unpaid_invoice:
payment_transaction_obj._process_payment_provider_recurring_payment(
self, unpaid_invoice
)
if not mollie_customer_id:
return False
customer = mollie_client.customers.get(mollie_customer_id)
mandate = customer.mandates.get(self.payment_provider_mandate_id.reference)
if not mandate:
return False
invoices = self.invoice_ids.filtered(lambda i: i.invoice_date == date_ref)
if not invoices and date_ref == self.recurring_next_date:
self.generate_invoice()
unpaid_invoice = self.invoice_ids.filtered(
lambda i: i.invoice_date == date_ref and i.payment_state == "not_paid"
)
if not unpaid_invoice:
return False
payment_transaction_obj._process_payment_provider_recurring_payment(
self, unpaid_invoice
)
return True

@api.model
Expand Down

0 comments on commit 5dfe6ef

Please sign in to comment.