2
0
forked from Wavyzz/dolibarr

Fix migration into product_lot

This commit is contained in:
Laurent Destailleur
2017-06-27 16:42:37 +02:00
parent 1a860c42ee
commit c213624c14
2 changed files with 34 additions and 24 deletions

View File

@@ -31,6 +31,15 @@
-- Requests to clean corrupted data
-- VMYSQL4.1 INSERT IGNORE INTO llx_product_lot (entity, fk_product, batch, eatby, sellby, datec, fk_user_creat, fk_user_modif) SELECT DISTINCT e.entity, ps.fk_product, pb.batch, pb.eatby, pb.sellby, pb.tms, e.fk_user_author, e.fk_user_author from llx_product_batch as pb, llx_product_stock as ps, llx_entrepot as e WHERE pb.fk_product_stock = ps.rowid AND ps.fk_entrepot = e.rowid;
-- -- a tester VPGSQL9.5 INSERT IGNORE INTO llx_product_lot (entity, fk_product, batch, eatby, sellby, datec, fk_user_creat, fk_user_modif) SELECT DISTINCT e.entity, ps.fk_product, pb.batch, pb.eatby, pb.sellby, pb.tms, e.fk_user_author, e.fk_user_author from llx_product_batch as pb, llx_product_stock as ps, llx_entrepot as e WHERE pb.fk_product_stock = ps.rowid AND ps.fk_entrepot = e.rowid ON CONFLICT DO NOTHING;
-- -- avant 9.5 faire en variant x pour qu'au 2eme passage, le premier doublon soit dans la tabel cible
-- -- INSERT INTO llx_product_lot (entity, fk_product, batch, eatby, sellby, datec, fk_user_creat, fk_user_modif)
-- -- SELECT DISTINCT e.entity, ps.fk_product, pb.batch, pb.eatby, pb.sellby, pb.tms, e.fk_user_author, e.fk_user_author
-- -- from llx_product_batch as pb, llx_product_stock as ps, llx_entrepot as e
-- -- WHERE pb.fk_product_stock = ps.rowid AND ps.fk_entrepot = e.rowid
-- -- AND NOT EXISTS (SELECT 1 FROM llx_product_lot as b WHERE b.fk_product=ps.fk_product and pb.batch=b.batch) LIMIT x
UPDATE llx_user set api_key = null where api_key = '';
@@ -99,6 +108,8 @@ DELETE FROM llx_product_lot WHERE fk_product NOT IN (select rowid from llx_produ
DELETE FROM llx_product_stock WHERE fk_product NOT IN (select rowid from llx_product);
DELETE FROM llx_product_stock WHERE reel = 0 AND rowid NOT IN (SELECT fk_product_stock FROM llx_product_batch as pb);
-- Merge splitted lines into one in table llx_product_batch
DROP TABLE tmp_llx_product_batch;
DROP TABLE tmp_llx_product_batch2;
@@ -356,4 +367,3 @@ drop table tmp_c_shipment_mode;
-- Backport a change of value into the hourly rate.
-- update llx_projet_task_time as ptt set ptt.thm = (SELECT thm from llx_user as u where ptt.fk_user = u.rowid) where (ptt.thm is null)

View File

@@ -43,12 +43,12 @@ class Productlot extends CommonObject
* @var string Name of table without prefix where object is stored
*/
public $table_element = 'product_lot';
public $picto='barcode';
public $isnolinkedbythird = 1;
public $ismultientitymanaged = 1;
/**
* @var ProductlotLine[] Lines
*/
@@ -56,7 +56,7 @@ class Productlot extends CommonObject
/**
*/
public $entity;
public $fk_product;
public $batch;
@@ -70,7 +70,7 @@ class Productlot extends CommonObject
/**
*/
/**
* Constructor
@@ -97,7 +97,7 @@ class Productlot extends CommonObject
$error = 0;
// Clean parameters
if (isset($this->entity)) {
$this->entity = trim($this->entity);
}
@@ -117,7 +117,7 @@ class Productlot extends CommonObject
$this->import_key = trim($this->import_key);
}
// Check parameters
// Put here code to add control on parameters values
@@ -207,7 +207,7 @@ class Productlot extends CommonObject
$sql .= " t.import_key";
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
if ($product_id > 0 && $batch != '') {
$sql .= ' WHERE t.batch = ' . '\'' . $this->db->escape($batch) . '\' AND t.fk_product = ' . $product_id;
$sql .= " WHERE t.batch = '". $this->db->escape($batch) . "' AND t.fk_product = " . $product_id;
} else {
$sql .= ' WHERE t.rowid = ' . $id;
}
@@ -221,9 +221,9 @@ class Productlot extends CommonObject
$this->id = $obj->rowid;
$this->ref = $obj->rowid;
//$this->ref = $obj->fk_product.'_'.$obj->batch;
$this->batch = $obj->batch;
$this->entity = $obj->entity;
$this->fk_product = $obj->fk_product;
$this->eatby = $this->db->jdate($obj->eatby);
@@ -239,7 +239,7 @@ class Productlot extends CommonObject
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
$this->fetch_optionals($this->id,$extralabels);
}
$this->db->free($resql);
@@ -271,7 +271,7 @@ class Productlot extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG);
// Clean parameters
if (isset($this->entity)) {
$this->entity = trim($this->entity);
}
@@ -437,8 +437,8 @@ class Productlot extends CommonObject
return - 1;
}
}
/**
* Return label of status of object
*
@@ -449,7 +449,7 @@ class Productlot extends CommonObject
{
return $this->LibStatut(0,$mode);
}
/**
* Return label of a given status
*
@@ -460,13 +460,13 @@ class Productlot extends CommonObject
function LibStatut($statut,$mode=0)
{
global $langs;
//$langs->load('stocks');
return '';
}
/**
* Return a link to the a lot card (with optionaly the picto)
* Use this->id,this->lastname, this->firstname
@@ -498,7 +498,7 @@ class Productlot extends CommonObject
{
$label.= '<br><b>' . $langs->trans('SellByDate') . ':</b> ' . dol_print_date($this->sellby, 'day');
}
$link = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_card.php?id='.$this->id.'"';
$link.= ($notooltip?'':' title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip'.($morecss?' '.$morecss:'').'"');
$link.= '>';
@@ -512,9 +512,9 @@ class Productlot extends CommonObject
$result.= $link . $this->batch . $linkend;
return $result;
}
/**
/**
* Initialise object with example values
* Id must be 0 if object instance is a specimen
*
@@ -523,7 +523,7 @@ class Productlot extends CommonObject
public function initAsSpecimen()
{
$this->id = 0;
$this->entity = '';
$this->fk_product = '';
$this->batch = '';