Merge pull request #6065 from atm-florian/3.9

FIX : delete contract extrafields on contract deletion
This commit is contained in:
Laurent Destailleur 2016-12-07 11:54:04 +01:00 committed by GitHub
commit ad467989bf
3 changed files with 51 additions and 39 deletions

View File

@ -56,7 +56,7 @@ class Contrat extends CommonObject
* @var string * @var string
*/ */
var $ref_customer; var $ref_customer;
/** /**
* Supplier reference of the contract * Supplier reference of the contract
* @var string * @var string
@ -536,7 +536,7 @@ class Contrat extends CommonObject
return -1; return -1;
} }
} }
/** /**
* Load a contract from database * Load a contract from database
* *
@ -1134,6 +1134,16 @@ class Contrat extends CommonObject
} }
} }
// Removed extrafields
if (! $error) {
$result=$this->deleteExtraFields();
if ($result < 0)
{
$error++;
dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR);
}
}
if (! $error) if (! $error)
{ {
// We remove directory // We remove directory
@ -1333,7 +1343,7 @@ class Contrat extends CommonObject
$localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->societe, $mysoc); $localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->societe, $mysoc);
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, 1,$mysoc, $localtaxes_type); $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, 1,$mysoc, $localtaxes_type);
$total_ht = $tabprice[0]; $total_ht = $tabprice[0];
$total_tva = $tabprice[1]; $total_tva = $tabprice[1];
@ -1356,9 +1366,9 @@ class Contrat extends CommonObject
if (empty($pa_ht)) $pa_ht=0; if (empty($pa_ht)) $pa_ht=0;
// if buy price not defined, define buyprice as configured in margin admin // if buy price not defined, define buyprice as configured in margin admin
if ($this->pa_ht == 0) if ($this->pa_ht == 0)
{ {
if (($result = $this->defineBuyPrice($pu_ht, $remise_percent, $fk_product)) < 0) if (($result = $this->defineBuyPrice($pu_ht, $remise_percent, $fk_product)) < 0)
{ {
@ -1515,7 +1525,7 @@ class Contrat extends CommonObject
$localtaxes_type=getLocalTaxesFromRate($tvatx, 0, $this->societe, $mysoc); $localtaxes_type=getLocalTaxesFromRate($tvatx, 0, $this->societe, $mysoc);
$tvatx = preg_replace('/\s*\(.*\)/','',$tvatx); // Remove code into vatrate. $tvatx = preg_replace('/\s*\(.*\)/','',$tvatx); // Remove code into vatrate.
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $tvatx, $localtax1tx, $localtax2tx, 0, $price_base_type, $info_bits, 1, $mysoc, $localtaxes_type); $tabprice=calcul_price_total($qty, $pu, $remise_percent, $tvatx, $localtax1tx, $localtax2tx, 0, $price_base_type, $info_bits, 1, $mysoc, $localtaxes_type);
$total_ht = $tabprice[0]; $total_ht = $tabprice[0];
$total_tva = $tabprice[1]; $total_tva = $tabprice[1];
@ -1539,7 +1549,7 @@ class Contrat extends CommonObject
if (empty($pa_ht)) $pa_ht=0; if (empty($pa_ht)) $pa_ht=0;
// if buy price not defined, define buyprice as configured in margin admin // if buy price not defined, define buyprice as configured in margin admin
if ($this->pa_ht == 0) if ($this->pa_ht == 0)
{ {
if (($result = $this->defineBuyPrice($pu_ht, $remise_percent)) < 0) if (($result = $this->defineBuyPrice($pu_ht, $remise_percent)) < 0)
{ {
@ -2571,7 +2581,7 @@ class ContratLigne extends CommonObjectLine
if (empty($this->pa_ht)) $this->pa_ht=0; if (empty($this->pa_ht)) $this->pa_ht=0;
// if buy price not defined, define buyprice as configured in margin admin // if buy price not defined, define buyprice as configured in margin admin
if ($this->pa_ht == 0) if ($this->pa_ht == 0)
{ {
if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0)
{ {

View File

@ -1,4 +1,4 @@
<?php <?php
if (empty($keyforselect) || empty($keyforelement) || empty($keyforaliasextra)) if (empty($keyforselect) || empty($keyforelement) || empty($keyforaliasextra))
{ {
@ -15,36 +15,38 @@ if ($resql) // This can fail when class is used on old database (during migra
{ {
while ($obj=$this->db->fetch_object($resql)) while ($obj=$this->db->fetch_object($resql))
{ {
$fieldname=$keyforaliasextra.'.'.$obj->name; if ($obj->type!='separate') {
$fieldlabel=ucfirst($obj->label); $fieldname=$keyforaliasextra.'.'.$obj->name;
$typeFilter="Text"; $fieldlabel=ucfirst($obj->label);
switch($obj->type) $typeFilter="Text";
{ switch($obj->type)
case 'int': {
case 'double': case 'int':
case 'price': case 'double':
$typeFilter="Numeric"; case 'price':
break; $typeFilter="Numeric";
case 'date': break;
case 'datetime': case 'date':
$typeFilter="Date"; case 'datetime':
break; $typeFilter="Date";
case 'boolean': break;
$typeFilter="Boolean"; case 'boolean':
break; $typeFilter="Boolean";
case 'sellist': break;
$tmp=''; case 'sellist':
$tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null $tmp='';
if ($tmpparam['options'] && is_array($tmpparam['options'])) { $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
$tmpkeys=array_keys($tmpparam['options']); if ($tmpparam['options'] && is_array($tmpparam['options'])) {
$tmp=array_shift($tmpkeys); $tmpkeys=array_keys($tmpparam['options']);
} $tmp=array_shift($tmpkeys);
if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp; }
break; if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
break;
}
$this->export_fields_array[$r][$fieldname]=$fieldlabel;
$this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
$this->export_entities_array[$r][$fieldname]=$keyforelement;
} }
$this->export_fields_array[$r][$fieldname]=$fieldlabel;
$this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
$this->export_entities_array[$r][$fieldname]=$keyforelement;
} }
} }
// End add axtra fields // End add axtra fields

View File

@ -1202,7 +1202,7 @@ class FichinterLigne extends CommonObjectLine
// Mise a jour ligne en base // Mise a jour ligne en base
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinterdet SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."fichinterdet SET";
$sql.= " description='".$this->db->escape($this->desc)."'"; $sql.= " description='".$this->db->escape($this->desc)."'";
$sql.= ",date=".$this->db->idate($this->datei); $sql.= ",date='".$this->db->idate($this->datei)."'";
$sql.= ",duree=".$this->duration; $sql.= ",duree=".$this->duration;
$sql.= ",rang='".$this->rang."'"; $sql.= ",rang='".$this->rang."'";
$sql.= " WHERE rowid = ".$this->rowid; $sql.= " WHERE rowid = ".$this->rowid;