item related cleanup

This commit is contained in:
Nabin Hait 2014-02-06 15:51:01 +05:30
commit 574c7e7c63
13 changed files with 63 additions and 74 deletions

View File

@ -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):

View File

@ -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"]:

View File

@ -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

View File

@ -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
return out

View File

@ -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 = ''

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

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

View File

@ -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