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

14.0 chorus improve #571

Open
wants to merge 6 commits into
base: 14.0
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions l10n_fr_chorus_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"data/transmit_method.xml",
"data/cron.xml",
"data/mail_template.xml",
"data/mail_activity_data.xml",
"wizard/account_invoice_chorus_send_view.xml",
"views/account_journal_dashboard_view.xml",
"views/chorus_flow.xml",
"views/chorus_partner_service.xml",
"views/partner.xml",
Expand Down
11 changes: 11 additions & 0 deletions l10n_fr_chorus_account/data/mail_activity_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

<record id="mail_activity_type_chorus_error" model="mail.activity.type">
<field name="name">Traité l'erreur de transmission Chorus</field>
<field name="icon">fa-exclamation-triangle</field>
<field name="sequence">3</field>
<field name="res_model_id" ref="account.model_account_move" />
</record>

</odoo>
1 change: 1 addition & 0 deletions l10n_fr_chorus_account/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from . import company
from . import config_settings
from . import account_move
from . import account_journal
45 changes: 45 additions & 0 deletions l10n_fr_chorus_account/models/account_journal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2024 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).


from odoo import models
from odoo.tools.misc import formatLang


class AccountJournal(models.Model):
_inherit = "account.journal"

def get_journal_dashboard_datas(self):
number_chorus_error = sum_chorus_error = 0
res = super().get_journal_dashboard_datas()

Check warning on line 15 in l10n_fr_chorus_account/models/account_journal.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_account/models/account_journal.py#L14-L15

Added lines #L14 - L15 were not covered by tests
if self.type == "sale":
data = self.env["account.move"].read_group(

Check warning on line 17 in l10n_fr_chorus_account/models/account_journal.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_account/models/account_journal.py#L17

Added line #L17 was not covered by tests
[
("journal_id", "=", self.id),
(
"activity_type_id",
"=",
self.env.ref(
"l10n_fr_chorus_account.mail_activity_type_chorus_error"
).id,
),
],
["amount_total_signed"],
["journal_id"],
)
if data:
number_chorus_error = data[0]["journal_id_count"]
currency = self.currency_id or self.company_id.currency_id
sum_chorus_error = formatLang(

Check warning on line 34 in l10n_fr_chorus_account/models/account_journal.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_account/models/account_journal.py#L32-L34

Added lines #L32 - L34 were not covered by tests
self.env,
currency.round(data[0]["amount_total_signed"]),
currency_obj=currency,
)
res.update(

Check warning on line 39 in l10n_fr_chorus_account/models/account_journal.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_account/models/account_journal.py#L39

Added line #L39 was not covered by tests
{
"number_chorus_error": number_chorus_error,
"sum_chorus_error": sum_chorus_error,
}
)
return res

Check warning on line 45 in l10n_fr_chorus_account/models/account_journal.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_chorus_account/models/account_journal.py#L45

Added line #L45 was not covered by tests
168 changes: 100 additions & 68 deletions l10n_fr_chorus_account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
readonly=True,
states={"draft": [("readonly", False)]},
)
# Transmit method is set to readonly to avoid by passing chorus check by changing
# the transmission method after validating the invoice
transmit_method_id = fields.Many2one(
states={"draft": [("readonly", False)]},
readonly=True,
)

def _get_commitment_number(self):
self.ensure_one()
Expand Down Expand Up @@ -162,91 +168,102 @@

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 not cpartner.fr_chorus_required:
raise UserError(

Check warning on line 197 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#L197

Added line #L197 was not covered by tests
_(
"The field 'Info Required for Chorus' on the partner is empty "
"please fill as it's required for chorus"
)
)
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 207 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#L207

Added line #L207 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 219 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#L219

Added line #L219 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 234 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#L234

Added line #L234 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(commitment_number)
self._chorus_check_payment_data()

Check warning on line 266 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#L265-L266

Added lines #L265 - L266 were not covered by tests

def _chorus_check_payment_data(self):
self.ensure_one()
Expand Down Expand Up @@ -493,3 +510,18 @@
)
logger.warning("Commitment number %s not found in Chorus Pro.", order_ref)
return False

def _chorus_set_as_rejected(self, error):
self.ensure_one()
self.chorus_flow_id = None
self.activity_schedule(

Check warning on line 517 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#L515-L517

Added lines #L515 - L517 were not covered by tests
"l10n_fr_chorus_account.mail_activity_type_chorus_error",
note=_(
"This invoice has been <b>rejected by Chorus Pro</b> "
"for the following reason:<br/><i>%s</i><br/>"
"You should fix the error and send this invoice to "
"Chorus Pro again."
)
% error,
user_id=self.create_uid.id,
)
Loading
Loading