diff --git a/accounts/doctype/journal_voucher/journal_voucher.py b/accounts/doctype/journal_voucher/journal_voucher.py index 79ee19f22f8..551b07d7573 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/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index 82261ed5ea9..f144ce951b6 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/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index 2e48f91879a..60bf0102ab1 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/buying/doctype/purchase_common/purchase_common.py b/buying/doctype/purchase_common/purchase_common.py index 615c4535815..700fd7a87b6 100644 --- a/buying/doctype/purchase_common/purchase_common.py +++ b/buying/doctype/purchase_common/purchase_common.py @@ -449,16 +449,9 @@ class DocType(BuyingController): arg = eval(arg) rate = sql("select account_type, tax_rate from `tabAccount` where name = '%s'" %(arg['account_head']), as_dict=1) - ret = { - 'rate' : rate and (rate[0]['account_type'] == 'Tax' and not arg['charge_type'] == 'Actual') and flt(rate[0]['tax_rate']) or 0 - } - #msgprint(ret) - return ret - - def get_total_in_words(self, currency, amount): - from webnotes.utils import money_in_words - return money_in_words(amount, currency) - + return {'rate': rate and (rate[0]['account_type'] == 'Tax' \ + and not arg['charge_type'] == 'Actual') and flt(rate[0]['tax_rate']) or 0 } + def get_prevdoc_date(self, obj): for d in getlist(obj.doclist, obj.fname): if d.prevdoc_doctype and d.prevdoc_docname: diff --git a/buying/doctype/purchase_order/purchase_order.py b/buying/doctype/purchase_order/purchase_order.py index f08a319b452..6cef02a20b2 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 4f28ecf59cb..c8f528276e4 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 d7a2964c49e..f48b626d5db 100644 --- a/controllers/buying_controller.py +++ b/controllers/buying_controller.py @@ -31,6 +31,9 @@ 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 + self.set_total_in_words() def update_item_details(self): for item in self.doclist.get({"parentfield": self.fname}): @@ -68,3 +71,12 @@ 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): + 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.grand_total, company_currency) + if self.meta.get_field("in_words_import"): + self.doc.in_words_import = money_in_words(self.doc.grand_total_import, + self.doc.currency) \ No newline at end of file diff --git a/controllers/selling_controller.py b/controllers/selling_controller.py new file mode 100644 index 00000000000..8dd188295a1 --- /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 651cc77776d..0f8e1ce2527 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/patches/january_2013/update_fraction_for_usd.py b/patches/january_2013/update_fraction_for_usd.py new file mode 100644 index 00000000000..f90f8658819 --- /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 dda35247a44..cdaa2ad9a19 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 diff --git a/selling/doctype/lead/lead.py b/selling/doctype/lead/lead.py index dd24ff696ca..94231353524 100644 --- a/selling/doctype/lead/lead.py +++ b/selling/doctype/lead/lead.py @@ -16,16 +16,16 @@ 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 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 @@ -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 diff --git a/selling/doctype/quotation/quotation.py b/selling/doctype/quotation/quotation.py index e77cad3d03c..6c1300b28d7 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 b0b04bf68eb..82acaa1bed4 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 f035cdc6569..868608123e3 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/setup/utils.py b/setup/utils.py index 396dc16a7dd..1b61ea9201e 100644 --- a/setup/utils.py +++ b/setup/utils.py @@ -46,4 +46,4 @@ def get_price_list_currency(args): if result and len(result)==1: return {"price_list_currency": result[0][0]} else: - return {} + return {} \ No newline at end of file diff --git a/stock/doctype/delivery_note/delivery_note.py b/stock/doctype/delivery_note/delivery_note.py index 53f66c32dec..4c5aeee4efa 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() diff --git a/stock/doctype/purchase_receipt/purchase_receipt.py b/stock/doctype/purchase_receipt/purchase_receipt.py index 5c4aebdecbb..46484e042ee 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()