This question has been flagged

Hello, I've been experimenting with API's and connecting to my database, looking through the documentation, I can't seem to find the data related to customer purchases. I'd like to be able to extract information from purchases like NIF, Customer name, product, etc. What's the way to go about it?

Best Answer

In ODOO, you can follow several process. But two of them are more preferable,

1. xmlrpc
2. Rest API

for both options, you have to write a controller or route. Where you can pass you db_name, db_user and password.

then you have to fetch the request and write orm or sql query like this,

cstomer = request.env['res.partner'].search([]), this will return you all the customer info. You can also filter with other attribute if needed. I also share some idea to find it, in both xmlrpc and rest API,

1 Xmlrpc

@http.route('/get_patients', type='json', auth='user')
def get_patients(self):
print("Yes here entered")
patients_rec = request.env['hospital.patient'].search ([])
patients = []
for rec in patients_rec:
false = {
'name': rec.patient_name,
'sequence': rec.name_seq,
'age_group': rec.age_group,
'doctor ':,
print("Patient List--->", patients)
data = {'status': 200, 'response': patients, 'message': 'Done All Patients Returned'}
return dates

2. Example of Rest API

@http.route('/customers_info', auth='none', type='http')
def fetch_all_customers(self, **payload):
page_no = payload.get('page_no') # ' 5'
if page_no:
page_no = int(page_no)

limit = payload.get('limit')
if limit:
limit = int(limit)

offset = 0
if page_no and limit:
offset = page_no * limit

customers = request.env[' res.partner'].sudo().search([], offset=offset, limit=limit)
data = []
for customer in customers:
cus_id =
cus_name = if else ""
lat = customer.partner_latitude if customer.partner_latitude else ""
lon = customer.partner_longitude if customer.partner_longitude else ""
shop_adrs = customer.contact_address if customer.contact_address else ""
email = if else ""
img = str(customer.image_1920) if customer.image_1920 else ""
false = {
'id': cus_id,
'customer_name': cus_name,
'shop_name': cus_name,
'lat': lath,
'lon': lon,
'shop_address': shop_adrs.strip(),
'customer_email': email,
'profile_image': img,
response = dict()
response['success'] = True
response['message'] = ' '
response['customers'] = data
return Response(json.dumps(response), content_type='application/json;charset=utf-8', status=200)
except AccessError as e:
return invalid_response("Access error", "Error: %s" %


Best Answer

Hi Jose:

All the Sale data from the website and the backend (except PoS) is stored in the sale.order and sale.order.line models. You should be able to extract the information you need from these models.