Dolibarr / dolibarr

Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). it's an open source Web application (written in PHP) designed for businesses of any sizes, foundations and freelancers.
https://www.dolibarr.org
GNU General Public License v3.0
5.47k stars 2.8k forks source link

REST products fail to insert new product when autoref is enabled #14291

Closed dpriskorn closed 4 years ago

dpriskorn commented 4 years ago

Bug

Got this response on the endpoint: {'error': {'code': 400, 'message': 'Bad Request: ref field missing'}, 'debug': {'source': 'api_products.class.php:1617 at call stage', 'stages': {'success': ['get', 'route', 'negotiate', 'authenticate', 'validate'], 'failure': ['call', 'message']}}}

Environment

Expected and actual behavior

I expected Dolibarr to make up a new ref according to the elephant ref-model and return 200 ok.

dpriskorn commented 4 years ago

It works fine if this line is commented out: https://github.com/Dolibarr/dolibarr/blob/b93cab2e77f0188e430f6b87642a23ad4dd77e55/htdocs/product/class/api_products.class.php#L41

eldy commented 4 years ago

Did you try with value ref = 'auto' ?

dpriskorn commented 4 years ago

Will try and report back.

dpriskorn commented 4 years ago

I tried it on /supplierorders and it works there. But for /products it does not work: curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'DOLAPIKEY: ' -d '{"label": "test","ref": "auto","type": 0}' 'http://dolibarr.localhost/api/index.php/products' response 200: 1384 (results in ref=auto instead of formatted like my settings in elephant: {yy}{mm}-{00000} $ curl -X GET --header 'Accept: application/json' --header 'DOLAPIKEY: ' 'http://dolibarr.localhost/api/index.php/products/1384' { "label": "test", "description": "", "other": null, "type": "0", "price": "0.00000000", "price_ttc": "0.00000000", "price_min": "0.00000000", "price_min_ttc": "0.00000000", "price_base_type": "", "multiprices": { "1": "0.00000000", "2": null }, "multiprices_ttc": { "1": "0.00000000", "2": null }, "multiprices_base_type": { "1": "", "2": null }, "multiprices_min": { "1": "0.00000000", "2": null }, "multiprices_min_ttc": { "1": "0.00000000", "2": null }, "multiprices_tva_tx": { "1": "0.000", "2": null }, "multiprices_recuperableonly": { "1": "0", "2": null }, "prices_by_qty": [], "prices_by_qty_list": [], "default_vat_code": null, "tva_tx": "0.000", "tva_npr": "0", "localtax1_tx": "0.000", "localtax2_tx": "0.000", "localtax1_type": "0", "localtax2_type": "0", "stock_reel": null, "stock_theorique": null, "cost_price": null, "pmp": "0.00000000", "seuil_stock_alerte": "0", "desiredstock": "0", "duration_value": false, "duration_unit": "", "status": "0", "status_buy": "0", "finished": null, "status_batch": "0", "customcode": "", "url": null, "weight": null, "weight_units": null, "length": null, "length_units": null, "width": null, "width_units": null, "height": null, "height_units": null, "surface": null, "surface_units": null, "volume": null, "volume_units": null, "net_measure": null, "net_measure_units": null, "accountancy_code_sell": "", "accountancy_code_sell_intra": "", "accountancy_code_sell_export": "", "accountancy_code_buy": "", "accountancy_code_buy_intra": "", "accountancy_code_buy_export": "", "barcode": null, "barcode_type": null, "barcode_type_code": null, "barcodes_extra": [], "multilangs": [], "imgWidth": null, "imgHeight": null, "date_creation": "2020-08-01 11:43:43", "date_modification": "2020-08-01 13:43:43.497256", "product_fourn_id": null, "nbphoto": 0, "stock_warehouse": [], "fk_default_warehouse": null, "fk_price_expression": null, "fourn_pu": null, "fourn_price_base_type": null, "fourn_socid": null, "ref_fourn": null, "ref_supplier": null, "fk_unit": null, "price_autogen": "0", "id": "1384", "import_key": null, "array_options": [], "array_languages": null, "linkedObjectsIds": null, "canvas": "", "fk_project": null, "contact": null, "contact_id": null, "thirdparty": null, "user": null, "origin": null, "origin_id": null, "ref": "auto", "ref_ext": null, "statut": null, "country": null, "country_id": null, "country_code": "", "state": null, "state_id": null, "state_code": null, "barcode_type_label": null, "barcode_type_coder": null, "mode_reglement_id": null, "cond_reglement_id": null, "cond_reglement": null, "shipping_method_id": null, "modelpdf": null, "last_main_doc": null, "fk_account": null, "note_public": null, "note_private": null, "note": null, "total_ht": null, "total_tva": null, "total_localtax1": null, "total_localtax2": null, "total_ttc": null, "lines": null, "fk_incoterms": null, "label_incoterms": null, "location_incoterms": null, "date_validation": null, "duration": "", "entity": "1" }