From be55fb31e4df74c806636db6da1be577d80fbf2f Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 8 Sep 2021 21:11:46 +0530 Subject: [PATCH] fix: Autoname for customer and supplier --- .../doctype/buying_settings/buying_settings.json | 4 ++-- erpnext/buying/doctype/supplier/supplier.py | 15 +++++++++++---- erpnext/selling/doctype/customer/customer.py | 9 +++++---- .../selling_settings/selling_settings.json | 6 +++--- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/erpnext/buying/doctype/buying_settings/buying_settings.json b/erpnext/buying/doctype/buying_settings/buying_settings.json index b9c77d59b18..b828a43d3cf 100644 --- a/erpnext/buying/doctype/buying_settings/buying_settings.json +++ b/erpnext/buying/doctype/buying_settings/buying_settings.json @@ -28,7 +28,7 @@ "fieldname": "supp_master_name", "fieldtype": "Select", "label": "Supplier Naming By", - "options": "Supplier Name\nNaming Series" + "options": "Supplier Name\nNaming Series\nAuto Name" }, { "fieldname": "supplier_group", @@ -123,7 +123,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-06-24 10:38:28.934525", + "modified": "2021-09-08 19:26:23.548837", "modified_by": "Administrator", "module": "Buying", "name": "Buying Settings", diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py index c9750caa65a..3936dbf43e8 100644 --- a/erpnext/buying/doctype/supplier/supplier.py +++ b/erpnext/buying/doctype/supplier/supplier.py @@ -4,9 +4,14 @@ from __future__ import unicode_literals import frappe import frappe.defaults -from frappe import msgprint, _ -from frappe.model.naming import set_name_by_naming_series -from frappe.contacts.address_and_contact import load_address_and_contact, delete_contact_and_address +from frappe import _, msgprint +from frappe.contacts.address_and_contact import ( + delete_contact_and_address, + load_address_and_contact, +) +from frappe.model.naming import set_name_by_naming_series, set_name_from_naming_options + +from erpnext.accounts.party import get_dashboard_info, validate_party_accounts from erpnext.utilities.transaction_base import TransactionBase from erpnext.accounts.party import validate_party_accounts, get_dashboard_info, get_timeline_data # keep this @@ -35,8 +40,10 @@ class Supplier(TransactionBase): supp_master_name = frappe.defaults.get_global_default('supp_master_name') if supp_master_name == 'Supplier Name': self.name = self.supplier_name - else: + elif supp_master_name == 'Naming Series': set_name_by_naming_series(self) + else: + self.name = set_name_from_naming_options(frappe.get_meta(self.doctype).autoname, self) def on_update(self): if not self.naming_series: diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 27e9f08e8d6..59e430b17a6 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -9,9 +9,8 @@ from frappe import _, msgprint import frappe.defaults from frappe.utils import flt, cint, cstr, today, get_formatted_email from frappe.desk.reportview import build_match_conditions, get_filters_cond -from erpnext.utilities.transaction_base import TransactionBase -from erpnext.accounts.party import validate_party_accounts, get_dashboard_info, get_timeline_data # keep this -from frappe.contacts.address_and_contact import load_address_and_contact, delete_contact_and_address +from frappe.model.mapper import get_mapped_doc +from frappe.model.naming import set_name_by_naming_series, set_name_from_naming_options from frappe.model.rename_doc import update_linked_doctypes from frappe.model.mapper import get_mapped_doc from frappe.utils.user import get_users_with_role @@ -34,8 +33,10 @@ class Customer(TransactionBase): cust_master_name = frappe.defaults.get_global_default('cust_master_name') if cust_master_name == 'Customer Name': self.name = self.get_customer_name() - else: + elif cust_master_name == 'Naming Series': set_name_by_naming_series(self) + else: + self.name = set_name_from_naming_options(frappe.get_meta(self.doctype).autoname, self) def get_customer_name(self): diff --git a/erpnext/selling/doctype/selling_settings/selling_settings.json b/erpnext/selling/doctype/selling_settings/selling_settings.json index f01934b7e6b..016b23e3883 100644 --- a/erpnext/selling/doctype/selling_settings/selling_settings.json +++ b/erpnext/selling/doctype/selling_settings/selling_settings.json @@ -33,14 +33,14 @@ "fieldtype": "Select", "in_list_view": 1, "label": "Customer Naming By", - "options": "Customer Name\nNaming Series" + "options": "Customer Name\nNaming Series\nAuto Name" }, { "fieldname": "campaign_naming_by", "fieldtype": "Select", "in_list_view": 1, "label": "Campaign Naming By", - "options": "Campaign Name\nNaming Series" + "options": "Campaign Name\nNaming Series\nAuto Name" }, { "fieldname": "customer_group", @@ -159,7 +159,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-04-04 20:18:12.814624", + "modified": "2021-09-08 19:38:10.175989", "modified_by": "Administrator", "module": "Selling", "name": "Selling Settings",