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

This commit is contained in:
Laurent Destailleur 2020-01-18 19:53:58 +01:00
commit a1b03e094c
2 changed files with 51 additions and 60 deletions

View File

@ -154,51 +154,32 @@ class StockMovements extends DolibarrApi
return $obj_ret;
}
/*
* @param int $product_id Id product id {@min 1}
* @param int $warehouse_id Id warehouse {@min 1}
* @param float $qty Qty to add (Use negative value for a stock decrease) {@min 0} {@message qty must be higher than 0}
* @param string $lot Lot
* @param string $movementcode Movement code {@example INV123}
* @param string $movementlabel Movement label {@example Inventory number 123}
* @param string $price To update AWP (Average Weighted Price) when you make a stock increase (qty must be higher then 0).
*/
/**
* Create stock movement object.
* You can use the following message to test this RES API:
* { "product_id": 1, "warehouse_id": 1, "qty": 1, "lot": "", "movementcode": "INV123", "movementlabel": "Inventory 123", "price": 0 }
* @param int $product_id Id product id {@min 1} {@from body} {@required true}
* @param int $warehouse_id Id warehouse {@min 1} {@from body} {@required true}
* @param float $qty Qty to add (Use negative value for a stock decrease) {@min 0} {@message qty must be higher than 0} {@from body} {@required true}
* @param string $lot Lot {@from body}
* @param string $movementcode Movement code {@example INV123} {@from body}
* @param string $movementlabel Movement label {@example Inventory number 123} {@from body}
* @param string $price To update AWP (Average Weighted Price) when you make a stock increase (qty must be higher then 0). {@from body}
* @param string $dlc {@from body} {@type date}
* @param string $dluo {@from body} {@type date}
*
* @param array $request_data Request data
* @return int ID of stock movement
* @throws RestException
*/
//function post($product_id, $warehouse_id, $qty, $lot='', $movementcode='', $movementlabel='', $price=0)
public function post($request_data = null)
public function post($product_id, $warehouse_id, $qty, $lot = '', $movementcode = '', $movementlabel = '', $price = '', $dlc = '', $dluo = '')
{
if(! DolibarrApiAccess::$user->rights->stock->creer) {
throw new RestException(401);
}
// Check mandatory fields
//$result = $this->_validate($request_data);
foreach($request_data as $field => $value) {
//$this->stockmovement->$field = $value;
if ($field == 'product_id') $product_id = $value;
if ($field == 'warehouse_id') $warehouse_id = $value;
if ($field == 'qty') $qty = $value;
if ($field == 'lot') $lot = $value;
if ($field == 'movementcode') $movementcode = $value;
if ($field == 'movementlabel') $movementlabel = $value;
if ($field == 'price') $price = $value;
}
// Type increase or decrease
if ($qty >= 0) $type = 3;
else $type = 2;
if($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, '', '', '', $lot) <= 0) {
if($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, '', $dlc, $dluo, $lot) <= 0) {
throw new RestException(503, 'Error when create stock movement : '.$this->stockmovement->error);
}
@ -342,7 +323,7 @@ class StockMovements extends DolibarrApi
private function _validate($data)
{
$stockmovement = array();
foreach (Warehouses::$FIELDS as $field) {
foreach (self::$FIELDS as $field) {
if (!isset($data[$field]))
throw new RestException(400, "$field field missing");
$stockmovement[$field] = $data[$field];

View File

@ -5,7 +5,7 @@
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2008 Patrick Raguin <patrick.raguin@auguria.net>
* Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2011-2013 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
@ -1070,13 +1070,13 @@ else
$linkback = "";
print load_fiche_titre($langs->trans("NewThirdParty"), $linkback, 'building');
if (!empty($conf->use_javascript_ajax) && !empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION))
{
print "\n".'<script type="text/javascript">';
print '$(document).ready(function () {
if (!empty($conf->use_javascript_ajax)) {
if (!empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION)) {
print "\n" . '<script type="text/javascript">';
print '$(document).ready(function () {
id_te_private=8;
id_ef15=1;
is_private='.$private.';
is_private=' . $private . ';
if (is_private) {
$(".individualline").show();
} else {
@ -1103,7 +1103,7 @@ else
});
function init_customer_categ() {
console.log("is customer or prospect = "+jQuery("#customerprospect").val());
if (jQuery("#customerprospect").val() == 0 && (jQuery("#fournisseur").val() == 0 || '.(empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER) ? '1' : '0').'))
if (jQuery("#customerprospect").val() == 0 && (jQuery("#fournisseur").val() == 0 || ' . (empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER) ? '1' : '0') . '))
{
jQuery(".visibleifcustomer").hide();
}
@ -1134,28 +1134,38 @@ else
document.formsoc.submit();
});
});';
print '</script>'."\n";
print '</script>' . "\n";
print '<div id="selectthirdpartytype">';
print '<div class="hideonsmartphone float">';
print $langs->trans("ThirdPartyType").': &nbsp; &nbsp; ';
print '</div>';
print '<label for="radiocompany" class="radiocompany">';
print '<input type="radio" id="radiocompany" class="flat" name="private" value="0"'.($private ? '' : ' checked').'>';
print '&nbsp;';
print $langs->trans("CreateThirdPartyOnly");
print '</label>';
print ' &nbsp; &nbsp; ';
print '<label for="radioprivate" class="radioprivate">';
$text = '<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private ? ' checked' : '').'>';
$text .= '&nbsp;';
$text .= $langs->trans("CreateThirdPartyAndContact");
$htmltext = $langs->trans("ToCreateContactWithSameName");
print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
print '</label>';
print '</div>';
print "<br>\n";
}
print '<div id="selectthirdpartytype">';
print '<div class="hideonsmartphone float">';
print $langs->trans("ThirdPartyType") . ': &nbsp; &nbsp; ';
print '</div>';
print '<label for="radiocompany" class="radiocompany">';
print '<input type="radio" id="radiocompany" class="flat" name="private" value="0"' . ($private ? '' : ' checked') . '>';
print '&nbsp;';
print $langs->trans("CreateThirdPartyOnly");
print '</label>';
print ' &nbsp; &nbsp; ';
print '<label for="radioprivate" class="radioprivate">';
$text = '<input type="radio" id="radioprivate" class="flat" name="private" value="1"' . ($private ? ' checked' : '') . '>';
$text .= '&nbsp;';
$text .= $langs->trans("CreateThirdPartyAndContact");
$htmltext = $langs->trans("ToCreateContactWithSameName");
print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
print '</label>';
print '</div>';
print "<br>\n";
} else {
print '<script type="text/javascript">';
print '$(document).ready(function () {
$("#selectcountry_id").change(function() {
document.formsoc.action.value="create";
document.formsoc.submit();
});
});';
print '</script>' . "\n";
}
}
dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');