From ef06a4b349613607359c730a5931a6baef03ee7b Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 9 May 2013 15:13:47 +0530 Subject: [PATCH] [autoname] [cleanup] strip blank spaces and remove autoname where naming_series: can be set in doctype --- accounts/doctype/c_form/c_form.py | 4 ---- accounts/doctype/cost_center/cost_center.py | 2 +- .../journal_voucher/journal_voucher.py | 5 ----- .../doctype/sales_invoice/sales_invoice.py | 4 ---- .../quality_inspection/quality_inspection.py | 20 ++++-------------- .../quality_inspection/quality_inspection.txt | 6 +++--- hr/doctype/attendance/attendance.py | 4 ---- hr/doctype/employee/employee.py | 2 +- .../production_order/production_order.py | 3 --- .../installation_note/installation_note.py | 7 +------ .../installation_note/installation_note.txt | 18 +++++----------- utilities/doctype/address/address.py | 3 ++- utilities/doctype/contact/contact.py | 21 ++++++++++--------- 13 files changed, 28 insertions(+), 71 deletions(-) diff --git a/accounts/doctype/c_form/c_form.py b/accounts/doctype/c_form/c_form.py index 9f89ad5d07..25a8c3bfc1 100644 --- a/accounts/doctype/c_form/c_form.py +++ b/accounts/doctype/c_form/c_form.py @@ -17,16 +17,12 @@ from __future__ import unicode_literals import webnotes from webnotes.utils import flt, getdate -from webnotes.model.doc import make_autoname from webnotes.model.bean import getlist class DocType: def __init__(self,d,dl): self.doc, self.doclist = d,dl - def autoname(self): - self.doc.name = make_autoname(self.doc.naming_series + '.#####') - def validate(self): """Validate invoice that c-form is applicable and no other c-form is received for that""" diff --git a/accounts/doctype/cost_center/cost_center.py b/accounts/doctype/cost_center/cost_center.py index bf0918879f..4e9b7fd9e7 100644 --- a/accounts/doctype/cost_center/cost_center.py +++ b/accounts/doctype/cost_center/cost_center.py @@ -29,7 +29,7 @@ class DocType(DocTypeNestedSet): def autoname(self): company_abbr = webnotes.conn.sql("select abbr from tabCompany where name=%s", self.doc.company_name)[0][0] - self.doc.name = self.doc.cost_center_name + ' - ' + company_abbr + self.doc.name = self.doc.cost_center_name.strip() + ' - ' + company_abbr def validate_mandatory(self): if not self.doc.group_or_ledger: diff --git a/accounts/doctype/journal_voucher/journal_voucher.py b/accounts/doctype/journal_voucher/journal_voucher.py index f7d4035a58..a5a4f10f34 100644 --- a/accounts/doctype/journal_voucher/journal_voucher.py +++ b/accounts/doctype/journal_voucher/journal_voucher.py @@ -34,11 +34,6 @@ class DocType(AccountsController): self.credit_days_global = -1 self.is_approving_authority = -1 - def autoname(self): - if not self.doc.naming_series: - webnotes.msgprint("""Naming Series is mandatory""", raise_exception=1) - self.doc.name = make_autoname(self.doc.naming_series+'.#####') - def validate(self): if not self.doc.is_opening: self.doc.is_opening='No' diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index 87f73c19ab..b643007add 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.py +++ b/accounts/doctype/sales_invoice/sales_invoice.py @@ -30,7 +30,6 @@ from webnotes import _, msgprint month_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12} - from controllers.selling_controller import SellingController class DocType(SellingController): @@ -40,9 +39,6 @@ class DocType(SellingController): self.tname = 'Sales Invoice Item' self.fname = 'entries' - def autoname(self): - self.doc.name = make_autoname(self.doc.naming_series+ '.#####') - def validate(self): super(DocType, self).validate() self.fetch_missing_values() diff --git a/buying/doctype/quality_inspection/quality_inspection.py b/buying/doctype/quality_inspection/quality_inspection.py index 336aabee8d..48a9a7a6f5 100644 --- a/buying/doctype/quality_inspection/quality_inspection.py +++ b/buying/doctype/quality_inspection/quality_inspection.py @@ -17,28 +17,16 @@ from __future__ import unicode_literals import webnotes -from webnotes.model import db_exists -from webnotes.model.doc import addchild, make_autoname -from webnotes.model.bean import copy_doclist - -sql = webnotes.conn.sql - - +from webnotes.model.doc import addchild class DocType: def __init__(self, doc, doclist=[]): self.doc = doc self.doclist = doclist - # Autoname - # --------- - def autoname(self): - self.doc.name = make_autoname(self.doc.naming_series+'.#####') - - def get_item_specification_details(self): self.doclist = self.doc.clear_table(self.doclist, 'qa_specification_details') - specification = sql("select specification, value from `tabItem Quality Inspection Parameter` \ + specification = webnotes.conn.sql("select specification, value from `tabItem Quality Inspection Parameter` \ where parent = '%s' order by idx" % (self.doc.item_code)) for d in specification: child = addchild(self.doc, 'qa_specification_details', 'Quality Inspection Reading', self.doclist) @@ -48,13 +36,13 @@ class DocType: def on_submit(self): if self.doc.purchase_receipt_no: - sql("update `tabPurchase Receipt Item` t1, `tabPurchase Receipt` t2 set t1.qa_no = '%s', t2.modified = '%s' \ + webnotes.conn.sql("update `tabPurchase Receipt Item` t1, `tabPurchase Receipt` t2 set t1.qa_no = '%s', t2.modified = '%s' \ where t1.parent = '%s' and t1.item_code = '%s' and t1.parent = t2.name" \ % (self.doc.name, self.doc.modified, self.doc.purchase_receipt_no, self.doc.item_code)) def on_cancel(self): if self.doc.purchase_receipt_no: - sql("update `tabPurchase Receipt Item` t1, `tabPurchase Receipt` t2 set t1.qa_no = '', t2.modified = '%s' \ + webnotes.conn.sql("update `tabPurchase Receipt Item` t1, `tabPurchase Receipt` t2 set t1.qa_no = '', t2.modified = '%s' \ where t1.parent = '%s' and t1.item_code = '%s' and t1.parent = t2.name" \ % (self.doc.modified, self.doc.purchase_receipt_no, self.doc.item_code)) diff --git a/buying/doctype/quality_inspection/quality_inspection.txt b/buying/doctype/quality_inspection/quality_inspection.txt index e8650e0554..60ede7093e 100644 --- a/buying/doctype/quality_inspection/quality_inspection.txt +++ b/buying/doctype/quality_inspection/quality_inspection.txt @@ -1,13 +1,13 @@ [ { - "creation": "2013-01-10 16:34:11", + "creation": "2013-04-30 13:13:03", "docstatus": 0, - "modified": "2013-01-22 14:57:21", + "modified": "2013-05-09 14:34:10", "modified_by": "Administrator", "owner": "Administrator" }, { - "autoname": "QAI/.######", + "autoname": "naming_series:", "doctype": "DocType", "is_submittable": 1, "module": "Buying", diff --git a/hr/doctype/attendance/attendance.py b/hr/doctype/attendance/attendance.py index 67af429dd0..ac41acf815 100644 --- a/hr/doctype/attendance/attendance.py +++ b/hr/doctype/attendance/attendance.py @@ -18,7 +18,6 @@ from __future__ import unicode_literals import webnotes from webnotes.utils import getdate, nowdate -from webnotes.model.doc import make_autoname from webnotes import msgprint, _ sql = webnotes.conn.sql @@ -28,9 +27,6 @@ class DocType: self.doc = doc self.doclist = doclist - def autoname(self): - self.doc.name = make_autoname(self.doc.naming_series+'.#####') - def get_emp_name(self): return { "employee_name": webnotes.conn.get_value("Employee", diff --git a/hr/doctype/employee/employee.py b/hr/doctype/employee/employee.py index 87fe9a45e9..9a9ed136af 100644 --- a/hr/doctype/employee/employee.py +++ b/hr/doctype/employee/employee.py @@ -36,7 +36,7 @@ class DocType: if ret[0][0]=='Naming Series': self.doc.name = make_autoname(self.doc.naming_series + '.####') elif ret[0][0]=='Employee Number': - self.doc.name = make_autoname(self.doc.employee_number) + self.doc.name = self.doc.employee_number self.doc.employee = self.doc.name diff --git a/manufacturing/doctype/production_order/production_order.py b/manufacturing/doctype/production_order/production_order.py index a0498e063f..c76a87f6b8 100644 --- a/manufacturing/doctype/production_order/production_order.py +++ b/manufacturing/doctype/production_order/production_order.py @@ -18,9 +18,6 @@ from __future__ import unicode_literals import webnotes from webnotes.utils import cstr, flt, now, nowdate -from webnotes.model import db_exists -from webnotes.model.doc import make_autoname -from webnotes.model.bean import copy_doclist from webnotes.model.code import get_obj from webnotes import msgprint diff --git a/selling/doctype/installation_note/installation_note.py b/selling/doctype/installation_note/installation_note.py index b0e1d966d9..ea20d51d64 100644 --- a/selling/doctype/installation_note/installation_note.py +++ b/selling/doctype/installation_note/installation_note.py @@ -18,9 +18,7 @@ from __future__ import unicode_literals import webnotes from webnotes.utils import cstr, getdate -from webnotes.model import db_exists -from webnotes.model.doc import make_autoname -from webnotes.model.bean import getlist, copy_doclist +from webnotes.model.bean import getlist from webnotes.model.code import get_obj from webnotes import msgprint from stock.utils import get_valid_serial_nos @@ -37,9 +35,6 @@ class DocType(TransactionBase): self.tname = 'Installation Note Item' self.fname = 'installed_item_details' - def autoname(self): - self.doc.name = make_autoname(self.doc.naming_series+'.#####') - def validate(self): self.validate_fiscal_year() self.validate_installation_date() diff --git a/selling/doctype/installation_note/installation_note.txt b/selling/doctype/installation_note/installation_note.txt index 52917e0b01..9dd851d583 100644 --- a/selling/doctype/installation_note/installation_note.txt +++ b/selling/doctype/installation_note/installation_note.txt @@ -1,13 +1,13 @@ [ { - "creation": "2013-01-10 16:34:18", + "creation": "2013-04-30 13:13:06", "docstatus": 0, - "modified": "2013-01-22 14:56:02", + "modified": "2013-05-09 14:43:28", "modified_by": "Administrator", "owner": "Administrator" }, { - "autoname": "IN/.####", + "autoname": "naming_series:", "doctype": "DocType", "is_submittable": 1, "module": "Selling", @@ -33,6 +33,7 @@ "permlevel": 0, "read": 1, "report": 1, + "role": "Sales User", "submit": 1, "write": 1 }, @@ -302,15 +303,6 @@ "options": "Installation Note Item" }, { - "doctype": "DocPerm", - "role": "System Manager" - }, - { - "doctype": "DocPerm", - "role": "Sales User" - }, - { - "doctype": "DocPerm", - "role": "Sales Manager" + "doctype": "DocPerm" } ] \ No newline at end of file diff --git a/utilities/doctype/address/address.py b/utilities/doctype/address/address.py index 243bbdd7e3..cfcbea582f 100644 --- a/utilities/doctype/address/address.py +++ b/utilities/doctype/address/address.py @@ -18,6 +18,7 @@ from __future__ import unicode_literals import webnotes from webnotes import msgprint +from webnotes.utils import cstr class DocType: def __init__(self, doc, doclist=[]): @@ -29,7 +30,7 @@ class DocType: self.doc.address_title = self.doc.customer or self.doc.supplier or self.doc.sales_partner if self.doc.address_title: - self.doc.name = self.doc.address_title + "-" + self.doc.address_type + self.doc.name = cstr(self.doc.address_title).strip() + "-" + cstr(self.doc.address_type).strip() else: webnotes.msgprint("""Address Title is mandatory.""", raise_exception=True) diff --git a/utilities/doctype/contact/contact.py b/utilities/doctype/contact/contact.py index bceee7d6a1..a19501f100 100644 --- a/utilities/doctype/contact/contact.py +++ b/utilities/doctype/contact/contact.py @@ -16,7 +16,7 @@ from __future__ import unicode_literals import webnotes - +from webnotes.utils import cstr from utilities.transaction_base import TransactionBase @@ -32,15 +32,16 @@ class DocType(TransactionBase): webnotes.conn.set(self.doc, 'status', 'Replied') def autoname(self): - if self.doc.customer: - self.doc.name = self.doc.first_name + (self.doc.last_name and ' ' + self.doc.last_name or '') + '-' + self.doc.customer - elif self.doc.supplier: - self.doc.name = self.doc.first_name + (self.doc.last_name and ' ' + self.doc.last_name or '') + '-' + self.doc.supplier - elif self.doc.sales_partner: - self.doc.name = self.doc.first_name + (self.doc.last_name and ' ' + self.doc.last_name or '') + '-' + self.doc.sales_partner - else: - self.doc.name = self.doc.first_name + (self.doc.last_name and ' ' + self.doc.last_name or '') - + # concat first and last name + self.doc.name = " ".join(filter(None, + [cstr(self.doc.fields.get(f)).strip() for f in ["first_name", "last_name"]])) + + # concat party name if reqd + for fieldname in ("customer", "supplier", "sales_partner"): + if self.doc.fields.get(fieldname): + self.doc.name = self.doc.name + "-" + cstr(self.doc.fields.get(fieldname)).strip() + break + def validate(self): self.validate_primary_contact()