Some people find it easier to understand the API calls by turning on
logging so they can see, in real-time, what Odoo is doing as it creates
and processes different kinds of documents.
https://www.odoo.com/documentation/13.0/reference/cmdline.html#logging
All I have is a script written in Python for version 12.0, we made major changes to the Accounting framework and account.invoice and account.invoice.line no longer exist. You should be able to adapt this to work with account.move and account.move.line instead:
Switch the calls based on the examples at
import xmlrpclib
import csv
import requests
import base64
from dateutil.parser import parse
from time import gmtime, strftime
username = ''
pwd = ''
dbname = ''
sock_common = xmlrpclib.ServerProxy ('http://server:8069/xmlrpc/common', allow_none=True)
uid = sock_common.login(dbname, username, pwd)
sock = xmlrpclib.ServerProxy('http://server:8069/xmlrpc/2/object', allow_none=True)
reader = csv.reader(open('/opt/imports/vendor_bills.csv','rb'))
count = 0
for row in reader:
if count == 0:
count+=1
continue
count += 1
invoice_id = False
invoice_exist = False
partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'search', [('ref', '=', row[0]),('company_id', '=', 1)])
partner_id = partner_id[0]
if float(row[7]) > 0:
invoice_type = 'in_invoice'
price_unit = row[7]
else:
invoice_type = 'in_refund'
price_unit = -float(row[7])
currency = sock.execute(dbname, uid, pwd, 'res.currency', 'search', [('name', '=', 'USD')])
journal = sock.execute(dbname, uid, pwd, 'account.journal', 'search', [('name', '=', 'Vendor Bills'),('company_id', '=', 1)])
invoice_vals = {
'move_name': row[2],
'name': row[2],
'type': invoice_type,
'company_id': 1,
'date_invoice': parse(row[3]).strftime("%Y-%m-%d"),
'date_due': parse(row[5]).strftime("%Y-%m-%d"),
'partner_id': partner_id,
'currency_id': currency and currency[0],
'journal_id': journal and journal[0] or False,
'x_migrated':True,
'origin': 'Imported AP',
'user_id': False,
}
invoice_id = sock.execute(dbname, uid,pwd, 'account.invoice','create',invoice_vals)
account_id = sock.execute(dbname, uid, pwd, 'account.account', 'search', [('name', '=', 'Open AP'),('company_id', '=', 1)])
invoice_line_vals = {
'quantity': 1,
'price_unit': price_unit,
'account_id': account_id and account_id[0],
'company_id':1,
'name': 'Open AP',
'invoice_id': invoice_id,
'partner_id': partner_id,
}
sock.execute(dbname, uid,pwd, 'account.invoice.line','create',invoice_line_vals)
sock.execute_kw(dbname, uid, pwd, 'account.invoice', 'action_invoice_open', [invoice_id])