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

Custom Trigger Not updating totals in 20.0.1 #31224

Open
whp-jeffm opened this issue Oct 2, 2024 · 2 comments
Open

Custom Trigger Not updating totals in 20.0.1 #31224

whp-jeffm opened this issue Oct 2, 2024 · 2 comments
Labels
Bug This is a bug (something does not work as expected)

Comments

@whp-jeffm
Copy link

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 whp-jeffm added the Bug This is a bug (something does not work as expected) label Oct 2, 2024
@whp-jeffm
Copy link
Author

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

@whp-jeffm
Copy link
Author

Seems like this issue persists in 20.0.1 as well.

@whp-jeffm whp-jeffm changed the title Custom Trigger Not updating totals in 20.0.0 Custom Trigger Not updating totals in 20.0.1 Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is a bug (something does not work as expected)
Projects
None yet
Development

No branches or pull requests

1 participant