Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW : allow stock management by product #30230

Open
wants to merge 37 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
387d272
Update as proposed
aspangaro Oct 12, 2023
7c03476
Code part
aspangaro Jun 11, 2023
53645ff
Code part 2
thomas-Ngr Oct 12, 2023
29904fd
Fix : invert a const
thomas-Ngr Oct 12, 2023
8dd43c8
Fix : invert disable/enable stock values
thomas-Ngr Oct 17, 2023
1566d18
Fix
MaximilienR-easya Feb 15, 2024
7b3262c
Merge branch 'Dolibarr:develop' into develop_new-stockableproduct
MaximilienR-easya Feb 15, 2024
2362323
phpcs
MaximilienR-easya Feb 15, 2024
4944282
Fix missing column from select inside sql request
MaximilienR-easya Feb 15, 2024
1a6ad59
Fix input hidden missing name
MaximilienR-easya Feb 15, 2024
ab52991
ajout d'un commentaire
MaximilienR-easya Feb 16, 2024
63cab3b
Merge branch 'develop' into develop_new-stockableproduct
thomas-Ngr Mar 25, 2024
cb731c1
small fixes
Mar 13, 2024
ec71157
remove unrelated lines
thomas-Ngr Apr 16, 2024
b1e6de6
stickler fix
thomas-Ngr Apr 16, 2024
014b504
pre-commit fixes
thomas-Ngr Apr 19, 2024
7ed6877
pre-commit fixes
thomas-Ngr May 14, 2024
c34c7e9
pre-commit fix
thomas-Ngr May 14, 2024
ede7e03
phan fix
thomas-Ngr May 14, 2024
dba9f7b
Merge branch 'develop' into develop_new-stockableproduct
thomas-Ngr May 28, 2024
810d4a3
fix missing translation
thomas-Ngr May 28, 2024
a308088
Merge branch 'develop' into develop_new-stockableproduct
thomas-Ngr Jun 10, 2024
dd45b38
Fix phpstan
thomas-Ngr Jun 10, 2024
57e455d
Merge branch 'develop' into develop_new-stockableproduct
thomas-Ngr Jun 10, 2024
28517af
fix winCI
thomas-Ngr Jun 10, 2024
a47396f
Merge branch 'develop' into develop_new-stockableproduct
thomas-Ngr Jul 1, 2024
a055302
remove french translations
thomas-Ngr Jul 17, 2024
c3f6546
right type and value for property ExpeditionLigne::stockable_product
thomas-Ngr Jul 17, 2024
62c1f29
Forbid to have products with batch numbers not managed in stock. Allo…
thomas-Ngr Jul 19, 2024
d38c728
Merge branch 'develop' into develop_new-stockableproduct_2
thomas-Ngr Jul 19, 2024
acc97e9
Merge branch 'develop' into develop_new-stockableproduct_2
thomas-Ngr Aug 2, 2024
9ce2ab2
fix Phan
thomas-Ngr Aug 2, 2024
2ac2deb
try to fix PHAN
thomas-Ngr Aug 2, 2024
260f73a
try to fix PHAN
thomas-Ngr Aug 2, 2024
78e6d43
Merge remote-tracking branch 'origin/develop' into develop_new-stocka…
thomas-Ngr Aug 28, 2024
cc60e9f
Merge branch 'develop' into develop_new-stockableproduct_2
thomas-Ngr Sep 5, 2024
91d7bca
Phan suggestion
thomas-Ngr Sep 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion htdocs/core/lib/product.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function product_prepare_head($object)
$h++;
}

if ($object->isProduct() || ($object->isService() && getDolGlobalString('STOCK_SUPPORTS_SERVICES'))) { // If physical product we can stock (or service with option)
if (($object->isProduct() || ($object->isService() && getDolGlobalString('STOCK_SUPPORTS_SERVICES'))) && $object->stockable_product == Product::ENABLED_STOCK) { // If physical product we can stock (or service with option)
if (isModEnabled('stock') && $user->hasRight('stock', 'lire')) {
$head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$object->id;
$head[$h][1] = $langs->trans("Stock");
Expand Down
38 changes: 27 additions & 11 deletions htdocs/expedition/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
$subtotalqty = 0;

$j = 0;

$batch = "batchl".$i."_0";
$stockLocation = "ent1".$i."_0";
$qty = "qtyl".$i;
Expand Down Expand Up @@ -394,7 +395,7 @@
$nbstockline = count($stockLine[$i]);
for ($j = 0; $j < $nbstockline; $j++) {
if ($stockLine[$i][$j]['qty'] > 0 || ($stockLine[$i][$j]['qty'] == 0 && getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
$ret = $object->addline($stockLine[$i][$j]['warehouse_id'], $stockLine[$i][$j]['ix_l'], $stockLine[$i][$j]['qty'], $array_options[$i]);
$ret = $object->addline($stockLine[$i][$j]['warehouse_id'], $stockLine[$i][$j]['ix_l'], $stockLine[$i][$j]['qty'], $array_options[$i], (bool) $product->stockable_product);
if ($ret < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$error++;
Expand All @@ -413,7 +414,7 @@
$entrepot_id = 0;
}

$ret = $object->addline($entrepot_id, GETPOSTINT($idl), price2num(GETPOSTINT($qty), 'MS'), $array_options[$i]);
$ret = $object->addline($entrepot_id, GETPOSTINT($idl), price2num(GETPOSTINT($qty), 'MS'), $array_options[$i], (bool) $product->stockable_product);
if ($ret < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$error++;
Expand Down Expand Up @@ -1240,7 +1241,7 @@
$text = $product_static->getNomUrl(1);
$text .= ' - '.(!empty($line->label) ? $line->label : $line->product_label);
$description = ($showdescinproductdesc ? '' : dol_htmlentitiesbr($line->desc));

$description .= empty($product->stockable_product) ? $langs->trans('StockDisabled') : $langs->trans('StockEnabled');
print $form->textwithtooltip($text, $description, 3, '', '', $i);

// Show range
Expand Down Expand Up @@ -1350,8 +1351,11 @@
if (!getDolGlobalInt('STOCK_ALLOW_NEGATIVE_TRANSFER')) {
$stockMin = 0;
}
print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 1, 0, $line->fk_product, '', 1, 0, array(), 'minwidth200', '', 1, $stockMin, 'stock DESC, e.ref');

if ($product->stockable_product == Product::ENABLED_STOCK) {
print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 1, 0, $line->fk_product, '', 1, 0, array(), 'minwidth200', '', 1, $stockMin, 'stock DESC, e.ref');
} else {
print img_warning().' '.$langs->trans('StockDisabled');
}
if ($tmpentrepot_id > 0 && $tmpentrepot_id == $warehouse_id) {
//print $stock.' '.$quantityToBeDelivered;
if ($stock < $quantityToBeDelivered) {
Expand Down Expand Up @@ -1582,10 +1586,13 @@
if (isModEnabled('stock')) {
print '<td class="left">';
if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
print $tmpwarehouseObject->getNomUrl(0).' ';

print '<!-- Show details of stock -->';
print '('.$stock.')';
if ($product->stockable_product == Product::ENABLED_STOCK) {
print $tmpwarehouseObject->getNomUrl(0).' ';
print '<!-- Show details of stock -->';
print '('.$stock.')';
} else {
print img_warning().' '.$langs->trans('StockDisabled');
}
} else {
print '<span class="opacitymedium">('.$langs->trans("Service").')</span>';
}
Expand Down Expand Up @@ -1745,6 +1752,10 @@
if ($warehouse_selected_id <= 0) { // We did not force a given warehouse, so we won't have no warehouse to change qty.
$disabled = 'disabled="disabled"';
}
// finally we overwrite the input with the product status stockable_product if it's disabled
if ($product->stockable_product == Product::DISABLED_STOCK) {
$disabled = '';
}
print '<input class="qtyl right" name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="0"'.($disabled ? ' '.$disabled : '').'> ';
if (empty($disabled) && getDolGlobalString('STOCK_ALLOW_NEGATIVE_TRANSFER')) {
print '<input name="ent1' . $indiceAsked . '_' . $subj . '" type="hidden" value="' . $warehouse_selected_id . '">';
Expand All @@ -1762,7 +1773,11 @@
print img_warning().' '.$langs->trans("NoProductToShipFoundIntoStock", $warehouseObject->label);
} else {
if ($line->fk_product) {
print img_warning().' '.$langs->trans("StockTooLow");
if ($product->stockable_product == Product::ENABLED_STOCK) {
print img_warning().' '.$langs->trans('StockTooLow');
} else {
print img_warning().' '.$langs->trans('StockDisabled');
}
} else {
print '';
}
Expand Down Expand Up @@ -2370,6 +2385,7 @@
$product_static->surface_units = $lines[$i]->surface_units;
$product_static->volume = $lines[$i]->volume;
$product_static->volume_units = $lines[$i]->volume_units;
$product_static->stockable_product = $lines[$i]->stockable_product;

$text = $product_static->getNomUrl(1);
$text .= ' - '.$label;
Expand Down Expand Up @@ -2540,7 +2556,7 @@
print '<td class="linecolwarehousesource tdoverflowmax200">';
if ($lines[$i]->product_type == Product::TYPE_SERVICE && getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) {
print '<span class="opacitymedium">('.$langs->trans("Service").')</span>';
} elseif ($lines[$i]->entrepot_id > 0) {
} elseif ($lines[$i]->entrepot_id > 0 && $lines[$i]->stockable_product == Product::ENABLED_STOCK) {
$entrepot = new Entrepot($db);
$entrepot->fetch($lines[$i]->entrepot_id);
print $entrepot->getNomUrl(1);
Expand Down
26 changes: 19 additions & 7 deletions htdocs/expedition/class/expedition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -923,9 +923,10 @@ public function create_delivery($user)
* @param int $id Id of source line (order line)
* @param float $qty Quantity
* @param array $array_options extrafields array
* @param bool $stock_managed should we manage stock ?
* @return int Return integer <0 if KO, >0 if OK
*/
public function addline($entrepot_id, $id, $qty, $array_options = [])
public function addline($entrepot_id, $id, $qty, $array_options = [], $stock_managed = true)
{
global $conf, $langs;

Expand All @@ -948,13 +949,13 @@ public function addline($entrepot_id, $id, $qty, $array_options = [])
if (isModEnabled('stock') && !empty($orderline->fk_product)) {
$fk_product = $orderline->fk_product;

if (!($entrepot_id > 0) && !getDolGlobalString('STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS') && !(getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES') && $line->product_type == Product::TYPE_SERVICE)) {
if ($stock_managed && !($entrepot_id > 0) && !getDolGlobalString('STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS') && !(getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES') && $line->product_type == Product::TYPE_SERVICE)) {
$langs->load("errors");
$this->error = $langs->trans("ErrorWarehouseRequiredIntoShipmentLine");
return -1;
}

if (getDolGlobalString('STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT')) {
if ($stock_managed && getDolGlobalString('STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT')) {
$product = new Product($this->db);
$product->fetch($fk_product);

Expand All @@ -971,7 +972,7 @@ public function addline($entrepot_id, $id, $qty, $array_options = [])
$isavirtualproduct = ($product->hasFatherOrChild(1) > 0);
// The product is qualified for a check of quantity (must be enough in stock to be added into shipment).
if (!$isavirtualproduct || !getDolGlobalString('PRODUIT_SOUSPRODUITS') || ($isavirtualproduct && !getDolGlobalString('STOCK_EXCLUDE_VIRTUAL_PRODUCTS'))) { // If STOCK_EXCLUDE_VIRTUAL_PRODUCTS is set, we do not manage stock for kits/virtual products.
if ($product_stock < $qty) {
if ($product_stock < $qty && $product->stockable_product == Product::ENABLED_STOCK) {
$langs->load("errors");
$this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
$this->errorhidden = 'ErrorStockIsNotEnoughToAddProductOnShipment';
Expand Down Expand Up @@ -1627,7 +1628,9 @@ public function fetch_lines()
$sql .= ", cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc, cd.rang, cd.date_start, cd.date_end";
$sql .= ", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_element, ed.fk_elementdet, ed.element_type, ed.fk_entrepot";
$sql .= ", p.ref as product_ref, p.label as product_label, p.fk_product_type, p.barcode as product_barcode";
$sql .= ", p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units, p.tosell as product_tosell, p.tobuy as product_tobuy, p.tobatch as product_tobatch";
$sql .= ", p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units";
$sql .= ", p.surface, p.surface_units, p.volume, p.volume_units, p.tosell as product_tosell, p.tobuy as product_tobuy";
$sql .= ", p.tobatch as product_tobatch, p.stockable_product";
$sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = cd.fk_product";
$sql .= " WHERE ed.fk_expedition = ".((int) $this->id);
Expand Down Expand Up @@ -1690,6 +1693,7 @@ public function fetch_lines()

$line->fk_expedition = $this->id; // id of parent

$line->stockable_product = $obj->stockable_product;
$line->product_type = $obj->product_type;
$line->fk_product = $obj->fk_product;
$line->fk_product_type = $obj->fk_product_type;
Expand Down Expand Up @@ -1717,8 +1721,9 @@ public function fetch_lines()
$line->surface = $obj->surface;
$line->surface_units = $obj->surface_units;
$line->volume = $obj->volume;
$line->volume_units = $obj->volume_units;
$line->fk_unit = $obj->fk_unit;
$line->volume_units = $obj->volume_units;
$line->stockable_product = $obj->stockable_product;
$line->fk_unit = $obj->fk_unit;

$line->pa_ht = $obj->pa_ht;

Expand Down Expand Up @@ -2829,6 +2834,13 @@ class ExpeditionLigne extends CommonObjectLine
public $volume;
public $volume_units;

/**
* 0=This service or product is not managed in stock, 1=This service or product is managed in stock
*
* @var bool
*/
public $stockable_product = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public $stockable_product = 1;


// Invoicing
public $remise_percent;
public $tva_tx;
Expand Down
Loading
Loading