NEW Add estimated duration on the BOM module

This commit is contained in:
Laurent Destailleur 2019-10-14 11:38:36 +02:00
parent 323f31d832
commit 7973b03201
5 changed files with 79 additions and 50 deletions

View File

@ -94,6 +94,7 @@ class BOM extends CommonObject
'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>35, 'notnull'=>1, 'index'=>1, 'help'=>'ProductBOMHelp'), 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>35, 'notnull'=>1, 'index'=>1, 'help'=>'ProductBOMHelp'),
'qty' => array('type'=>'real', 'label'=>'Quantity', 'enabled'=>1, 'visible'=>1, 'default'=>1, 'position'=>55, 'notnull'=>1, 'isameasure'=>'1', 'css'=>'maxwidth75imp'), 'qty' => array('type'=>'real', 'label'=>'Quantity', 'enabled'=>1, 'visible'=>1, 'default'=>1, 'position'=>55, 'notnull'=>1, 'isameasure'=>'1', 'css'=>'maxwidth75imp'),
'efficiency' => array('type'=>'real', 'label'=>'ManufacturingEfficiency', 'enabled'=>1, 'visible'=>-1, 'default'=>1, 'position'=>100, 'notnull'=>0, 'css'=>'maxwidth50imp', 'help'=>'ValueOfMeansLoss'), 'efficiency' => array('type'=>'real', 'label'=>'ManufacturingEfficiency', 'enabled'=>1, 'visible'=>-1, 'default'=>1, 'position'=>100, 'notnull'=>0, 'css'=>'maxwidth50imp', 'help'=>'ValueOfMeansLoss'),
'duration' => array('type'=>'real', 'label'=>'EstimatedDuration', 'enabled'=>1, 'visible'=>-1, 'position'=>101, 'notnull'=>-1, 'css'=>'maxwidth50imp', 'help'=>'EstimatedDurationDesc'),
'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>-1, 'position'=>161, 'notnull'=>-1,), 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>-1, 'position'=>161, 'notnull'=>-1,),
'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>-1, 'position'=>162, 'notnull'=>-1,), 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>-1, 'position'=>162, 'notnull'=>-1,),
'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>300, 'notnull'=>1,), 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>300, 'notnull'=>1,),
@ -202,7 +203,7 @@ class BOM extends CommonObject
*/ */
public function create(User $user, $notrigger = false) public function create(User $user, $notrigger = false)
{ {
if ($this->efficiency < 0 || $this->efficiency > 1) $this->efficiency = 1; if ($this->efficiency <= 0 || $this->efficiency > 1) $this->efficiency = 1;
return $this->createCommon($user, $notrigger); return $this->createCommon($user, $notrigger);
} }
@ -412,7 +413,7 @@ class BOM extends CommonObject
*/ */
public function update(User $user, $notrigger = false) public function update(User $user, $notrigger = false)
{ {
if ($this->efficiency < 0 || $this->efficiency > 1) $this->efficiency = 1; if ($this->efficiency <= 0 || $this->efficiency > 1) $this->efficiency = 1;
return $this->updateCommon($user, $notrigger); return $this->updateCommon($user, $notrigger);
} }

View File

@ -2572,8 +2572,7 @@ abstract class CommonObject
public function updateRangOfLine($rowid, $rang) public function updateRangOfLine($rowid, $rang)
{ {
$fieldposition = 'rang'; // @TODO Rename 'rang' into 'position' $fieldposition = 'rang'; // @TODO Rename 'rang' into 'position'
if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; if (in_array($this->table_element_line, array('bom_bomline', 'ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
if (in_array($this->table_element_line, array('bom_bomline'))) $fieldposition = 'position';
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang;
$sql.= ' WHERE rowid = '.$rowid; $sql.= ' WHERE rowid = '.$rowid;
@ -2879,11 +2878,11 @@ abstract class CommonObject
$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL"; $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL";
elseif ($this->element == 'commande' || $this->element == 'order') elseif ($this->element == 'commande' || $this->element == 'order')
$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER"; $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER";
elseif ($this->element == 'facture') elseif ($this->element == 'facture' || $this->element == 'invoice')
$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE"; $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE";
elseif ($this->element == 'facture_fourn') elseif ($this->element == 'facture_fourn' || $this->element == 'supplier_invoice')
$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE"; $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE";
elseif ($this->element == 'order_supplier') elseif ($this->element == 'order_supplier' || $this->element == 'supplier_order')
$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER"; $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER";
elseif ($this->element == 'supplier_proposal') elseif ($this->element == 'supplier_proposal')
$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL";
@ -6271,13 +6270,7 @@ abstract class CommonObject
$value=''; $value='';
} }
} }
elseif ($type == 'double') elseif ($type == 'double' || $type == 'real')
{
if (!empty($value)) {
$value=price($value);
}
}
elseif ($type == 'real')
{ {
if (!empty($value)) { if (!empty($value)) {
$value=price($value); $value=price($value);
@ -7115,7 +7108,7 @@ abstract class CommonObject
* Function test if type is array * Function test if type is array
* *
* @param array $info content informations of field * @param array $info content informations of field
* @return bool * @return bool true if array
*/ */
protected function isArray($info) protected function isArray($info)
{ {
@ -7124,42 +7117,26 @@ abstract class CommonObject
if(isset($info['type']) && $info['type']=='array') return true; if(isset($info['type']) && $info['type']=='array') return true;
else return false; else return false;
} }
else return false; return false;
}
/**
* Function test if type is null
*
* @param array $info content informations of field
* @return bool
*/
protected function isNull($info)
{
if(is_array($info))
{
if(isset($info['type']) && $info['type']=='null') return true;
else return false;
}
else return false;
} }
/** /**
* Function test if type is date * Function test if type is date
* *
* @param array $info content informations of field * @param array $info content informations of field
* @return bool * @return bool true if date
*/ */
public function isDate($info) public function isDate($info)
{ {
if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true;
else return false; return false;
} }
/** /**
* Function test if type is integer * Function test if type is integer
* *
* @param array $info content informations of field * @param array $info content informations of field
* @return bool * @return bool true if integer
*/ */
public function isInt($info) public function isInt($info)
{ {
@ -7175,7 +7152,7 @@ abstract class CommonObject
* Function test if type is float * Function test if type is float
* *
* @param array $info content informations of field * @param array $info content informations of field
* @return bool * @return bool true if float
*/ */
public function isFloat($info) public function isFloat($info)
{ {
@ -7184,14 +7161,14 @@ abstract class CommonObject
if (isset($info['type']) && (preg_match('/^(double|real|price)/i', $info['type']))) return true; if (isset($info['type']) && (preg_match('/^(double|real|price)/i', $info['type']))) return true;
else return false; else return false;
} }
else return false; return false;
} }
/** /**
* Function test if type is text * Function test if type is text
* *
* @param array $info content informations of field * @param array $info content informations of field
* @return bool * @return bool true if type text
*/ */
public function isText($info) public function isText($info)
{ {
@ -7200,8 +7177,40 @@ abstract class CommonObject
if(isset($info['type']) && $info['type']=='text') return true; if(isset($info['type']) && $info['type']=='text') return true;
else return false; else return false;
} }
return false;
}
/**
* Function test if field can be null
*
* @param array $info content informations of field
* @return bool true if it can be null
*/
protected function canBeNull($info)
{
if(is_array($info))
{
if(isset($info['notnull']) && $info['notnull']!='1') return true;
else return false; else return false;
} }
return true;
}
/**
* Function test if field is forced to null if zero or empty
*
* @param array $info content informations of field
* @return bool true if forced to null
*/
protected function isForcedToNullIfZero($info)
{
if(is_array($info))
{
if(isset($info['notnull']) && $info['notnull']=='-1') return true;
else return false;
}
return false;
}
/** /**
* Function test if is indexed * Function test if is indexed
@ -7216,7 +7225,7 @@ abstract class CommonObject
if(isset($info['index']) && $info['index']==true) return true; if(isset($info['index']) && $info['index']==true) return true;
else return false; else return false;
} }
else return false; return false;
} }
/** /**
@ -7309,17 +7318,30 @@ abstract class CommonObject
elseif($this->isInt($info)) elseif($this->isInt($info))
{ {
if ($field == 'rowid') $this->id = (int) $obj->{$field}; if ($field == 'rowid') $this->id = (int) $obj->{$field};
else $this->{$field} = (int) $obj->{$field}; else
{
if ($this->isForcedToNullIfZero($info))
{
if (empty($obj->{$field})) $this->{$field} = null;
else $this->{$field} = (double) $obj->{$field};
}
else
{
$this->{$field} = (int) $obj->{$field};
}
}
} }
elseif($this->isFloat($info)) elseif($this->isFloat($info))
{
if ($this->isForcedToNullIfZero($info))
{
if (empty($obj->{$field})) $this->{$field} = null;
else $this->{$field} = (double) $obj->{$field};
}
else
{ {
$this->{$field} = (double) $obj->{$field}; $this->{$field} = (double) $obj->{$field};
} }
elseif($this->isNull($info))
{
$val = $obj->{$field};
// zero is not null
$this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val);
} }
else else
{ {
@ -7376,6 +7398,7 @@ abstract class CommonObject
if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now); if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now);
if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id; if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id;
unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert.
if (array_key_exists('ref', $fieldvalues)) $fieldvalues['ref']=dol_string_nospecial($fieldvalues['ref']); // If field is a ref,we sanitize data
$keys=array(); $keys=array();
$values = array(); $values = array();

View File

@ -49,6 +49,8 @@ UPDATE llx_c_units SET label = 'SurfaceUnitm2' WHERE code IN ('M2');
-- For v11 -- For v11
ALTER TABLE llx_bom_bom ADD COLUMN duration double(8,4) DEFAULT NULL;
create table llx_categorie_warehouse create table llx_categorie_warehouse
( (
fk_categorie integer NOT NULL, fk_categorie integer NOT NULL,

View File

@ -26,6 +26,7 @@ CREATE TABLE llx_bom_bom(
fk_product integer, fk_product integer,
qty double(24,8), qty double(24,8),
efficiency double(8,4) DEFAULT 1, efficiency double(8,4) DEFAULT 1,
duration double(8,4) DEFAULT NULL,
date_creation datetime NOT NULL, date_creation datetime NOT NULL,
date_valid datetime, date_valid datetime,
tms timestamp, tms timestamp,

View File

@ -22,3 +22,5 @@ QtyToProduce=Qty to produce
DateStartPlannedMo=Date start planned DateStartPlannedMo=Date start planned
DateEndPlannedMo=Date end planned DateEndPlannedMo=Date end planned
KeepEmptyForAsap=Empty means 'As Soon As Possible' KeepEmptyForAsap=Empty means 'As Soon As Possible'
EstimatedDuration=Estimated duration
EstimatedDurationDesc=Estimated duration to manufacture this product using this BOM