Set product quantity to custom value

Hi,

while adding a product to an invoice, iam trying to override the given quantity value by an external value.

My problem is: iam not sure where i have to do this.
My attempt was to do it in the “LINEBILL_INSERT” trigger event, but when i try to override $object->qty the change will be ignored.
Checking facture.class.php it turns out, that the returned result from the trigger is just a statuscode.
Hope someone can give me a hint, maybe i totally overlooked something.
Thanks alot in advance!

I was able to solve my problem, but of course there is a new one.
After changing the qty of a product inside a bill i would like to recalculate the total prices - is there a way to trigger it without calculating these values on my own?

Hi LuHe,

To change the values for the totals, use the following to calculate it. In order to refresh the page though, you would need to add a hook.

$object->qty * $object->subprice - ($object->qty * $object->subprice * ($object->remise_percent / 100))

I haven’t tried it, but if you have any problems give me a shout.

Matt

Hi LuHe,
Nope, it should be done automatically if your trigger is working. The update_price() is run on the parent invoice after the line->insert().
Check in the addline function of the Facture class what’s the outcome of the line->insert() with and without your trigger activated.
Regards,
Marc

Hi,

Here is the code I use to update a Qty, and then update the BILL :

$object->qty = price2num($new_qty,'MU');

//Update the line total
$tabprice = calcul_price_total($object->qty, $object->subprice, $object->remise_percent, $object->tva_tx, $object->localtax1_tx, $object->localtax2_tx, 0, 'HT', 0, $object->product_type);
$object->total_ht = $tabprice[0];
$object->total_tva = $tabprice[1];
$object->total_ttc = $tabprice[2];
$object->total_localtax1 = $tabprice[9];
$object->total_localtax2 = $tabprice[10];
		
// Then update the object, without re-launching the trigger
$result=$object->update($user, 1);

//Then update the bill
if($result > 0) {
	$main_object->update_price();
}

Thanks alot for your response! Iam glad that there is a way to do it like this.

Unfortunetly your code results for me in a blank page.
Where do i get $main_object from?

I changed the trigger to “BILLREC_MODIFY” cause my changes should trigger after editing a custom field for a invoice template, but i guess that shouldnt change any behavior, right?

Is there a place where i can find something like that in the documentation? In my oppinion handling something like this is quite important.
Thank you very very much!

Blank page = php error => Check the php logs

Sorry I miss that part

			$main_object=new Facture($this->db);
			$main_object->fetch($object->fk_facture);

You also need that at the beghining

//Need to add pricelib
require_once (DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php');

I don’t know.
Personally I use :

if ($action == 'LINEBILL_INSERT' || $action == 'LINEBILL_UPDATE')

No, it is too specific, I don’t think that a documentation exist on that.