Merge pull request #10922 from altatof/cloneorder
clone of order like in propal (ref_client, contacts)
This commit is contained in:
commit
31963be6a0
@ -1075,7 +1075,7 @@ class Commande extends CommonOrder
|
|||||||
*/
|
*/
|
||||||
public function createFromClone($socid = 0)
|
public function createFromClone($socid = 0)
|
||||||
{
|
{
|
||||||
global $user,$hookmanager;
|
global $conf, $user,$hookmanager;
|
||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
@ -1085,69 +1085,88 @@ class Commande extends CommonOrder
|
|||||||
foreach($this->lines as $line)
|
foreach($this->lines as $line)
|
||||||
$line->fetch_optionals();
|
$line->fetch_optionals();
|
||||||
|
|
||||||
// Load source object
|
// Load source object
|
||||||
$objFrom = clone $this;
|
$objFrom = clone $this;
|
||||||
|
|
||||||
// Change socid if needed
|
// Change socid if needed
|
||||||
if (! empty($socid) && $socid != $this->socid)
|
if (! empty($socid) && $socid != $this->socid)
|
||||||
|
{
|
||||||
|
$objsoc = new Societe($this->db);
|
||||||
|
|
||||||
|
if ($objsoc->fetch($socid)>0)
|
||||||
{
|
{
|
||||||
$objsoc = new Societe($this->db);
|
$this->socid = $objsoc->id;
|
||||||
|
$this->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
|
||||||
if ($objsoc->fetch($socid)>0)
|
$this->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
|
||||||
{
|
$this->fk_project = 0;
|
||||||
$this->socid = $objsoc->id;
|
$this->fk_delivery_address = 0;
|
||||||
$this->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
|
|
||||||
$this->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
|
|
||||||
$this->fk_project = 0;
|
|
||||||
$this->fk_delivery_address = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Change product price if multi-prices
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->id=0;
|
// TODO Change product price if multi-prices
|
||||||
$this->ref = '';
|
}
|
||||||
$this->statut=self::STATUS_DRAFT;
|
|
||||||
|
|
||||||
// Clear fields
|
$this->id=0;
|
||||||
$this->user_author_id = $user->id;
|
$this->ref = '';
|
||||||
$this->user_valid = '';
|
$this->statut=self::STATUS_DRAFT;
|
||||||
$this->date = dol_now();
|
|
||||||
$this->date_commande = dol_now();
|
|
||||||
$this->date_creation = '';
|
|
||||||
$this->date_validation = '';
|
|
||||||
$this->ref_client = '';
|
|
||||||
|
|
||||||
// Create clone
|
// Clear fields
|
||||||
$this->context['createfromclone'] = 'createfromclone';
|
$this->user_author_id = $user->id;
|
||||||
$result=$this->create($user);
|
$this->user_valid = '';
|
||||||
if ($result < 0) $error++;
|
$this->date = dol_now();
|
||||||
|
$this->date_commande = dol_now();
|
||||||
|
$this->date_creation = '';
|
||||||
|
$this->date_validation = '';
|
||||||
|
if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) $this->ref_client = '';
|
||||||
|
|
||||||
if (! $error)
|
// Create clone
|
||||||
|
$this->context['createfromclone'] = 'createfromclone';
|
||||||
|
$result=$this->create($user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
// copy internal contacts
|
||||||
|
if ($this->copy_linked_contact($objFrom, 'internal') < 0)
|
||||||
{
|
{
|
||||||
// Hook of thirdparty module
|
$error++;
|
||||||
if (is_object($hookmanager))
|
|
||||||
{
|
|
||||||
$parameters=array('objFrom'=>$objFrom);
|
|
||||||
$action='';
|
|
||||||
$reshook=$hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
||||||
if ($reshook < 0) $error++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unset($this->context['createfromclone']);
|
if (! $error)
|
||||||
|
{
|
||||||
|
// copy external contacts if same company
|
||||||
|
if ($this->socid == $objFrom->socid)
|
||||||
|
{
|
||||||
|
if ($this->copy_linked_contact($objFrom, 'external') < 0)
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// End
|
if (! $error)
|
||||||
if (! $error)
|
{
|
||||||
|
// Hook of thirdparty module
|
||||||
|
if (is_object($hookmanager))
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
$parameters=array('objFrom'=>$objFrom);
|
||||||
return $this->id;
|
$action='';
|
||||||
}
|
$reshook=$hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
||||||
else
|
if ($reshook < 0) $error++;
|
||||||
{
|
|
||||||
$this->db->rollback();
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($this->context['createfromclone']);
|
||||||
|
|
||||||
|
// End
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->db->commit();
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user