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

FIX - Repair the replenishment list #29336

Merged
merged 10 commits into from
Apr 17, 2024

Conversation

atm-lucasmantegari
Copy link
Contributor

FIX - Repair the replenishment list

Repair the replenishment list which was not sorted correctly with the warehouses

@eldy eldy added the PR to fix - See feedback in comments PR needs to be fixed to be integrated (some comments should describes the fix to do) label Apr 12, 2024
@atm-lucasmantegari
Copy link
Contributor Author

@eldy

I solved the problem this way, is this the best solution?

$list_warehouse_selected = ($fk_entrepot < 0) ? '0' : $fk_entrepot;

$sql .= ' FROM ' . MAIN_DB_PREFIX . 'product as p';
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_stock as s ON p.rowid = s.fk_product';
if ($list_warehouse_selected == 0) {
	$list_warehouse = (empty($listofqualifiedwarehousesid) ? '0' : $listofqualifiedwarehousesid);
	$sql .= ' AND s.fk_entrepot  IN (' . $db->sanitize($list_warehouse) . ')';
} else {
	$sql .= ' AND s.fk_entrepot  IN (' . $db->sanitize($list_warehouse_selected) . ')';
}

@eldy
Copy link
Member

eldy commented Apr 15, 2024

The $listofqualifiedwarehousesid is a security protection. It is list of warehouse allowed according to the multicompany we are connected to.
So the test on it must ALWAYS be present. With your suggested change if a filter is set, you can bypass the security filter.
Then if there is a custom filter, the filter must be added.

@atm-lucasmantegari
Copy link
Contributor Author

@eldy

With these modifications everything is good and works correctly while maintaining the security test on the entity's warehouses.

$list_warehouse = (empty($listofqualifiedwarehousesid) ? '0' : $listofqualifiedwarehousesid);

$sql .= ' FROM ' . MAIN_DB_PREFIX . 'product as p';
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_stock as s ON p.rowid = s.fk_product';
$sql .= ' AND s.fk_entrepot  IN (' . $db->sanitize($list_warehouse) . ')';

$list_warehouse_selected = ($fk_entrepot < 0) ? '0' : $fk_entrepot;
$sql .= ' AND s.fk_entrepot  IN (' . $db->sanitize($list_warehouse_selected) . ')';

@eldy
Copy link
Member

eldy commented Apr 15, 2024

@eldy

With these modifications everything is good and works correctly while maintaining the security test on the entity's warehouses.

$list_warehouse = (empty($listofqualifiedwarehousesid) ? '0' : $listofqualifiedwarehousesid);

$sql .= ' FROM ' . MAIN_DB_PREFIX . 'product as p';
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_stock as s ON p.rowid = s.fk_product';
$sql .= ' AND s.fk_entrepot  IN (' . $db->sanitize($list_warehouse) . ')';

$list_warehouse_selected = ($fk_entrepot < 0) ? '0' : $fk_entrepot;
$sql .= ' AND s.fk_entrepot  IN (' . $db->sanitize($list_warehouse_selected) . ')';

Looks better. Can you confirm that when product_stock is empty for product or just into non zllowed or not the filtered watehouse, the line of product is returned (but qty will be viewed as 0)

@atm-lucasmantegari
Copy link
Contributor Author

@eldy

Yes I confirm this, however the sorting on the selected warehouse only happens when the pse.desiredstock is >0

@eldy eldy merged commit 31ce8f8 into Dolibarr:18.0 Apr 17, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR to fix - See feedback in comments PR needs to be fixed to be integrated (some comments should describes the fix to do)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants