From 4c558ee98c0ff129ab27f9f4421d89e9c6e20cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Tue, 12 Jul 2022 13:03:47 +0200 Subject: [PATCH] l10n_fr_chorus_account: use _get_commitment_number to be able to retrieve the right commitment number --- l10n_fr_chorus_account/models/account_move.py | 23 ++++++++++++------- l10n_fr_chorus_facturx/models/account_move.py | 15 ++++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/l10n_fr_chorus_account/models/account_move.py b/l10n_fr_chorus_account/models/account_move.py index 0086e670e..e739072da 100644 --- a/l10n_fr_chorus_account/models/account_move.py +++ b/l10n_fr_chorus_account/models/account_move.py @@ -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 @@ -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( @@ -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( _( @@ -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( _( @@ -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 " @@ -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 %s checked via Chorus Pro API.") - % self.ref + % commitment_number ) return res diff --git a/l10n_fr_chorus_facturx/models/account_move.py b/l10n_fr_chorus_facturx/models/account_move.py index 39d031c0b..57f28d461 100644 --- a/l10n_fr_chorus_facturx/models/account_move.py +++ b/l10n_fr_chorus_facturx/models/account_move.py @@ -2,12 +2,27 @@ # @author: Alexis de Lattre # 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: