I want to create Supplier Invoice N° unique

Hello to all community.

I need to do the exact same thing that is explained in the Number 3) in this link.

http://sbkolate.blogspot.com/2015/06/how-to-write-client-side-and-server.html

But I’m new in erpnext, and I don’t understand some things. so, these are my questions.

  1. He says:

In hooks.py write this code

doc_events = {
    "Purchase Invoice": {
        "validate": "sf_custom_changes.sf_acc.purchase.validate_bill_no"
    }
}

I need to create a new app for this?, I mean the file hooks.py that he’s making reference to is the hooks.py of the new app? or is the hooks.py from
/frappe-bench/apps/erpnext/erpnext?

  1. in the line:
    “validate”: “sf_custom_changes.sf_acc.purchase.validate_bill_no”

what’s the format to call the function validate_bill_no?

  1. If I need create the app for this where I should place the file purchase.py?

Thank all.

Check Account Settings

1 Like

@josmediaz21

There is a check box in the Account settings which when checked will check for supplier invoice number uniqueness. Please refer the screenshot attached.

Hope this helps.

1 Like

This explains hooks.py are the ‘duct tape’

https://frappe.github.io/frappe/user/en/guides/basics/hooks

And to avoid merge conflicts with update changes to frappe and erpnext, put your custom code in your own app module. (At this point I am not sure that applies for client-side code but definately server-side changes.)

Before you go too far the superb docs will help keep you out of trouble :slight_smile:

1 Like

I have this checked already,


but ERPNext don’t let me create another Purchase Invoice with different supplier and with the same Suplier Invoice Number.

I made an Update from a Previous version Frappe and ERPNext, is that a problem?

Well before you do a ‘bench update’ it’s always a good idea to do a ‘bench backup’

If the logs don’t report a problem then presumably you have no problem…

Felicadades y buena suerte!

1 Like

it sound like a bug …it should check supplier and invoice number so if u have invoice number 123 for 2 different suppliers it should work …can u double check if supplier has another invoice number 123?

Thanks man. I didn’t have problems in the update. But I still can’t solve my problem,

i think the problem could be here:

frappe.db.sql('''select name from `tabPurchase Invoice`
					where
						bill_no = %(bill_no)s
						and name != %(name)s
						and docstatus < 2
						and posting_date between %(year_start_date)s and %(year_end_date)s''', {
							"bill_no": self.bill_no,
							"name": self.name,
							"year_start_date": fiscal_year.year_start_date,
							"year_end_date": fiscal_year.year_end_date
						})

it seems supplier id is not in the query …probably it should be kind of:

frappe.db.sql('''select name from `tabPurchase Invoice`
					where
					bill_no = %(bill_no)s
					and supplier = %(supplier)s
					and name != %(name)s
					and docstatus < 2
					and posting_date between %(year_start_date)s and %(year_end_date)s''', {
							"bill_no": self.bill_no,
							"supplier": self.supplier,
							"name": self.name,
							"year_start_date": fiscal_year.year_start_date,
							"year_end_date": fiscal_year.year_end_date
						})

Can you open an issue on github?

1 Like

I will… thanks man. Can I check that query? what’s the file?

that’s right… the supplier is not in the query, I check the file and the supplier is missing… What do you recommend? should I modify this file by myself? or there is any specific procedure to do this.?

Open an issue on github Issues · frappe/erpnext · GitHub

sent a pull request to fix the issue:
https://github.com/frappe/erpnext/pull/8400

Update: merged into erpnext