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

T1657 - Fix invoice generation for Sub Proposal (3/3) #1947

Merged
merged 9 commits into from
Aug 22, 2024
2 changes: 1 addition & 1 deletion crm_request/models/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def message_update(self, msg_dict, update_vals=None):
in_leave.write({"stage_id": stage_new, "user_id": False})
return result

@api.returns('mail.message', lambda value: value.id)
@api.returns("mail.message", lambda value: value.id)
def message_post(self, **kwargs):
"""Change the stage to "Resolve" when the employee answer
to the supporter but not if it's an automatic answer.
Expand Down
4 changes: 2 additions & 2 deletions interaction_resume/models/crm_request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import models, api
from odoo import api, models
from odoo.tools.mail import html2plaintext


Expand Down Expand Up @@ -51,7 +51,7 @@ def _get_interaction_partner_domain(self, partner):
("email_from", "=", partner.email),
]

@api.returns('mail.message', lambda value: value.id)
@api.returns("mail.message", lambda value: value.id)
def message_post(self, **kwargs):
res = super().message_post(**kwargs)
self.partner_id.with_delay().fetch_interactions()
Expand Down
39 changes: 37 additions & 2 deletions sponsorship_compassion/models/contract_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ def _compute_contains_sponsorship(self):
and s.state not in ("terminated", "cancelled")
)

def _generate_invoices(self, invoicer):
def _generate_invoices(self, invoicer, contract_id=None):
# Exclude gifts from regular generation
super(
ContractGroup, self.with_context(open_invoices_sponsorship_only=True)
)._generate_invoices(invoicer)
)._generate_invoices(invoicer, contract_id)
# We don't generate gift if the contract isn't active
contracts = self.mapped("contract_ids").filtered(lambda c: c.state == "active")
contracts._generate_gifts(invoicer, BIRTHDAY_GIFT)
Expand Down Expand Up @@ -70,3 +70,38 @@ def _get_partner_for_contract(self, contract):
if not contract.send_gifts_to
else contract[contract.send_gifts_to]
)

def _should_skip_invoice_generation(self, invoicing_date, contract=None):
self.ensure_one()

if contract is None:
return super()._should_skip_invoice_generation(invoicing_date)

search_filter = [
("state", "!=", "cancel"),
("invoice_date_due", "=", invoicing_date),
("partner_id", "=", self.partner_id.id),
("move_type", "=", "out_invoice"),
("line_ids.contract_id", "=", contract.id),
(
"line_ids.product_id",
"in",
contract.product_ids.ids,
),
]

existing_invoices = self.env["account.move"].search_count(search_filter)

is_sub_proposal = contract.parent_id.child_id and not contract.invoice_line_ids

# If invoices come from sub proposal, ignore group suspension to also generate
# already paid invoices
if is_sub_proposal:
return bool(existing_invoices)
else:
is_suspended = (
self.invoice_suspended_until
and self.invoice_suspended_until > invoicing_date
)
return bool(existing_invoices) or is_suspended

5 changes: 4 additions & 1 deletion sponsorship_compassion/wizards/generate_gift_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,8 @@ def _build_invoice_gen_data(self, invoicing_date, invoicer):
if not invoicer:
invoicer = self.env["recurring.invoicer"].create({})
return self.contract_id.group_id._build_invoice_gen_data(
invoicing_date=invoicing_date, invoicer=invoicer, gift_wizard=self
invoicing_date=invoicing_date,
invoicer=invoicer,
contracts=self.contract_id,
gift_wizard=self,
)
Loading