diff --git a/ChangeLog b/ChangeLog index 4ba65941254..00962b10419 100644 --- a/ChangeLog +++ b/ChangeLog @@ -106,6 +106,7 @@ NEW: when multiple order linked to facture, show list into note. NEW: when we delete several objects with massaction, if somes object has child we must see which objects are concerned and nevertheless delete objects which can be deleted NEW: Editing a page in website module keep old page with name .back NEW: External backups can be downloaded from the "About info page". +NEW: Add massaction to switch status on sale / on purchase of a product. For developers: diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 51a72d6beb2..ea94e76a84d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4132,12 +4132,13 @@ abstract class CommonObject * Set status of an object * * @param int $status Status to set - * @param int $elementId Id of element to force (use this->id by default) + * @param int $elementId Id of element to force (use this->id by default if null) * @param string $elementType Type of element to force (use this->table_element by default) - * @param string $trigkey Trigger key to use for trigger + * @param string $trigkey Trigger key to use for trigger. Use '' means automatic but it not recommended and is deprecated. + * @param string $fieldstatus Name of status field in this->table_element * @return int <0 if KO, >0 if OK */ - public function setStatut($status, $elementId = null, $elementType = '', $trigkey = '') + public function setStatut($status, $elementId = null, $elementType = '', $trigkey = '', $fieldstatus = 'fk_statut') { global $user, $langs, $conf; @@ -4148,7 +4149,6 @@ abstract class CommonObject $this->db->begin(); - $fieldstatus = "fk_statut"; if ($elementTable == 'facture_rec') { $fieldstatus = "suspended"; } @@ -4217,9 +4217,16 @@ abstract class CommonObject if (!$error) { $this->db->commit(); - if (empty($savElementId)) { // If the element we update was $this (so $elementId is null) - $this->statut = $status; - $this->status = $status; + if (empty($savElementId)) { + // If the element we update is $this (so $elementId was provided as null) + if ($fieldstatus == 'tosell') { + $this->status = $status; + } elseif ($fieldstatus == 'tobuy') { + $this->status_buy = $status; + } else { + $this->statut = $status; + $this->status = $status; + } } return 1; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 82ef8ff9697..94148722862 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3650,7 +3650,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $ 'technic', 'ticket', 'error', 'warning', 'recent', 'reception', 'recruitmentcandidature', 'recruitmentjobposition', 'resource', 'recurring', - 'shapes', 'supplier', 'supplier_proposal', 'supplier_order', 'supplier_invoice', + 'shapes', 'square', 'stop-circle', 'supplier', 'supplier_proposal', 'supplier_order', 'supplier_invoice', 'timespent', 'title_setup', 'title_accountancy', 'title_bank', 'title_hrm', 'title_agenda', 'uncheck', 'user-cog', 'vat', 'website', 'workstation', 'conferenceorbooth', 'eventorganization' @@ -3797,7 +3797,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $ 'other'=>'#ddd', 'partnership'=>'#6c6aa8', 'playdisabled'=>'#ccc', 'printer'=>'#444', 'projectpub'=>'#986c6a', 'reception'=>'#a69944', 'resize'=>'#444', 'rss'=>'#cba', //'shipment'=>'#a69944', - 'security'=>'#999', 'stats'=>'#444', 'switch_off'=>'#999', 'technic'=>'#999', 'timespent'=>'#555', + 'security'=>'#999', 'square'=>'#888', 'stop-circle'=>'#888', 'stats'=>'#444', 'switch_off'=>'#999', 'technic'=>'#999', 'timespent'=>'#555', 'uncheck'=>'#800', 'uparrow'=>'#555', 'user-cog'=>'#999', 'country'=>'#aaa', 'globe-americas'=>'#aaa', 'region'=>'#aaa', 'state'=>'#aaa', 'website'=>'#304', 'workstation'=>'#a69944' ); diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 9a6efce02b0..a8ec90a47ab 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -408,3 +408,5 @@ mandatoryHelper=Message to the user on the need to enter a start date and an end DefaultBOM=Default BOM DefaultBOMDesc=The default BOM recommended to use to manufacture this product. This field can be set only if nature of product is '%s'. Rank=Rank +SwitchOnSaleStatus=Switch on sale status +SwitchOnPurchaseStatus=Switch on purchase status diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 14d9b320e8e..949158289a0 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -355,6 +355,25 @@ if (empty($reshook)) { $permissiontoadd = $user->rights->{$rightskey}->creer; $uploaddir = $conf->product->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; + + if (!$error && $massaction == 'switchonsalestatus' && $permissiontoadd) { + $product = new Product($db); + foreach ($toselect as $toselectid) { + $result = $product->fetch($toselectid); + if ($result > 0 && $product->id > 0) { + $product->setStatut($product->status ? 0 : 1, null, 'product', 'PRODUCT_MODIFY', 'tosell'); + } + } + } + if (!$error && $massaction == 'switchonpurchasestatus' && $permissiontoadd) { + $product = new Product($db); + foreach ($toselect as $toselectid) { + $result = $product->fetch($toselectid); + if ($result > 0 && $product->id > 0) { + $product->setStatut($product->status_buy ? 0 : 1, null, 'product', 'PRODUCT_MODIFY', 'tobuy'); + } + } + } } @@ -710,6 +729,8 @@ if ($resql) { $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); } if ($user->rights->{$rightskey}->creer) { + $arrayofmassactions['switchonsalestatus'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SwitchOnSaleStatus"); + $arrayofmassactions['switchonpurchasestatus'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SwitchOnPurchaseStatus"); $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag"); } if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) {