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

View File

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

View File

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