Fix: wrong fk_parent_line in credit note with invoiceAvoirWithLines

option
This commit is contained in:
Regis Houssin 2016-03-11 15:42:14 +01:00
parent 5292920a84
commit f87bb1206e

View File

@ -755,10 +755,17 @@ if (empty($reshook))
$facture_source = new Facture($db); // fetch origin object $facture_source = new Facture($db); // fetch origin object
if ($facture_source->fetch($object->fk_facture_source)>0) if ($facture_source->fetch($object->fk_facture_source)>0)
{ {
$fk_parent_line = 0;
foreach($facture_source->lines as $line) foreach($facture_source->lines as $line)
{ {
// Reset fk_parent_line for no child products and special product
if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
$fk_parent_line = 0;
}
$line->fk_facture = $object->id; $line->fk_facture = $object->id;
$line->fk_parent_line = $fk_parent_line;
$line->subprice =-$line->subprice; // invert price for object $line->subprice =-$line->subprice; // invert price for object
$line->pa_ht = -$line->pa_ht; $line->pa_ht = -$line->pa_ht;
@ -768,9 +775,14 @@ if (empty($reshook))
$line->total_localtax1=-$line->total_localtax1; $line->total_localtax1=-$line->total_localtax1;
$line->total_localtax2=-$line->total_localtax2; $line->total_localtax2=-$line->total_localtax2;
$line->insert(); $result = $line->insert();
$object->lines[] = $line; // insert new line in current object $object->lines[] = $line; // insert new line in current object
// Defined the new fk_parent_line
if ($result > 0 && $line->product_type == 9) {
$fk_parent_line = $result;
}
} }
$object->update_price(1); $object->update_price(1);