Fix trigger to insert lines where called when inserting line but also

when cloning parent object, making no way to know when to use them or
not. I introduced a context to allow code to know that and do not
triggers twice.
This commit is contained in:
Laurent Destailleur 2015-02-26 13:19:19 +01:00
parent 41a74c62e2
commit fe7889e266
3 changed files with 37 additions and 19 deletions

View File

@ -239,27 +239,30 @@ class Propal extends CommonObject
return -5; return -5;
} }
$propalligne=new PropaleLigne($this->db); $line=new PropaleLigne($this->db);
$propalligne->fk_propal=$this->id;
$propalligne->fk_remise_except=$remise->id; $this->line->context = $this->context;
$propalligne->desc=$remise->description; // Description ligne
$propalligne->tva_tx=$remise->tva_tx; $line->fk_propal=$this->id;
$propalligne->subprice=-$remise->amount_ht; $line->fk_remise_except=$remise->id;
$propalligne->fk_product=0; // Id produit predefini $line->desc=$remise->description; // Description ligne
$propalligne->qty=1; $line->tva_tx=$remise->tva_tx;
$propalligne->remise=0; $line->subprice=-$remise->amount_ht;
$propalligne->remise_percent=0; $line->fk_product=0; // Id produit predefini
$propalligne->rang=-1; $line->qty=1;
$propalligne->info_bits=2; $line->remise=0;
$line->remise_percent=0;
$line->rang=-1;
$line->info_bits=2;
// TODO deprecated // TODO deprecated
$propalligne->price=-$remise->amount_ht; $line->price=-$remise->amount_ht;
$propalligne->total_ht = -$remise->amount_ht; $line->total_ht = -$remise->amount_ht;
$propalligne->total_tva = -$remise->amount_tva; $line->total_tva = -$remise->amount_tva;
$propalligne->total_ttc = -$remise->amount_ttc; $line->total_ttc = -$remise->amount_ttc;
$result=$propalligne->insert(); $result=$line->insert();
if ($result > 0) if ($result > 0)
{ {
$result=$this->update_price(1); $result=$this->update_price(1);
@ -276,7 +279,7 @@ class Propal extends CommonObject
} }
else else
{ {
$this->error=$propalligne->error; $this->error=$line->error;
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
@ -547,6 +550,8 @@ class Propal extends CommonObject
// Update line // Update line
$this->line=new PropaleLigne($this->db); $this->line=new PropaleLigne($this->db);
$this->line->context = $this->context;
// Stock previous line records // Stock previous line records
$staticline=new PropaleLigne($this->db); $staticline=new PropaleLigne($this->db);
$staticline->fetch($rowid); $staticline->fetch($rowid);

View File

@ -1205,6 +1205,8 @@ class Commande extends CommonOrder
// Insert line // Insert line
$this->line=new OrderLine($this->db); $this->line=new OrderLine($this->db);
$this->line->context = $this->context;
$this->line->fk_commande=$this->id; $this->line->fk_commande=$this->id;
$this->line->label=$label; $this->line->label=$label;
$this->line->desc=$desc; $this->line->desc=$desc;
@ -1319,6 +1321,8 @@ class Commande extends CommonOrder
$line=new OrderLine($this->db); $line=new OrderLine($this->db);
$line->context = $this->context;
$line->fk_product=$idproduct; $line->fk_product=$idproduct;
$line->desc=$prod->description; $line->desc=$prod->description;
$line->qty=$qty; $line->qty=$qty;
@ -2401,6 +2405,8 @@ class Commande extends CommonOrder
// Update line // Update line
$this->line=new OrderLine($this->db); $this->line=new OrderLine($this->db);
$this->line->context = $this->context;
// Stock previous line records // Stock previous line records
$staticline=new OrderLine($this->db); $staticline=new OrderLine($this->db);
$staticline->fetch($rowid); $staticline->fetch($rowid);

View File

@ -2047,6 +2047,9 @@ class Facture extends CommonInvoice
// Insert line // Insert line
$this->line=new FactureLigne($this->db); $this->line=new FactureLigne($this->db);
$this->line->context = $this->context;
$this->line->fk_facture=$this->id; $this->line->fk_facture=$this->id;
$this->line->label=$label; // deprecated $this->line->label=$label; // deprecated
$this->line->desc=$desc; $this->line->desc=$desc;
@ -2185,6 +2188,8 @@ class Facture extends CommonInvoice
// Update line into database // Update line into database
$this->line=new FactureLigne($this->db); $this->line=new FactureLigne($this->db);
$this->line->context = $this->context;
// Stock previous line records // Stock previous line records
$staticline=new FactureLigne($this->db); $staticline=new FactureLigne($this->db);
$staticline->fetch($rowid); $staticline->fetch($rowid);
@ -2298,6 +2303,8 @@ class Facture extends CommonInvoice
$line=new FactureLigne($this->db); $line=new FactureLigne($this->db);
$line->context = $this->context;
// For triggers // For triggers
$line->fetch($rowid); $line->fetch($rowid);