NEW subproduct triggers in product class (#25142)

* NEW subproduct triggers in product class

* add notrigger parameter to functions

* add doc comment for new parameters

---------

Co-authored-by: Benjamin Falière <benjamin.faliere@altairis.fr>
This commit is contained in:
Benjamin Falière 2023-10-12 17:50:18 +02:00 committed by GitHub
parent 879c6d1e1f
commit 131fa0d52b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,7 +15,8 @@
* Copyright (C) 2016-2018 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2017 Gustavo Novaro
* Copyright (C) 2019-2023 Frédéric France <frederic.france@netlogic.fr>
*
* Copyright (C) 2023 Benjamin Falière <benjamin.faliere@altairis.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
@ -4254,10 +4255,13 @@ class Product extends CommonObject
* @param int $id_fils Id of child product/service
* @param int $qty Quantity
* @param int $incdec 1=Increase/decrease stock of child when parent stock increase/decrease
* @param int $notrigger Disable triggers
* @return int < 0 if KO, > 0 if OK
*/
public function add_sousproduit($id_pere, $id_fils, $qty, $incdec = 1)
public function add_sousproduit($id_pere, $id_fils, $qty, $incdec = 1, $notrigger = 0)
{
global $user;
// phpcs:enable
// Clean parameters
if (!is_numeric($id_pere)) {
@ -4296,6 +4300,17 @@ class Product extends CommonObject
dol_print_error($this->db);
return -1;
} else {
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('PRODUCT_SUBPRODUCT_ADD', $user);
if ($result < 0) {
$this->error = $this->db->lasterror();
dol_syslog(get_class($this).'::addSubproduct error='.$this->error, LOG_ERR);
return -1;
}
}
// End call triggers
return 1;
}
} else {
@ -4313,10 +4328,13 @@ class Product extends CommonObject
* @param int $id_fils Id of child product/service
* @param int $qty Quantity
* @param int $incdec 1=Increase/decrease stock of child when parent stock increase/decrease
* @param int $notrigger Disable triggers
* @return int < 0 if KO, > 0 if OK
*/
public function update_sousproduit($id_pere, $id_fils, $qty, $incdec = 1)
public function update_sousproduit($id_pere, $id_fils, $qty, $incdec = 1, $notrigger = 0)
{
global $user;
// phpcs:enable
// Clean parameters
if (!is_numeric($id_pere)) {
@ -4341,6 +4359,17 @@ class Product extends CommonObject
dol_print_error($this->db);
return -1;
} else {
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('PRODUCT_SUBPRODUCT_UPDATE', $user);
if ($result < 0) {
$this->error = $this->db->lasterror();
dol_syslog(get_class($this).'::updateSubproduct error='.$this->error, LOG_ERR);
return -1;
}
// End call triggers
}
return 1;
}
}
@ -4351,10 +4380,13 @@ class Product extends CommonObject
*
* @param int $fk_parent Id of parent product (child will no more be linked to it)
* @param int $fk_child Id of child product
* @param int $notrigger Disable triggers
* @return int < 0 if KO, > 0 if OK
*/
public function del_sousproduit($fk_parent, $fk_child)
public function del_sousproduit($fk_parent, $fk_child, $notrigger = 0)
{
global $user;
// phpcs:enable
if (!is_numeric($fk_parent)) {
$fk_parent = 0;
@ -4391,6 +4423,18 @@ class Product extends CommonObject
}
}
}
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('PRODUCT_SUBPRODUCT_DELETE', $user);
if ($result < 0) {
$this->error = $this->db->lasterror();
dol_syslog(get_class($this).'::delSubproduct error='.$this->error, LOG_ERR);
return -1;
}
// End call triggers
}
return 1;
}