Skip to content

Commit

Permalink
l10n_fr_chorus_account: extract check method
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienbeau committed Sep 29, 2024
1 parent fc647e6 commit 18a83ac
Showing 1 changed file with 72 additions and 68 deletions.
140 changes: 72 additions & 68 deletions l10n_fr_chorus_account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,91 +168,95 @@ def _check_chorus_attachments(self):

def action_post(self):
"""Check validity of Chorus invoices"""
for inv in self.filtered(
lambda x: x.move_type in ("out_invoice", "out_refund")
and x.transmit_method_code == "fr-chorus"
for inv in self:
if (
inv.move_type in ("out_invoice", "out_refund")
and inv.transmit_method_code == "fr-chorus"
):
inv._chorus_check_validity()

Check warning on line 176 in l10n_fr_chorus_account/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_account/models/account_move.py#L176

Added line #L176 was not covered by tests
return super().action_post()

def _chorus_check_validity(self):
commitment_number = self._get_commitment_number()
company_partner = self.company_id.partner_id

Check warning on line 181 in l10n_fr_chorus_account/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_account/models/account_move.py#L180-L181

Added lines #L180 - L181 were not covered by tests
if not company_partner.siren or not company_partner.nic:
raise UserError(

Check warning on line 183 in l10n_fr_chorus_account/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_account/models/account_move.py#L183

Added line #L183 was not covered by tests
_("Missing SIRET on partner '%s' linked to company '%s'.")
% (company_partner.display_name, self.company_id.display_name)
)
cpartner = self.commercial_partner_id

Check warning on line 187 in l10n_fr_chorus_account/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_account/models/account_move.py#L187

Added line #L187 was not covered by tests
if not cpartner.siren or not cpartner.nic:
raise UserError(

Check warning on line 189 in l10n_fr_chorus_account/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_account/models/account_move.py#L189

Added line #L189 was not covered by tests
_(
"Missing SIRET on partner '%s'. "
"This information is required for Chorus invoices."
)
% cpartner.display_name
)
if (
cpartner.fr_chorus_required in ("service", "service_and_engagement")
and not self.partner_id.chorus_service_ok()
):
commitment_number = self._get_commitment_number()
company_partner = inv.company_id.partner_id
if not company_partner.siren or not company_partner.nic:
raise UserError(
_("Missing SIRET on partner '%s' linked to company '%s'.")
% (company_partner.display_name, inv.company_id.display_name)
raise UserError(

Check warning on line 200 in l10n_fr_chorus_account/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_account/models/account_move.py#L200

Added line #L200 was not covered by tests
_(
"Partner '%s' is configured as Service required for "
"Chorus, so you must select a contact as customer "
"for the invoice and this contact should have a name "
"and a Chorus service and the Chorus service must "
"be active."
)
cpartner = inv.commercial_partner_id
if not cpartner.siren or not cpartner.nic:
% cpartner.display_name
)
if cpartner.fr_chorus_required in ("engagement", "service_and_engagement"):
if commitment_number:
self.chorus_invoice_check_commitment_number(commitment_number)

Check warning on line 212 in l10n_fr_chorus_account/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_account/models/account_move.py#L212

Added line #L212 was not covered by tests
else:
raise UserError(
_(
"Missing SIRET on partner '%s'. "
"This information is required for Chorus invoices."
"Partner '%s' is configured as Engagement required for "
"Chorus, so the field 'Reference' of its invoices must "
"contain an engagement number."
)
% cpartner.display_name
)
if (
cpartner.fr_chorus_required in ("service", "service_and_engagement")
and not inv.partner_id.chorus_service_ok()
):
elif (
self.partner_id.fr_chorus_service_id
and self.partner_id.fr_chorus_service_id.engagement_required
):
if commitment_number:
self.chorus_invoice_check_commitment_number(commitment_number)

Check warning on line 227 in l10n_fr_chorus_account/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_account/models/account_move.py#L227

Added line #L227 was not covered by tests
else:
raise UserError(
_(
"Partner '%s' is configured as Service required for "
"Chorus, so you must select a contact as customer "
"for the invoice and this contact should have a name "
"and a Chorus service and the Chorus service must "
"be active."
"Partner '%s' is linked to Chorus service '%s' "
"which is marked as 'Engagement required', so the "
"field 'Reference' of its invoices must "
"contain an engagement number."
)
% (
self.partner_id.display_name,
self.partner_id.fr_chorus_service_id.code,
)
% cpartner.display_name
)
if cpartner.fr_chorus_required in ("engagement", "service_and_engagement"):
if commitment_number:
inv.chorus_invoice_check_commitment_number(commitment_number)
else:

if cpartner.fr_chorus_required == "service_or_engagement":
if not self.partner_id.chorus_service_ok():
if not commitment_number:
raise UserError(
_(
"Partner '%s' is configured as Engagement required for "
"Chorus, so the field 'Reference' of its invoices must "
"contain an engagement number."
"Partner '%s' is configured as "
"'Service or Engagement' required for Chorus but "
"there is no engagement number in the field "
"'Reference' and the customer of the "
"invoice is not correctly configured as a service "
"(should be a contact with a Chorus service "
"and a name)."
)
% cpartner.display_name
)
elif (
inv.partner_id.fr_chorus_service_id
and inv.partner_id.fr_chorus_service_id.engagement_required
):
if commitment_number:
inv.chorus_invoice_check_commitment_number(commitment_number)
else:
raise UserError(
_(
"Partner '%s' is linked to Chorus service '%s' "
"which is marked as 'Engagement required', so the "
"field 'Reference' of its invoices must "
"contain an engagement number."
)
% (
inv.partner_id.display_name,
inv.partner_id.fr_chorus_service_id.code,
)
)

if cpartner.fr_chorus_required == "service_or_engagement":
if not inv.partner_id.chorus_service_ok():
if not commitment_number:
raise UserError(
_(
"Partner '%s' is configured as "
"'Service or Engagement' required for Chorus but "
"there is no engagement number in the field "
"'Reference' and the customer of the "
"invoice is not correctly configured as a service "
"(should be a contact with a Chorus service "
"and a name)."
)
% cpartner.display_name
)
else:
inv.chorus_invoice_check_commitment_number()
inv._chorus_check_payment_data()
return super().action_post()
self.chorus_invoice_check_commitment_number()
self._chorus_check_payment_data()

Check warning on line 259 in l10n_fr_chorus_account/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_account/models/account_move.py#L258-L259

Added lines #L258 - L259 were not covered by tests

def _chorus_check_payment_data(self):
self.ensure_one()
Expand Down

0 comments on commit 18a83ac

Please sign in to comment.