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

T1985 : Correct missing analytic lines in new sponsorships #247

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 14 additions & 4 deletions recurring_contract/models/contract_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ def _should_skip_invoice_generation(self, invoicing_date, contract=None):
),
]

has_all_invoices = bool(self.env["account.move"].search_count(search_filter))
has_all_invoices = bool(
self.env["account.move"].search_count(search_filter)
)
else:
search_filter = [
("invoice_date_due", "=", invoicing_date),
Expand All @@ -354,13 +356,18 @@ def _should_skip_invoice_generation(self, invoicing_date, contract=None):
"in",
self.active_contract_ids.mapped("product_ids").ids,
),
('state', '!=', 'cancel')
("state", "!=", "cancel"),
]

open_invoices = self.env["account.move"].search(search_filter)

has_all_invoices = len(self.active_contract_ids -
open_invoices.mapped("line_ids.contract_id")) == 0
has_all_invoices = (
len(
self.active_contract_ids
- open_invoices.mapped("line_ids.contract_id")
)
== 0
)

is_suspended = (
self.invoice_suspended_until
Expand Down Expand Up @@ -437,6 +444,9 @@ def _process_invoice_generation(self, invoicer, invoicing_date, contract=None):
"payment_mode_id": self.payment_mode_id.id,
}
)
open_invoice.mapped("invoice_line_ids").filtered(
lambda line: line.contract_id in contract_lines_to_inv.contract_id
).create_analytic_lines()
Comment on lines +447 to +449
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not this directly?

Suggested change
open_invoice.mapped("invoice_line_ids").filtered(
lambda line: line.contract_id in contract_lines_to_inv.contract_id
).create_analytic_lines()
contract_lines_to_inv.create_analytic_lines()

else:
# Building invoices data
contracts = self.active_contract_ids
Expand Down
10 changes: 6 additions & 4 deletions recurring_contract/models/recurring_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,12 @@ def _cancel_invoices(self):
)
if remaining_lines:
# We can move or remove the line
invoice.write({
"invoice_line_ids": [(2, inv_line.id)],
"payment_mode_id": invoice.payment_mode_id.id,
})
invoice.write(
{
"invoice_line_ids": [(2, inv_line.id)],
"payment_mode_id": invoice.payment_mode_id.id,
}
)
else:
# The invoice would be empty if we remove the line
empty_invoices |= invoice
Expand Down
Loading