2
0
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:
Laurent Destailleur
2014-03-16 17:37:54 +01:00
parent dba37d74ed
commit 2d3c700a7d
7 changed files with 48 additions and 36 deletions

View File

@@ -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 * 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". * renvoyer leur erreur par l'intermediaire de leur propriete "error".
* *
* @param DoliDB $db Database handler * @param DoliDB $db Database handler
* @param string $error String or array of errors strings to show * @param mixed $error String or array of errors strings to show
* @return void * @return void
* @see dol_htmloutput_errors * @see dol_htmloutput_errors
*/ */
function dol_print_error($db='',$error='') function dol_print_error($db='',$error='')
{ {

View File

@@ -114,7 +114,7 @@ abstract class DolibarrModules
$sql=str_replace('__ENTITY__', $conf->entity, $sql); $sql=str_replace('__ENTITY__', $conf->entity, $sql);
dol_syslog(get_class($this)."::_init ignoreerror=".$ignoreerror." sql=".$sql, LOG_DEBUG); 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 (! $result)
{ {
if (! $ignoreerror) if (! $ignoreerror)

View File

@@ -28,7 +28,7 @@
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; 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 class modBarcode extends DolibarrModules
{ {
@@ -77,22 +77,16 @@ class modBarcode extends DolibarrModules
$this->rights_class = 'barcode'; $this->rights_class = 'barcode';
$this->rights[1][0] = 300; // id de la permission $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][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][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][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][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][3] = 0; // La permission est-elle une permission par defaut
$this->rights[2][4] = 'creer'; $this->rights[2][4] = 'creer_advance';
$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';
// Main menu entries // Main menu entries
$r=0; $r=0;

View File

@@ -168,7 +168,7 @@ CloneProduct=Clone product or service
ConfirmCloneProduct=Are you sure you want to clone product or service <b>%s</b> ? ConfirmCloneProduct=Are you sure you want to clone product or service <b>%s</b> ?
CloneContentProduct=Clone all main informations of product/service CloneContentProduct=Clone all main informations of product/service
ClonePricesProduct=Clone main informations and prices ClonePricesProduct=Clone main informations and prices
CloneCompositionProduct=Clone product/service composition CloneCompositionProduct=Clone virtual product/services
ProductIsUsed=This product is used ProductIsUsed=This product is used
NewRefForClone=Ref. of new product/service NewRefForClone=Ref. of new product/service
CustomerPrices=Customers prices CustomerPrices=Customers prices

View File

@@ -302,9 +302,9 @@ class Product extends CommonObject
$this->db->begin(); $this->db->begin();
// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts) // 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 // If error, this->errors[] is filled
$result = $this->verify(); $result = $this->verify();
@@ -582,7 +582,7 @@ class Product extends CommonObject
if ($result >= 0) if ($result >= 0)
{ {
// For automatic creation // 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 = "UPDATE ".MAIN_DB_PREFIX."product";
$sql.= " SET label = '" . $this->db->escape($this->libelle) ."'"; $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 * Return value is stored into this->barcode
* *
* @param Product $object Object product or service * @param Product $object Object product or service
* @param int $type Barcode type (ean, isbn, ...) * @param string $type Barcode type (ean, isbn, ...)
* @return void * @return void
*/ */
function get_barcode($object,$type='') function get_barcode($object,$type='')
{ {
global $conf; global $conf;
$result='';
if (! empty($conf->global->BARCODE_PRODUCT_ADDON_NUM)) if (! empty($conf->global->BARCODE_PRODUCT_ADDON_NUM))
{ {
$dirsociete=array_merge(array('/core/modules/barcode/'),$conf->modules_parts['barcode']); $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; $var = $conf->global->BARCODE_PRODUCT_ADDON_NUM;
$mod = new $var; $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;
} }
/** /**

View File

@@ -94,6 +94,9 @@ $hookmanager->initHooks(array('productcard'));
* Actions * 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); $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 $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; $error=$hookmanager->error; $errors=$hookmanager->errors;
@@ -109,15 +112,15 @@ if (empty($reshook))
} }
// Barcode type // 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); header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit; exit;
} }
// Barcode value // Barcode value
if ($action == 'setbarcode' && $user->rights->barcode->creer) if ($action == 'setbarcode' && $createbarcode)
{ {
$result=$object->check_barcode(GETPOST('barcode')); $result=$object->check_barcode(GETPOST('barcode'));
@@ -354,7 +357,8 @@ if (empty($reshook))
$object->status = 0; $object->status = 0;
$object->status_buy = 0; $object->status_buy = 0;
$object->id = null; $object->id = null;
$object->barcode = -1;
if ($object->check()) if ($object->check())
{ {
$id = $object->create($user); $id = $object->create($user);
@@ -401,8 +405,16 @@ if (empty($reshook))
else else
{ {
$db->rollback(); $db->rollback();
setEventMessage($langs->trans($object->error), 'errors'); if (count($object->errors))
dol_print_error($db,$object->error); {
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>'; print '</td></tr>';
} }
$showbarcode=empty($conf->barcode->enabled)?0:1;
$showbarcode=(! empty($conf->barcode->enabled) && $user->rights->barcode->lire); if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode=0;
if ($showbarcode) if ($showbarcode)
{ {
@@ -1038,7 +1050,8 @@ else
} }
// Barcode // 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) if ($showbarcode)
{ {
@@ -1207,7 +1220,8 @@ else
dol_fiche_head($head, 'card', $titre, 0, $picto); dol_fiche_head($head, 'card', $titre, 0, $picto);
$showphoto=$object->is_photo_available($conf->product->multidir_output[$object->entity]); $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 // En mode visu
print '<table class="border" width="100%"><tr>'; print '<table class="border" width="100%"><tr>';

View File

@@ -1476,8 +1476,9 @@ else
dol_htmloutput_errors($error,$errors); dol_htmloutput_errors($error,$errors);
$showlogo=$object->logo; $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%">'; print '<table class="border" width="100%">';
// Ref // Ref