Add clean conditions to show "create purchase order" button in sale order card (#29906)

* Add clean conditions to show "create purchase order" button in sale order card

* Add clean conditions to show "create purchase order" button in sale order card

* Add clean conditions to show "create purchase order" button in sale order card
This commit is contained in:
Vincent Maury 2024-06-08 02:48:59 +02:00 committed by GitHub
parent a362532f0b
commit 19f68b0b67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 3 deletions

View file

@ -2949,11 +2949,12 @@ if ($action == 'create' && $usercancreate) {
}
$arrayforbutaction = array();
// Create a purchase order
$arrayforbutaction[] = array('lang'=>'orders', 'enabled'=>(isModEnabled("supplier_order") && $object->statut > Commande::STATUS_DRAFT && $object->getNbOfServicesLines() > 0), 'perm'=>$usercancreatepurchaseorder, 'label'=>'AddPurchaseOrder', 'url'=>'/fourn/commande/card.php?action=create&origin='.$object->element.'&originid='.$object->id);
if (getDolGlobalInt('COMMANDE_DISABLE_ADD_PURCHASE_ORDER') == 0) {
$arrayforbutaction[] = array('lang'=>'orders', 'enabled'=>(isModEnabled("supplier_order") && $object->statut > Commande::STATUS_DRAFT && $object->getNbLinesProductOrServiceOnBuy(getDolGlobalInt('COMMANDE_ADD_PURCHASE_ORDER_IGNORE_FREE_PRODUCTS')) > 0), 'perm'=>$usercancreatepurchaseorder, 'label'=>'AddPurchaseOrder', 'url'=>'/fourn/commande/card.php?action=create&origin='.$object->element.'&originid='.$object->id);
}
/*if (isModEnabled("supplier_order") && $object->statut > Commande::STATUS_DRAFT && $object->getNbOfServicesLines() > 0) {
if ($usercancreatepurchaseorder) {
if ($usercancreatepurchaseorder) { isModEnabled("supplier_order") && $object->statut > Commande::STATUS_DRAFT && $object->getNbOfServicesLines() > 0
print dolGetButtonAction('', $langs->trans('AddPurchaseOrder'), 'default', DOL_URL_ROOT.'/fourn/commande/card.php?action=create&origin='.$object->element.'&originid='.$object->id, '');
}
}*/

View file

@ -71,6 +71,28 @@ abstract class CommonOrder extends CommonObject
return $return;
}
/** return nb of fines of order where products or services that can be buyed
*
* @param boolean $ignoreFree Ignore free lines
* @return int number of products or services on buy in a command
*/
public function getNbLinesProductOrServiceOnBuy($ignoreFree = false)
{
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
$product = new Product($this->db);
$return = 0;
foreach ($this->lines as $line) {
if (empty($line->fk_product) && !$ignoreFree) {
$return ++;
} elseif ((int) $line->fk_product > 0) {
if ($product->fetch($line->fk_product) > 0) {
if ($product->status_buy) $return ++;
}
}
}
return $return;
}
/**
* @var string code
*/