forked from Wavyzz/dolibarr
Fix: When cloning product, autogenerating barcode must not use same
number. Qual: Moved dedicated permission of module to "advance" permissions.
This commit is contained in:
@@ -2236,10 +2236,10 @@ function info_admin($text, $infoonimgalt = 0, $nodiv=0)
|
||||
* Toutefois, il faut essayer de ne l'appeler qu'au sein de pages php, les classes devant
|
||||
* renvoyer leur erreur par l'intermediaire de leur propriete "error".
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
* @param string $error String or array of errors strings to show
|
||||
* @return void
|
||||
* @see dol_htmloutput_errors
|
||||
* @param DoliDB $db Database handler
|
||||
* @param mixed $error String or array of errors strings to show
|
||||
* @return void
|
||||
* @see dol_htmloutput_errors
|
||||
*/
|
||||
function dol_print_error($db='',$error='')
|
||||
{
|
||||
|
||||
@@ -114,7 +114,7 @@ abstract class DolibarrModules
|
||||
$sql=str_replace('__ENTITY__', $conf->entity, $sql);
|
||||
|
||||
dol_syslog(get_class($this)."::_init ignoreerror=".$ignoreerror." sql=".$sql, LOG_DEBUG);
|
||||
$result=$this->db->query($sql);
|
||||
$result=$this->db->query($sql, $ignoreerror);
|
||||
if (! $result)
|
||||
{
|
||||
if (! $ignoreerror)
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
|
||||
|
||||
/**
|
||||
* Classe de description et activation du module Barcode
|
||||
* Class to describe Barcode
|
||||
*/
|
||||
class modBarcode extends DolibarrModules
|
||||
{
|
||||
@@ -77,22 +77,16 @@ class modBarcode extends DolibarrModules
|
||||
$this->rights_class = 'barcode';
|
||||
|
||||
$this->rights[1][0] = 300; // id de la permission
|
||||
$this->rights[1][1] = 'Lire les codes barres'; // libelle de la permission
|
||||
$this->rights[1][1] = 'Read barcodes'; // libelle de la permission
|
||||
$this->rights[1][2] = 'r'; // type de la permission (deprecie a ce jour)
|
||||
$this->rights[1][3] = 1; // La permission est-elle une permission par defaut
|
||||
$this->rights[1][4] = 'lire';
|
||||
$this->rights[1][4] = 'lire_advance';
|
||||
|
||||
$this->rights[2][0] = 301; // id de la permission
|
||||
$this->rights[2][1] = 'Creer/modifier les codes barres'; // libelle de la permission
|
||||
$this->rights[2][1] = 'Create/modify barcodes'; // libelle de la permission
|
||||
$this->rights[2][2] = 'w'; // type de la permission (deprecie a ce jour)
|
||||
$this->rights[2][3] = 0; // La permission est-elle une permission par defaut
|
||||
$this->rights[2][4] = 'creer';
|
||||
|
||||
$this->rights[4][0] = 302; // id de la permission
|
||||
$this->rights[4][1] = 'Supprimer les codes barres'; // libelle de la permission
|
||||
$this->rights[4][2] = 'd'; // type de la permission (deprecie a ce jour)
|
||||
$this->rights[4][3] = 0; // La permission est-elle une permission par defaut
|
||||
$this->rights[4][4] = 'supprimer';
|
||||
$this->rights[2][4] = 'creer_advance';
|
||||
|
||||
// Main menu entries
|
||||
$r=0;
|
||||
|
||||
@@ -168,7 +168,7 @@ CloneProduct=Clone product or service
|
||||
ConfirmCloneProduct=Are you sure you want to clone product or service <b>%s</b> ?
|
||||
CloneContentProduct=Clone all main informations of product/service
|
||||
ClonePricesProduct=Clone main informations and prices
|
||||
CloneCompositionProduct=Clone product/service composition
|
||||
CloneCompositionProduct=Clone virtual product/services
|
||||
ProductIsUsed=This product is used
|
||||
NewRefForClone=Ref. of new product/service
|
||||
CustomerPrices=Customers prices
|
||||
|
||||
@@ -302,9 +302,9 @@ class Product extends CommonObject
|
||||
$this->db->begin();
|
||||
|
||||
// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
|
||||
if ($this->barcode == -1) $this->get_barcode($this,$this->barcode_type_code);
|
||||
if ($this->barcode == -1) $this->barcode = $this->get_barcode($this,$this->barcode_type_code);
|
||||
|
||||
// Check more parameters
|
||||
// Check more parameters
|
||||
// If error, this->errors[] is filled
|
||||
$result = $this->verify();
|
||||
|
||||
@@ -582,7 +582,7 @@ class Product extends CommonObject
|
||||
if ($result >= 0)
|
||||
{
|
||||
// For automatic creation
|
||||
if ($this->barcode == -1) $this->get_barcode($this,$this->barcode_type_code);
|
||||
if ($this->barcode == -1) $this->barcode = $this->get_barcode($this,$this->barcode_type_code);
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product";
|
||||
$sql.= " SET label = '" . $this->db->escape($this->libelle) ."'";
|
||||
@@ -3259,16 +3259,18 @@ class Product extends CommonObject
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribut un code barre a partir du module de controle des codes.
|
||||
* Get a barcode from the module to generate barcode values.
|
||||
* Return value is stored into this->barcode
|
||||
*
|
||||
* @param Product $object Object product or service
|
||||
* @param int $type Barcode type (ean, isbn, ...)
|
||||
* @param string $type Barcode type (ean, isbn, ...)
|
||||
* @return void
|
||||
*/
|
||||
function get_barcode($object,$type='')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$result='';
|
||||
if (! empty($conf->global->BARCODE_PRODUCT_ADDON_NUM))
|
||||
{
|
||||
$dirsociete=array_merge(array('/core/modules/barcode/'),$conf->modules_parts['barcode']);
|
||||
@@ -3280,10 +3282,11 @@ class Product extends CommonObject
|
||||
$var = $conf->global->BARCODE_PRODUCT_ADDON_NUM;
|
||||
$mod = new $var;
|
||||
|
||||
$this->barcode = $mod->getNextValue($object,$type);
|
||||
$result=$mod->getNextValue($object,$type);
|
||||
|
||||
dol_syslog(get_class($this)."::get_barcode barcode=".$this->barcode." module=".$var);
|
||||
dol_syslog(get_class($this)."::get_barcode barcode=".$result." module=".$var);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -94,6 +94,9 @@ $hookmanager->initHooks(array('productcard'));
|
||||
* Actions
|
||||
*/
|
||||
|
||||
$createbarcode=empty($conf->barcode->enabled)?0:1;
|
||||
if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->creer_advance)) $createbarcode=0;
|
||||
|
||||
$parameters=array('id'=>$id, 'ref'=>$ref, 'objcanvas'=>$objcanvas);
|
||||
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
|
||||
$error=$hookmanager->error; $errors=$hookmanager->errors;
|
||||
@@ -109,15 +112,15 @@ if (empty($reshook))
|
||||
}
|
||||
|
||||
// Barcode type
|
||||
if ($action == 'setfk_barcode_type' && $user->rights->barcode->creer)
|
||||
if ($action == 'setfk_barcode_type' && $createbarcode)
|
||||
{
|
||||
$result = $object->setValueFrom('fk_barcode_type', GETPOST('fk_barcode_type'));
|
||||
$result = $object->setValueFrom('fk_barcode_type', GETPOST('fk_barcode_type'));
|
||||
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Barcode value
|
||||
if ($action == 'setbarcode' && $user->rights->barcode->creer)
|
||||
if ($action == 'setbarcode' && $createbarcode)
|
||||
{
|
||||
$result=$object->check_barcode(GETPOST('barcode'));
|
||||
|
||||
@@ -354,7 +357,8 @@ if (empty($reshook))
|
||||
$object->status = 0;
|
||||
$object->status_buy = 0;
|
||||
$object->id = null;
|
||||
|
||||
$object->barcode = -1;
|
||||
|
||||
if ($object->check())
|
||||
{
|
||||
$id = $object->create($user);
|
||||
@@ -401,8 +405,16 @@ if (empty($reshook))
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
setEventMessage($langs->trans($object->error), 'errors');
|
||||
dol_print_error($db,$object->error);
|
||||
if (count($object->errors))
|
||||
{
|
||||
setEventMessage($object->errors, 'errors');
|
||||
dol_print_error($db,$object->errors);
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessage($langs->trans($object->error), 'errors');
|
||||
dol_print_error($db,$object->error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -780,8 +792,8 @@ else
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
|
||||
$showbarcode=(! empty($conf->barcode->enabled) && $user->rights->barcode->lire);
|
||||
$showbarcode=empty($conf->barcode->enabled)?0:1;
|
||||
if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode=0;
|
||||
|
||||
if ($showbarcode)
|
||||
{
|
||||
@@ -1038,7 +1050,8 @@ else
|
||||
}
|
||||
|
||||
// Barcode
|
||||
$showbarcode=(! empty($conf->barcode->enabled) && $user->rights->barcode->lire);
|
||||
$showbarcode=empty($conf->barcode->enabled)?0:1;
|
||||
if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode=0;
|
||||
|
||||
if ($showbarcode)
|
||||
{
|
||||
@@ -1207,7 +1220,8 @@ else
|
||||
dol_fiche_head($head, 'card', $titre, 0, $picto);
|
||||
|
||||
$showphoto=$object->is_photo_available($conf->product->multidir_output[$object->entity]);
|
||||
$showbarcode=(! empty($conf->barcode->enabled) && $user->rights->barcode->lire);
|
||||
$showbarcode=empty($conf->barcode->enabled)?0:1;
|
||||
if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode=0;
|
||||
|
||||
// En mode visu
|
||||
print '<table class="border" width="100%"><tr>';
|
||||
|
||||
@@ -1476,8 +1476,9 @@ else
|
||||
dol_htmloutput_errors($error,$errors);
|
||||
|
||||
$showlogo=$object->logo;
|
||||
$showbarcode=(! empty($conf->barcode->enabled) && $user->rights->barcode->lire);
|
||||
|
||||
$showbarcode=empty($conf->barcode->enabled)?0:1;
|
||||
if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode=0;
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
// Ref
|
||||
|
||||
Reference in New Issue
Block a user