This commit is contained in:
Laurent Destailleur 2020-02-03 04:48:17 +01:00
parent 1dab308e4a
commit e5808e3335
2 changed files with 13 additions and 2 deletions

View File

@ -155,6 +155,8 @@ if (empty($reshook))
if (!$error)
{
$lastposition = 0;
$bomline = new BOMLine($db);
$bomline->fk_bom = $id;
$bomline->fk_product = $idprod;
@ -163,6 +165,12 @@ if (empty($reshook))
$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)
{

View File

@ -2744,10 +2744,13 @@ abstract class CommonObject
public function line_max($fk_parent_line = 0)
{
// phpcs:enable
$positionfield = 'rang';
if ($this->table_element = 'bom') $positionfield = 'position';
// Search the last rang with fk_parent_line
if ($fk_parent_line)
{
$sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql = 'SELECT max('.$positionfield.') FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql .= ' WHERE '.$this->fk_element.' = '.$this->id;
$sql .= ' AND fk_parent_line = '.$fk_parent_line;
@ -2769,7 +2772,7 @@ abstract class CommonObject
// If not, search the last rang of element
else
{
$sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql = 'SELECT max('.$positionfield.') FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql .= ' WHERE '.$this->fk_element.' = '.$this->id;
dol_syslog(get_class($this)."::line_max", LOG_DEBUG);