Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made sure unique invoices are being generated with correct dates #230

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions recurring_contract/models/contract_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,35 @@ def _generate_invoices(self, invoicer):
_logger.info(
f"Starting generation of invoices for contract groups : {self.ids}"
)

# Set to track processed invoices to avoid duplication
processed_invoices = set()

for group in self:
# Calculate the initial invoicing date and starting offset
invoicing_date, starting_offset = group._calculate_start_date_and_offset()

# Iterate through invoice offsets to generate invoices
for invoice_offset in range(
starting_offset, group.advance_billing_months + 1, group.month_interval
):
invoicing_date += relativedelta(months=invoice_offset)
if group._should_skip_invoice_generation(invoicing_date):
# Calculate the current invoicing date for this offset
current_invoicing_date = invoicing_date + relativedelta(months=invoice_offset)

# Check if invoice generation should be skipped for this date
if group._should_skip_invoice_generation(current_invoicing_date):
continue
group._process_invoice_generation(invoicer, invoicing_date)

# Create a unique key for the invoice to track it
invoice_key = (group.id, current_invoicing_date)

# Check if the invoice for this key has already been processed
if invoice_key not in processed_invoices:
# Process invoice generation if not already processed
group._process_invoice_generation(invoicer, current_invoicing_date)
# Add the invoice key to the set of processed invoices
processed_invoices.add(invoice_key)

# Refresh state to check whether invoices are missing in some contracts
self.mapped("active_contract_ids")._compute_missing_invoices()
_logger.info("Process successfully generated invoices")
Expand Down
Loading