Skip to content

Commit

Permalink
Fix: Replaced invoices by invoice we delete are freed from status
Browse files Browse the repository at this point in the history
'replaced' (so they can be opened again).
  • Loading branch information
eldy committed Aug 5, 2014
1 parent 372a3a5 commit 4af102f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions htdocs/compta/facture/class/facture.class.php
Expand Up @@ -1303,6 +1303,22 @@ function delete($rowid=0, $notrigger=0, $idwarehouse=-1)
}
}

// Replaced invoices by invoice we delete are freed from status 'replaced' (so they can be opened again)
if (! empty($this->fk_facture_source) && $this->fk_facture_source > 0)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
$sql.= " SET close_code = 'abandon' where close_code = 'replaced'";
$sql.= ' AND rowid = '.$this->fk_facture_source;
dol_syslog(get_class($this)."::delete sql=".$sql);
if (! $this->db->query($sql))
{
$this->error=$this->db->error()." sql=".$sql;
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
$this->db->rollback();
return -6;
}
}

// If we decrament stock on invoice validation, we increment
if ($this->type != 3 && $result >= 0 && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $idwarehouse!=-1)
{
Expand Down
3 changes: 3 additions & 0 deletions htdocs/install/mysql/migration/repair.sql
Expand Up @@ -54,6 +54,9 @@ delete from llx_adherent_extrafields where fk_object not in (select rowid from l
delete from llx_product_extrafields where fk_object not in (select rowid from llx_product);
--delete from llx_societe_commerciaux where fk_soc not in (select rowid from llx_societe);

-- Clean invoice thare were replaced and after the replacing invoice were deleted
-- To detect such records: select * from llx_facture as f1 left join llx_facture as f2 on f2.fk_facture_source = f1.rowid where f1.fk_statut = 3 AND f1.close_code = 'replaced' AND f2.rowid IS NULL;
--update llx_facture set close_code = 'abandon' where fk_statut = 3 AND close_code = 'replaced' and rowid not in (select fk_facture_source from llx_facture);

-- Fix: delete category child with no category parent.
drop table tmp_categorie;
Expand Down

0 comments on commit 4af102f

Please sign in to comment.