Skip to content

Commit

Permalink
CLOSE Dolibarr#26384 Implement STOCK_USE_WAREHOUSE_USAGE for use of n…
Browse files Browse the repository at this point in the history
…on-counting warehouses e.g. quarantine

This feature implements the global variable of STOCK_USE_WAREHOUSE_USAGE. This variable allows warehouses to exclude their products from stock calculations. A button was added to the stock module in the admin panel. A simple "AND" check for the warehouse_usage column in the entrepot SQL table is added to the load_stock function to facilitate this change.
  • Loading branch information
DaBootO committed Jul 1, 2024
1 parent cff25de commit bf265c5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
13 changes: 13 additions & 0 deletions htdocs/admin/stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,19 @@
print "</td>\n";
print "</tr>\n";

// warehouse_usage activation
print '<tr class="oddeven">';
print '<td>'.$langs->trans("ActivateWarehouseUsage").'</td>';
print '<td class="right">';
if ($conf->use_javascript_ajax) {
print ajax_constantonoff('STOCK_USE_WAREHOUSE_USAGE');
} else {
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
print $form->selectarray("STOCK_USE_WAREHOUSE_USAGE", $arrval, $conf->global->STOCK_USE_WAREHOUSE_USAGE);
}
print "</td>\n";
print "</tr>\n";

/* Disabled. Would be better to be managed with a user cookie
if (isModEnabled('productbatch')) {
print '<tr class="oddeven">';
Expand Down
3 changes: 3 additions & 0 deletions htdocs/langs/en_US/stocks.lang
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,6 @@ LatestModifiedWarehouses=Latest %s modified warehouses
LatestStockMovements=Latest %s stock movements
QtyCurrentlyKnownInStock=System estimated quantity you have in stock. As long as the inventory is not closed, this is a realtime value and it may change if you continue to make stock movement during the inventory (not recommended).
QtyInStockWhenInventoryWasValidated=System estimated quantity you had in stock when the inventory was validated (before the stock correction)
ActivateWarehouseUsage=Activate the option that products in a warehouse do not count towards the stock (e.g., quarantine warehouse)
WarehouseUsageCount=included in stock
WarehouseUsageNoCount=excluded from stock
3 changes: 3 additions & 0 deletions htdocs/product/class/product.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -5877,6 +5877,9 @@ public function load_stock($option = '', $includedraftpoforvirtual = null, $date
if (count($warehouseStatus)) {
$sql .= " AND w.statut IN (".$this->db->sanitize(implode(',', $warehouseStatus)).")";
}
if (getDolGlobalString('STOCK_USE_WAREHOUSE_USAGE')) {
$sql .= " AND w.warehouse_usage = 1";
}

$sql .= " ORDER BY ps.reel ".(getDolGlobalString('DO_NOT_TRY_TO_DEFRAGMENT_STOCKS_WAREHOUSE') ? 'DESC' : 'ASC'); // Note : qty ASC is important for expedition card, to avoid stock fragmentation;

Expand Down
17 changes: 17 additions & 0 deletions htdocs/product/stock/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
$object->country_id = GETPOST("country_id");
$object->phone = GETPOST("phone");
$object->fax = GETPOST("fax");
$object->warehouse_usage = GETPOST("warehouse_usage");

// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
Expand Down Expand Up @@ -966,6 +967,22 @@

print '</td></tr>';

// warehouse usage
if (getDolGlobalString('STOCK_USE_WAREHOUSE_USAGE')) {
print '<tr><td>'.$langs->trans("WarehouseUsage").'</td><td>';
print '<select id="warehouseusage" name="warehouse_usage" class="flat">';
foreach ($object->warehouse_usage_label as $key => $value) {
if ($key == $object->warehouse_usage) {
print '<option value="'.$key.'" selected>'.$langs->trans($value).'</option>';
} else {
print '<option value="'.$key.'">'.$langs->trans($value).'</option>';
}
}
print '</select>';
print ajax_combobox('warehouseusage');
print '</td></tr>';
}

// Other attributes
$parameters = array('colspan' => ' colspan="3"', 'cols' => '3');
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
Expand Down
23 changes: 21 additions & 2 deletions htdocs/product/stock/class/entrepot.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ class Entrepot extends CommonObject
*/
public $warehouse_usage;

/**
* @var array Warehouse usage ID labels
*/
public $warehouse_usage_label;

/**
* 'type' field format:
* 'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',
Expand Down Expand Up @@ -175,7 +180,7 @@ class Entrepot extends CommonObject
//'fk_user_author' =>array('type'=>'integer', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-2, 'position'=>82),
'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 300),
'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 301),
'warehouse_usage' => array('type' => 'integer', 'label' => 'WarehouseUsage', 'enabled' => 'getDolGlobalInt("MAIN_FEATURES_LEVEL")', 'visible' => 1, 'position' => 400, 'default' => 1, 'arrayofkeyval' => array(1 => 'InternalWarehouse', 2 => 'ExternalWarehouse')),
'warehouse_usage' => array('type' => 'integer', 'label' => 'WarehouseUsage', 'enabled' => 'getDolGlobalInt("STOCK_USE_WAREHOUSE_USAGE")', 'visible' => 1, 'position' => 400, 'default' => 1, 'arrayofkeyval' => array(1 => 'InternalWarehouse', 2 => 'ExternalWarehouse')),
//'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000),
//'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>1010),
'statut' => array('type' => 'tinyint(4)', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'position' => 500, 'css' => 'minwidth50'),
Expand Down Expand Up @@ -203,7 +208,15 @@ class Entrepot extends CommonObject
*/
const STATUS_OPENEXT_ALL = 3; // TODO Implement this

/**
* Warehouse is being used for stock calculations
*/
const WAREHOUSE_COUNT = 1;

/**
* Warehouse is NOT being used for stock calculations
*/
const WAREHOUSE_NOCOUNT = 2;

/**
* Constructor
Expand All @@ -223,6 +236,10 @@ public function __construct($db)
} else {
$this->labelStatus[self::STATUS_OPEN_ALL] = 'Opened';
}
$this->warehouse_usage_label[self::WAREHOUSE_COUNT] = 'WarehouseUsageCount';
if (getDolGlobalString('STOCK_USE_WAREHOUSE_USAGE')) {
$this->warehouse_usage_label[self::WAREHOUSE_NOCOUNT] = 'WarehouseUsageNoCount';
}
}

/**
Expand Down Expand Up @@ -355,6 +372,7 @@ public function update($id, $user, $notrigger = 0)
$sql .= ", fk_pays = ".((int) $this->country_id);
$sql .= ", phone = '".$this->db->escape($this->phone)."'";
$sql .= ", fax = '".$this->db->escape($this->fax)."'";
$sql .= ", warehouse_usage = '".$this->db->escape($this->warehouse_usage)."'";
$sql .= " WHERE rowid = ".((int) $id);

$this->db->begin();
Expand Down Expand Up @@ -507,7 +525,7 @@ public function fetch($id, $ref = '')
return -1;
}

$sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,";
$sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax, warehouse_usage,";
$sql .= " model_pdf, import_key";
$sql .= " FROM ".$this->db->prefix()."entrepot";
if ($id) {
Expand Down Expand Up @@ -539,6 +557,7 @@ public function fetch($id, $ref = '')
$this->country_id = $obj->country_id;
$this->phone = $obj->phone;
$this->fax = $obj->fax;
$this->warehouse_usage= $obj->warehouse_usage;

$this->model_pdf = $obj->model_pdf;
$this->import_key = $obj->import_key;
Expand Down

0 comments on commit bf265c5

Please sign in to comment.