Fix #10359 cloning of proposal

This commit is contained in:
Laurent Destailleur 2019-01-19 13:17:07 +01:00
parent 2bbaae88d6
commit 55c90b0578
2 changed files with 39 additions and 33 deletions

View File

@ -1225,26 +1225,27 @@ class Propal extends CommonObject
$error=0; $error=0;
$now=dol_now(); $now=dol_now();
dol_syslog(__METHOD__, LOG_DEBUG);
$object = new self($this->db);
$this->db->begin(); $this->db->begin();
// get extrafields so they will be clone // Load source object
foreach($this->lines as $line) $object->fetch($this->id);
$line->fetch_optionals(); $object->fetch_lines();
// Load dest object
$clonedObj = clone $this;
$objsoc=new Societe($this->db); $objsoc=new Societe($this->db);
// Change socid if needed // Change socid if needed
if (! empty($socid) && $socid != $clonedObj->socid) if (! empty($socid) && $socid != $object->socid)
{ {
if ($objsoc->fetch($socid) > 0) if ($objsoc->fetch($socid) > 0)
{ {
$clonedObj->socid = $objsoc->id; $object->socid = $objsoc->id;
$clonedObj->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); $object->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
$clonedObj->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); $object->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
$clonedObj->fk_delivery_address = ''; $object->fk_delivery_address = '';
/*if (!empty($conf->projet->enabled)) /*if (!empty($conf->projet->enabled))
{ {
@ -1256,45 +1257,51 @@ class Propal extends CommonObject
$clonedObj->fk_project = ''; $clonedObj->fk_project = '';
} }
}*/ }*/
$clonedObj->fk_project = ''; // A cloned proposal is set by default to no project. $object->fk_project = ''; // A cloned proposal is set by default to no project.
} }
// reset ref_client // reset ref_client
$clonedObj->ref_client = ''; $object->ref_client = '';
// TODO Change product price if multi-prices // TODO Change product price if multi-prices
} }
else else
{ {
$objsoc->fetch($clonedObj->socid); $objsoc->fetch($object->socid);
} }
$clonedObj->id=0; $object->id=0;
$clonedObj->ref=''; $object->ref='';
$clonedObj->statut=self::STATUS_DRAFT; $object->statut=self::STATUS_DRAFT;
// Clear fields // Clear fields
$clonedObj->user_author = $user->id; $object->user_author = $user->id;
$clonedObj->user_valid = ''; $object->user_valid = '';
$clonedObj->date = $now; $object->date = $now;
$clonedObj->datep = $now; // deprecated $object->datep = $now; // deprecated
$clonedObj->fin_validite = $clonedObj->date + ($clonedObj->duree_validite * 24 * 3600); $object->fin_validite = $object->date + ($object->duree_validite * 24 * 3600);
if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) $clonedObj->ref_client = ''; if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) $object->ref_client = '';
// Create clone // Create clone
$this->context['createfromclone']='createfromclone'; $object->context['createfromclone']='createfromclone';
$result=$clonedObj->create($user); $result=$object->create($user);
if ($result < 0) $error++; if ($result < 0) $error++;
else
if (! $error)
{ {
// copy internal contacts // copy internal contacts
if ($clonedObj->copy_linked_contact($this, 'internal') < 0) if ($object->copy_linked_contact($this, 'internal') < 0)
{
$error++; $error++;
}
}
if (! $error)
{
// copy external contacts if same company // copy external contacts if same company
elseif ($this->socid == $clonedObj->socid) if ($this->socid == $object->socid)
{ {
if ($clonedObj->copy_linked_contact($this, 'external') < 0) if ($object->copy_linked_contact($this, 'external') < 0)
$error++; $error++;
} }
} }
@ -1311,13 +1318,13 @@ class Propal extends CommonObject
} }
} }
unset($this->context['createfromclone']); unset($object->context['createfromclone']);
// End // End
if (! $error) if (! $error)
{ {
$this->db->commit(); $this->db->commit();
return $clonedObj->id; return $object->id;
} }
else else
{ {

View File

@ -593,7 +593,6 @@ class Website extends CommonObject
{ {
// Delete old file // Delete old file
$filetplold=$pathofwebsitenew.'/page'.$pageid.'.tpl.php'; $filetplold=$pathofwebsitenew.'/page'.$pageid.'.tpl.php';
dol_syslog("We regenerate alias page new name=".$filealias.", old name=".$fileoldalias);
dol_delete_file($filetplold); dol_delete_file($filetplold);
// Create new file // Create new file
@ -633,7 +632,7 @@ class Website extends CommonObject
if (! $res > 0) if (! $res > 0)
{ {
$error++; $error++;
setEventMessages($objectpage->error, $objectpage->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
if (! $error) if (! $error)