Error when trying to create Sales order via custom app

Dear community,

I am currently trying to develop a pipedrive/erpnext connector using pipedrive’s webhooks and a custom erpnext app.
So far I can get all information from PD without an issue and I’m trying to create a sales order from a pipedrive deal.

I am getting errors when inserting the sales order into erpnext, here is the strack trace :

Traceback (most recent call last):

File “/home/erpnext/frappe_bench/apps/frappe/frappe/”, line 67, in application

response = frappe.api.handle()

File “/home/erpnext/frappe_bench/apps/frappe/frappe/”, line 59, in handle

return frappe.handler.handle()

File “/home/erpnext/frappe_bench/apps/frappe/frappe/”, line 24, in handle

data = execute_cmd(cmd)

File “/home/erpnext/frappe_bench/apps/frappe/frappe/”, line 64, in execute_cmd

return, **frappe.form_dict)

File “/home/erpnext/frappe_bench/apps/frappe/frappe/”, line 1074, in call

return fn(*args, **newargs)

File “/home/erpnext/frappe_bench/apps/pdconnector/pdconnector/”, line 113, in print_data


File “/home/erpnext/frappe_bench/apps/frappe/frappe/model/”, line 230, in insert


File “/home/erpnext/frappe_bench/apps/frappe/frappe/model/”, line 896, in run_before_save_methods


File “/home/erpnext/frappe_bench/apps/frappe/frappe/model/”, line 797, in run_method

out = Document.hook(fn)(self, *args, **kwargs)

File “/home/erpnext/frappe_bench/apps/frappe/frappe/model/”, line 1073, in composer

return composed(self, method, *args, **kwargs)

File “/home/erpnext/frappe_bench/apps/frappe/frappe/model/”, line 1056, in runner

add_to_return_value(self, fn(self, *args, **kwargs))

File “/home/erpnext/frappe_bench/apps/frappe/frappe/model/”, line 791, in <lambda>

fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)

File “/home/erpnext/frappe_bench/apps/erpnext/erpnext/selling/doctype/sales_order/”, line 36, in validate

super(SalesOrder, self).validate()

File “/home/erpnext/frappe_bench/apps/erpnext/erpnext/controllers/”, line 40, in validate

super(SellingController, self).validate()

File “/home/erpnext/frappe_bench/apps/erpnext/erpnext/controllers/”, line 21, in validate

super(StockController, self).validate()

File “/home/erpnext/frappe_bench/apps/erpnext/erpnext/controllers/”, line 80, in validate


File “/home/erpnext/frappe_bench/apps/erpnext/erpnext/controllers/”, line 189, in calculate_taxes_and_totals


File “/home/erpnext/frappe_bench/apps/erpnext/erpnext/controllers/”, line 17, in init


File “/home/erpnext/frappe_bench/apps/erpnext/erpnext/controllers/”, line 24, in calculate


File “/home/erpnext/frappe_bench/apps/erpnext/erpnext/controllers/”, line 38, in _calculate


File “/home/erpnext/frappe_bench/apps/erpnext/erpnext/controllers/”, line 96, in calculate_item_values


File “/home/erpnext/frappe_bench/apps/frappe/frappe/model/”, line 1128, in round_floats_in

doc.set(fieldname, flt(doc.get(fieldname), self.precision(fieldname, doc.parentfield)))

File “/home/erpnext/frappe_bench/apps/frappe/frappe/model/”, line 732, in precision

if df.fieldtype in ("Currency", "Float", "Percent"):

AttributeError: ‘NoneType’ object has no attribute ‘fieldtype’

Due to the lack of information of this stack trace I have added some try/catch blocks and prints to frappe’s function to find which field is causing issues.
It seems there were missing fields in my sales order request, however these fields are not mandatory fields so I don’t understand why it does not work.
The missing fields were :
item.total_weight, item.opening_stock, item.stock_qty, item.discount_amount

However, after adding those fields to my item dict, I am now blocked by this method :
found here in
the error is now : AttributeError: ‘Item’ object has no attribute “‘prevdoc_docname’”
It seems that erpnext tries to find an associated quotation in order to create a sales order. Can’t I create a sales order without a quotation?
Any help would be greatly appreciated, regarding the errors or the quotation.
I cant also provide some code if needed.

My version is :
ERPNext: v12.19.0 (version-12)
Frappe Framework: v12.16.3 (version-12)

Thank you!