Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2022-08-22 13:20:10 +02:00
commit 5ada158e03
5 changed files with 23 additions and 50 deletions

View File

@ -181,24 +181,10 @@ if (empty($reshook)) {
} }
if (!$error) { if (!$error) {
$bomline = new BOMLine($db); $result = $object->addLine($idprod, $qty, $qty_frozen, $disable_stock_change, $efficiency, -1, $bom_child_id, null);
$bomline->fk_bom = $id;
$bomline->fk_product = $idprod;
$bomline->fk_bom_child = $bom_child_id;
$bomline->qty = $qty;
$bomline->qty_frozen = (int) $qty_frozen;
$bomline->disable_stock_change = (int) $disable_stock_change;
$bomline->efficiency = $efficiency;
// Rang to use
$rangmax = $object->line_max(0);
$ranktouse = $rangmax + 1;
$bomline->position = ($ranktouse + 1);
$result = $bomline->create($user);
if ($result <= 0) { if ($result <= 0) {
setEventMessages($bomline->error, $bomline->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
$action = ''; $action = '';
} else { } else {
unset($_POST['idprod']); unset($_POST['idprod']);
@ -207,13 +193,11 @@ if (empty($reshook)) {
unset($_POST['disable_stock_change']); unset($_POST['disable_stock_change']);
$object->fetchLines(); $object->fetchLines();
$object->calculateCosts();
} }
} }
} }
// Add line // Update line
if ($action == 'updateline' && $user->rights->bom->write) { if ($action == 'updateline' && $user->rights->bom->write) {
$langs->load('errors'); $langs->load('errors');
$error = 0; $error = 0;
@ -229,26 +213,23 @@ if (empty($reshook)) {
$error++; $error++;
} }
$bomline = new BOMLine($db); if (!$error) {
$bomline->fetch($lineid); $bomline = new BOMLine($db);
$bomline->qty = $qty; $bomline->fetch($lineid);
$bomline->qty_frozen = (int) $qty_frozen;
$bomline->disable_stock_change = (int) $disable_stock_change;
$bomline->efficiency = $efficiency;
$result = $bomline->update($user); $result = $object->updateLine($lineid, $qty, (int) $qty_frozen, (int) $disable_stock_change, $efficiency, $bomline->position, $bomline->import_key);
if ($result <= 0) {
setEventMessages($bomline->error, $bomline->errors, 'errors');
$action = '';
} else {
unset($_POST['idprod']);
unset($_POST['qty']);
unset($_POST['qty_frozen']);
unset($_POST['disable_stock_change']);
$object->fetchLines(); if ($result <= 0) {
setEventMessages($object->error, $object->errors, 'errors');
$action = '';
} else {
unset($_POST['idprod']);
unset($_POST['qty']);
unset($_POST['qty_frozen']);
unset($_POST['disable_stock_change']);
$object->calculateCosts(); $object->fetchLines();
}
} }
} }
} }

View File

@ -391,7 +391,6 @@ class Boms extends DolibarrApi
$request_data->disable_stock_change, $request_data->disable_stock_change,
$request_data->efficiency, $request_data->efficiency,
$request_data->position, $request_data->position,
$request_data->fk_bom_child,
$request_data->import_key $request_data->import_key
); );

View File

@ -517,7 +517,6 @@ class BOM extends CommonObject
*/ */
public function addLine($fk_product, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $fk_bom_child = null, $import_key = null) public function addLine($fk_product, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $fk_bom_child = null, $import_key = null)
{ {
global $mysoc, $conf, $langs, $user; global $mysoc, $conf, $langs, $user;
$logtext = "::addLine bomid=$this->id, qty=$qty, fk_product=$fk_product, qty_frozen=$qty_frozen, disable_stock_change=$disable_stock_change, efficiency=$efficiency"; $logtext = "::addLine bomid=$this->id, qty=$qty, fk_product=$fk_product, qty_frozen=$qty_frozen, disable_stock_change=$disable_stock_change, efficiency=$efficiency";
@ -612,17 +611,15 @@ class BOM extends CommonObject
* @param int $disable_stock_change Disable stock change on using in MO * @param int $disable_stock_change Disable stock change on using in MO
* @param float $efficiency Efficiency in MO * @param float $efficiency Efficiency in MO
* @param int $position Position of BOM-Line in BOM-Lines * @param int $position Position of BOM-Line in BOM-Lines
* @param int $fk_bom_child Id of BOM Child
* @param string $import_key Import Key * @param string $import_key Import Key
* @return int <0 if KO, Id of updated BOM-Line if OK * @return int <0 if KO, Id of updated BOM-Line if OK
*/ */
public function updateLine($rowid, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $fk_bom_child = null, $import_key = null) public function updateLine($rowid, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $import_key = null)
{ {
global $mysoc, $conf, $langs, $user; global $mysoc, $conf, $langs, $user;
$logtext = "::updateLine bomid=$this->id, qty=$qty, qty_frozen=$qty_frozen, disable_stock_change=$disable_stock_change, efficiency=$efficiency"; $logtext = "::updateLine bomid=$this->id, qty=$qty, qty_frozen=$qty_frozen, disable_stock_change=$disable_stock_change, efficiency=$efficiency";
$logtext .= ", fk_bom_child=$fk_bom_child, import_key=$import_key"; $logtext .= ", import_key=$import_key";
dol_syslog(get_class($this).$logtext, LOG_DEBUG); dol_syslog(get_class($this).$logtext, LOG_DEBUG);
if ($this->statut == self::STATUS_DRAFT) { if ($this->statut == self::STATUS_DRAFT) {
@ -641,9 +638,6 @@ class BOM extends CommonObject
if (empty($efficiency)) { if (empty($efficiency)) {
$efficiency = 1.0; $efficiency = 1.0;
} }
if (empty($fk_bom_child)) {
$fk_bom_child = null;
}
if (empty($import_key)) { if (empty($import_key)) {
$import_key = null; $import_key = null;
} }
@ -688,7 +682,6 @@ class BOM extends CommonObject
$this->line->qty_frozen = $qty_frozen; $this->line->qty_frozen = $qty_frozen;
$this->line->disable_stock_change = $disable_stock_change; $this->line->disable_stock_change = $disable_stock_change;
$this->line->efficiency = $efficiency; $this->line->efficiency = $efficiency;
$this->line->fk_bom_child = $fk_bom_child;
$this->line->import_key = $import_key; $this->line->import_key = $import_key;
$this->line->position = $rankToUse; $this->line->position = $rankToUse;

View File

@ -9372,16 +9372,16 @@ function dol_set_focus($selector)
/** /**
* Return getmypid() or random PID when function is disabled * Return getmypid() or random PID when function is disabled
* Some web hosts disable this php function for security reasons * Some web hosts disable this php function for security reasons
* and sometimes we can't redeclare function * and sometimes we can't redeclare function.
* *
* @return int * @return int
*/ */
function dol_getmypid() function dol_getmypid()
{ {
if (!function_exists('getmypid')) { if (!function_exists('getmypid')) {
return mt_rand(1, 32768); return mt_rand(99900000, 99965535);
} else { } else {
return getmypid(); return getmypid(); // May be a number on 64 bits (depending on OS)
} }
} }

View File

@ -209,7 +209,7 @@ if ($object->id > 0) {
if (get_class($objthirdparty) == 'Societe') { if (get_class($objthirdparty) == 'Societe') {
$out .= '&amp;socid='.$objthirdparty->id; $out .= '&amp;socid='.$objthirdparty->id;
} }
$out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '').'&amp;backtopage=1&amp;percentage=-1'; $out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '').'&amp;backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'&amp;percentage=-1';
//$out.=$langs->trans("AddAnAction").' '; //$out.=$langs->trans("AddAnAction").' ';
//$out.=img_picto($langs->trans("AddAnAction"),'filenew'); //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
//$out.="</a>"; //$out.="</a>";