AttributeError: 'PurchaseInvoice' object has no attribute 'project'

Traceback (most recent call last):
File “/opt/erpnext/erpnext/apps/frappe/frappe/app.py”, line 64, in application
response = frappe.api.handle()
File “/opt/erpnext/erpnext/apps/frappe/frappe/api.py”, line 58, in handle
return frappe.handler.handle()
File “/opt/erpnext/erpnext/apps/frappe/frappe/handler.py”, line 30, in handle
data = execute_cmd(cmd)
File “/opt/erpnext/erpnext/apps/frappe/frappe/handler.py”, line 69, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/opt/erpnext/erpnext/apps/frappe/frappe/init.py”, line 1086, in call
return fn(*args, **newargs)
File “/opt/erpnext/erpnext/apps/frappe/frappe/desk/form/save.py”, line 19, in savedocs
doc.submit()
File “/opt/erpnext/erpnext/apps/frappe/frappe/model/document.py”, line 897, in submit
self._submit()
File “/opt/erpnext/erpnext/apps/frappe/frappe/model/document.py”, line 886, in _submit
self.save()
File “/opt/erpnext/erpnext/apps/frappe/frappe/model/document.py”, line 281, in save
return self._save(*args, **kwargs)
File “/opt/erpnext/erpnext/apps/frappe/frappe/model/document.py”, line 333, in _save
self.run_post_save_methods()
File “/opt/erpnext/erpnext/apps/frappe/frappe/model/document.py”, line 963, in run_post_save_methods
self.run_method(“on_submit”)
File “/opt/erpnext/erpnext/apps/frappe/frappe/model/document.py”, line 827, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/opt/erpnext/erpnext/apps/frappe/frappe/model/document.py”, line 1119, in composer
return composed(self, method, *args, **kwargs)
File “/opt/erpnext/erpnext/apps/frappe/frappe/model/document.py”, line 1102, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/opt/erpnext/erpnext/apps/frappe/frappe/model/document.py”, line 821, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/opt/erpnext/erpnext/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py”, line 397, in on_submit
self.make_gl_entries()
File “/opt/erpnext/erpnext/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py”, line 406, in make_gl_entries
gl_entries = self.get_gl_entries()
File “/opt/erpnext/erpnext/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py”, line 433, in get_gl_entries
self.make_supplier_gl_entry(gl_entries)
File “/opt/erpnext/erpnext/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py”, line 481, in make_supplier_gl_entry
“project”: self.project,
AttributeError: ‘PurchaseInvoice’ object has no attribute ‘project’

May we know what command produced the message? Also the version of ERPNext and how and when installed?

I am seeing the exact same error when I attempt to submit a Purchase Invoice. (As far as I can tell, any Purchase Invoice. It saves as draft fine, but I can’t Submit it.) I am running the latest develop version of frappe and erpnext, just updated today. (specifically, commit ac23ac6 of ERPNext). Thanks for any help/thoughts/pointers. – Glen Whitney

The two-line patch at the end of this posting alleviates the error for me and seems to result in perfectly good general ledger entries. However, I am not familiar enough with the code for PurchaseInvoice to know if this is a reasonable long-term solution or if this problem is a symptom of something else that should be fixed independently, or even some misconfiguration of ERPNext by both me and the OP. That said, if you would like me to file a pull request for this small change, referencing this thread, I am happy to. Just let me know.

--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -34,6 +34,8 @@ form_grid_templates = {
 class PurchaseInvoice(BuyingController):
        def __init__(self, *args, **kwargs):
                super(PurchaseInvoice, self).__init__(*args, **kwargs)
+               if not hasattr(self, 'project'):
+                       self.project = None
                self.status_updater = [{
                        'source_dt': 'Purchase Invoice Item',
                        'target_dt': 'Purchase Order Item',

Yes same here

Does this resolves the issue?

It does for me (note the extra + that snuck in to your posting from the “diff” format, that should not be in the code). But it remains to be seen if the ERPNext developers feel this is the proper way to modify the code, hopefully someone will weigh in on that. If not, I recommend filing an issue on github frappe/erpnext if there is not one already, or I can if you like. Best, Glen

I also got this issue when i upgraded to the latest v12. The solution is to run the following command :
bench --site your_site_name migrate

replace your_site_name with your own site.

Regards

1 Like