New: add possibility to linked other objects from external modules

This commit is contained in:
Regis Houssin
2012-02-22 01:16:24 +08:00
parent 34fd843767
commit ea83e474dc
5 changed files with 77 additions and 46 deletions

View File

@@ -86,6 +86,7 @@ class Commande extends CommonObject
var $origin; var $origin;
var $origin_id; var $origin_id;
var $linked_objects=array();
var $user_author_id; var $user_author_id;
@@ -706,37 +707,44 @@ class Commande extends CommonObject
if ($this->id) if ($this->id)
{ {
$this->ref="(PROV".$this->id.")"; $this->ref="(PROV".$this->id.")";
// Add linked object // Add object linked
if ($this->origin && $this->origin_id) if (is_array($this->linked_objects) && ! empty($this->linked_objects))
{ {
$ret = $this->add_object_linked(); foreach($this->linked_objects as $origin => $origin_id)
if (! $ret) dol_print_error($this->db); {
} $ret = $this->add_object_linked($origin, $origin_id);
if (! $ret)
// TODO mutualiser {
if ($this->origin == 'propal' && $this->origin_id) dol_print_error($this->db);
{ $error++;
// On recupere les differents contact interne et externe }
$prop = new Propal($this->db, $this->socid, $this->origin_id);
// TODO mutualiser
// On recupere le commercial suivi propale if ($origin == 'propal' && $origin_id)
$this->userid = $prop->getIdcontact('internal', 'SALESREPFOLL'); {
// On recupere les differents contact interne et externe
if ($this->userid) $prop = new Propal($this->db, $this->socid, $origin_id);
{
//On passe le commercial suivi propale en commercial suivi commande // On recupere le commercial suivi propale
$this->add_contact($this->userid[0], 'SALESREPFOLL', 'internal'); $this->userid = $prop->getIdcontact('internal', 'SALESREPFOLL');
}
if ($this->userid)
// On recupere le contact client suivi propale {
$this->contactid = $prop->getIdcontact('external', 'CUSTOMER'); //On passe le commercial suivi propale en commercial suivi commande
$this->add_contact($this->userid[0], 'SALESREPFOLL', 'internal');
if ($this->contactid) }
{
//On passe le contact client suivi propale en contact client suivi commande // On recupere le contact client suivi propale
$this->add_contact($this->contactid[0], 'CUSTOMER', 'external'); $this->contactid = $prop->getIdcontact('external', 'CUSTOMER');
}
if ($this->contactid)
{
//On passe le contact client suivi propale en contact client suivi commande
$this->add_contact($this->contactid[0], 'CUSTOMER', 'external');
}
}
}
} }
} }

View File

@@ -2,7 +2,7 @@
/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com> * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com> * Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
@@ -229,6 +229,13 @@ if ($action == 'add' && $user->rights->commande->creer)
$object->origin = $_POST['origin']; $object->origin = $_POST['origin'];
$object->origin_id = $_POST['originid']; $object->origin_id = $_POST['originid'];
// Possibility to add external linked objects with hooks
$object->linked_objects[$object->origin] = $object->origin_id;
if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects']))
{
$object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
}
$object_id = $object->create($user); $object_id = $object->create($user);
@@ -1368,7 +1375,7 @@ if ($action == 'create' && $user->rights->commande->creer)
} }
// Other attributes // Other attributes
$parameters=array('colspan' => ' colspan="3"'); $parameters=array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label)) if (empty($reshook) && ! empty($extrafields->attribute_label))
{ {

View File

@@ -3,7 +3,7 @@
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com> * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr> * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
@@ -742,6 +742,13 @@ if ($action == 'add' && $user->rights->facture->creer)
$object->origin = $_POST['origin']; $object->origin = $_POST['origin'];
$object->origin_id = $_POST['originid']; $object->origin_id = $_POST['originid'];
// Possibility to add external linked objects with hooks
$object->linked_objects[$object->origin] = $object->origin_id;
if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects']))
{
$object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
}
$id = $object->create($user); $id = $object->create($user);
@@ -1802,7 +1809,7 @@ if ($action == 'create')
} }
// Other attributes // Other attributes
$parameters=array('colspan' => ' colspan="3"'); $parameters=array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label)) if (empty($reshook) && ! empty($extrafields->attribute_label))
{ {

View File

@@ -90,6 +90,7 @@ class Facture extends CommonObject
var $fk_facture_source; var $fk_facture_source;
var $origin; var $origin;
var $origin_id; var $origin_id;
var $linked_objects=array();
var $fk_project; var $fk_project;
var $date_lim_reglement; var $date_lim_reglement;
var $cond_reglement_id; // Id in llx_c_paiement var $cond_reglement_id; // Id in llx_c_paiement
@@ -242,14 +243,17 @@ class Facture extends CommonObject
if (! $resql) $error++; if (! $resql) $error++;
// Add object linked // Add object linked
if (! $error && $this->id && $this->origin && $this->origin_id) if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects))
{ {
$ret = $this->add_object_linked(); foreach($this->linked_objects as $origin => $origin_id)
if (! $ret) {
{ $ret = $this->add_object_linked($origin, $origin_id);
dol_print_error($this->db); if (! $ret)
$error++; {
} dol_print_error($this->db);
$error++;
}
}
} }
/* /*

View File

@@ -1458,12 +1458,17 @@ abstract class CommonObject
} }
/** /**
* Add objects linked in llx_element_element. * Add objects linked in llx_element_element.
* *
* @return int <=0 if KO, >0 if OK * @param string $origin Linked element type
* @param int $origin_id Linked element id
* @return int <=0 if KO, >0 if OK
*/ */
function add_object_linked() function add_object_linked($origin=null, $origin_id=null)
{ {
$origin = (! empty($origin) ? $origin : $this->origin);
$origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id);
$this->db->begin(); $this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
@@ -1472,8 +1477,8 @@ abstract class CommonObject
$sql.= ", fk_target"; $sql.= ", fk_target";
$sql.= ", targettype"; $sql.= ", targettype";
$sql.= ") VALUES ("; $sql.= ") VALUES (";
$sql.= $this->origin_id; $sql.= $origin_id;
$sql.= ", '".$this->origin."'"; $sql.= ", '".$origin."'";
$sql.= ", ".$this->id; $sql.= ", ".$this->id;
$sql.= ", '".$this->element."'"; $sql.= ", '".$this->element."'";
$sql.= ")"; $sql.= ")";