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

l10n_fr_chorus_account: use _get_commitment_number to be able to retrieve the right commitment number #570

Merged
merged 1 commit into from
Sep 29, 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
23 changes: 15 additions & 8 deletions l10n_fr_chorus_account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
states={"draft": [("readonly", False)]},
)

def _get_commitment_number(self):
self.ensure_one()
return self.ref

Check warning on line 88 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#L87-L88

Added lines #L87 - L88 were not covered by tests

@api.constrains("chorus_attachment_ids", "transmit_method_id")
def _check_chorus_attachments(self):
# https://communaute.chorus-pro.gouv.fr/pieces-jointes-dans-chorus-pro-quelques-regles-a-respecter/ # noqa: B950
Expand Down Expand Up @@ -162,6 +166,7 @@
lambda x: x.move_type in ("out_invoice", "out_refund")
and x.transmit_method_code == "fr-chorus"
):
commitment_number = self._get_commitment_number()

Check warning on line 169 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#L169

Added line #L169 was not covered by tests
company_partner = inv.company_id.partner_id
if not company_partner.siren or not company_partner.nic:
raise UserError(
Expand Down Expand Up @@ -192,8 +197,8 @@
% cpartner.display_name
)
if cpartner.fr_chorus_required in ("engagement", "service_and_engagement"):
if inv.ref:
inv.chorus_invoice_check_commitment_number()
if commitment_number:
inv.chorus_invoice_check_commitment_number(commitment_number)

Check warning on line 201 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#L201

Added line #L201 was not covered by tests
else:
raise UserError(
_(
Expand All @@ -207,8 +212,8 @@
inv.partner_id.fr_chorus_service_id
and inv.partner_id.fr_chorus_service_id.engagement_required
):
if inv.ref:
inv.chorus_invoice_check_commitment_number()
if commitment_number:
inv.chorus_invoice_check_commitment_number(commitment_number)

Check warning on line 216 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#L216

Added line #L216 was not covered by tests
else:
raise UserError(
_(
Expand All @@ -225,7 +230,7 @@

if cpartner.fr_chorus_required == "service_or_engagement":
if not inv.partner_id.chorus_service_ok():
if not inv.ref:
if not commitment_number:
raise UserError(
_(
"Partner '%s' is configured as "
Expand Down Expand Up @@ -400,15 +405,17 @@
)
logger.info("End of the update of chorus invoice status")

def chorus_invoice_check_commitment_number(self, raise_if_not_found=True):
def chorus_invoice_check_commitment_number(
self, commitment_number, raise_if_not_found=True
):
self.ensure_one()
res = self.chorus_check_commitment_number(
self.company_id, self.ref, raise_if_not_found=raise_if_not_found
self.company_id, commitment_number, raise_if_not_found=raise_if_not_found
)
if res is True:
self.message_post(
body=_("Engagement juridique <b>%s</b> checked via Chorus Pro API.")
% self.ref
% commitment_number
)
return res

Expand Down
15 changes: 15 additions & 0 deletions l10n_fr_chorus_facturx/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from lxml import etree

from odoo import api, models


class AccountMove(models.Model):
_inherit = "account.move"

def _cii_add_buyer_order_reference(self, trade_agreement, ns):
self.ensure_one()

Check warning on line 14 in l10n_fr_chorus_facturx/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_facturx/models/account_move.py#L14

Added line #L14 was not covered by tests
if self.transmit_method_code == "fr-chorus":
buyer_order_ref = etree.SubElement(

Check warning on line 16 in l10n_fr_chorus_facturx/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_facturx/models/account_move.py#L16

Added line #L16 was not covered by tests
trade_agreement, ns["ram"] + "BuyerOrderReferencedDocument"
)
buyer_order_id = etree.SubElement(

Check warning on line 19 in l10n_fr_chorus_facturx/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_facturx/models/account_move.py#L19

Added line #L19 was not covered by tests
buyer_order_ref, ns["ram"] + "IssuerAssignedID"
)
buyer_order_id.text = self._get_commitment_number()

Check warning on line 22 in l10n_fr_chorus_facturx/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_facturx/models/account_move.py#L22

Added line #L22 was not covered by tests
else:
return super()._cii_add_buyer_order_reference(trade_agreement, ns)

Check warning on line 24 in l10n_fr_chorus_facturx/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_facturx/models/account_move.py#L24

Added line #L24 was not covered by tests

@api.model
def _cii_trade_contact_department_name(self, partner):
if partner.fr_chorus_service_id:
Expand Down
Loading