Merge pull request #7467 from Oeris/6.0-api

NEW get and post lines of an invoice using the REST API
This commit is contained in:
Laurent Destailleur 2017-09-24 22:01:33 +02:00 committed by GitHub
commit cee57129d6
12 changed files with 199 additions and 12 deletions

View File

@ -17,8 +17,48 @@ Following changes may create regressions for some external modules, but were nec
__PROPALREF__, ...)
***** ChangeLog for 6.0.1 compared to 6.0.* *****
FIX: #7000 Dashboard link for late pending payment supplier invoices do not work
FIX: #7325 Default VAT rate when editing template invoices is 0%
FIX: #7330
FIX: #7359
FIX: #7367
FIX: #7368
FIX: #7391
FIX: #7420
FIX: Add some missing attributes in Adherent:makeSubstitution (type, phone…
FIX: Bad const name
FIX: Bad link to unpayed suppliers invoices
FIX: Better protection to no send email when we change limit
FIX: Calculation in the activity box
FIX: Clean bad parameters when inserting line of template invoice
FIX: dateSelector was not taken into account
FIX: hidden option MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN
FIX: journalization for bank journal should not rely on a label.
FIX: menu enty when url is external link
FIX: missing supplier qty and supplier discount in available fields for product export.
FIX: multicompany better accuracy in rounding and with revenue stamp.
FIX: Must use pdf format page as default for merging PDF.
FIX: PDF output was sharing 2 different currencies in same total
FIX: Position of signature on strato template
FIX: Protection to avoid to apply credit note discount > remain to pay
FIX: Remove warning when using log into syslog
FIX: Responsive
FIX: Security fixes (filter onload js, less verbose error message in
FIX: SEPA recording payment must save one payment in bank per customer
FIX: Several problem with the last event box on project/tasks
FIX: Sign of amount in origin currency on credit note created from lines
FIX: Some page of admin were not responsive
FIX: SQL injection
FIX: time.php crashed without project id in param
FIX: transfer of line extrafields from order to invoice
FIX: Upgrade missing on field
FIX: View of timespent for another user
FIX: ODT generation
FIX: CVE-2017-9840, CVE-2017-14238, CVE-2017-14239, CVE-2017-14240, CVE-2017-14241,
CVE-2017-14242
***** ChangeLog for 6.0.0 compared to 5.0.* *****
NEW: Add experimental BlockeLog module (to log business events in a non reversible log file).
NEW: Add a payment module for Stripe.
NEW: Add module "Product variant" (like red, blue for the product shoes)

View File

@ -48,7 +48,7 @@ class DolibarrApi
*/
function __construct($db, $cachedir='', $refreshCache=false)
{
global $conf;
global $conf, $dolibarr_main_url_root;
if (empty($cachedir)) $cachedir = $conf->api->dir_temp;
Defaults::$cacheDirectory = $cachedir;
@ -56,7 +56,9 @@ class DolibarrApi
$this->db = $db;
$production_mode = ( empty($conf->global->API_PRODUCTION_MODE) ? false : true );
$this->r = new Restler($production_mode, $refreshCache);
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
$this->r->setBaseUrls(DOL_MAIN_URL_ROOT, $urlwithroot);
$this->r->setAPIVersion(1);
}

View File

@ -1414,6 +1414,7 @@ if (empty($reshook))
{
$line->origin = $object->origin;
$line->origin_id = $line->id;
$line->fetch_optionals($line->id);
}
}
@ -1435,7 +1436,21 @@ if (empty($reshook))
$object->situation_counter = $object->situation_counter + 1;
$id = $object->createFromCurrent($user);
if ($id <= 0) $mesg = $object->error;
if ($id <= 0)
{
$mesg = $object->error;
}
else
{
$nextSituationInvoice = new Facture($db);
$nextSituationInvoice->fetch($id);
// create extrafields with data from create form
$extralabels = $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $nextSituationInvoice);
if ($ret > 0) {
$nextSituationInvoice->insertExtraFields();
}
}
}
}

View File

@ -276,6 +276,107 @@ class Invoices extends DolibarrApi
);
}
/**
* Get lines of a given invoice
*
* @param int $id Id of invoice
*
* @url GET {id}/lines
*
* @return array
*/
function getLines($id) {
if(! DolibarrApiAccess::$user->rights->facture->lire) {
throw new RestException(401);
}
$result = $this->invoice->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Invoice not found');
}
if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$this->invoice->getLinesArray();
$result = array();
foreach ($this->invoice->lines as $line) {
array_push($result,$this->_cleanObjectDatas($line));
}
return $result;
}
/**
* Add a line to a given invoice
*
* Exemple of POST query : { "desc": "Desc", "subprice": "1.00000000", "qty": "1", "tva_tx": "20.000", "localtax1_tx": "0.000", "localtax2_tx": "0.000", "fk_product": "1", "remise_percent": "0", "date_start": "", "date_end": "", "fk_code_ventilation": 0, "info_bits": "0", "fk_remise_except": null, "product_type": "1", "rang": "-1", "special_code": "0", "fk_parent_line": null, "fk_fournprice": null, "pa_ht": "0.00000000", "label": "", "array_options": [], "situation_percent": "100", "fk_prev_id": null, "fk_unit": null }
*
* @param int $id Id of invoice
* @param array $request_data Invoiceline data
*
* @url POST {id}/lines
*
* @return int
*/
function postLine($id, $request_data = NULL) {
if(! DolibarrApiAccess::$user->rights->facture->creer) {
throw new RestException(401);
}
$result = $this->invoice->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Invoice not found');
}
if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$request_data = (object) $request_data;
// Reset fk_parent_line for no child products and special product
if (($request_data->product_type != 9 && empty($request_data->fk_parent_line)) || $request_data->product_type == 9) {
$request_data->fk_parent_line = 0;
}
$updateRes = $this->invoice->addline(
$request_data->desc,
$request_data->subprice,
$request_data->qty,
$request_data->tva_tx,
$request_data->localtax1_tx,
$request_data->localtax2_tx,
$request_data->fk_product,
$request_data->remise_percent,
$request_data->date_start,
$request_data->date_end,
$request_data->fk_code_ventilation,
$request_data->info_bits,
$request_data->fk_remise_except,
'HT',
0,
$request_data->product_type,
$request_data->rang,
$request_data->special_code,
'facture',
$id,
$request_data->fk_parent_line,
$request_data->fk_fournprice,
$request_data->pa_ht,
$request_data->label,
$request_data->array_options,
$request_data->situation_percent,
$request_data->fk_prev_id,
$request_data->fk_unit
);
if ($updateRes > 0) {
return $this->get($id)->line->rowid;
}
throw new RestException(400, 'Unable to insert the new line. Check your inputs.');
}
/**
* Validate an order
*

View File

@ -3277,7 +3277,7 @@ class Form
$return= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
$sql = 'SELECT rowid, label from '.MAIN_DB_PREFIX.'c_units';
$sql = 'SELECT rowid, label, code from '.MAIN_DB_PREFIX.'c_units';
$sql.= ' WHERE active > 0';
$resql = $this->db->query($sql);

View File

@ -780,9 +780,15 @@ if ($action == 'create')
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if (empty($reshook) && ! empty($extrafields->attribute_label)) {
print $object->showOptionals($extrafields, 'edit');
}
if (empty($reshook) && ! empty($extrafields->attribute_label)) {
// copy from order
$orderExtrafields = new Extrafields($db);
$orderExtrafieldLabels = $orderExtrafields->fetch_name_optionals_label($object->table_element);
if ($object->fetch_optionals($object->id, $orderExtrafieldLabels) > 0) {
$expe->array_options = array_merge($expe->array_options, $object->array_options);
}
print $object->showOptionals($extrafields, 'edit');
}
// Incoterms
@ -1304,8 +1310,13 @@ if ($action == 'create')
if (is_array($extralabelslines) && count($extralabelslines)>0)
{
$colspan=5;
$orderLineExtrafields = new Extrafields($db);
$orderLineExtrafieldLabels = $orderLineExtrafields->fetch_name_optionals_label($object->table_element_line);
$srcLine = new OrderLine($db);
$srcLine->fetch_optionals($line->id,$orderLineExtrafieldLabels); // fetch extrafields also available in orderline
$line = new ExpeditionLigne($db);
$line->fetch_optionals($object->id,$extralabelslines);
$line->array_options = array_merge($line->array_options, $srcLine->array_options);
print '<tr class="oddeven">';
print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
print '</tr>';

View File

@ -417,7 +417,7 @@ if (empty($reshook))
$localtax1_tx,
$localtax2_tx,
$idprod,
$productsupplier->id,
$productsupplier->product_fourn_price_id,
$productsupplier->fourn_ref,
$remise_percent,
'HT',

View File

@ -157,7 +157,7 @@ ErrorPriceExpression22=Negative result '%s'
ErrorPriceExpressionInternal=Internal error '%s'
ErrorPriceExpressionUnknown=Unknown error '%s'
ErrorSrcAndTargetWarehouseMustDiffers=Source and target warehouses must differs
ErrorTryToMakeMoveOnProductRequiringBatchData=Error, trying to make a stock movement without lot/serial information, on a product requiring lot/serial information
ErrorTryToMakeMoveOnProductRequiringBatchData=Error, trying to make a stock movement without lot/serial information, on product '%s' requiring lot/serial information
ErrorCantSetReceptionToTotalDoneWithReceptionToApprove=All recorded receptions must first be verified (approved or denied) before being allowed to do this action
ErrorCantSetReceptionToTotalDoneWithReceptionDenied=All recorded receptions must first be verified (approved) before being allowed to do this action
ErrorGlobalVariableUpdater0=HTTP request failed with error '%s'

View File

@ -565,6 +565,14 @@ else
}
// Other attributes
if ($action = 'create_delivery') {
// copy from expedition
$expeditionExtrafields = new Extrafields($db);
$expeditionExtrafieldLabels = $expeditionExtrafields->fetch_name_optionals_label($expedition->table_element);
if ($expedition->fetch_optionals($object->origin_id, $expeditionExtrafieldLabels) > 0) {
$object->array_options = array_merge($object->array_options, $expedition->array_options);
}
}
$cols = 2;
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
@ -665,6 +673,13 @@ else
$mode = ($object->statut == 0) ? 'edit' : 'view';
$line = new LivraisonLigne($db);
$line->fetch_optionals($object->lines[$i]->id,$extralabelslines);
if ($action = 'create_delivery') {
$srcLine = new ExpeditionLigne($db);
$expeditionLineExtrafields = new Extrafields($db);
$expeditionLineExtrafieldLabels = $expeditionLineExtrafields->fetch_name_optionals_label($srcLine->table_element);
$srcLine->fetch_optionals($expedition->lines[$i]->id,$expeditionLineExtrafieldLabels);
$line->array_options = array_merge($line->array_options, $srcLine->array_options);
}
print '<tr class="oddeven">';
print $line->showOptionals($extrafieldsline, $mode, array('style'=>$bc[$var], 'colspan'=>$colspan),$i);
print '</tr>';

View File

@ -1532,6 +1532,7 @@ class Product extends CommonObject
$obj->price = $price_result;
}
}
$this->product_fourn_price_id = $obj->rowid;
$this->buyprice = $obj->price; // deprecated
$this->fourn_pu = $obj->price / $obj->quantity; // Unit price of product of supplier
$this->fourn_price_base_type = 'HT'; // Price base type
@ -1577,6 +1578,7 @@ class Product extends CommonObject
$obj->price = $price_result;
}
}
$this->product_fourn_price_id = $obj->rowid;
$this->buyprice = $obj->price; // deprecated
$this->fourn_qty = $obj->quantity; // min quantity for price for a virtual supplier
$this->fourn_pu = $obj->price / $obj->quantity; // Unit price of product for a virtual supplier

View File

@ -96,6 +96,7 @@ class MouvementStock extends CommonObject
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
$langs->load("errors");
$error = 0;
dol_syslog(get_class($this)."::_create start userid=$user->id, fk_product=$fk_product, warehouse_id=$entrepot_id, qty=$qty, type=$type, price=$price, label=$label, inventorycode=$inventorycode, datem=".$datem.", eatby=".$eatby.", sellby=".$sellby.", batch=".$batch.", skip_batch=".$skip_batch);
@ -141,7 +142,7 @@ class MouvementStock extends CommonObject
{
if (empty($batch))
{
$this->errors[]=$langs->trans("ErrorTryToMakeMoveOnProductRequiringBatchData", $product->name);
$this->errors[]=$langs->trans("ErrorTryToMakeMoveOnProductRequiringBatchData", $product->ref);
dol_syslog("Try to make a movement of a product with status_batch on without any batch data");
$this->db->rollback();

View File

@ -237,7 +237,7 @@ print "</tr>\n";
print '<tr class="liste_titre">';
if (! empty($arrayfields['t.ref']['checked'])) print_liste_field_titre($arrayfields['t.ref']['label'],$_SERVER["PHP_SELF"],"t.ref","",$param,"",$sortfield,$sortorder);
if (! empty($arrayfields['ty.label']['checked'])) print_liste_field_titre($arrayfields['ty.label']['label'],$_SERVER["PHP_SELF"],"t.code","",$param,"",$sortfield,$sortorder);
if (! empty($arrayfields['ty.label']['checked'])) print_liste_field_titre($arrayfields['ty.label']['label'],$_SERVER["PHP_SELF"],"ty.label","",$param,"",$sortfield,$sortorder);
// Extra fields
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
{