# -*- coding: utf-8 -*- from main import * _logger = logging.getLogger(__name__) # List of REST resources in current file: # (url prefix) (method) (action) # /api/vendor.farmer GET - Read all (with optional filters, offset, limit, order) # /api/vendor.farmer/ GET - Read one # /api/vendor.farmer POST - Create one # /api/vendor.farmer/ PUT - Update one # /api/vendor.farmer/ DELETE - Delete one # /api/vendor.farmer// PUT - Call method (with optional parameters) # List of IN/OUT data (json data and HTTP-headers) for each REST resource: # /api/vendor.farmer GET - Read all (with optional filters, offset, limit, order) # IN data: # HEADERS: # 'access_token' # JSON: # (optional filters (Odoo domain), offset, limit, order) # { # editable # "filters": "[('some_field_1', '=', some_value_1), ('some_field_2', '!=', some_value_2), ...]", # "offset": XXX, # "limit": XXX, # "order": "list_of_fields" # default 'name asc' # } # OUT data: OUT__vendor_farmer__read_all__SUCCESS_CODE = 200 # editable # JSON: # { # "count": XXX, # number of returned records # "results": [ OUT__vendor_farmer__read_all__JSON = ( # editable 'id', 'name', 'phone', 'email', 'address', 'gender', 'head_of_household', 'num_household_members', 'spouse_firstname', 'spouse_lastname', 'cellphone_alt', 'cell_carrier', 'membership_id', 'ar_tractors', 'ar_harverster', 'ar_dryer', 'ar_thresher', 'ar_safestorage', 'ar_other', 'mws_dam', 'mws_well', 'mws_borehole', 'mws_rs', 'mws_pb', 'mws_irrigation', 'mws_none', 'mws_other', 'user_id', 'storage_details', 'other_details', 'total_land_plot_size', 'categ_total_land_plot_size', ('access_info_ids', [( 'id', 'ar_aes', 'ar_cri', 'ar_seeds', 'ar_of', 'ar_if', 'ar_labour', 'ar_iwp', 'ar_ss', 'harvest_id', 'vendor_id' )]), ('vendor_land_ids', [( 'id', 'vendor_id', 'plot_size', 'lat', 'lng', 'harvest_id' )]), ('forecast_vendor_ids', [( 'id', 'total_arable_land_plots', 'expected_production_in_mt', 'forecasted_yield_mt', 'forecasted_harvest_sale_value', 'total_coop_land_size', 'farmer_percentage_land', 'current_ppp_commitment', 'farmer_contribution_ppp', 'farmer_expected_min_ppp', 'minimum_flow_price', 'harvest_id', 'vendor_id' )]), ('finance_data_ids', [( 'id', 'outstanding_loan', 'total_loan_amount', 'total_outstanding', 'interest_rate', 'duration', 'loan_provider', 'loan_purpose_i', 'loan_purpose_a', 'loan_purpose_o', 'mobile_money_account', 'harvest_id', 'vendor_id' )]), ('baseline_ids', [( 'id', 'seasona_harvest', 'lost_harvest_total', 'sold_harvest_total', 'total_qty_coops', 'price_sold_coops', 'total_qty_middlemen', 'price_sold_middlemen', 'harvest_id', 'vendor_id' )]) ) # ] # } # /api/vendor.farmer/ GET - Read one # IN data: # HEADERS: # 'access_token' # JSON: # (optional parameter 'search_field' for search object not by 'id' field) # {"search_field": "some_field_name"} # editable # OUT data: OUT__vendor_farmer__read_one__SUCCESS_CODE = 200 # editable OUT__vendor_farmer__read_one__JSON = ( # editable # (The order of fields of different types maybe arbitrary) # simple fields (non relational): 'id', 'name', 'phone', 'email', 'address', 'gender', 'head_of_household', 'num_household_members', 'spouse_firstname', 'spouse_lastname', 'cellphone_alt', 'cell_carrier', 'membership_id', 'ar_tractors', 'ar_harverster', 'ar_dryer', 'ar_thresher', 'ar_safestorage', 'ar_other', 'mws_dam', 'mws_well', 'mws_borehole', 'mws_rs', 'mws_pb', 'mws_irrigation', 'mws_none', 'mws_other', 'user_id', 'total_land_plot_size', 'storage_details', 'other_details', 'categ_total_land_plot_size', ('access_info_ids', [( 'id', 'ar_aes', 'ar_cri', 'ar_seeds', 'ar_of', 'ar_if', 'ar_labour', 'ar_iwp', 'ar_ss', 'harvest_id', 'vendor_id' )]), ('vendor_land_ids', [( 'id', 'vendor_id', 'plot_size', 'lat', 'lng', 'harvest_id' )]), ('forecast_vendor_ids', [( 'id', 'total_arable_land_plots', 'expected_production_in_mt', 'forecasted_yield_mt', 'forecasted_harvest_sale_value', 'total_coop_land_size', 'farmer_percentage_land', 'current_ppp_commitment', 'farmer_contribution_ppp', 'farmer_expected_min_ppp', 'minimum_flow_price', 'harvest_id', 'vendor_id' )]), ('finance_data_ids', [( 'id', 'outstanding_loan', 'total_loan_amount', 'total_outstanding', 'interest_rate', 'duration', 'loan_provider', 'loan_purpose_i', 'loan_purpose_a', 'loan_purpose_o', 'mobile_money_account', 'harvest_id', 'vendor_id' )]), ('baseline_ids', [( 'id', 'seasona_harvest', 'lost_harvest_total', 'sold_harvest_total', 'total_qty_coops', 'price_sold_coops', 'total_qty_middlemen', 'price_sold_middlemen', 'harvest_id', 'vendor_id' )]) ) # /api/vendor.farmer POST - Create one # IN data: # HEADERS: # 'access_token' # DEFAULTS: # (optional default values of fields) DEFAULTS__vendor_farmer__create_one__JSON = { # editable #"some_field_1": some_value_1, #"some_field_2": some_value_2, #... } # JSON: # (fields and its values of created object; # don't forget about model's mandatory fields!) # ... # editable # OUT data: OUT__vendor_farmer__create_one__SUCCESS_CODE = 200 # editable OUT__vendor_farmer__create_one__JSON = ( # editable 'id', ) # /api/vendor.farmer/ PUT - Update one # IN data: # HEADERS: # 'access_token' # JSON: # (fields and new values of updated object) # editable # ... # OUT data: OUT__vendor_farmer__update_one__SUCCESS_CODE = 200 # editable # /api/vendor.farmer/ DELETE - Delete one # IN data: # HEADERS: # 'access_token' # OUT data: OUT__vendor_farmer__delete_one__SUCCESS_CODE = 200 # editable # /api/vendor.farmer// PUT - Call method (with optional parameters) # IN data: # HEADERS: # 'access_token' # JSON: # (named parameters of method) # editable # ... # OUT data: OUT__vendor_farmer__call_method__SUCCESS_CODE = 200 # editable # HTTP controller of REST resources: class ControllerREST(http.Controller): # Read all (with optional filters, offset, limit, order): @http.route('/api/vendor.farmer', methods=['GET'], type='http', auth='none') @check_permissions def api__vendor_farmer__GET(self): return wrap__resource__read_all( modelname='vendor.farmer', default_domain=[], success_code=OUT__vendor_farmer__read_all__SUCCESS_CODE, OUT_fields=OUT__vendor_farmer__read_all__JSON ) # Read one: @http.route('/api/vendor.farmer/', methods=['GET'], type='http', auth='none') @check_permissions def api__vendor_farmer__id_GET(self, id): return wrap__resource__read_one( modelname='vendor.farmer', id=id, success_code=OUT__vendor_farmer__read_one__SUCCESS_CODE, OUT_fields=OUT__vendor_farmer__read_one__JSON ) # Create one: @http.route('/api/vendor.farmer', methods=['POST'], type='http', auth='none', csrf=False) @check_permissions def api__vendor_farmer__POST(self): return wrap__resource__create_one( modelname='vendor.farmer', default_vals=DEFAULTS__vendor_farmer__create_one__JSON, success_code=OUT__vendor_farmer__create_one__SUCCESS_CODE, OUT_fields=OUT__vendor_farmer__create_one__JSON ) # Update one: @http.route('/api/vendor.farmer/', methods=['PUT'], type='http', auth='none', csrf=False) @check_permissions def api__vendor_farmer__id_PUT(self, id): return wrap__resource__update_one( modelname='vendor.farmer', id=id, success_code=OUT__vendor_farmer__update_one__SUCCESS_CODE ) # Delete one: @http.route('/api/vendor.farmer/', methods=['DELETE'], type='http', auth='none', csrf=False) @check_permissions def api__vendor_farmer__id_DELETE(self, id): return wrap__resource__delete_one( modelname='vendor.farmer', id=id, success_code=OUT__vendor_farmer__delete_one__SUCCESS_CODE ) # Call method (with optional parameters): @http.route('/api/vendor.farmer//', methods=['PUT'], type='http', auth='none', csrf=False) @check_permissions def api__vendor_farmer__id__method_PUT(self, id, method): return wrap__resource__call_method( modelname='vendor.farmer', id=id, method=method, success_code=OUT__vendor_farmer__call_method__SUCCESS_CODE )