Odoo Lab 4
unknown
python
4 years ago
984 B
14
Indexable
#This is the controllers.py file
from odoo import http
import logging
import json
logger = logging.getLogger(__name__)
class Os21Pharmacy(http.Controller):
#Change the route to whatever you want
@http.route('/displaydetails/', auth='public')
def index(self, **kw):
#Change the model name in the following line to match your model name
medicines = http.request.env['os21.pharmacy.medicine'].search([])
dic = []
#This is a loop for the array, make sure you have price defined in the model
for medicine in medicines:
dic.append({'name': medicine.name, 'price': medicine.price})
return json.dumps(dic)
#--------------------------
#in the controllers folder, in the init file type in the following to import the controllers.py file:
from . import controllers
#--------------------------
#in the main init file type in the following to import the controllers folder:
from . import controllersEditor is loading...