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()