diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py index 19fda8e817f..9fa972d564a 100644 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py @@ -113,9 +113,8 @@ class AccountsReceivableReport(object): if not hasattr(self, "account_map"): self.account_map = dict(((r.name, r) for r in webnotes.conn.sql("""select acc.name, cust.name as customer, cust.customer_name, cust.territory - from `tabAccount` acc, `tabCustomer` cust - where acc.master_type="Customer" - and cust.name=acc.master_name""", as_dict=True))) + from `tabAccount` acc left join `tabCustomer` cust + on cust.name=acc.master_name where acc.master_type="Customer" """, as_dict=True))) return self.account_map @@ -134,7 +133,6 @@ class AccountsReceivableReport(object): self.gl_entries = webnotes.conn.sql("""select * from `tabGL Entry` where docstatus < 2 {0} order by posting_date, account""".format(conditions), values, as_dict=True) - return self.gl_entries def prepare_conditions(self): diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 941c2ae74f9..495284a7bfd 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -355,20 +355,23 @@ def get_actual_expense(args): and fiscal_year='%(fiscal_year)s' and company='%(company)s' %(condition)s """ % (args))[0][0] -def rename_account_for(dt, olddn, newdn, merge): +def rename_account_for(dt, olddn, newdn, merge, company): old_account = get_account_for(dt, olddn) if old_account: new_account = None if not merge: - if old_account == olddn: - new_account = webnotes.rename_doc("Account", olddn, newdn) + if old_account == add_abbr_if_missing(olddn, company): + new_account = webnotes.rename_doc("Account", old_account, newdn) else: existing_new_account = get_account_for(dt, newdn) new_account = webnotes.rename_doc("Account", old_account, existing_new_account or newdn, merge=True if existing_new_account else False) - if new_account: - webnotes.conn.set_value("Account", new_account, "master_name", newdn) + webnotes.conn.set_value("Account", new_account or old_account, "master_name", newdn) + +def add_abbr_if_missing(dn, company): + from setup.doctype.company.company import get_name_with_abbr + return get_name_with_abbr(dn, company) def get_account_for(account_for_doctype, account_for): if account_for_doctype in ["Customer", "Supplier"]: diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.py b/erpnext/buying/doctype/purchase_common/purchase_common.py index d967b2450de..2ec67fd0f4e 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.py +++ b/erpnext/buying/doctype/purchase_common/purchase_common.py @@ -93,7 +93,7 @@ class DocType(BuyingController): if not item: webnotes.throw("Item %s does not exist in Item Master." % cstr(d.item_code)) - from erpnext.stock.utils import validate_end_of_life + from erpnext.stock.doctype.item.item import validate_end_of_life validate_end_of_life(d.item_code, item[0][3]) # validate stock item diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py index 9fe52c8b995..94a16f5a4eb 100644 --- a/erpnext/buying/doctype/supplier/supplier.py +++ b/erpnext/buying/doctype/supplier/supplier.py @@ -92,7 +92,7 @@ class DocType(TransactionBase): def before_rename(self, olddn, newdn, merge=False): from erpnext.accounts.utils import rename_account_for - rename_account_for("Supplier", olddn, newdn, merge) + rename_account_for("Supplier", olddn, newdn, merge, self.doc.company) def after_rename(self, olddn, newdn, merge=False): set_field = '' @@ -126,5 +126,4 @@ def get_dashboard_info(supplier): out["total_billing"] = billing[0][0] out["total_unpaid"] = billing[0][1] - return out - \ No newline at end of file + return out \ No newline at end of file diff --git a/patches/1401/fix_planned_qty.py b/erpnext/patches/1401/fix_planned_qty.py similarity index 100% rename from patches/1401/fix_planned_qty.py rename to erpnext/patches/1401/fix_planned_qty.py diff --git a/patches/1401/fix_serial_no_status_and_warehouse.py b/erpnext/patches/1401/fix_serial_no_status_and_warehouse.py similarity index 100% rename from patches/1401/fix_serial_no_status_and_warehouse.py rename to erpnext/patches/1401/fix_serial_no_status_and_warehouse.py diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index f51cd552fd4..df17689df75 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -3,15 +3,12 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import cstr from webnotes.model.doc import Document, make_autoname from webnotes import msgprint, _ import webnotes.defaults from erpnext.utilities.transaction_base import TransactionBase -from erpnext.utilities.doctype.address.address import get_address_display -from erpnext.utilities.doctype.contact.contact import get_contact_details from erpnext.accounts.party import create_party_account class DocType(TransactionBase): @@ -128,7 +125,7 @@ class DocType(TransactionBase): def before_rename(self, olddn, newdn, merge=False): from erpnext.accounts.utils import rename_account_for - rename_account_for("Customer", olddn, newdn, merge) + rename_account_for("Customer", olddn, newdn, merge, self.doc.company) def after_rename(self, olddn, newdn, merge=False): set_field = '' diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index 16938b40270..dcb6c0fdeef 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -260,3 +260,47 @@ class DocType(DocListController): webnotes.conn.set_default("allow_negative_stock", webnotes.conn.get_value("Stock Settings", None, "allow_negative_stock")) webnotes.conn.auto_commit_on_many_writes = 0 + +def validate_end_of_life(item_code, end_of_life=None, verbose=1): + if not end_of_life: + end_of_life = webnotes.conn.get_value("Item", item_code, "end_of_life") + + from webnotes.utils import getdate, now_datetime, formatdate + if end_of_life and getdate(end_of_life) <= now_datetime().date(): + msg = (_("Item") + " %(item_code)s: " + _("reached its end of life on") + \ + " %(date)s. " + _("Please check") + ": %(end_of_life_label)s " + \ + "in Item master") % { + "item_code": item_code, + "date": formatdate(end_of_life), + "end_of_life_label": webnotes.get_doctype("Item").get_label("end_of_life") + } + + _msgprint(msg, verbose) + +def validate_is_stock_item(item_code, is_stock_item=None, verbose=1): + if not is_stock_item: + is_stock_item = webnotes.conn.get_value("Item", item_code, "is_stock_item") + + if is_stock_item != "Yes": + msg = (_("Item") + " %(item_code)s: " + _("is not a Stock Item")) % { + "item_code": item_code, + } + + _msgprint(msg, verbose) + +def validate_cancelled_item(item_code, docstatus=None, verbose=1): + if docstatus is None: + docstatus = webnotes.conn.get_value("Item", item_code, "docstatus") + + if docstatus == 2: + msg = (_("Item") + " %(item_code)s: " + _("is a cancelled Item")) % { + "item_code": item_code, + } + + _msgprint(msg, verbose) + +def _msgprint(msg, verbose): + if verbose: + msgprint(msg, raise_exception=True) + else: + raise webnotes.ValidationError, msg \ No newline at end of file diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index f219aa06a56..f61bd40de50 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -90,8 +90,8 @@ class DocType(StockController): raise webnotes.ValidationError def validate_item(self, item_code, row_num): - from erpnext.stock.utils import validate_end_of_life, validate_is_stock_item, \ - validate_cancelled_item + from erpnext.stock.doctype.item.item import validate_end_of_life, \ + validate_is_stock_item, validate_cancelled_item # using try except to catch all validation msgs and display together diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py index 0f2d138a062..68dea059ae2 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.py +++ b/erpnext/stock/doctype/warehouse/warehouse.py @@ -106,7 +106,7 @@ class DocType: webnotes.conn.sql("delete from `tabBin` where warehouse=%s", olddn) from erpnext.accounts.utils import rename_account_for - rename_account_for("Warehouse", olddn, new_warehouse, merge) + rename_account_for("Warehouse", olddn, newdn, merge, self.doc.company) return new_warehouse diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index 69a024b7e92..f203023bfb4 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -63,50 +63,6 @@ def update_bin(args): msgprint("[Stock Update] Ignored %s since it is not a stock item" % args.get("item_code")) -def validate_end_of_life(item_code, end_of_life=None, verbose=1): - if not end_of_life: - end_of_life = webnotes.conn.get_value("Item", item_code, "end_of_life") - - from webnotes.utils import getdate, now_datetime, formatdate - if end_of_life and getdate(end_of_life) <= now_datetime().date(): - msg = (_("Item") + " %(item_code)s: " + _("reached its end of life on") + \ - " %(date)s. " + _("Please check") + ": %(end_of_life_label)s " + \ - "in Item master") % { - "item_code": item_code, - "date": formatdate(end_of_life), - "end_of_life_label": webnotes.get_doctype("Item").get_label("end_of_life") - } - - _msgprint(msg, verbose) - -def validate_is_stock_item(item_code, is_stock_item=None, verbose=1): - if not is_stock_item: - is_stock_item = webnotes.conn.get_value("Item", item_code, "is_stock_item") - - if is_stock_item != "Yes": - msg = (_("Item") + " %(item_code)s: " + _("is not a Stock Item")) % { - "item_code": item_code, - } - - _msgprint(msg, verbose) - -def validate_cancelled_item(item_code, docstatus=None, verbose=1): - if docstatus is None: - docstatus = webnotes.conn.get_value("Item", item_code, "docstatus") - - if docstatus == 2: - msg = (_("Item") + " %(item_code)s: " + _("is a cancelled Item")) % { - "item_code": item_code, - } - - _msgprint(msg, verbose) - -def _msgprint(msg, verbose): - if verbose: - msgprint(msg, raise_exception=True) - else: - raise webnotes.ValidationError, msg - def get_incoming_rate(args): """Get Incoming Rate based on valuation method""" from erpnext.stock.stock_ledger import get_previous_sle diff --git a/erpnext/utilities/doctype/sms_control/sms_control.py b/erpnext/utilities/doctype/sms_control/sms_control.py index 41ff2a15159..5c08a413161 100644 --- a/erpnext/utilities/doctype/sms_control/sms_control.py +++ b/erpnext/utilities/doctype/sms_control/sms_control.py @@ -8,7 +8,7 @@ from webnotes.utils import nowdate, cstr from webnotes.model.code import get_obj from webnotes.model.doc import Document from webnotes import msgprint, throw, _ -from webnotes.model.bean import getlist, copy_doclist +from webnotes.model.bean import getlist class DocType: def __init__(self, doc, doclist=[]): @@ -55,7 +55,7 @@ class DocType: def send_form_sms(self, arg): "called from client side" args = json.loads(arg) - self.send_sms([str(args['number'])], str(args['message'])) + self.send_sms([cstr(args['number'])], cstr(args['message'])) def send_sms(self, receiver_list, msg, sender_name = ''): receiver_list = self.validate_receiver_nos(receiver_list) diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py index 098a4bd8e9d..83a3857807f 100644 --- a/erpnext/utilities/transaction_base.py +++ b/erpnext/utilities/transaction_base.py @@ -201,14 +201,6 @@ def validate_conversion_rate(currency, conversion_rate, conversion_rate_label, c "from_currency": currency, "to_currency": company_currency }, raise_exception=True) - -def validate_item_fetch(args, item): - from erpnext.stock.utils import validate_end_of_life - validate_end_of_life(item.name, item.end_of_life) - - # validate company - if not args.company: - msgprint(_("Please specify Company"), raise_exception=True) def validate_currency(args, item, meta=None): from webnotes.model.meta import get_field_precision