Skip to content

Commit

Permalink
made sure unique invoices are being generated with correct dates (#230)
Browse files Browse the repository at this point in the history
* made sure unique invoices are being generated with correct dates

* Update contract_group.py

updateing

---------

Co-authored-by: dcruz <[email protected]>
  • Loading branch information
2 people authored and ecino committed Aug 27, 2024
1 parent 2ba0b44 commit 8de05ba
Showing 1 changed file with 23 additions and 3 deletions.
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

0 comments on commit 8de05ba

Please sign in to comment.