FIX Creation of credit note on invoice with deposit stole the discount.

This commit is contained in:
Laurent Destailleur 2017-01-28 15:55:44 +01:00
parent 2c07d2df22
commit 4f76626f51
2 changed files with 15 additions and 11 deletions

View File

@ -812,14 +812,14 @@ if (empty($reshook))
$line->fk_parent_line = $fk_parent_line; $line->fk_parent_line = $fk_parent_line;
$line->subprice =-$line->subprice; // invert price for object $line->subprice =-$line->subprice; // invert price for object
$line->pa_ht = -$line->pa_ht; $line->pa_ht = $line->pa_ht; // we choosed to have buy/cost price always positive, so no revert of sign here
$line->total_ht=-$line->total_ht; $line->total_ht=-$line->total_ht;
$line->total_tva=-$line->total_tva; $line->total_tva=-$line->total_tva;
$line->total_ttc=-$line->total_ttc; $line->total_ttc=-$line->total_ttc;
$line->total_localtax1=-$line->total_localtax1; $line->total_localtax1=-$line->total_localtax1;
$line->total_localtax2=-$line->total_localtax2; $line->total_localtax2=-$line->total_localtax2;
$result = $line->insert(); $result = $line->insert(0, 1); // When creating credit note with same lines than source, we must ignore error if discount alreayd linked
$object->lines[] = $line; // insert new line in current object $object->lines[] = $line; // insert new line in current object

View File

@ -4097,9 +4097,10 @@ class FactureLigne extends CommonInvoiceLine
* Insert line into database * Insert line into database
* *
* @param int $notrigger 1 no triggers * @param int $notrigger 1 no triggers
* @param int $noerrorifdiscountalreadylinked 1=Do not make error if lines is linked to a discount and discount already linked to another
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function insert($notrigger=0) function insert($notrigger=0, $noerrorifdiscountalreadylinked=0)
{ {
global $langs,$user,$conf; global $langs,$user,$conf;
@ -4244,13 +4245,16 @@ class FactureLigne extends CommonInvoiceLine
if ($result > 0) if ($result > 0)
{ {
// Check if discount not already affected to another invoice // Check if discount not already affected to another invoice
if ($discount->fk_facture) if ($discount->fk_facture_line > 0)
{
if (empty($noerrorifdiscountalreadylinked))
{ {
$this->error=$langs->trans("ErrorDiscountAlreadyUsed",$discount->id); $this->error=$langs->trans("ErrorDiscountAlreadyUsed",$discount->id);
dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR);
$this->db->rollback(); $this->db->rollback();
return -3; return -3;
} }
}
else else
{ {
$result=$discount->link_to_invoice($this->rowid,0); $result=$discount->link_to_invoice($this->rowid,0);