NEW: Add massaction to switch status on sale / on purchase of a product.

This commit is contained in:
Laurent Destailleur 2021-12-06 02:48:34 +01:00
parent eb60e3c16d
commit 259b7dfe5a
5 changed files with 40 additions and 9 deletions

View File

@ -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:

View File

@ -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;

View File

@ -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'
);

View File

@ -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

View File

@ -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'))) {