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

Conflicts:
	htdocs/admin/dict.php
	htdocs/product/stock/replenish.php
This commit is contained in:
Laurent Destailleur 2021-05-17 10:47:00 +02:00
commit b2ba1f5540
3 changed files with 25 additions and 11 deletions

View File

@ -9,7 +9,7 @@
* Copyright (C) 2012-2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@ltairis.fr>
* Copyright (C) 2011-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2015-2021 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2015 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2019-2020 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
@ -819,9 +819,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
$sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
} elseif (in_array($keycode, array('joinfile', 'private', 'position', 'scale'))) {
$sql .= (int) GETPOST($keycode, 'int');
} elseif ($keycode == 'localtax2') {
$sql .= "'".GETPOST($keycode, 'alpha')."'";
} else {
} else {
$sql .= "'".$db->escape(GETPOST($keycode, 'nohtml'))."'";
}
@ -888,9 +886,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
$sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
} elseif (in_array($keycode, array('private', 'position', 'scale'))) {
$sql .= (int) GETPOST($keycode, 'int');
} elseif ($keycode == 'localtax2') {
$sql .= "'".GETPOST($keycode, 'alpha')."'";
} else {
} else {
$sql .= "'".$db->escape(GETPOST($keycode, 'nohtml'))."'";
}

View File

@ -278,6 +278,11 @@ class CommandeFournisseur extends CommonOrder
const STATUS_REFUSED = 9;
/**
* The constant used into source field to track the order was generated by the replenishement feature
*/
const SOURCE_ID_REPLENISHMENT = 42;
/**

View File

@ -205,17 +205,24 @@ if ($action == 'order' && GETPOST('valid'))
foreach ($suppliers as $supplier)
{
$order = new CommandeFournisseur($db);
// Check if an order for the supplier exists
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande_fournisseur";
$sql .= " WHERE fk_soc = ".$suppliersid[$i];
$sql .= " AND source = 42 AND fk_statut = 0";
$sql .= " WHERE fk_soc = ".((int) $suppliersid[$i]);
$sql .= " AND source = ".((int) $order::SOURCE_ID_REPLENISHMENT)." AND fk_statut = ".$order::STATUS_DRAFT;
$sql .= " AND entity IN (".getEntity('commande_fournisseur').")";
$sql .= " ORDER BY date_creation DESC";
$resql = $db->query($sql);
if ($resql && $db->num_rows($resql) > 0) {
$obj = $db->fetch_object($resql);
$order->fetch($obj->rowid);
$order->fetch_thirdparty();
foreach ($supplier['lines'] as $line) {
if (empty($line->remise_percent)) {
$line->remise_percent = $order->thirdparty->remise_supplier_percent;
}
$result = $order->addline(
$line->desc,
$line->subprice,
@ -249,13 +256,19 @@ if ($action == 'order' && GETPOST('valid'))
} else {
$order->socid = $suppliersid[$i];
$order->fetch_thirdparty();
//trick to know which orders have been generated this way
$order->source = 42;
// Trick to know which orders have been generated using the replenishment feature
$order->source = $order::SOURCE_ID_REPLENISHMENT;
foreach ($supplier['lines'] as $line) {
if (empty($line->remise_percent)) {
$line->remise_percent = $order->thirdparty->remise_supplier_percent;
}
$order->lines[] = $line;
}
$order->cond_reglement_id = $order->thirdparty->cond_reglement_supplier_id;
$order->mode_reglement_id = $order->thirdparty->mode_reglement_supplier_id;
$id = $order->create($user);
if ($id < 0) {
$fail++;