Skip to content

Commit

Permalink
Merge PR #570 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by alexis-via
  • Loading branch information
OCA-git-bot committed Sep 29, 2024
2 parents b50587e + 4c558ee commit 9258126
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
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 @@ class AccountMove(models.Model):
states={"draft": [("readonly", False)]},
)

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

@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 @@ def action_post(self):
lambda x: x.move_type in ("out_invoice", "out_refund")
and x.transmit_method_code == "fr-chorus"
):
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(
Expand Down Expand Up @@ -192,8 +197,8 @@ def action_post(self):
% 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)
else:
raise UserError(
_(
Expand All @@ -207,8 +212,8 @@ def action_post(self):
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)
else:
raise UserError(
_(
Expand All @@ -225,7 +230,7 @@ def action_post(self):

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 @@ def chorus_update_invoice_status(self):
)
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()
if self.transmit_method_code == "fr-chorus":
buyer_order_ref = etree.SubElement(
trade_agreement, ns["ram"] + "BuyerOrderReferencedDocument"
)
buyer_order_id = etree.SubElement(
buyer_order_ref, ns["ram"] + "IssuerAssignedID"
)
buyer_order_id.text = self._get_commitment_number()
else:
return super()._cii_add_buyer_order_reference(trade_agreement, ns)

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

0 comments on commit 9258126

Please sign in to comment.