Skip to content

Commit

Permalink
Merge PR #430 into 17.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Feb 20, 2025
2 parents 43feb68 + 834e7ad commit 861130f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 31 deletions.
60 changes: 30 additions & 30 deletions account_credit_control/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ Control Lines* menu.

On each generated line, you have many choices:

- Send a email
- Print a letter
- Change the state (so you can ignore or reopen lines)
- Mark a line as Manually Overridden. The line will get the ignored
state when a second credit control run is done.
- Mark one line as Manual followup will also mark all the lines of the
partner. The partner will be visible in "Do Manual Follow-ups".
- Send a email
- Print a letter
- Change the state (so you can ignore or reopen lines)
- Mark a line as Manually Overridden. The line will get the ignored
state when a second credit control run is done.
- Mark one line as Manual followup will also mark all the lines of the
partner. The partner will be visible in "Do Manual Follow-ups".

Once your lines are properly set up, go back to the "run" and click on
*Run channel action* to massively generate and queue communication
Expand Down Expand Up @@ -105,29 +105,29 @@ Authors
Contributors
------------

- Nicolas Bessi (Camptocamp)
- Guewen Baconnier (Camptocamp)
- Sylvain Van Hoof (Okia SPRL) <[email protected]>
- Akim Juillerat (Camptocamp) <[email protected]>
- Kinner Vachhani (Access Bookings Ltd) <[email protected]>
- Raf Ven <[email protected]>
- Quentin Groulard (ACSONE) <[email protected]>
- `Tecnativa <https://www.tecnativa.com>`__:

- Vicent Cubells
- Manuel Calero
- Ernesto Tejeda
- Pedro M. Baeza
- Jairo Llopis
- João Marques
- César A. Sánchez
- Víctor Martínez

- Enric Tobella <[email protected]>
- Naglis Jonaitis (Versada UAB) <[email protected]>
- `360ERP <https://www.360erp.com>`__:

- Andrea Stirpe
- Nicolas Bessi (Camptocamp)
- Guewen Baconnier (Camptocamp)
- Sylvain Van Hoof (Okia SPRL) <[email protected]>
- Akim Juillerat (Camptocamp) <[email protected]>
- Kinner Vachhani (Access Bookings Ltd) <[email protected]>
- Raf Ven <[email protected]>
- Quentin Groulard (ACSONE) <[email protected]>
- `Tecnativa <https://www.tecnativa.com>`__:

- Vicent Cubells
- Manuel Calero
- Ernesto Tejeda
- Pedro M. Baeza
- Jairo Llopis
- João Marques
- César A. Sánchez
- Víctor Martínez

- Enric Tobella <[email protected]>
- Naglis Jonaitis (Versada UAB) <[email protected]>
- `360ERP <https://www.360erp.com>`__:

- Andrea Stirpe

Maintainers
-----------
Expand Down
31 changes: 30 additions & 1 deletion account_credit_control/models/credit_control_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# Copyright 2020 Manuel Calero - Tecnativa
# Copyright 2023 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
import threading

from odoo import _, api, fields, models, modules, registry, tools
from odoo.tools.misc import format_amount, format_date


Expand Down Expand Up @@ -225,12 +227,39 @@ def _generate_emails(self):
comm.credit_control_line_ids.filtered(
lambda line: line.state == "to_be_sent"
).write({"state": "queued"})
comm._send_mails()

def _send_mails(self):
# Launch process in new thread to improve the user speedup
if not tools.config["test_enable"] and not modules.module.current_test:

@self.env.cr.postcommit.add
def _launch_print_thread():
threaded_calculation = threading.Thread(
target=self.send_mails_threaded,
args=self.ids,
)
threaded_calculation.start()
else:
self._send_communications_by_email()

def send_mails_threaded(self, record_ids):
with registry(self._cr.dbname).cursor() as cr:
self = self.with_env(self.env(cr=cr))
communications = self.browse(record_ids)
communications._send_communications_by_email()

def _send_communications_by_email(self):
for comm in self:
comm.message_mail_with_source(
comm.policy_level_id.email_template_id,
subtype_id=self.env["ir.model.data"]._xmlid_to_res_id(
"account_credit_control.mt_request"
),
)
comm.credit_control_line_ids.filtered(
lambda line: line.state == "queued"
).state = "sent"

def _mark_credit_line_as_sent(self):
lines = self.mapped("credit_control_line_ids")
Expand Down
10 changes: 10 additions & 0 deletions account_credit_control/models/credit_control_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ def run_channel_action(self):
comm_obj = self.env["credit.control.communication"]
comms = comm_obj._generate_comm_from_credit_lines(email_lines)
comms._generate_emails()
# Notify user that the emails will be sent in background
self.env["bus.bus"]._sendone(
self.env.user.partner_id,
"simple_notification",
{
"type": "info",
"title": _("Notifications"),
"message": _("The emails will be sent in the background"),
},
)
if letter_lines:
wiz = self.env["credit.control.printer"].create(
{"line_ids": letter_lines.ids}
Expand Down
1 change: 1 addition & 0 deletions account_credit_control/tests/test_credit_control_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def test_sent_email_invoice_detail(self):
self.assertIn(self.invoice.name, new_communication.message_ids.body)
# CASE 2: set the policy level to show invoice details = False
control_lines.policy_level_id.mail_show_invoice_detail = False
control_lines.state = "to_be_sent"
marker = self.env["credit.control.marker"].create(
{"name": "to_be_sent", "line_ids": [(6, 0, control_lines.ids)]}
)
Expand Down

0 comments on commit 861130f

Please sign in to comment.