# Video of using my new Python library to import a product, an order, an invoice & a payment via command line into Dolibarr in seconds

**URL:** <https://www.dolibarr.org/forum/t/video-of-using-my-new-python-library-to-import-a-product-an-order-an-invoice-a-payment-via-command-line-into-dolibarr-in-seconds/19389>\
**Category:** Using my Dolibarr\
**Tags:** v12\
**Created:** [August 5, 2020, 10:25pm UTC](https://www.dolibarr.org/forum/t/video-of-using-my-new-python-library-to-import-a-product-an-order-an-invoice-a-payment-via-command-line-into-dolibarr-in-seconds/19389 "2020-08-05T22:25:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![egils](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/e/a88e57/32.png) [@egils](https://www.dolibarr.org/forum/u/egils)\
**Post date:** [August 5, 2020, 10:25pm UTC](https://www.dolibarr.org/forum/t/video-of-using-my-new-python-library-to-import-a-product-an-order-an-invoice-a-payment-via-command-line-into-dolibarr-in-seconds/19389/1 "2020-08-05T22:25:33Z")

</div>

[![asciicast](https://asciinema.org/a/3GtCTff9xUXkfX99yn76FXLI9.svg)](https://asciinema.org/a/3GtCTff9xUXkfX99yn76FXLI9)

> **[Egils Dolibarr Library demonstration - Wish supplier order ($2001904) ·...](https://gitlab.com/-/snippets/2001904)**
>
> GitLab.com

  
It imports a product, create a supplier order, generate a supplier invoice, validate the invoice and add a payment in under a minute with minimum hassle.

I have also made another script for batch importing a cart csv from a supplier with 44 lines in a few minutes with almost no manual input.

The library behind the scene is at the time of writing a big class on 2500+ lines and currently support:

- inserting and reading from many Dolibarr objects (falling back on direct database editing when no REST API exist yet)
- calculating prices based on purchase prices
- fetching weight from a csv from the supplier
- fetching image-links from a supplier website
- handling of extrafields
- handling of multiprices
- handling of multicurrency
- reading supplier VAT rate from thirdparties extrafield
- …

**I’m a freelancing developer. Feel free to contact me if you have any needs for automation that you want help with.**

The full list of functions is:  
def **init**  
###################################  
##### PYPI SUPPLIER SPECIFIC API ######  
###################################  
## GET ##  
def get\_correct\_supplier\_id\_or\_fail  
def get\_delivery\_delay\_or\_exit  
def get\_supplier\_tax\_or\_exit  
def get\_supplier\_id  
def get\_product\_by\_id  
## POST ##  
def insert\_payment\_line\_on\_supplier\_invoice  
def validate\_supplier\_invoice  
def create\_supplier\_invoice  
def create\_product  
## PUT ##  
def update\_description  
def update\_weight  
def retire\_product  
def unretire\_product  
##############################  
####### SQL FUNCTIONS ########  
##############################  
def db\_connect  
def db\_disconnect  
## SELECT ##  
def get\_fk\_multicurrency\_or\_exit  
def find\_codename  
def get\_stock\_movements\_by\_fk\_origin  
def get\_product\_categories\_with\_ref\_ext  
def get\_category\_id\_by\_ref\_ext  
def list\_tradera\_categories  
def has\_tradera\_category  
def check\_if\_product\_was\_imported  
def find\_product\_id\_from\_extrafield  
def find\_id\_from\_supplier\_product\_id  
def get\_purchase\_data  
## INSERT ##  
def insert\_link  
def insert\_dispatch\_shipment  
def insert\_revert\_stock\_movement  
def insert\_purchase\_prices\_on\_existing\_products  
def insert\_category  
def insert\_purchase\_price  
def insert\_product\_extrafields  
def insert\_codename  
def insert\_multiprice  
def insert\_product\_category  
def yes\_no\_question  
def insert\_supplier\_order  
def insert\_supplier\_order\_line  
def already\_scraped  
## UPDATE ##  
def update\_supplier\_order\_to\_approved\_and\_made  
def update\_invoice\_prices  
def update\_order\_totals  
## REMOVE ##  
def remove\_purchase\_prices  
##############################  
######### UTILITIES ##########  
##############################  
def response\_to\_int\_or\_fail  
def ask\_and\_insert\_categories  
def get\_supplier\_order\_details\_or\_exit  
def ask\_date  
def prepare\_and\_create\_new\_product  
def search\_and\_insert\_tradera\_category  
def print\_result  
def extract\_from\_list\_api\_or\_fail  
def check\_and\_scrape\_if\_not\_already\_scraped  
def scrape\_picture  
def clean\_number\_to\_float  
def clean\_number\_to\_int  
def empty\_or\_false  
def extrafield  
def empty\_or\_false\_extrafield  
def multiprices\_ttc  
def extract\_and\_convert\_doli\_weight  
def producturl  
def ask\_int  
def get\_weight\_from\_supplier\_data  
def fallback\_weight  
def ask\_mandatory  
#####################################  
##### SUPPLIER SPECIFIC ######  
#####################################  
def scrape\_from\_ms  
## CSV ##  
def get\_weight\_from\_ms\_file  
def get\_supplier\_price\_from\_ms\_file  
def fetch\_and\_calculate\_supplier\_price  
############################  
##### SUPPLIER SPECIFIC ######  
############################  
def scrape\_from\_jo

---

<div class="post-metadata">

**Author:** ![egils](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/e/a88e57/32.png) [@egils](https://www.dolibarr.org/forum/u/egils)\
**Post date:** [August 5, 2020, 10:34pm UTC](https://www.dolibarr.org/forum/t/video-of-using-my-new-python-library-to-import-a-product-an-order-an-invoice-a-payment-via-command-line-into-dolibarr-in-seconds/19389/2 "2020-08-05T22:34:11Z")

</div>

Example use: I just ran this script to insert 7000+ categories from the online marketplace Tradera into my Dolibarr installation. It took about 2 minutes.  
`
import dolibarr_library as dl
import csv
dl = dl.Dolibarr_library()
#traderakategorin har id=14 i dolibarr
parent=14
#dit under ska alla in
with open(“data/tradera-kategorier-sv-200727.csv”) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=’,’)
line_count = 0
for row in csv_reader:
if line_count == 0:
print(f’Column names are {", ".join(row)}’)
line_count += 1
else:
ref_ext=row[0]
ext_parent=row[1]
label=row[3]
desc=ext_parent
#test=dl.get_category_id_by_ref_ext(ref_ext)
dl.insert_category(parent, label, ref_ext, desc)
line_count += 1
print(f’Processed {line_count} lines.’)
`
