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.37k stars 2.77k forks source link

Custom Trigger Not updating totals in 20.0.1 #31224

Open whp-jeffm opened 2 weeks ago

whp-jeffm commented 2 weeks ago

Bug

I have a custom trigger that worked fine in 19.0.3, but for some reason in 20.0.0 it will only update the total_ht field. The other 4 total fields remain unchanged in the database following the object->update($user, 1) command. Any suggestions as to what changed in 20.0.0 that would have made this happen?

Dolibarr Version

20.0.0

Environment PHP

8.2.23

Environment Database

mysql (8.0.39-0ubuntu0.24.04.2)

Steps to reproduce the behavior and expected behavior

The Issue

In my custom module trigger file, I am trying to update the total price for an invoice and proposal line item. In 19.0.3 my code worked which enabled me to calculate an extra quantity field and update the line totals accordingly.

For an unknown reason (I cannot find anything in the change logs referencing this), only the total_ht field updates while, total_tva, total_localtax1, total_localtax2, and total_ttc remain unchanged after running an object->update with the updated amounts in the object.

CODE

The Trigger

case 'LINEBILL_MODIFY': $main_object=new Facture($this->db); $main_object->fetch($object->fk_facture); if ($main_object->array_options['options_isrental']) { $this->adjust_rental($action, $object, $main_object, $user, $langs, $conf); }; break;

The custom function:

`public function adjust_rental($action, $line_object, $main_object, User $user, Translate $langs, Conf $conf) {

    $rental_length = $line_object->array_options['options_rentallength'];
    $updated_qty = $line_object->qty * $rental_length;
    $tabprice = calcul_price_total($updated_qty, $line_object->subprice, $line_object->remise_percent, $line_object->tva_tx, $line_object->localtax1_tx, 0, 0, 'HT', 0, $line_object->product_type);
    $line_object->total_ht = $tabprice[0];
    $line_object->total_tva = $tabprice[1];
    $line_object->total_ttc = $tabprice[2];
    $line_object->total_localtax1 = $tabprice[9];
    $line_object->total_localtax2 = $tabprice[10];
    $line_object->skip_update_total = 0;
    $result=$line_object->update($user, 1);
    dol_syslog("Trigger '".$this->name."' for action '".$action."' launched by ".__FILE__.". id=".$line_object->id);

}`

For additional context, rental_length is an extra_field that serves as an additional quantity field that we use for rental events. For example, we want to rent 4 boxes for 4 days, the updated_qty should be 16. I need to update the rest of the total fields in

Attached files

The custom fields on the invoice card: image

The tooltip shows the correct amount in v. 19.0.3 after updating the fields as expected image

The tooltip shows the incorrect amount in v. 20.0.0 after updating the fields image

whp-jeffm commented 1 week ago

Does anyone have an idea why this might be happening or where I can look for a fix?

whp-jeffm commented 1 week ago

Seems like this issue persists in 20.0.1 as well.