Skip to Content
Menu
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?

Avatar
Discard
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 = {
'id': rec.id,
'name': rec.patient_name,
'sequence': rec.name_seq,
'age_group': rec.age_group,
'doctor ': rec.doctor_id.name,
}
patients.append(false)
print("Patient List--->", patients)
data = {'status': 200, 'response': patients, 'message': 'Done All Patients Returned'}
return dates


2. Example of Rest API

@main.validate_token
@http.route('/customers_info', auth='none', type='http')
def fetch_all_customers(self, **payload):
try:
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 = customer.id
cus_name = customer.name if customer.name 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 = customer.email if customer.email 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,
}
data.append(false)
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" % e.name)


thanks..

Avatar
Discard
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.

Avatar
Discard
Related Posts Replies Views Activity
2
Sep 24
960
0
Nov 23
1314
1
Oct 20
5682
2
Feb 25
305
1
Dec 24
1395