Qual: control of delete usage

This commit is contained in:
Laurent Destailleur 2013-10-27 02:23:25 +02:00
parent 62bedffb49
commit ca95bd67f8
2 changed files with 17 additions and 8 deletions

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2013 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2007-2011 Jean Heimburger <jean@tiaris.info>
@ -457,7 +457,7 @@ class Product extends CommonObject
if (empty($this->localtax2_tx)) $this->localtax2_tx = 0;
if (empty($this->status)) $this->status = 0;
if (empty($this->status_buy)) $this->status_buy = 0;
if (empty($this->country_id)) $this->country_id = 0;
$this->accountancy_code_buy = trim($this->accountancy_code_buy);
@ -588,15 +588,25 @@ class Product extends CommonObject
/**
* Delete a product from database (if not used)
*
* @param int $id Product id
* @param int $id Product id (usage of this is deprecated, delete should be called without parameters on a fetched object)
* @return int < 0 if KO, 0 = Not possible, > 0 if OK
*/
function delete($id)
function delete($id=0)
{
global $conf,$user,$langs;
$error=0;
// Clean parameters
if (empty($id)) $id=$this->id;
else $this->fetch($id);
// Check parameters
if (empty($id))
{
$this->error = "Object must be fetched before calling delete";
return -1;
}
if (($this->type == 0 && empty($user->rights->produit->supprimer)) || ($this->type == 1 && empty($user->rights->service->supprimer)))
{
$this->error = "ErrorForbidden";
@ -904,7 +914,7 @@ class Product extends CommonObject
function get_buyprice($prodfournprice,$qty,$product_id=0,$fourn_ref=0)
{
$result = 0;
// We do select by searching with qty and prodfournprice
$sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity,";
$sql.= " pfp.fk_product, pfp.ref_fourn, pfp.fk_soc, pfp.tva_tx";

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,8 +25,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
/**
* \class Service
* \brief Classe permettant la gestion des services predefinis
* Class to manage predefined services
*/
class Service extends CommonObject
{