Fix: problem to clone proposals with fk_parent_line

This commit is contained in:
Regis Houssin 2011-04-09 20:06:25 +00:00
parent ec426648be
commit caff474114

View File

@ -407,7 +407,7 @@ class Propal extends CommonObject
if ($result > 0) if ($result > 0)
{ {
$this->db->commit(); $this->db->commit();
return 1; return $this->line->rowid;
} }
else else
{ {
@ -675,9 +675,17 @@ class Propal extends CommonObject
*/ */
if (! $error) if (! $error)
{ {
for ($i = 0 ; $i < sizeof($this->lines) ; $i++) $fk_parent_line=0;
$num=sizeof($this->lines);
for ($i=0;$i<$num;$i++)
{ {
$resql = $this->addline( // Reset fk_parent_line for no child products and special product
if (($this->lines[$i]->product_type != 9 && empty($this->lines[$i]->fk_parent_line)) || $this->lines[$i]->product_type == 9) {
$fk_parent_line = 0;
}
$result = $this->addline(
$this->id, $this->id,
$this->lines[$i]->desc, $this->lines[$i]->desc,
$this->lines[$i]->subprice, $this->lines[$i]->subprice,
@ -692,16 +700,21 @@ class Propal extends CommonObject
0, 0,
$this->lines[$i]->product_type, $this->lines[$i]->product_type,
$this->lines[$i]->rang, $this->lines[$i]->rang,
$this->lines[$i]->special_code $this->lines[$i]->special_code,
$fk_parent_line
); );
if ($resql < 0) if ($result < 0)
{ {
$error++; $error++;
$this->error=$this->db->error; $this->error=$this->db->error;
dol_print_error($this->db); dol_print_error($this->db);
break; break;
} }
// Defined the new fk_parent_line
if ($result > 0 && $this->lines[$i]->product_type == 9) {
$fk_parent_line = $result;
}
} }
} }
@ -839,20 +852,18 @@ class Propal extends CommonObject
} }
// Clear fields // Clear fields
$object->user_author = $user->id; $object->user_author = $user->id;
$object->user_valid = ''; $object->user_valid = '';
$object->date = ''; $object->date = '';
$object->datep = $now; $object->datep = $now;
$object->fin_validite = $object->datep + ($this->duree_validite * 24 * 3600); $object->fin_validite = $object->datep + ($this->duree_validite * 24 * 3600);
$object->ref_client = ''; $object->ref_client = '';
// Set ref
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/".$conf->global->PROPALE_ADDON.".php"); require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/".$conf->global->PROPALE_ADDON.".php");
$obj = $conf->global->PROPALE_ADDON; $obj = $conf->global->PROPALE_ADDON;
$modPropale = new $obj; $modPropale = new $obj;
$numpr = $modPropale->getNextValue($objsoc,$object); $object->ref = $modPropale->getNextValue($objsoc,$object);
// Set ref
$object->ref = $numpr;
// Create clone // Create clone
$result=$object->create($user); $result=$object->create($user);