Task # 608 : forgot to clone lines... Now lines are also cloned and prices are valid prices at the clone date

This commit is contained in:
Maxime Kohlhaas 2012-11-23 09:00:17 +01:00
parent 0bb3f766f6
commit 3306d91ce1

View File

@ -954,34 +954,67 @@ class CommandeFournisseur extends CommonOrder
{ {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande_fournisseur"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande_fournisseur");
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; if ($this->id) {
$sql.= " SET ref='(PROV".$this->id.")'"; $num=count($this->lines);
$sql.= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::create sql=".$sql);
if ($this->db->query($sql))
{
// On logue creation pour historique
$this->log($user, 0, time());
if (! $notrigger) /*
{ * Insertion du detail des produits dans la base
// Appel des triggers */
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; for ($i=0;$i<$num;$i++)
$interface=new Interfaces($this->db); {
$result=$interface->run_triggers('ORDER_SUPPLIER_CREATE',$this,$user,$langs,$conf); $result = $this->addline(
if ($result < 0) { $error++; $this->errors=$interface->errors; } $this->lines[$i]->desc,
// Fin appel triggers $this->lines[$i]->subprice,
} $this->lines[$i]->qty,
$this->lines[$i]->tva_tx,
$this->lines[$i]->localtax1_tx,
$this->lines[$i]->localtax2_tx,
$this->lines[$i]->fk_product,
0,
$this->lines[$i]->ref_fourn,
$this->lines[$i]->remise_percent,
'HT',
0,
$this->lines[$i]->info_bits
);
if ($result < 0)
{
$this->error=$this->db->lasterror();
dol_print_error($this->db);
$this->db->rollback();
return -1;
}
}
$this->db->commit(); $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
return $this->id; $sql.= " SET ref='(PROV".$this->id.")'";
} $sql.= " WHERE rowid=".$this->id;
else dol_syslog(get_class($this)."::create sql=".$sql);
{ if ($this->db->query($sql))
$this->error=$this->db->error(); {
dol_syslog(get_class($this)."::create: Failed -2 - ".$this->error, LOG_ERR); // On logue creation pour historique
$this->db->rollback(); $this->log($user, 0, time());
return -2;
if (! $notrigger)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_SUPPLIER_CREATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
$this->db->commit();
return $this->id;
}
else
{
$this->error=$this->db->error();
dol_syslog(get_class($this)."::create: Failed -2 - ".$this->error, LOG_ERR);
$this->db->rollback();
return -2;
}
} }
} }
else else
@ -1107,7 +1140,6 @@ class CommandeFournisseur extends CommonOrder
} }
$desc=trim($desc); $desc=trim($desc);
// Check parameters // Check parameters
if ($qty < 1 && ! $fk_product) if ($qty < 1 && ! $fk_product)
{ {
@ -1116,7 +1148,6 @@ class CommandeFournisseur extends CommonOrder
} }
if ($type < 0) return -1; if ($type < 0) return -1;
if ($this->statut == 0) if ($this->statut == 0)
{ {
$this->db->begin(); $this->db->begin();