ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Creating document by API


#1

I’m trying create a simple Delivery Note document by frappe API, but:

Error:

         File "/home/ubuntu/frappe-bench/apps/frappe/frappe/app.py", line 67, in application
        response = frappe.api.handle()
      File "/home/ubuntu/frappe-bench/apps/frappe/frappe/api.py", line 119, in handle
        "data": frappe.get_doc(data).insert().as_dict()
      File "/home/ubuntu/frappe-bench/apps/frappe/frappe/__init__.py", line 638, in get_doc
        return frappe.model.document.get_doc(*args, **kwargs)
      File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 68, in get_doc
        return controller(*args, **kwargs)
      File "/home/ubuntu/frappe-bench/apps/erpnext/erpnext/stock/doctype/delivery_note/delivery_note.py", line 25, in __init__
        super(DeliveryNote, self).__init__(*args, **kwargs)
      File "/home/ubuntu/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py", line 19, in __init__
        super(AccountsController, self).__init__(*args, **kwargs)
      File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 112, in __init__
        super(Document, self).__init__(kwargs)
      File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 54, in __init__
        self.update(d)
      File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 77, in update
        self.set(key, value)
      File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 124, in set
        self.extend(key, value)
      File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 152, in extend
        self.append(key, v)
      File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 138, in append
        value = self._init_child(value, key)
      File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 164, in _init_child
        value["doctype"] = self.get_table_field_doctype(key)
      File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 278, in get_table_field_doctype
        return self.meta.get_field(fieldname).options
    AttributeError: 'NoneType' object has no attribute 'options'

Code:

#Create a document by Frappe API                                                                                                                                       
url = 'http://erp.mracing.dev/api/resource/Delivery Note'                                                                                                                
body = {                                                                                                                                                                 
    "naming_series": "DN-",                                                                                                                                          
    "posting_date": "12/12/2017",                                                                                                                                    
    "posting_time": "17:50:00",                                                                                                                                      
    "customer": "AGUA MEL FARMACIA DE MANIPULACAO LTDA ME",                                                                                                          
    "item": [       {                                                                                                                                                
                    "item_code": 1777,                                                                                                                         
                    "qty": 2                                                                                                                                         
                    }                                                                                                                                                
            ]                                                                                                                                                        
    }                                                                                                                                                                
rpost = session.post(url, data=json.dumps(body))                                                                                                                         
print rpost.content                                                                                                                                                            

Can you help me find out what’s the problem?


Error creating a Sales Order using REST API
#2

Found it!

Some field names on body are wrong, like table name “item” , the right name is “items


#3