From d3b625035c867910b27d8a321ee1a32d26353fdc Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 21 Jan 2013 17:24:31 +0530 Subject: [PATCH 1/4] fixes in total_in_words --- .../doctype/purchase_invoice/purchase_invoice.py | 9 --------- buying/doctype/purchase_common/purchase_common.py | 8 -------- buying/doctype/purchase_order/purchase_order.py | 4 ---- .../doctype/supplier_quotation/supplier_quotation.py | 9 +-------- controllers/buying_controller.py | 12 +++++++++++- setup/utils.py | 6 ++++++ stock/doctype/purchase_receipt/purchase_receipt.py | 7 +------ 7 files changed, 19 insertions(+), 36 deletions(-) diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index 82261ed5ea..f144ce951b 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -366,15 +366,6 @@ class DocType(BuyingController): self.doc.posting_date,'Posting Date') self.validate_write_off_account() - - #get Purchase Common Obj - pc_obj = get_obj(dt='Purchase Common') - - # get total in words - dcc = get_company_currency(self.doc.company) - self.doc.in_words = pc_obj.get_total_in_words(dcc, self.doc.grand_total) - self.doc.in_words_import = pc_obj.get_total_in_words(self.doc.currency, - self.doc.grand_total_import) def check_prev_docstatus(self): for d in getlist(self.doclist,'entries'): diff --git a/buying/doctype/purchase_common/purchase_common.py b/buying/doctype/purchase_common/purchase_common.py index 79e4fe0de6..42b558c491 100644 --- a/buying/doctype/purchase_common/purchase_common.py +++ b/buying/doctype/purchase_common/purchase_common.py @@ -456,14 +456,6 @@ class DocType(BuyingController): } #msgprint(ret) return ret - - - - # Get total in words - # ================================================================== - def get_total_in_words(self, currency, amount): - from webnotes.utils import money_in_words - return money_in_words(amount, currency) # get against document date #----------------------------- diff --git a/buying/doctype/purchase_order/purchase_order.py b/buying/doctype/purchase_order/purchase_order.py index f08a319b45..6cef02a20b 100644 --- a/buying/doctype/purchase_order/purchase_order.py +++ b/buying/doctype/purchase_order/purchase_order.py @@ -67,10 +67,6 @@ class DocType(BuyingController): # Check for stopped status self.check_for_stopped_status(pc_obj) - # get total in words - dcc = get_company_currency(self.doc.company) - self.doc.in_words = pc_obj.get_total_in_words(dcc, self.doc.grand_total) - self.doc.in_words_import = pc_obj.get_total_in_words(self.doc.currency, self.doc.grand_total_import) def get_default_schedule_date(self): get_obj(dt = 'Purchase Common').get_default_schedule_date(self) diff --git a/buying/doctype/supplier_quotation/supplier_quotation.py b/buying/doctype/supplier_quotation/supplier_quotation.py index 4f28ecf59c..c8f528276e 100644 --- a/buying/doctype/supplier_quotation/supplier_quotation.py +++ b/buying/doctype/supplier_quotation/supplier_quotation.py @@ -37,7 +37,6 @@ class DocType(BuyingController): self.validate_fiscal_year() self.validate_common() - self.set_in_words() def on_submit(self): purchase_controller = webnotes.get_obj("Purchase Common") @@ -79,10 +78,4 @@ class DocType(BuyingController): pc.validate_mandatory(self) pc.validate_for_items(self) pc.get_prevdoc_date(self) - pc.validate_reference_value(self) - - def set_in_words(self): - pc = get_obj('Purchase Common') - company_currency = get_company_currency(self.doc.company) - self.doc.in_words = pc.get_total_in_words(company_currency, self.doc.grand_total) - self.doc.in_words_import = pc.get_total_in_words(self.doc.currency, self.doc.grand_total_import) + pc.validate_reference_value(self) \ No newline at end of file diff --git a/controllers/buying_controller.py b/controllers/buying_controller.py index d7a2964c49..1127d82bbb 100644 --- a/controllers/buying_controller.py +++ b/controllers/buying_controller.py @@ -20,7 +20,7 @@ from webnotes import _, msgprint from webnotes.utils import flt from buying.utils import get_item_details -from setup.utils import get_company_currency +from setup.utils import get_company_currency, get_total_in_words from utilities.transaction_base import TransactionBase class BuyingController(TransactionBase): @@ -31,6 +31,10 @@ class BuyingController(TransactionBase): if self.doc.price_list_name and self.doc.price_list_currency: self.validate_conversion_rate("price_list_currency", "plc_conversion_rate") + + # set total in words + if self.meta.get_field("in_words") and self.meta.get_field("in_words_import"): + self.set_total_in_words() def update_item_details(self): for item in self.doclist.get({"parentfield": self.fname}): @@ -68,3 +72,9 @@ class BuyingController(TransactionBase): msgprint(_('Please enter valid ') + conversion_rate_label + (': ') + ("1 %s = [?] %s" % (currency, self.company_currency)), raise_exception=True) + + def set_total_in_words(self): + company_currency = get_company_currency(self.doc.company) + self.doc.in_words = get_total_in_words(self.doc.grand_total, company_currency) + self.doc.in_words_import = get_total_in_words(self.doc.grand_total_import, + self.doc.currency) \ No newline at end of file diff --git a/setup/utils.py b/setup/utils.py index 396dc16a7d..7005235c3c 100644 --- a/setup/utils.py +++ b/setup/utils.py @@ -47,3 +47,9 @@ def get_price_list_currency(args): return {"price_list_currency": result[0][0]} else: return {} + +@webnotes.whitelist() +def get_total_in_words(amount, currency): + from webnotes.utils import money_in_words + fraction = webnotes.conn.get_value("Currency", currency, "fraction") + return money_in_words(amount, currency, fraction) \ No newline at end of file diff --git a/stock/doctype/purchase_receipt/purchase_receipt.py b/stock/doctype/purchase_receipt/purchase_receipt.py index 5c4aebdecb..46484e042e 100644 --- a/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/stock/doctype/purchase_receipt/purchase_receipt.py @@ -17,12 +17,11 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import cstr, flt, get_defaults, getdate +from webnotes.utils import cstr, flt, get_defaults from webnotes.model.doc import addchild from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj from webnotes import msgprint -from setup.utils import get_company_currency sql = webnotes.conn.sql @@ -136,10 +135,6 @@ class DocType(BuyingController): pc_obj.validate_reference_value(self) self.check_for_stopped_status(pc_obj) - # get total in words - dcc = get_company_currency(self.doc.company) - self.doc.in_words = pc_obj.get_total_in_words(dcc, self.doc.grand_total) - self.doc.in_words_import = pc_obj.get_total_in_words(self.doc.currency, self.doc.grand_total_import) # update valuation rate self.update_valuation_rate() From f0881a9e9241d6dcd11471366b0a1927f73a7ce6 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 22 Jan 2013 11:21:55 +0530 Subject: [PATCH 2/4] updated fraction for USD --- patches/january_2013/update_fraction_for_usd.py | 3 +++ patches/patch_list.py | 1 + 2 files changed, 4 insertions(+) create mode 100644 patches/january_2013/update_fraction_for_usd.py diff --git a/patches/january_2013/update_fraction_for_usd.py b/patches/january_2013/update_fraction_for_usd.py new file mode 100644 index 0000000000..f90f865881 --- /dev/null +++ b/patches/january_2013/update_fraction_for_usd.py @@ -0,0 +1,3 @@ +def execute(): + import webnotes + webnotes.conn.sql("""update `tabCurrency` set fraction = 'Cent' where fraction = 'Cent[D]'""") \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index dda35247a4..cdaa2ad9a1 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -154,4 +154,5 @@ patch_list = [ "patches.january_2013.update_number_format", "patches.january_2013.purchase_price_list", "execute:webnotes.reload_doc('accounts','Print Format','Payment Receipt Voucher')", + "patches.january_2013.update_fraction_for_usd", ] \ No newline at end of file From ec52db84904afae570a0bf7202e7efc901b59ef9 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 22 Jan 2013 11:53:14 +0530 Subject: [PATCH 3/4] commonified in_words function and introduced selling_controller --- .../journal_voucher/journal_voucher.py | 11 +++--- .../doctype/sales_invoice/sales_invoice.py | 35 ++++++++----------- controllers/selling_controller.py | 33 +++++++++++++++++ hr/doctype/salary_slip/salary_slip.py | 5 +-- selling/doctype/lead/lead.py | 4 +-- selling/doctype/quotation/quotation.py | 17 +++------ selling/doctype/sales_common/sales_common.py | 19 +++------- selling/doctype/sales_order/sales_order.py | 17 ++++----- stock/doctype/delivery_note/delivery_note.py | 16 ++++----- 9 files changed, 79 insertions(+), 78 deletions(-) create mode 100644 controllers/selling_controller.py diff --git a/accounts/doctype/journal_voucher/journal_voucher.py b/accounts/doctype/journal_voucher/journal_voucher.py index 79ee19f22f..551b07d757 100644 --- a/accounts/doctype/journal_voucher/journal_voucher.py +++ b/accounts/doctype/journal_voucher/journal_voucher.py @@ -237,11 +237,12 @@ class DocType: self.doc.pay_to_recd_from = webnotes.conn.get_value(master_type, ' - '.join(d.account.split(' - ')[:-1]), master_type == 'Customer' and 'customer_name' or 'supplier_name') if acc_type == 'Bank or Cash': - dcc = get_company_currency(self.doc.company) - amt = cint(d.debit) and d.debit or d.credit - self.doc.total_amount = dcc +' '+ cstr(amt) - self.doc.total_amount_in_words = get_obj('Sales Common').get_total_in_words(dcc, cstr(amt)) - + company_currency = get_company_currency(self.doc.company) + amt = flt(d.debit) and d.debit or d.credit + self.doc.total_amount = company_currency +' '+ cstr(amt) + from webnotes.utils import money_in_words + self.doc.total_amount_in_words = money_in_words(amt, company_currency) + def get_values(self): cond = (flt(self.doc.write_off_amount) > 0) and ' and outstanding_amount <= '+self.doc.write_off_amount or '' if self.doc.write_off_based_on == 'Accounts Receivable': diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index 2e48f91879..60bf0102ab 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.py +++ b/accounts/doctype/sales_invoice/sales_invoice.py @@ -17,25 +17,21 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import add_days, cint, cstr, date_diff, flt, getTraceback, getdate, now, nowdate, sendmail, validate_email_add - +from webnotes.utils import add_days, cint, cstr, date_diff, flt, getdate, nowdate, sendmail from webnotes.utils import comma_and -from webnotes import _ -from webnotes.model import db_exists from webnotes.model.doc import make_autoname -from webnotes.model.wrapper import getlist, copy_doclist +from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj -from webnotes import session, form, msgprint -from setup.utils import get_company_currency +from webnotes import _, msgprint session = webnotes.session month_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12} -from utilities.transaction_base import TransactionBase +from controllers.selling_controller import SellingController -class DocType(TransactionBase): +class DocType(SellingController): def __init__(self,d,dl): self.doc, self.doclist = d, dl self.log = [] @@ -46,6 +42,8 @@ class DocType(TransactionBase): self.doc.name = make_autoname(self.doc.naming_series+ '.#####') def validate(self): + super(DocType, self).validate() + self.so_dn_required() self.validate_proj_cust() sales_com_obj = get_obj('Sales Common') @@ -70,7 +68,6 @@ class DocType(TransactionBase): self.validate_item_code() self.update_current_stock() self.validate_delivery_note() - self.set_in_words() if not self.doc.is_opening: self.doc.is_opening = 'No' self.set_aging_date() @@ -253,11 +250,14 @@ class DocType(TransactionBase): ret = get_obj('Sales Common').get_item_details(args, self) return self.get_pos_details(args, ret) else: - obj = get_obj('Sales Common') for doc in self.doclist: if doc.fields.get('item_code'): - arg = {'item_code':doc.fields.get('item_code'), 'income_account':doc.fields.get('income_account'), - 'cost_center': doc.fields.get('cost_center'), 'warehouse': doc.fields.get('warehouse')}; + arg = { + 'item_code':doc.fields.get('item_code'), + 'income_account':doc.fields.get('income_account'), + 'cost_center': doc.fields.get('cost_center'), + 'warehouse': doc.fields.get('warehouse') + }; ret = self.get_pos_details(arg) for r in ret: @@ -411,13 +411,6 @@ class DocType(TransactionBase): msgprint("Please select income head with account type 'Fixed Asset Account' as Item %s is an asset item" % d.item_code) raise Exception - - def set_in_words(self): - dcc = get_company_currency(self.doc.company) - self.doc.in_words = get_obj('Sales Common').get_total_in_words(dcc, self.doc.rounded_total) - self.doc.in_words_export = get_obj('Sales Common').get_total_in_words(self.doc.currency, self.doc.rounded_total_export) - - def clear_advances(self): get_obj('GL Control').clear_advances(self, 'Sales Invoice Advance','advance_adjustment_details') @@ -744,7 +737,7 @@ def manage_recurring_invoices(next_date=None): new_invoice_wrapper = make_new_invoice(ref_wrapper, next_date) send_notification(new_invoice_wrapper) webnotes.conn.commit() - except Exception, e: + except: webnotes.conn.rollback() webnotes.conn.begin() diff --git a/controllers/selling_controller.py b/controllers/selling_controller.py new file mode 100644 index 0000000000..8dd188295a --- /dev/null +++ b/controllers/selling_controller.py @@ -0,0 +1,33 @@ +# ERPNext - web based ERP (http://erpnext.com) +# Copyright (C) 2012 Web Notes Technologies Pvt Ltd +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from __future__ import unicode_literals +import webnotes +from setup.utils import get_company_currency + +from utilities.transaction_base import TransactionBase +class SellingController(TransactionBase): + def validate(self): + self.set_total_in_words() + + def set_total_in_words(self): + from webnotes.utils import money_in_words + company_currency = get_company_currency(self.doc.company) + if self.meta.get_field("in_words"): + self.doc.in_words = money_in_words(self.doc.rounded_total, company_currency) + if self.meta.get_field("in_words_export"): + self.doc.in_words_export = money_in_words(self.doc.rounded_total_export, + self.doc.currency) \ No newline at end of file diff --git a/hr/doctype/salary_slip/salary_slip.py b/hr/doctype/salary_slip/salary_slip.py index 651cc77776..0f8e1ce252 100644 --- a/hr/doctype/salary_slip/salary_slip.py +++ b/hr/doctype/salary_slip/salary_slip.py @@ -136,9 +136,10 @@ class DocType(TransactionBase): def validate(self): + from webnotes.utils import money_in_words self.check_existing() - dcc = get_company_currency(self.doc.company) - self.doc.total_in_words = get_obj('Sales Common').get_total_in_words(dcc, self.doc.rounded_total) + company_currency = get_company_currency(self.doc.company) + self.doc.total_in_words = money_in_words(self.doc.rounded_total, company_currency) def calculate_earning_total(self): diff --git a/selling/doctype/lead/lead.py b/selling/doctype/lead/lead.py index dd24ff696c..81c0d88de7 100644 --- a/selling/doctype/lead/lead.py +++ b/selling/doctype/lead/lead.py @@ -23,9 +23,9 @@ from webnotes import session, msgprint sql = webnotes.conn.sql -from utilities.transaction_base import TransactionBase +from controllers.selling_controller import SellingController -class DocType(TransactionBase): +class DocType(SellingController): def __init__(self, doc, doclist): self.doc = doc self.doclist = doclist diff --git a/selling/doctype/quotation/quotation.py b/selling/doctype/quotation/quotation.py index 111b0b493b..145bcb4ccf 100644 --- a/selling/doctype/quotation/quotation.py +++ b/selling/doctype/quotation/quotation.py @@ -21,14 +21,13 @@ from webnotes.utils import cstr, getdate from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj from webnotes import msgprint -from setup.utils import get_company_currency sql = webnotes.conn.sql -from utilities.transaction_base import TransactionBase +from controllers.selling_controller import SellingController -class DocType(TransactionBase): +class DocType(SellingController): def __init__(self, doc, doclist=[]): self.doc = doc self.doclist = doclist @@ -172,12 +171,10 @@ class DocType(TransactionBase): else: msgprint("Contact Date Cannot be before Last Contact Date") raise Exception - #webnotes.conn.set(self.doc, 'contact_date_ref',self.doc.contact_date) - - # Validate - # -------- def validate(self): + super(DocType, self).validate() + import utilities utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Order Confirmed", "Order Lost", "Cancelled"]) @@ -189,13 +186,9 @@ class DocType(TransactionBase): self.validate_for_items() sales_com_obj = get_obj('Sales Common') sales_com_obj.check_active_sales_items(self) - sales_com_obj.validate_max_discount(self,'quotation_details') #verify whether rate is not greater than max_discount + sales_com_obj.validate_max_discount(self,'quotation_details') sales_com_obj.check_conversion_rate(self) - # Get total in words - dcc = get_company_currency(self.doc.company) - self.doc.in_words = sales_com_obj.get_total_in_words(dcc, self.doc.rounded_total) - self.doc.in_words_export = sales_com_obj.get_total_in_words(self.doc.currency, self.doc.rounded_total_export) def on_update(self): # Set Quotation Status diff --git a/selling/doctype/sales_common/sales_common.py b/selling/doctype/sales_common/sales_common.py index b0b04bf68e..82acaa1bed 100644 --- a/selling/doctype/sales_common/sales_common.py +++ b/selling/doctype/sales_common/sales_common.py @@ -17,12 +17,11 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import add_days, cint, cstr, default_fields, flt, getdate, now, nowdate, formatdate -from webnotes.model import db_exists +from webnotes.utils import cint, cstr, flt, getdate, nowdate, formatdate from webnotes.model.doc import addchild -from webnotes.model.wrapper import getlist, copy_doclist +from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj -from webnotes import form, msgprint, _ +from webnotes import msgprint, _ from setup.utils import get_company_currency get_value = webnotes.conn.get_value @@ -546,17 +545,10 @@ class DocType(TransactionBase): tuple(delete_list)) return obj.doclist - - # Get total in words - # ================================================================== - def get_total_in_words(self, currency, amount): - from webnotes.utils import money_in_words - return money_in_words(amount, currency) - # Get month based on date (required in sales person and sales partner) - # ======================================================================== def get_month(self,date): + """Get month based on date (required in sales person and sales partner)""" month_list = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] month_idx = cint(cstr(date).split('-')[1])-1 return month_list[month_idx] @@ -616,10 +608,7 @@ class DocType(TransactionBase): "fiscal_year": fiscal_year }, raise_exception=1) - # get against document date self.prevdoc_date_field - #----------------------------- def get_prevdoc_date(self, obj): - import datetime for d in getlist(obj.doclist, obj.fname): if d.prevdoc_doctype and d.prevdoc_docname: if d.prevdoc_doctype == 'Sales Invoice': diff --git a/selling/doctype/sales_order/sales_order.py b/selling/doctype/sales_order/sales_order.py index f035cdc656..868608123e 100644 --- a/selling/doctype/sales_order/sales_order.py +++ b/selling/doctype/sales_order/sales_order.py @@ -21,14 +21,13 @@ from webnotes.utils import cstr, flt, getdate from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj from webnotes import msgprint -from setup.utils import get_company_currency sql = webnotes.conn.sql -from utilities.transaction_base import TransactionBase +from controllers.selling_controller import SellingController -class DocType(TransactionBase): +class DocType(SellingController): def __init__(self, doc, doclist=None): self.doc = doc if not doclist: doclist = [] @@ -204,6 +203,8 @@ class DocType(TransactionBase): raise Exception def validate(self): + super(DocType, self).validate() + self.validate_fiscal_year() self.validate_order_type() self.validate_mandatory() @@ -215,16 +216,9 @@ class DocType(TransactionBase): sales_com_obj.check_active_sales_items(self) sales_com_obj.check_conversion_rate(self) - # verify whether rate is not greater than max_discount sales_com_obj.validate_max_discount(self,'sales_order_details') - # this is to verify that the allocated % of sales persons is 100% sales_com_obj.get_allocated_sum(self) self.doclist = sales_com_obj.make_packing_list(self,'sales_order_details') - - # get total in words - dcc = get_company_currency(self.doc.company) - self.doc.in_words = sales_com_obj.get_total_in_words(dcc, self.doc.rounded_total) - self.doc.in_words_export = sales_com_obj.get_total_in_words(self.doc.currency, self.doc.rounded_total_export) if not self.doc.status: self.doc.status = "Draft" @@ -268,7 +262,8 @@ class DocType(TransactionBase): self.check_prev_docstatus() self.update_stock_ledger(update_stock = 1) # update customer's last sales order no. - update_customer = sql("update `tabCustomer` set last_sales_order = '%s', modified = '%s' where name = '%s'" %(self.doc.name, self.doc.modified, self.doc.customer)) + sql("""update `tabCustomer` set last_sales_order = '%s', modified = '%s' + where name = '%s'""" % (self.doc.name, self.doc.modified, self.doc.customer)) get_obj('Sales Common').check_credit(self,self.doc.grand_total) get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.grand_total, self) diff --git a/stock/doctype/delivery_note/delivery_note.py b/stock/doctype/delivery_note/delivery_note.py index 53f66c32de..4c5aeee4ef 100644 --- a/stock/doctype/delivery_note/delivery_note.py +++ b/stock/doctype/delivery_note/delivery_note.py @@ -21,14 +21,13 @@ from webnotes.utils import cstr, flt, getdate from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj from webnotes import msgprint -from setup.utils import get_company_currency sql = webnotes.conn.sql -from utilities.transaction_base import TransactionBase +from controllers.selling_controller import SellingController -class DocType(TransactionBase): +class DocType(SellingController): def __init__(self, doc, doclist=[]): self.doc = doc self.doclist = doclist @@ -131,6 +130,8 @@ class DocType(TransactionBase): def validate(self): + super(DocType, self).validate() + import utilities utilities.validate_status(self.doc.status, ["Draft", "submitted", "Cancelled"]) @@ -144,14 +145,9 @@ class DocType(TransactionBase): self.validate_mandatory() self.validate_reference_value() self.validate_for_items() - sales_com_obj.validate_max_discount(self, 'delivery_note_details') #verify whether rate is not greater than max discount - sales_com_obj.get_allocated_sum(self) # this is to verify that the allocated % of sales persons is 100% + sales_com_obj.validate_max_discount(self, 'delivery_note_details') + sales_com_obj.get_allocated_sum(self) sales_com_obj.check_conversion_rate(self) - - # Get total in Words - dcc = get_company_currency(self.doc.company) - self.doc.in_words = sales_com_obj.get_total_in_words(dcc, self.doc.rounded_total) - self.doc.in_words_export = sales_com_obj.get_total_in_words(self.doc.currency, self.doc.rounded_total_export) # Set actual qty for each item in selected warehouse self.update_current_stock() From 3d55e3dd59d7002564c66d71c06ef0b19f97d660 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 22 Jan 2013 12:09:51 +0530 Subject: [PATCH 4/4] fmt_money - don't format flat types --- selling/doctype/lead/lead.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/selling/doctype/lead/lead.py b/selling/doctype/lead/lead.py index dd24ff696c..1b7311166b 100644 --- a/selling/doctype/lead/lead.py +++ b/selling/doctype/lead/lead.py @@ -16,7 +16,7 @@ from __future__ import unicode_literals import webnotes - +from webnotes import _ from webnotes.utils import cstr, validate_email_add from webnotes.model.doc import Document, addchild from webnotes import session, msgprint @@ -51,10 +51,23 @@ class DocType(TransactionBase): if not validate_email_add(self.doc.email_id): msgprint('Please enter valid email id.') raise Exception + def on_update(self): if self.doc.contact_date: self.add_calendar_event() + + self.check_email_id_is_unique() + + def check_email_id_is_unique(self): + if self.doc.email_id: + # validate email is unique + email_list = webnotes.conn.sql("""select name from tabLead where email_id=%s""", + self.doc.email_id) + if len(email_list) > 1: + items = [e[0] for e in email_list if e[0]!=self.doc.name] + webnotes.msgprint(_("""Email Id must be unique, already exists for: """) + \ + ", ".join(items), raise_exception=True) def add_calendar_event(self): # delete any earlier event by this lead