Dolibarr / dolibarr

Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). it's an open source Web application (written in PHP) designed for businesses of any sizes, foundations and freelancers.
https://www.dolibarr.org
GNU General Public License v3.0
5.42k stars 2.78k forks source link

Notifications are generated before the triggering process is completed #25738

Open jacotec opened 1 year ago

jacotec commented 1 year ago

Bug

The "processing hook" of the module seems to be too early:

As a conclusion: The notification should be processed after all the things which had triggered the notification are completely processed. Or the notification should be in general delayed by a few seconds, so it can be assured that all the needed processes are completed before the notification is generated.

Environment Version

18.0.0

Environment OS

Ubuntu 22.04

Environment Web server

NGINX

Environment PHP

8.1

Environment Database

MariaDB 11

Environment URL(s)

No response

Expected and actual behavior

See above. The notification should be generated after all underlying processes which are triggering the notification are completed, so that it can be assured that all variables, links and attached files are already up-to-date.

Maybe a solution is to add a delay of a few seconds before the notification task is triggered, so that it can be assured that all underlying variables and documents are processed and up-to-date before generating the notification.

Steps to reproduce the behavior

Follow the procedure in the description and i.e. validate an invoice which sends a notification to the customer.

The reference is still the previois "PROV" number, the file is not attached (as the invoice is not yet finally generated when the notification is triggered).

Attached files

No response

narkin commented 12 months ago

I can confirm that this is still happening in 18.0.2

JonBendtsen commented 11 months ago

This issue just bite me when it comes to stripe payments because the automatic notification sends this url:

/dolibarr/public/payment/newpayment.php?source=order&ref=%28PROV301%29&securekey=...

where as if I send the email manually then the url are:

/dolibarr/public/payment/newpayment.php?source=order&ref=SO2311-0065&securekey=...

I wish this bug would be prioritized higher, as it seems to affect more than just one place, this issue is most likely related https://github.com/Dolibarr/dolibarr/issues/26396

broken_payment correct_payment

JonBendtsen commented 11 months ago

Notifications are generated before the triggering process is completed #25738

This is still an issue in 18.0.3 tuxgasy docker image

JonBendtsen commented 9 months ago

also related to #23682

priojk commented 9 months ago

The problem seems to be that the trigger, as it is currently designed, has a different purpose: By using it, a validation of an invoice can be prevented to happen. Therefore, the trigger is by design called, before the validation is completed.

What we need in many cases is a second trigger: one that confirms that a validation has been successfully completed in order to do something with the result (e.g. send validated invoice).

JonBendtsen commented 9 months ago

The problem seems to be that the trigger, as it is currently designed, has a different purpose: By using it, a validation of an invoice can be prevented to happen. Therefore, the trigger is by design called, before the validation is completed.

What we need in many cases is a second trigger: one that confirms that a validation has been successfully completed in order to do something with the result (e.g. send validated invoice).

thanks for explaining. It sounds like it would take a while before it would be solved.

Would it be possible to circumvent this by simply using a cronjob that would look for any "object" in the correct state and then send out the email? But what would prevent this cronjob from sending out the email again 5 minutes later?

priojk commented 9 months ago

As a quick fix you could create an extrafield as a flag, which gets checked and set, when the object is sent, to prevent double sending.

JonBendtsen commented 9 months ago

As a quick fix you could create an extrafield as a flag, which gets checked and set, when the object is sent, to prevent double sending.

True that could perhaps work. I would need 3 fields to as there are 3 I'd like to send email for, Proposal validated, Order Validated and Invoice Paid. Perhaps I could use bit vectors like 1, 2, 4, 8, ...

Then I either need to send email outside Dolibarr or wait for an API call to send emails :-/

JonBendtsen commented 7 months ago

What we need in many cases is a second trigger: one that confirms that a validation has been successfully completed in order to do something with the result (e.g. send validated invoice).

Is that the only possibility?

What if when the trigger happened a line was inserted into some database table stating that an (email) notification should be sent.

Then later, possibly using a cronjob the notification system could check that database table for such lines, actually send out notifications and then remove the line from the database table preventing it from being sent again.

RAF0846 commented 3 weeks ago

Hello, First at all, sorry for my english! I have the same issue with automatic email notification on 20.0.1 version. The PDF order confirmation sent to customer is not the validated one. It is the draft one.