diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php
index 8442a640fc0..e7083e767a2 100644
--- a/htdocs/bom/class/bom.class.php
+++ b/htdocs/bom/class/bom.class.php
@@ -41,6 +41,12 @@ class BOM extends CommonObject
*/
public $table_element = 'bom_bom';
+ /**
+ * @var string Name of subtable if this object has sub lines
+ */
+ public $table_element_line = 'bom_bomline';
+ public $fk_element = 'fk_bom';
+
/**
* @var int Does bom support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
*/
@@ -57,9 +63,6 @@ class BOM extends CommonObject
public $picto = 'bom';
- public $table_element_line = 'bom_bomline';
-
-
const STATUS_DRAFT = 0;
const STATUS_VALIDATED = 1;
const STATUS_CANCELED = 9;
@@ -222,7 +225,13 @@ class BOM extends CommonObject
$this->db->begin();
// Load source object
- $object->fetchCommon($fromid);
+ $result = $object->fetchCommon($fromid);
+ if ($result > 0 && ! empty($object->table_element_line)) $object->fetchLines();
+
+ // Get lines so they will be clone
+ //foreach($object->lines as $line)
+ // $line->fetch_optionals();
+
// Reset some properties
unset($object->id);
unset($object->fk_user_creat);
@@ -231,7 +240,7 @@ class BOM extends CommonObject
// Clear fields
$object->ref = "copy_of_".$object->ref;
$object->title = $langs->trans("CopyOf")." ".$object->title;
- // ...
+
// Clear extrafields that are unique
if (is_array($object->array_options) && count($object->array_options) > 0)
{
@@ -256,6 +265,29 @@ class BOM extends CommonObject
$this->errors = $object->errors;
}
+ if (! $error)
+ {
+ // copy internal contacts
+ if ($this->copy_linked_contact($object, 'internal') < 0)
+ {
+ $error++;
+ }
+ }
+
+ if (! $error)
+ {
+ // copy external contacts if same company
+ if (property_exists($this, 'socid') && $this->socid == $object->socid)
+ {
+ if ($this->copy_linked_contact($object, 'external') < 0)
+ $error++;
+ }
+ }
+
+ // If there is lines, create lines too
+
+
+
unset($object->context['createfromclone']);
// End
@@ -854,7 +886,7 @@ class BOM extends CommonObject
$this->lines=array();
$objectline = new BOMLine($this->db);
- $result = $objectline->fetchAll('', '', 0, 0, array('customsql'=>'fk_bom = '.$this->id));
+ $result = $objectline->fetchAll('ASC', 'rank', 0, 0, array('customsql'=>'fk_bom = '.$this->id));
if (is_numeric($result))
{
@@ -1071,71 +1103,6 @@ class BOMLine extends CommonObject
return $this->createCommon($user, $notrigger);
}
- /**
- * Clone an object into another one
- *
- * @param User $user User that creates
- * @param int $fromid Id of object to clone
- * @return mixed New object created, <0 if KO
- */
- public function createFromClone(User $user, $fromid)
- {
- global $langs, $hookmanager, $extrafields;
- $error = 0;
-
- dol_syslog(__METHOD__, LOG_DEBUG);
-
- $object = new self($this->db);
-
- $this->db->begin();
-
- // Load source object
- $object->fetchCommon($fromid);
- // Reset some properties
- unset($object->id);
- unset($object->fk_user_creat);
- unset($object->import_key);
-
- // Clear fields
- $object->ref = "copy_of_".$object->ref;
- $object->title = $langs->trans("CopyOf")." ".$object->title;
- // ...
- // Clear extrafields that are unique
- if (is_array($object->array_options) && count($object->array_options) > 0)
- {
- $extrafields->fetch_name_optionals_label($this->element);
- foreach($object->array_options as $key => $option)
- {
- $shortkey = preg_replace('/options_/', '', $key);
- if (! empty($extrafields->attributes[$this->element]['unique'][$shortkey]))
- {
- //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
- unset($object->array_options[$key]);
- }
- }
- }
-
- // Create clone
- $object->context['createfromclone'] = 'createfromclone';
- $result = $object->createCommon($user);
- if ($result < 0) {
- $error++;
- $this->error = $object->error;
- $this->errors = $object->errors;
- }
-
- unset($object->context['createfromclone']);
-
- // End
- if (!$error) {
- $this->db->commit();
- return $object;
- } else {
- $this->db->rollback();
- return -1;
- }
- }
-
/**
* Load object in memory from the database
*
diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php
index d3fb1f7607b..6df0362d1c4 100644
--- a/htdocs/bom/tpl/objectline_view.tpl.php
+++ b/htdocs/bom/tpl/objectline_view.tpl.php
@@ -57,7 +57,7 @@ $domData .= ' data-qty="'.$line->qty.'"';
$domData .= ' data-product_type="'.$line->product_type.'"';
// Lines for extrafield
-$objectline = new BOMLine($this->db);
+$objectline = new BOMLine($object->db);
?>
@@ -68,12 +68,9 @@ $objectline = new BOMLine($this->db);
textwithtooltip($text, $description, 3, '', '', $i, 0, (!empty($line->fk_parent_line)?img_picto('', 'rightarrow'):''));
- // Add description in form
- if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
- {
- print (! empty($line->description) && $line->description!=$line->product_label)?' '.dol_htmlentitiesbr($line->description):'';
- }
+ $tmpproduct = new Product($object->db);
+ $tmpproduct->fetch($line->fk_product);
+ print $tmpproduct->getNomUrl(1);
?>
|
diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php
index 40529413bbe..20e4d6a03ca 100644
--- a/htdocs/core/actions_addupdatedelete.inc.php
+++ b/htdocs/core/actions_addupdatedelete.inc.php
@@ -244,7 +244,6 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ! empty($permissiontoadd)
$objectutil = dol_clone($object, 1); // To avoid to denaturate loaded object when setting some properties for clone or if createFromClone modifies the object. We use native clone to keep this->db valid.
//$objectutil->date = dol_mktime(12, 0, 0, GETPOST('newdatemonth', 'int'), GETPOST('newdateday', 'int'), GETPOST('newdateyear', 'int'));
// ...
-
$result=$objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id));
if (is_object($result) || $result > 0)
{
diff --git a/htdocs/core/ajax/row.php b/htdocs/core/ajax/row.php
index 7270409a47a..2e2c8891b62 100644
--- a/htdocs/core/ajax/row.php
+++ b/htdocs/core/ajax/row.php
@@ -20,6 +20,11 @@
* \file htdocs/core/ajax/row.php
* \brief File to return Ajax response on Row move.
* This ajax page is called when doing an up or down drag and drop.
+ * Parameters:
+ * roworder (Example: '1,3,2,4'),
+ * table_element_line (Example: 'commandedet')
+ * fk_element (Example: 'fk_order')
+ * element_id (Example: 1)
*/
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disable token renewal
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 9852e2f2fb0..8754200117e 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -2443,8 +2443,9 @@ abstract class CommonObject
*/
public function updateRangOfLine($rowid, $rang)
{
- $fieldposition = 'rang';
+ $fieldposition = 'rang'; // @TODO Rename 'rang' and 'position' into 'rank'
if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
+ if (in_array($this->table_element_line, array('bom_bomline'))) $fieldposition = 'rank';
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang;
$sql.= ' WHERE rowid = '.$rowid;
@@ -7245,6 +7246,31 @@ abstract class CommonObject
if ($result < 0) $error++;
}
+ // Create lines
+ if (! empty($this->table_element_line) && ! empty($this->fk_element))
+ {
+ $num=(is_array($this->lines) ? count($this->lines) : 0);
+ for ($i = 0; $i < $num; $i++)
+ {
+ $line = $this->lines[$i];
+
+ $keyforparent = $this->fk_element;
+ $line->$keyforparent = $this->id;
+
+ // Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array
+ //if (! is_object($line)) $line=json_decode(json_encode($line), false); // convert recursively array into object.
+ if (! is_object($line)) $line = (object) $line;
+
+ $result = $line->create($user, 1);
+ if ($result < 0)
+ {
+ $this->error=$this->db->lasterror();
+ $this->db->rollback();
+ return -1;
+ }
+ }
+ }
+
// Triggers
if (! $error && ! $notrigger)
{
diff --git a/htdocs/install/mysql/migration/9.0.0-10.0.0.sql b/htdocs/install/mysql/migration/9.0.0-10.0.0.sql
index 81a1e315751..ac546b3249a 100644
--- a/htdocs/install/mysql/migration/9.0.0-10.0.0.sql
+++ b/htdocs/install/mysql/migration/9.0.0-10.0.0.sql
@@ -272,6 +272,10 @@ ALTER TABLE llx_bom_bomline ADD INDEX idx_bom_bomline_rowid (rowid);
ALTER TABLE llx_bom_bomline ADD INDEX idx_bom_bomline_fk_product (fk_product);
ALTER TABLE llx_bom_bomline ADD INDEX idx_bom_bomline_fk_bom (fk_bom);
+ALTER TABLE llx_bom_bom ADD UNIQUE INDEX uk_bom_bom_ref(ref, entity);
+ALTER TABLE llx_bom_bomline ADD CONSTRAINT llx_bom_bomline_fk_bom FOREIGN KEY (fk_bom) REFERENCES llx_bom_bom(rowid);
+
+
ALTER TABLE llx_product_fournisseur_price ADD COLUMN barcode varchar(180) DEFAULT NULL;
ALTER TABLE llx_product_fournisseur_price ADD COLUMN fk_barcode_type integer DEFAULT NULL;
ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_barcode (barcode);
diff --git a/htdocs/install/mysql/tables/llx_bom_bom.key.sql b/htdocs/install/mysql/tables/llx_bom_bom.key.sql
index 72631851e1b..aed37c7ce47 100644
--- a/htdocs/install/mysql/tables/llx_bom_bom.key.sql
+++ b/htdocs/install/mysql/tables/llx_bom_bom.key.sql
@@ -22,7 +22,7 @@ ALTER TABLE llx_bom_bom ADD INDEX idx_bom_bom_status (status);
ALTER TABLE llx_bom_bom ADD INDEX idx_bom_bom_fk_product (fk_product);
-- END MODULEBUILDER INDEXES
---ALTER TABLE llx_bom_bom ADD UNIQUE INDEX uk_bom_bom_fieldxy(fieldx, fieldy);
+ALTER TABLE llx_bom_bom ADD UNIQUE INDEX uk_bom_bom_ref(ref, entity);
--ALTER TABLE llx_bom_bom ADD CONSTRAINT llx_bom_bom_fk_field FOREIGN KEY (fk_field) REFERENCES llx_bom_myotherobject(rowid);
diff --git a/htdocs/install/mysql/tables/llx_bom_bomline.key.sql b/htdocs/install/mysql/tables/llx_bom_bomline.key.sql
index 89c65f78644..ee8eaaeeb6c 100644
--- a/htdocs/install/mysql/tables/llx_bom_bomline.key.sql
+++ b/htdocs/install/mysql/tables/llx_bom_bomline.key.sql
@@ -22,5 +22,5 @@ ALTER TABLE llx_bom_bomline ADD INDEX idx_bom_bomline_fk_bom (fk_bom);
--ALTER TABLE llx_bom_bomline ADD UNIQUE INDEX uk_bom_bomline_fieldxy(fieldx, fieldy);
---ALTER TABLE llx_bom_bomline ADD CONSTRAINT llx_bom_bomline_fk_field FOREIGN KEY (fk_field) REFERENCES llx_bom_myotherobject(rowid);
+ALTER TABLE llx_bom_bomline ADD CONSTRAINT llx_bom_bomline_fk_bom FOREIGN KEY (fk_bom) REFERENCES llx_bom_bom(rowid);
diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php
index a3e1f43b619..266b8d1925f 100644
--- a/htdocs/modulebuilder/template/class/myobject.class.php
+++ b/htdocs/modulebuilder/template/class/myobject.class.php
@@ -46,6 +46,7 @@ class MyObject extends CommonObject
* @var string Name of subtable if this object has sub lines
*/
//public $table_element_line = 'mymodule_myobjectline';
+ //public $fk_element = 'fk_myobject';
/**
* @var int Does myobject support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
@@ -267,12 +268,19 @@ class MyObject extends CommonObject
$this->db->begin();
// Load source object
- $object->fetchCommon($fromid);
+ $result = $object->fetchCommon($fromid);
+ if ($result > 0 && ! empty($object->table_element_line)) $object->fetchLines();
+
+ // get lines so they will be clone
+ //foreach($this->lines as $line)
+ // $line->fetch_optionals();
+
// Reset some properties
unset($object->id);
unset($object->fk_user_creat);
unset($object->import_key);
+
// Clear fields
$object->ref = "copy_of_".$object->ref;
$object->title = $langs->trans("CopyOf")." ".$object->title;
@@ -301,6 +309,25 @@ class MyObject extends CommonObject
$this->errors = $object->errors;
}
+ if (! $error)
+ {
+ // copy internal contacts
+ if ($this->copy_linked_contact($object, 'internal') < 0)
+ {
+ $error++;
+ }
+ }
+
+ if (! $error)
+ {
+ // copy external contacts if same company
+ if (property_exists($this, 'socid') && $this->socid == $object->socid)
+ {
+ if ($this->copy_linked_contact($object, 'external') < 0)
+ $error++;
+ }
+ }
+
unset($object->context['createfromclone']);
// End
@@ -671,7 +698,7 @@ class MyObject extends CommonObject
$this->lines=array();
$objectline = new MyObjectLine($this->db);
- $result = $objectline->fetchAll('', '', 0, 0, array('customsql'=>'fk_myobject = '.$this->id));
+ $result = $objectline->fetchAll('ASC', 'rank', 0, 0, array('customsql'=>'fk_myobject = '.$this->id));
if (is_numeric($result))
{
@@ -756,4 +783,5 @@ class MyObject extends CommonObject
class MyObjectLine
{
// To complete with content of an object MyObjectLine
+ // We should have a field rowid, fk_myobject and rank
}
|