[fix] [cleanup] fixes while testing and code cleanup

This commit is contained in:
Nabin Hait 2013-07-11 17:49:18 +05:30
parent 1ac928ed5c
commit cfecd2bc16
39 changed files with 197 additions and 409 deletions

View File

@ -18,9 +18,8 @@ from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import cint, cstr, flt, fmt_money, formatdate, getdate from webnotes.utils import cint, cstr, flt, fmt_money, formatdate, getdate
from webnotes.model.doc import addchild, make_autoname from webnotes.model.doc import addchild
from webnotes.model.bean import getlist from webnotes.model.bean import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint from webnotes import msgprint
from setup.utils import get_company_currency from setup.utils import get_company_currency
@ -39,13 +38,13 @@ class DocType(AccountsController):
self.doc.is_opening='No' self.doc.is_opening='No'
self.doc.clearance_date = None self.doc.clearance_date = None
super(DocType, self).validate_date_with_fiscal_year()
self.validate_debit_credit() self.validate_debit_credit()
self.validate_cheque_info() self.validate_cheque_info()
self.validate_entries_for_advance() self.validate_entries_for_advance()
self.validate_against_jv() self.validate_against_jv()
get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year, \
self.doc.posting_date, 'Posting Date')
self.set_against_account() self.set_against_account()
self.create_remarks() self.create_remarks()

View File

@ -144,25 +144,30 @@ def gl_entry_details(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond from controllers.queries import get_match_cond
return webnotes.conn.sql("""select gle.voucher_no, gle.posting_date, return webnotes.conn.sql("""select gle.voucher_no, gle.posting_date,
gle.%(account_type)s from `tabGL Entry` gle gle.%(account_type)s from `tabGL Entry` gle
where gle.account = '%(acc)s' where gle.account = '%(acc)s'
and gle.voucher_type = '%(dt)s' and gle.voucher_type = '%(dt)s'
and gle.voucher_no like '%(txt)s' and gle.voucher_no like '%(txt)s'
and ifnull(gle.is_cancelled, 'No') = 'No' and ifnull(gle.is_cancelled, 'No') = 'No'
and (ifnull(gle.against_voucher, '') = '' and (ifnull(gle.against_voucher, '') = ''
or ifnull(gle.against_voucher, '') = gle.voucher_no ) or ifnull(gle.against_voucher, '') = gle.voucher_no )
and ifnull(gle.%(account_type)s, 0) > 0 and ifnull(gle.%(account_type)s, 0) > 0
and (select ifnull(abs(sum(ifnull(debit, 0)) and (select ifnull(abs(sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))), 0)
- sum(ifnull(credit, 0))), 0) from `tabGL Entry`
from `tabGL Entry` where against_voucher_type = '%(dt)s'
where against_voucher_type = '%(dt)s' and against_voucher = gle.voucher_no
and against_voucher = gle.voucher_no and voucher_no != gle.voucher_no
and voucher_no != gle.voucher_no and ifnull(is_cancelled, 'No') = 'No')
and ifnull(is_cancelled, 'No') = 'No') != abs(ifnull(gle.debit, 0) - ifnull(gle.credit, 0)
!= abs(ifnull(gle.debit, 0) - ifnull(gle.credit, 0) )
) %(mcond)s
%(mcond)s ORDER BY gle.posting_date desc, gle.voucher_no desc
ORDER BY gle.posting_date desc, gle.voucher_no desc limit %(start)s, %(page_len)s""" % {
limit %(start)s, %(page_len)s""" % {dt:filters["dt"], acc:filters["acc"], "dt":filters["dt"],
account_type: filters['account_type'], 'mcond':get_match_cond(doctype, searchfield) "acc":filters["acc"],
'txt': "%%%s%%" % txt,"start": start, "page_len": page_len}) "account_type": filters['account_type'],
'mcond':get_match_cond(doctype, searchfield),
'txt': "%%%s%%" % txt,
"start": start,
"page_len": page_len
})

View File

@ -6,7 +6,7 @@ test_records = [
"conversion_rate": 1.0, "conversion_rate": 1.0,
"price_list_name": "_Test Price List", "price_list_name": "_Test Price List",
"company": "_Test Company", "company": "_Test Company",
"warehouse": "_Test Warehouse", "warehouse": "_Test Warehouse - _TC",
"territory": "_Test Territory", "territory": "_Test Territory",
"cash_bank_account": "_Test Account Bank Account - _TC", "cash_bank_account": "_Test Account Bank Account - _TC",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",

View File

@ -66,10 +66,6 @@ class DocType(BuyingController):
#set against account for credit to #set against account for credit to
self.set_against_expense_account() self.set_against_expense_account()
#FY validation
get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year,
self.doc.posting_date,'Posting Date')
self.validate_write_off_account() self.validate_write_off_account()
self.update_raw_material_cost() self.update_raw_material_cost()

View File

@ -65,8 +65,6 @@ class DocType(SellingController):
sales_com_obj.check_active_sales_items(self) sales_com_obj.check_active_sales_items(self)
sales_com_obj.check_conversion_rate(self) sales_com_obj.check_conversion_rate(self)
sales_com_obj.validate_max_discount(self, 'entries') sales_com_obj.validate_max_discount(self, 'entries')
sales_com_obj.validate_fiscal_year(self.doc.fiscal_year,
self.doc.posting_date,'Posting Date')
self.validate_customer_account() self.validate_customer_account()
self.validate_debit_acc() self.validate_debit_acc()
self.validate_fixed_asset_account() self.validate_fixed_asset_account()

View File

@ -327,7 +327,7 @@ class TestSalesInvoice(unittest.TestCase):
si.doc.name, as_dict=1)[0] si.doc.name, as_dict=1)[0]
self.assertTrue(sle) self.assertTrue(sle)
self.assertEquals([sle.item_code, sle.warehouse, sle.actual_qty], self.assertEquals([sle.item_code, sle.warehouse, sle.actual_qty],
["_Test Item", "_Test Warehouse", -1.0]) ["_Test Item", "_Test Warehouse - _TC", -1.0])
# check gl entries # check gl entries
stock_in_hand_account = webnotes.conn.get_value("Company", "_Test Company", stock_in_hand_account = webnotes.conn.get_value("Company", "_Test Company",

View File

@ -26,10 +26,10 @@ from utilities import build_filter_conditions
class FiscalYearError(webnotes.ValidationError): pass class FiscalYearError(webnotes.ValidationError): pass
def get_fiscal_year(date=None, fiscal_year=None, verbose=1): def get_fiscal_year(date=None, fiscal_year=None, label="Date", verbose=1):
return get_fiscal_years(date, fiscal_year, verbose=1)[0] return get_fiscal_years(date, fiscal_year, label, verbose=1)[0]
def get_fiscal_years(date=None, fiscal_year=None, verbose=1): def get_fiscal_years(date=None, fiscal_year=None, label="Date", verbose=1):
# if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate) # if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate)
cond = "" cond = ""
if fiscal_year: if fiscal_year:
@ -45,14 +45,14 @@ def get_fiscal_years(date=None, fiscal_year=None, verbose=1):
order by year_start_date desc""" % cond) order by year_start_date desc""" % cond)
if not fy: if not fy:
error_msg = """%s not in any Fiscal Year""" % formatdate(date) error_msg = """%s %s not in any Fiscal Year""" % (label, formatdate(date))
if verbose: webnotes.msgprint(error_msg) if verbose: webnotes.msgprint(error_msg)
raise FiscalYearError, error_msg raise FiscalYearError, error_msg
return fy return fy
def validate_fiscal_year(date, fiscal_year, label="Date"): def validate_fiscal_year(date, fiscal_year, label="Date"):
years = [f[0] for f in get_fiscal_years(date)] years = [f[0] for f in get_fiscal_years(date, label=label)]
if fiscal_year not in years: if fiscal_year not in years:
webnotes.msgprint(("%(label)s '%(posting_date)s': " + _("not within Fiscal Year") + \ webnotes.msgprint(("%(label)s '%(posting_date)s': " + _("not within Fiscal Year") + \
": '%(fiscal_year)s'") % { ": '%(fiscal_year)s'") % {

View File

@ -17,9 +17,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import add_days, cstr, flt from webnotes.utils import cstr, flt
from webnotes.model.bean import getlist from webnotes.model.bean import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint, _ from webnotes import msgprint, _
from buying.utils import get_last_purchase_details from buying.utils import get_last_purchase_details
@ -32,46 +31,11 @@ class DocType(BuyingController):
self.doc = doc self.doc = doc
self.doclist = doclist self.doclist = doclist
self.chk_tol_for_list = ['Material Request - Purchase Order', 'Purchase Order - Purchase Receipt', 'Purchase Order - Purchase Invoice']
self.update_qty = {
'Material Request - Purchase Order': 'ordered_qty',
'Purchase Order - Purchase Receipt': 'received_qty',
'Purchase Order - Purchase Invoice': 'billed_qty',
'Purchase Receipt - Purchase Invoice': 'billed_qty'
}
self.update_percent_field = {
'Material Request - Purchase Order': 'per_ordered',
'Purchase Order - Purchase Receipt': 'per_received',
'Purchase Order - Purchase Invoice': 'per_billed',
'Purchase Receipt - Purchase Invoice': 'per_billed'
}
# used in validation for items and update_prevdoc_detail
self.doctype_dict = {
'Material Request': 'Material Request Item',
'Purchase Order': 'Purchase Order Item',
'Purchase Receipt': 'Purchase Receipt Item'
}
self.next_dt_detail = {
'ordered_qty' : 'Purchase Order Item',
'billed_qty' : 'Purchase Invoice Item',
'received_qty': 'Purchase Receipt Item'
}
self.msg = []
def is_item_table_empty(self, obj): def is_item_table_empty(self, obj):
if not len(obj.doclist.get({"parentfield": obj.fname})): if not len(obj.doclist.get({"parentfield": obj.fname})):
msgprint(_("Hey there! You need to put at least one item in \ msgprint(_("Hey there! You need to put at least one item in \
the item table."), raise_exception=True) the item table."), raise_exception=True)
# Client Trigger functions
#------------------------------------------------------------------------------------------------
# Get Supplier Details
def get_supplier_details(self, name = ''): def get_supplier_details(self, name = ''):
details = sql("select supplier_name,address from `tabSupplier` where name = '%s' and docstatus != 2" %(name), as_dict = 1) details = sql("select supplier_name,address from `tabSupplier` where name = '%s' and docstatus != 2" %(name), as_dict = 1)
if details: if details:
@ -94,8 +58,6 @@ class DocType(BuyingController):
ret = { 'projected_qty' : bin and flt(bin[0]['projected_qty']) or 0 } ret = { 'projected_qty' : bin and flt(bin[0]['projected_qty']) or 0 }
return ret return ret
# --- Last Purchase Rate related methods ---
def update_last_purchase_rate(self, obj, is_submit): def update_last_purchase_rate(self, obj, is_submit):
"""updates last_purchase_rate in item table for each item""" """updates last_purchase_rate in item table for each item"""
@ -146,8 +108,6 @@ class DocType(BuyingController):
d.purchase_ref_rate = d.purchase_rate = d.import_ref_rate \ d.purchase_ref_rate = d.purchase_rate = d.import_ref_rate \
= d.import_rate = item_last_purchase_rate = d.import_rate = item_last_purchase_rate
# validate for same items and validate is_stock_item , is_purchase_item also validate uom and conversion factor
def validate_for_items(self, obj): def validate_for_items(self, obj):
check_list, chk_dupl_itm=[],[] check_list, chk_dupl_itm=[],[]
for d in getlist( obj.doclist, obj.fname): for d in getlist( obj.doclist, obj.fname):
@ -159,7 +119,7 @@ class DocType(BuyingController):
# udpate with latest quantities # udpate with latest quantities
bin = sql("select projected_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1) bin = sql("select projected_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1)
f_lst ={'projected_qty': bin and flt(bin[0]['projected_qty']) or 0, 'ordered_qty': 0, 'received_qty' : 0, 'billed_qty': 0} f_lst ={'projected_qty': bin and flt(bin[0]['projected_qty']) or 0, 'ordered_qty': 0, 'received_qty' : 0}
if d.doctype == 'Purchase Receipt Item': if d.doctype == 'Purchase Receipt Item':
f_lst.pop('received_qty') f_lst.pop('received_qty')
for x in f_lst : for x in f_lst :
@ -206,36 +166,7 @@ class DocType(BuyingController):
Please change any of the field value to enter the item twice.""" % d.item_code, raise_exception = 1) Please change any of the field value to enter the item twice.""" % d.item_code, raise_exception = 1)
else: else:
chk_dupl_itm.append(f) chk_dupl_itm.append(f)
# Check for Stopped status
def check_for_stopped_status(self, doctype, docname):
stopped = sql("select name from `tab%s` where name = '%s' and status = 'Stopped'" %
( doctype, docname))
if stopped:
msgprint("One cannot do any transaction against %s : %s, it's status is 'Stopped'" %
( doctype, docname), raise_exception=1)
# Check Docstatus of Next DocType on Cancel AND of Previous DocType on Submit
def check_docstatus(self, check, doctype, docname , detail_doctype = ''):
if check == 'Next':
# Convention := doctype => Next Doctype, docname = current_docname , detail_doctype = Next Doctype Detail Table
submitted = sql("select t1.name from `tab%s` t1,`tab%s` t2 where t1.name = t2.parent and t2.prevdoc_docname = '%s' and t1.docstatus = 1" % ( doctype, detail_doctype, docname))
if submitted:
msgprint(cstr(doctype) + " : " + cstr(submitted[0][0]) + " has already been submitted !")
raise Exception
if check == 'Previous':
# Convention := doctype => Previous Doctype, docname = Previous Docname
submitted = sql("select name from `tab%s` where docstatus = 1 and name = '%s'" % (doctype, docname))
if not submitted:
msgprint(cstr(doctype) + " : " + cstr(submitted[0][0]) + " not submitted !")
raise Exception
# Update Ref Doc
# =======================================================
def get_qty(self,curr_doctype,ref_tab_fname,ref_tab_dn,ref_doc_tname, transaction, curr_parent_name): def get_qty(self,curr_doctype,ref_tab_fname,ref_tab_dn,ref_doc_tname, transaction, curr_parent_name):
# Get total Quantities of current doctype (eg. PR) except for qty of this transaction # Get total Quantities of current doctype (eg. PR) except for qty of this transaction
#------------------------------ #------------------------------
@ -252,112 +183,35 @@ class DocType(BuyingController):
max_qty = sql("select qty from `tab%s` where name = '%s' and docstatus = 1"% (ref_doc_tname, ref_tab_dn)) max_qty = sql("select qty from `tab%s` where name = '%s' and docstatus = 1"% (ref_doc_tname, ref_tab_dn))
max_qty = max_qty and flt(max_qty[0][0]) or 0 max_qty = max_qty and flt(max_qty[0][0]) or 0
return cstr(qty)+'~~~'+cstr(max_qty) return cstr(qty)+'~~~'+cstr(max_qty)
def check_for_stopped_status(self, doctype, docname):
stopped = sql("select name from `tab%s` where name = '%s' and status = 'Stopped'" %
( doctype, docname))
if stopped:
msgprint("One cannot do any transaction against %s : %s, it's status is 'Stopped'" %
( doctype, docname), raise_exception=1)
def check_docstatus(self, check, doctype, docname , detail_doctype = ''):
if check == 'Next':
submitted = sql("""select t1.name from `tab%s` t1,`tab%s` t2
where t1.name = t2.parent and t2.prevdoc_docname = %s and t1.docstatus = 1"""
% (doctype, detail_doctype, '%s'), docname)
if submitted:
msgprint(cstr(doctype) + ": " + cstr(submitted[0][0])
+ _(" has already been submitted."), raise_exception=1)
if check == 'Previous':
def update_refdoc_qty(self, curr_qty, curr_doctype, ref_dn, ref_dt, ref_tab_fname, ref_tab_dn, transaction, item_code, is_submit, curr_parent_doctype, curr_parent_name): submitted = sql("""select name from `tab%s`
# Get Quantity where docstatus = 1 and name = %s"""% (doctype, '%s'), docname)
#------------------------------ if not submitted:
curr_ref_qty = self.get_qty(curr_doctype,ref_tab_fname,ref_tab_dn,self.doctype_dict[ref_dt], transaction, curr_parent_name) msgprint(cstr(doctype) + ": " + cstr(submitted[0][0])
qty, max_qty, max_qty_plus_tol = flt(curr_ref_qty.split('~~~')[0]), flt(curr_ref_qty.split('~~~')[1]), flt(curr_ref_qty.split('~~~')[1]) + _(" not submitted"), raise_exception=1)
# Qty above Tolerance should be allowed only once.
# But there is special case for Transaction 'Material Request-Purhcase Order' that there should be no restriction
# One can create any no. of PO against same Material Request!!!
if qty >= max_qty and is_submit and flt(curr_qty) > 0:
reason = (curr_parent_doctype == 'Purchase Order') and 'Ordered' or (curr_parent_doctype == 'Purchase Receipt') and 'Received' or (curr_parent_doctype == 'Purchase Invoice') and 'Billed'
msgprint("Error: Item Code : '%s' of '%s' is already %s." %(item_code,ref_dn,reason))
raise Exception
#check if tolerance added in item master
tolerance = flt(webnotes.conn.get_value('Item',item_code,'tolerance') or 0)
if not(tolerance):
tolerance = flt(webnotes.conn.get_value('Stock Settings',None,'tolerance') or 0)
if is_submit:
qty = qty + flt(curr_qty)
# Calculate max_qty_plus_tol i.e. max_qty with tolerance
#-----------------------------------------------------------------
if transaction in self.chk_tol_for_list:
max_qty_plus_tol = max_qty * (1 + (flt(tolerance)/ 100))
if max_qty_plus_tol < qty:
reason = (curr_parent_doctype == 'Purchase Order') and 'Ordered' or (curr_parent_doctype == 'Purchase Receipt') and 'Received' or (curr_parent_doctype == 'Purchase Invoice') and 'Billed'
msg = "error: Already %s Qty for %s is %s and \
maximum allowed Qty is %s [against %s: %s]" % \
(cstr(reason), item_code,
cstr(flt(qty) - flt(curr_qty)) , cstr(max_qty_plus_tol),
cstr(ref_dt), cstr(ref_dn))
msgprint(msg, raise_exception=1)
# Update qty
#------------------
sql("update `tab%s` set %s = '%s',modified = now() where name = '%s'" % (self.doctype_dict[ref_dt],self.update_qty[transaction] , flt(qty), ref_tab_dn))
def update_ref_doctype_dict(self, curr_qty, curr_doctype, ref_dn, ref_dt, ref_tab_fname, ref_tab_dn, transaction, item_code, is_submit, curr_parent_doctype, curr_parent_name):
# update qty
self.update_refdoc_qty( curr_qty, curr_doctype, ref_dn, ref_dt, ref_tab_fname, ref_tab_dn, transaction, item_code, is_submit, curr_parent_doctype, curr_parent_name)
# append distinct ref_dn in doctype_dict
if not self.ref_doctype_dict.has_key(ref_dn) and self.update_percent_field.has_key(transaction):
self.ref_doctype_dict[ref_dn] = [ ref_dt, self.doctype_dict[ref_dt],transaction]
# update prevdoc detail
# --------------------
def update_prevdoc_detail(self, obj, is_submit):
import math
self.ref_doctype_dict= {}
for d in getlist(obj.doclist, obj.fname):
if d.fields.has_key('prevdoc_docname') and d.prevdoc_docname:
transaction = cstr(d.prevdoc_doctype) + ' - ' + cstr(obj.doc.doctype)
curr_qty = (transaction == 'Material Request - Purchase Order') and flt(d.qty) * flt(d.conversion_factor) or flt(d.qty)
self.update_ref_doctype_dict( flt(curr_qty), d.doctype, d.prevdoc_docname, d.prevdoc_doctype, 'prevdoc_detail_docname', d.prevdoc_detail_docname, transaction, d.item_code, is_submit, obj.doc.doctype, obj.doc.name)
# for payable voucher
if d.fields.has_key('purchase_order') and d.purchase_order:
curr_qty = sql("select sum(qty) from `tabPurchase Invoice Item` where po_detail = '%s' and parent = '%s'" % (cstr(d.po_detail), cstr(obj.doc.name)))
curr_qty = curr_qty and flt(curr_qty[0][0]) or 0
self.update_ref_doctype_dict( curr_qty, d.doctype, d.purchase_order, 'Purchase Order', 'po_detail', d.po_detail, 'Purchase Order - ' + cstr(obj.doc.doctype), d.item_code, is_submit, obj.doc.doctype, obj.doc.name)
if d.fields.has_key('purchase_receipt') and d.purchase_receipt:
self.update_ref_doctype_dict( flt(d.qty), d.doctype, d.purchase_receipt, 'Purchase Receipt', 'pr_detail', d.pr_detail, 'Purchase Receipt - ' + cstr(obj.doc.doctype), d.item_code, is_submit, obj.doc.doctype, obj.doc.name)
for ref_dn in self.ref_doctype_dict:
# Calculate percentage
#----------------------
ref_doc_obj = get_obj(self.ref_doctype_dict[ref_dn][0],ref_dn,with_children = 1)
count = 0
percent = 0
for d in getlist(ref_doc_obj.doclist,ref_doc_obj.fname):
ref_qty = d.fields[self.update_qty[self.ref_doctype_dict[ref_dn][2]]]
if flt(d.qty) - flt(ref_qty) <= 0:
percent += 100
else:
percent += (flt(ref_qty)/flt(d.qty) * 100)
count += 1
percent_complete = math.floor(flt(percent)/ flt(count))
# update percent complete and modified
#-------------------------------------
sql("update `tab%s` set %s = '%s', modified = '%s' where name = '%s'" % (self.ref_doctype_dict[ref_dn][0], self.update_percent_field[self.ref_doctype_dict[ref_dn][2]], percent_complete, obj.doc.modified, ref_dn))
def validate_fiscal_year(self, fiscal_year, transaction_date, dn):
fy=sql("select year_start_date from `tabFiscal Year` where name='%s'"%fiscal_year)
ysd=fy and fy[0][0] or ""
yed=add_days(str(ysd),365)
if str(transaction_date) < str(ysd) or str(transaction_date) > str(yed):
msgprint("'%s' Not Within The Fiscal Year"%(dn))
raise Exception
def get_rate(self, arg, obj): def get_rate(self, arg, obj):
arg = eval(arg) arg = eval(arg)
rate = sql("select account_type, tax_rate from `tabAccount` where name = '%s'" %(arg['account_head']), as_dict=1) rate = sql("select account_type, tax_rate from `tabAccount` where name = %s"
, (arg['account_head']), as_dict=1)
return {'rate': rate and (rate[0]['account_type'] == 'Tax' \ return {'rate': rate and (rate[0]['account_type'] == 'Tax' \
and not arg['charge_type'] == 'Actual') and flt(rate[0]['tax_rate']) or 0 } and not arg['charge_type'] == 'Actual') and flt(rate[0]['tax_rate']) or 0 }
@ -365,5 +219,6 @@ class DocType(BuyingController):
def get_prevdoc_date(self, obj): def get_prevdoc_date(self, obj):
for d in getlist(obj.doclist, obj.fname): for d in getlist(obj.doclist, obj.fname):
if d.prevdoc_doctype and d.prevdoc_docname: if d.prevdoc_doctype and d.prevdoc_docname:
dt = sql("select transaction_date from `tab%s` where name = '%s'" % (d.prevdoc_doctype, d.prevdoc_docname)) dt = sql("select transaction_date from `tab%s` where name = %s"
% (d.prevdoc_doctype, '%s'), (d.prevdoc_docname))
d.prevdoc_date = dt and dt[0][0].strftime('%Y-%m-%d') or '' d.prevdoc_date = dt and dt[0][0].strftime('%Y-%m-%d') or ''

View File

@ -31,12 +31,21 @@ class DocType(BuyingController):
self.doclist = doclist self.doclist = doclist
self.tname = 'Purchase Order Item' self.tname = 'Purchase Order Item'
self.fname = 'po_details' self.fname = 'po_details'
self.status_updater = [{
'source_dt': 'Purchase Order Item',
'target_dt': 'Material Request Item',
'join_field': 'prevdoc_detail_docname',
'target_field': 'ordered_qty',
'target_parent_dt': 'Material Request',
'target_parent_field': 'per_ordered',
'target_ref_field': 'qty',
'source_field': 'qty',
'percent_join_field': 'prevdoc_docname',
}]
def validate(self): def validate(self):
super(DocType, self).validate() super(DocType, self).validate()
self.validate_fiscal_year()
if not self.doc.status: if not self.doc.status:
self.doc.status = "Draft" self.doc.status = "Draft"
@ -53,9 +62,6 @@ class DocType(BuyingController):
self.validate_for_subcontracting() self.validate_for_subcontracting()
self.update_raw_materials_supplied("po_raw_material_details") self.update_raw_materials_supplied("po_raw_material_details")
def validate_fiscal_year(self):
get_obj(dt = 'Purchase Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.transaction_date,'PO Date')
def validate_with_previous_doc(self): def validate_with_previous_doc(self):
super(DocType, self).validate_with_previous_doc(self.tname, { super(DocType, self).validate_with_previous_doc(self.tname, {
"Supplier Quotation": { "Supplier Quotation": {
@ -157,27 +163,18 @@ class DocType(BuyingController):
purchase_controller = webnotes.get_obj("Purchase Common") purchase_controller = webnotes.get_obj("Purchase Common")
purchase_controller.is_item_table_empty(self) purchase_controller.is_item_table_empty(self)
# Step 1 :=> Update Previous Doc i.e. update pending_qty and Status accordingly self.update_prevdoc_status()
purchase_controller.update_prevdoc_detail(self, is_submit = 1)
# Step 2 :=> Update Bin
self.update_bin(is_submit = 1, is_stopped = 0) self.update_bin(is_submit = 1, is_stopped = 0)
# Step 3 :=> Check For Approval Authority get_obj('Authorization Control').validate_approving_authority(self.doc.doctype,
get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.company, self.doc.grand_total) self.doc.company, self.doc.grand_total)
# Step 5 :=> Update last purchase rate
purchase_controller.update_last_purchase_rate(self, is_submit = 1) purchase_controller.update_last_purchase_rate(self, is_submit = 1)
# Step 6 :=> Set Status
webnotes.conn.set(self.doc,'status','Submitted') webnotes.conn.set(self.doc,'status','Submitted')
def on_cancel(self): def on_cancel(self):
pc_obj = get_obj(dt = 'Purchase Common') pc_obj = get_obj(dt = 'Purchase Common')
# Check if PO status is stopped
pc_obj.check_for_stopped_status(cstr(self.doc.doctype), cstr(self.doc.name))
self.check_for_stopped_status(pc_obj) self.check_for_stopped_status(pc_obj)
# Check if Purchase Receipt has been submitted against current Purchase Order # Check if Purchase Receipt has been submitted against current Purchase Order
@ -190,7 +187,7 @@ class DocType(BuyingController):
raise Exception raise Exception
webnotes.conn.set(self.doc,'status','Cancelled') webnotes.conn.set(self.doc,'status','Cancelled')
pc_obj.update_prevdoc_detail(self,is_submit = 0) self.update_prevdoc_status()
self.update_bin( is_submit = 0, is_stopped = 0) self.update_bin( is_submit = 0, is_stopped = 0)
pc_obj.update_last_purchase_rate(self, is_submit = 0) pc_obj.update_last_purchase_rate(self, is_submit = 0)

View File

@ -32,7 +32,7 @@ class TestPurchaseOrder(unittest.TestCase):
po = webnotes.bean("Purchase Order", po.doc.name) po = webnotes.bean("Purchase Order", po.doc.name)
po.submit() po.submit()
pr = make_purchase_receipt(po.doc.name) pr = make_purchase_receipt(po.doc.name)
pr[0]["supplier_warehouse"] = "_Test Warehouse 1" pr[0]["supplier_warehouse"] = "_Test Warehouse 1 - _TC"
self.assertEquals(pr[0]["doctype"], "Purchase Receipt") self.assertEquals(pr[0]["doctype"], "Purchase Receipt")
self.assertEquals(len(pr), len(test_records[0])) self.assertEquals(len(pr), len(test_records[0]))
@ -100,7 +100,7 @@ test_records = [
"qty": 10.0, "qty": 10.0,
"import_rate": 500.0, "import_rate": 500.0,
"amount": 5000.0, "amount": 5000.0,
"warehouse": "_Test Warehouse", "warehouse": "_Test Warehouse - _TC",
"stock_uom": "Nos", "stock_uom": "Nos",
"uom": "_Test UOM", "uom": "_Test UOM",
"schedule_date": "2013-03-01" "schedule_date": "2013-03-01"

View File

@ -34,7 +34,6 @@ class DocType(BuyingController):
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped", utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped",
"Cancelled"]) "Cancelled"])
self.validate_fiscal_year()
self.validate_common() self.validate_common()
self.validate_with_previous_doc() self.validate_with_previous_doc()
@ -49,10 +48,6 @@ class DocType(BuyingController):
def on_trash(self): def on_trash(self):
pass pass
def validate_fiscal_year(self):
get_obj(dt = 'Purchase Common').validate_fiscal_year( \
self.doc.fiscal_year, self.doc.transaction_date, 'Quotation Date')
def validate_with_previous_doc(self): def validate_with_previous_doc(self):
super(DocType, self).validate_with_previous_doc(self.tname, { super(DocType, self).validate_with_previous_doc(self.tname, {

View File

@ -70,7 +70,7 @@ test_records = [
"qty": 10.0, "qty": 10.0,
"import_rate": 500.0, "import_rate": 500.0,
"amount": 5000.0, "amount": 5000.0,
"warehouse": "_Test Warehouse", "warehouse": "_Test Warehouse - _TC",
"uom": "_Test UOM", "uom": "_Test UOM",
} }
], ],

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes import _, msgprint from webnotes import _, msgprint
from webnotes.utils import flt, cint, today from webnotes.utils import flt, cint, today
from setup.utils import get_company_currency, get_price_list_currency from setup.utils import get_company_currency, get_price_list_currency
from accounts.utils import get_fiscal_year from accounts.utils import get_fiscal_year, validate_fiscal_year
from utilities.transaction_base import TransactionBase, validate_conversion_rate from utilities.transaction_base import TransactionBase, validate_conversion_rate
import json import json
@ -27,6 +27,8 @@ class AccountsController(TransactionBase):
def validate(self): def validate(self):
self.set_missing_values(for_validate=True) self.set_missing_values(for_validate=True)
self.validate_date_with_fiscal_year()
if self.meta.get_field("currency"): if self.meta.get_field("currency"):
self.company_currency = get_company_currency(self.doc.company) self.company_currency = get_company_currency(self.doc.company)
@ -43,6 +45,18 @@ class AccountsController(TransactionBase):
self.doc.fields[fieldname] = today() self.doc.fields[fieldname] = today()
if not self.doc.fiscal_year: if not self.doc.fiscal_year:
self.doc.fiscal_year = get_fiscal_year(self.doc.fields[fieldname])[0] self.doc.fiscal_year = get_fiscal_year(self.doc.fields[fieldname])[0]
def validate_date_with_fiscal_year(self):
if self.meta.get_field("fiscal_year") :
date_field = ""
if self.meta.get_field("posting_date"):
date_field = "posting_date"
elif self.meta.get_field("transaction_date"):
date_field = "transaction_date"
if date_field and self.doc.fields[date_field]:
validate_fiscal_year(self.doc.fields[date_field], self.doc.fiscal_year,
label=self.meta.get_label(date_field))
def set_price_list_currency(self, buying_or_selling): def set_price_list_currency(self, buying_or_selling):
# TODO - change this, since price list now has only one currency allowed # TODO - change this, since price list now has only one currency allowed

View File

@ -16,7 +16,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import cstr
def get_filters_cond(doctype, filters, conditions): def get_filters_cond(doctype, filters, conditions):
if filters: if filters:
@ -202,7 +201,7 @@ def bom(doctype, txt, searchfield, start, page_len, filters):
from tabBOM from tabBOM
where tabBOM.docstatus=1 where tabBOM.docstatus=1
and tabBOM.is_active=1 and tabBOM.is_active=1
and tabBOM.%(key)s like "%s" and tabBOM.%(key)s like "%(txt)s"
%(fcond)s %(mcond)s %(fcond)s %(mcond)s
limit %(start)s, %(page_len)s """ % {'key': searchfield, 'txt': "%%%s%%" % txt, limit %(start)s, %(page_len)s """ % {'key': searchfield, 'txt': "%%%s%%" % txt,
'fcond': get_filters_cond(doctype, filters, conditions), 'fcond': get_filters_cond(doctype, filters, conditions),

View File

@ -17,12 +17,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import add_days
from webnotes.model.bean import getlist from webnotes.model.bean import getlist
from webnotes import form, msgprint from webnotes import msgprint
from webnotes.model.code import get_obj
sql = webnotes.conn.sql
class DocType: class DocType:
def __init__(self, doc, doclist=[]): def __init__(self, doc, doclist=[]):
@ -30,8 +26,6 @@ class DocType:
self.doclist = doclist self.doclist = doclist
def validate(self): def validate(self):
# if self.doc.exp_approver == self.doc.owner:
# webnotes.msgprint("""Self Approval is not allowed.""", raise_exception=1)
self.validate_fiscal_year() self.validate_fiscal_year()
self.validate_exp_details() self.validate_exp_details()
@ -41,12 +35,8 @@ class DocType:
'Rejected' before submitting""", raise_exception=1) 'Rejected' before submitting""", raise_exception=1)
def validate_fiscal_year(self): def validate_fiscal_year(self):
fy=sql("select year_start_date from `tabFiscal Year` where name='%s'"%self.doc.fiscal_year) from accounts.utils import validate_fiscal_year
ysd=fy and fy[0][0] or "" validate_fiscal_year(self.doc.posting_date, self.doc.fiscal_year, "Posting Date")
yed=add_days(str(ysd),365)
if str(self.doc.posting_date) < str(ysd) or str(self.doc.posting_date) > str(yed):
msgprint("Posting Date is not within the Fiscal Year selected")
raise Exception
def validate_exp_details(self): def validate_exp_details(self):
if not getlist(self.doclist, 'expense_voucher_details'): if not getlist(self.doclist, 'expense_voucher_details'):

View File

@ -172,7 +172,7 @@ cur_frm.fields_dict['item'].get_query = function(doc) {
return{ return{
query:"controllers.queries.item_query", query:"controllers.queries.item_query",
filters:{ filters:{
'has_serial_no': 'Yes' 'is_manufactured_item': 'Yes'
} }
} }
} }

View File

@ -17,7 +17,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import cstr, flt, now, nowdate from webnotes.utils import cstr, flt, nowdate
from webnotes.model.code import get_obj from webnotes.model.code import get_obj
from webnotes import msgprint from webnotes import msgprint
@ -65,6 +65,7 @@ class DocType:
where production_item = %s and sales_order = %s and docstatus < 2""", where production_item = %s and sales_order = %s and docstatus < 2""",
(self.doc.production_item, self.doc.sales_order))[0][0] (self.doc.production_item, self.doc.sales_order))[0][0]
total_qty = flt(ordered_qty_against_so) + flt(self.doc.qty)
# get qty from Sales Order Item table # get qty from Sales Order Item table
so_item_qty = webnotes.conn.sql("""select sum(qty) from `tabSales Order Item` so_item_qty = webnotes.conn.sql("""select sum(qty) from `tabSales Order Item`
@ -77,12 +78,12 @@ class DocType:
# total qty in SO # total qty in SO
so_qty = flt(so_item_qty) + flt(dnpi_qty) so_qty = flt(so_item_qty) + flt(dnpi_qty)
if ordered_qty_against_so > so_qty: if total_qty > so_qty:
webnotes.msgprint("""Total production order qty for item: %s against sales order: %s \ webnotes.msgprint("""Total production order qty for item: %s against sales order: %s \
will be %s, which is greater than sales order qty (%s). will be %s, which is greater than sales order qty (%s).
Please reduce qty or remove the item.""" % Please reduce qty or remove the item.""" %
(self.doc.production_item, self.doc.sales_order, (self.doc.production_item, self.doc.sales_order,
ordered_qty_against_so, so_qty), raise_exception=1) total_qty, so_qty), raise_exception=1)
def stop_unstop(self, status): def stop_unstop(self, status):

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-01-10 16:34:16", "creation": "2013-01-10 16:34:16",
"docstatus": 0, "docstatus": 0,
"modified": "2013-07-05 14:51:12", "modified": "2013-07-11 15:51:37",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -35,7 +35,6 @@
"permlevel": 0, "permlevel": 0,
"read": 1, "read": 1,
"report": 1, "report": 1,
"role": "Manufacturing User",
"submit": 1, "submit": 1,
"write": 1 "write": 1
}, },
@ -248,6 +247,15 @@
"read_only": 1 "read_only": 1
}, },
{ {
"doctype": "DocPerm" "doctype": "DocPerm",
"role": "System Manager"
},
{
"doctype": "DocPerm",
"role": "Manufacturing Manager"
},
{
"doctype": "DocPerm",
"role": "Manufacturing User"
} }
] ]

View File

@ -60,8 +60,8 @@ class DocType(TransactionBase):
" delivery note details have already been pulled", raise_exception=1) " delivery note details have already been pulled", raise_exception=1)
def validate_fiscal_year(self): def validate_fiscal_year(self):
get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year, self.doc.inst_date, from accounts.utils import validate_fiscal_year
'Installation Date') validate_fiscal_year(self.doc.inst_date, self.doc.fiscal_year, "Installation Date")
def is_serial_no_added(self, item_code, serial_no): def is_serial_no_added(self, item_code, serial_no):
ar_required = webnotes.conn.get_value("Item", item_code, "has_serial_no") ar_required = webnotes.conn.get_value("Item", item_code, "has_serial_no")

View File

@ -99,7 +99,7 @@ class DocType(SellingController):
@webnotes.whitelist() @webnotes.whitelist()
def make_customer(source_name, target_doclist=None): def make_customer(source_name, target_doclist=None):
_make_customer(source_name, target_doclist) return _make_customer(source_name, target_doclist)
def _make_customer(source_name, target_doclist=None, ignore_permissions=False): def _make_customer(source_name, target_doclist=None, ignore_permissions=False):
from webnotes.model.mapper import get_mapped_doclist from webnotes.model.mapper import get_mapped_doclist

View File

@ -17,7 +17,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import add_days, cstr, getdate, cint from webnotes.utils import cstr, getdate, cint
from webnotes.model.bean import getlist from webnotes.model.bean import getlist
from webnotes import msgprint from webnotes import msgprint
@ -129,14 +129,6 @@ class DocType(TransactionBase):
msgprint("Please select items for which enquiry needs to be made") msgprint("Please select items for which enquiry needs to be made")
raise Exception raise Exception
def validate_fiscal_year(self):
fy=sql("select year_start_date from `tabFiscal Year` where name='%s'"%self.doc.fiscal_year)
ysd=fy and fy[0][0] or ""
yed=add_days(str(ysd),365)
if str(self.doc.transaction_date) < str(ysd) or str(self.doc.transaction_date) > str(yed):
msgprint("Opportunity Date is not within the Fiscal Year selected")
raise Exception
def validate_lead_cust(self): def validate_lead_cust(self):
if self.doc.enquiry_from == 'Lead' and not self.doc.lead: if self.doc.enquiry_from == 'Lead' and not self.doc.lead:
msgprint("Lead Id is mandatory if 'Opportunity From' is selected as Lead", raise_exception=1) msgprint("Lead Id is mandatory if 'Opportunity From' is selected as Lead", raise_exception=1)
@ -144,11 +136,13 @@ class DocType(TransactionBase):
msgprint("Customer is mandatory if 'Opportunity From' is selected as Customer", raise_exception=1) msgprint("Customer is mandatory if 'Opportunity From' is selected as Customer", raise_exception=1)
def validate(self): def validate(self):
self.validate_fiscal_year()
self.set_last_contact_date() self.set_last_contact_date()
self.validate_item_details() self.validate_item_details()
self.validate_lead_cust() self.validate_lead_cust()
from accounts.utils import validate_fiscal_year
validate_fiscal_year(self.doc.transaction_date, self.doc.fiscal_year, "Opportunity Date")
if not self.doc.status: if not self.doc.status:
self.doc.status = "Draft" self.doc.status = "Draft"

View File

@ -75,11 +75,6 @@ class DocType(SellingController):
def get_rate(self,arg): def get_rate(self,arg):
return get_obj('Sales Common').get_rate(arg) return get_obj('Sales Common').get_rate(arg)
# Fiscal Year Validation
# ----------------------
def validate_fiscal_year(self):
get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.transaction_date,'Quotation Date')
# Does not allow same item code to be entered twice # Does not allow same item code to be entered twice
# ------------------------------------------------- # -------------------------------------------------
def validate_for_items(self): def validate_for_items(self):
@ -137,7 +132,6 @@ class DocType(SellingController):
utilities.validate_status(self.doc.status, ["Draft", "Submitted", utilities.validate_status(self.doc.status, ["Draft", "Submitted",
"Order Confirmed", "Order Lost", "Cancelled"]) "Order Confirmed", "Order Lost", "Cancelled"])
self.validate_fiscal_year()
self.set_last_contact_date() self.set_last_contact_date()
self.validate_order_type() self.validate_order_type()
self.validate_for_items() self.validate_for_items()
@ -245,10 +239,6 @@ def _make_sales_order(source_name, target_doclist=None, ignore_permissions=False
doclist = get_mapped_doclist("Quotation", source_name, { doclist = get_mapped_doclist("Quotation", source_name, {
"Quotation": { "Quotation": {
"doctype": "Sales Order", "doctype": "Sales Order",
"field_map": {
"name": "quotation_no",
"transaction_date": "quotation_date"
},
"validation": { "validation": {
"docstatus": ["=", 1] "docstatus": ["=", 1]
} }

View File

@ -17,7 +17,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import cint, cstr, flt, getdate, nowdate from webnotes.utils import cint, cstr, flt
from webnotes.model.doc import addchild from webnotes.model.doc import addchild
from webnotes.model.bean import getlist from webnotes.model.bean import getlist
from webnotes.model.code import get_obj from webnotes.model.code import get_obj
@ -30,26 +30,9 @@ from utilities.transaction_base import TransactionBase
class DocType(TransactionBase): class DocType(TransactionBase):
def __init__(self,d,dl): def __init__(self,d,dl):
self.doc, self.doclist = d,dl self.doc, self.doclist = d, dl
self.doctype_dict = {
'Sales Order' : 'Sales Order Item',
'Delivery Note' : 'Delivery Note Item',
'Sales Invoice':'Sales Invoice Item',
'Installation Note' : 'Installation Note Item'
}
self.ref_doctype_dict= {}
self.next_dt_detail = {
'delivered_qty' : 'Delivery Note Item',
'billed_qty' : 'Sales Invoice Item',
'installed_qty' : 'Installation Note Item'}
self.msg = []
# Get customer's contact person details
# ==============================================================
def get_contact_details(self, obj = '', primary = 0): def get_contact_details(self, obj = '', primary = 0):
cond = " and contact_name = '"+cstr(obj.doc.contact_person)+"'" cond = " and contact_name = '"+cstr(obj.doc.contact_person)+"'"
if primary: cond = " and is_primary_contact = 'Yes'" if primary: cond = " and is_primary_contact = 'Yes'"
@ -64,15 +47,11 @@ class DocType(TransactionBase):
if c['contact_address']: if c['contact_address']:
obj.doc.customer_address = c['contact_address'] obj.doc.customer_address = c['contact_address']
# get invoice details
# ====================
def get_invoice_details(self, obj = ''): def get_invoice_details(self, obj = ''):
if obj.doc.company: if obj.doc.company:
acc_head = webnotes.conn.sql("select name from `tabAccount` where name = '%s' and docstatus != 2" % (cstr(obj.doc.customer) + " - " + webnotes.conn.get_value('Company', obj.doc.company, 'abbr'))) acc_head = webnotes.conn.sql("select name from `tabAccount` where name = '%s' and docstatus != 2" % (cstr(obj.doc.customer) + " - " + webnotes.conn.get_value('Company', obj.doc.company, 'abbr')))
obj.doc.debit_to = acc_head and acc_head[0][0] or '' obj.doc.debit_to = acc_head and acc_head[0][0] or ''
#---------------------------------------- Get Tax Details -------------------------------#
def get_tax_details(self, item_code, obj): def get_tax_details(self, item_code, obj):
import json import json
tax = webnotes.conn.sql("select tax_type, tax_rate from `tabItem Tax` where parent = %s" , item_code) tax = webnotes.conn.sql("select tax_type, tax_rate from `tabItem Tax` where parent = %s" , item_code)
@ -83,8 +62,6 @@ class DocType(TransactionBase):
} }
return ret return ret
# Get Serial No Details
# ==========================================================================
def get_serial_details(self, serial_no, obj): def get_serial_details(self, serial_no, obj):
import json import json
item = webnotes.conn.sql("select item_code, make, label,brand, description from `tabSerial No` where name = '%s' and docstatus != 2" %(serial_no), as_dict=1) item = webnotes.conn.sql("select item_code, make, label,brand, description from `tabSerial No` where name = '%s' and docstatus != 2" %(serial_no), as_dict=1)
@ -339,8 +316,6 @@ class DocType(TransactionBase):
webnotes.conn.set_value("Item", d.item_code, "default_income_account", d.income_account) webnotes.conn.set_value("Item", d.item_code, "default_income_account", d.income_account)
# **************************************************************************************************************************************************
def check_credit(self,obj,grand_total): def check_credit(self,obj,grand_total):
acc_head = webnotes.conn.sql("select name from `tabAccount` where company = '%s' and master_name = '%s'"%(obj.doc.company, obj.doc.customer)) acc_head = webnotes.conn.sql("select name from `tabAccount` where company = '%s' and master_name = '%s'"%(obj.doc.company, obj.doc.customer))
if acc_head: if acc_head:
@ -352,10 +327,6 @@ class DocType(TransactionBase):
exact_outstanding = flt(tot_outstanding) + flt(grand_total) exact_outstanding = flt(tot_outstanding) + flt(grand_total)
get_obj('Account',acc_head[0][0]).check_credit_limit(acc_head[0][0], obj.doc.company, exact_outstanding) get_obj('Account',acc_head[0][0]).check_credit_limit(acc_head[0][0], obj.doc.company, exact_outstanding)
def validate_fiscal_year(self, fiscal_year, transaction_date, label):
import accounts.utils
accounts.utils.validate_fiscal_year(transaction_date, fiscal_year, label)
def get_prevdoc_date(self, obj): def get_prevdoc_date(self, obj):
for d in getlist(obj.doclist, obj.fname): for d in getlist(obj.doclist, obj.fname):
if d.prevdoc_doctype and d.prevdoc_docname: if d.prevdoc_doctype and d.prevdoc_docname:

View File

@ -56,9 +56,6 @@ class DocType(SellingController):
def get_rate(self,arg): def get_rate(self,arg):
return get_obj('Sales Common').get_rate(arg) return get_obj('Sales Common').get_rate(arg)
def validate_fiscal_year(self):
get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.transaction_date,'Sales Order Date')
def validate_mandatory(self): def validate_mandatory(self):
# validate transaction date v/s delivery date # validate transaction date v/s delivery date
if self.doc.delivery_date: if self.doc.delivery_date:
@ -156,7 +153,6 @@ class DocType(SellingController):
def validate(self): def validate(self):
super(DocType, self).validate() super(DocType, self).validate()
self.validate_fiscal_year()
self.validate_order_type() self.validate_order_type()
self.validate_delivery_date() self.validate_delivery_date()
self.validate_mandatory() self.validate_mandatory()
@ -398,7 +394,6 @@ def make_delivery_note(source_name, target_doclist=None):
"Sales Order": { "Sales Order": {
"doctype": "Delivery Note", "doctype": "Delivery Note",
"field_map": { "field_map": {
"name": "sales_order_no",
"shipping_address": "address_display", "shipping_address": "address_display",
"shipping_address_name": "customer_address", "shipping_address_name": "customer_address",
}, },

View File

@ -303,7 +303,7 @@ test_records = [
"basic_rate": 100.0, "basic_rate": 100.0,
"export_rate": 100.0, "export_rate": 100.0,
"amount": 1000.0, "amount": 1000.0,
"reserved_warehouse": "_Test Warehouse", "reserved_warehouse": "_Test Warehouse - _TC",
} }
], ],
] ]

View File

@ -6,11 +6,13 @@ test_records = [
"company_name": "_Test Company", "company_name": "_Test Company",
"abbr": "_TC", "abbr": "_TC",
"default_currency": "INR", "default_currency": "INR",
"domain": "Manufacturing"
}], }],
[{ [{
"doctype": "Company", "doctype": "Company",
"company_name": "_Test Company 1", "company_name": "_Test Company 1",
"abbr": "_TC1", "abbr": "_TC1",
"default_currency": "USD", "default_currency": "USD",
"domain": "Retail"
}], }],
] ]

View File

@ -3,21 +3,21 @@ test_records = [
[{ [{
"doctype": "Sales Person", "doctype": "Sales Person",
"sales_person_name": "_Test Sales Person", "sales_person_name": "_Test Sales Person",
"parent_sales_person": "All Sales Persons", "parent_sales_person": "Sales Team",
"is_group": "No", "is_group": "No",
"employee": "_T-Employee-0001", "employee": "_T-Employee-0001",
}], }],
[{ [{
"doctype": "Sales Person", "doctype": "Sales Person",
"sales_person_name": "_Test Sales Person 1", "sales_person_name": "_Test Sales Person 1",
"parent_sales_person": "All Sales Persons", "parent_sales_person": "Sales Team",
"is_group": "No", "is_group": "No",
"employee": "_T-Employee-0002", "employee": "_T-Employee-0002",
}], }],
[{ [{
"doctype": "Sales Person", "doctype": "Sales Person",
"sales_person_name": "_Test Sales Person 2", "sales_person_name": "_Test Sales Person 2",
"parent_sales_person": "All Sales Persons", "parent_sales_person": "Sales Team",
"is_group": "No", "is_group": "No",
"employee": "_T-Employee-0003", "employee": "_T-Employee-0003",
}] }]

View File

@ -50,10 +50,6 @@ class DocType(SellingController):
'keyword': 'Delivered' 'keyword': 'Delivered'
}] }]
def validate_fiscal_year(self):
get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.posting_date,'Posting Date')
def get_contact_details(self): def get_contact_details(self):
return get_obj('Sales Common').get_contact_details(self,0) return get_obj('Sales Common').get_contact_details(self,0)
@ -104,7 +100,6 @@ class DocType(SellingController):
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Cancelled"]) utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Cancelled"])
self.so_required() self.so_required()
self.validate_fiscal_year()
self.validate_proj_cust() self.validate_proj_cust()
sales_com_obj = get_obj(dt = 'Sales Common') sales_com_obj = get_obj(dt = 'Sales Common')
sales_com_obj.check_stop_sales_order(self) sales_com_obj.check_stop_sales_order(self)
@ -122,7 +117,6 @@ class DocType(SellingController):
self.validate_with_previous_doc() self.validate_with_previous_doc()
self.doc.status = 'Draft' self.doc.status = 'Draft'
if not self.doc.billing_status: self.doc.billing_status = 'Not Billed'
if not self.doc.installation_status: self.doc.installation_status = 'Not Installed' if not self.doc.installation_status: self.doc.installation_status = 'Not Installed'
def validate_with_previous_doc(self): def validate_with_previous_doc(self):

View File

@ -140,7 +140,7 @@ test_records = [
"basic_rate": 100.0, "basic_rate": 100.0,
"export_rate": 100.0, "export_rate": 100.0,
"amount": 500.0, "amount": 500.0,
"warehouse": "_Test Warehouse", "warehouse": "_Test Warehouse - _TC",
"stock_uom": "No." "stock_uom": "No."
} }
] ]

View File

@ -19,6 +19,7 @@ import unittest
import webnotes import webnotes
test_ignore = ["BOM"] test_ignore = ["BOM"]
test_dependencies = ["Warehouse"]
class TestItem(unittest.TestCase): class TestItem(unittest.TestCase):
def test_duplicate_price_list(self): def test_duplicate_price_list(self):
@ -41,7 +42,6 @@ class TestItem(unittest.TestCase):
item.doc.is_stock_item = "Yes" item.doc.is_stock_item = "Yes"
item.doc.default_warehouse = None item.doc.default_warehouse = None
self.assertRaises(WarehouseNotSet, item.insert) self.assertRaises(WarehouseNotSet, item.insert)
test_records = [ test_records = [
[{ [{
@ -63,11 +63,11 @@ test_records = [
"is_sub_contracted_item": "No", "is_sub_contracted_item": "No",
"stock_uom": "_Test UOM", "stock_uom": "_Test UOM",
"default_income_account": "Sales - _TC", "default_income_account": "Sales - _TC",
"default_warehouse": "_Test Warehouse", "default_warehouse": "_Test Warehouse - _TC",
}, { }, {
"doctype": "Item Reorder", "doctype": "Item Reorder",
"parentfield": "item_reorder", "parentfield": "item_reorder",
"warehouse": "_Test Warehouse", "warehouse": "_Test Warehouse - _TC",
"warehouse_reorder_level": 20, "warehouse_reorder_level": 20,
"warehouse_reorder_qty": 20, "warehouse_reorder_qty": 20,
"material_request_type": "Purchase" "material_request_type": "Purchase"
@ -86,7 +86,7 @@ test_records = [
"item_name": "_Test Item Home Desktop 100", "item_name": "_Test Item Home Desktop 100",
"description": "_Test Item Home Desktop 100", "description": "_Test Item Home Desktop 100",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"default_warehouse": "_Test Warehouse", "default_warehouse": "_Test Warehouse - _TC",
"default_income_account": "Sales - _TC", "default_income_account": "Sales - _TC",
"is_stock_item": "Yes", "is_stock_item": "Yes",
"is_asset_item": "No", "is_asset_item": "No",
@ -112,7 +112,7 @@ test_records = [
"item_name": "_Test Item Home Desktop 200", "item_name": "_Test Item Home Desktop 200",
"description": "_Test Item Home Desktop 200", "description": "_Test Item Home Desktop 200",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"default_warehouse": "_Test Warehouse", "default_warehouse": "_Test Warehouse - _TC",
"default_income_account": "Sales - _TC", "default_income_account": "Sales - _TC",
"is_stock_item": "Yes", "is_stock_item": "Yes",
"is_asset_item": "No", "is_asset_item": "No",
@ -154,7 +154,7 @@ test_records = [
"description": "_Test FG Item", "description": "_Test FG Item",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"is_stock_item": "Yes", "is_stock_item": "Yes",
"default_warehouse": "_Test Warehouse", "default_warehouse": "_Test Warehouse - _TC",
"default_income_account": "Sales - _TC", "default_income_account": "Sales - _TC",
"is_asset_item": "No", "is_asset_item": "No",
"has_batch_no": "No", "has_batch_no": "No",
@ -194,7 +194,7 @@ test_records = [
"description": "_Test Serialized Item", "description": "_Test Serialized Item",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"is_stock_item": "Yes", "is_stock_item": "Yes",
"default_warehouse": "_Test Warehouse", "default_warehouse": "_Test Warehouse - _TC",
"is_asset_item": "No", "is_asset_item": "No",
"has_batch_no": "No", "has_batch_no": "No",
"has_serial_no": "Yes", "has_serial_no": "Yes",

View File

@ -24,8 +24,6 @@ class DocType(BuyingController):
def check_if_already_pulled(self): def check_if_already_pulled(self):
pass#if self.[d.sales_order_no for d in getlist(self.doclist, 'indent_details')] pass#if self.[d.sales_order_no for d in getlist(self.doclist, 'indent_details')]
# Validate so items
# ----------------------------
def validate_qty_against_so(self): def validate_qty_against_so(self):
so_items = {} # Format --> {'SO/00001': {'Item/001': 120, 'Item/002': 24}} so_items = {} # Format --> {'SO/00001': {'Item/001': 120, 'Item/002': 24}}
for d in getlist(self.doclist, 'indent_details'): for d in getlist(self.doclist, 'indent_details'):
@ -49,14 +47,6 @@ class DocType(BuyingController):
if flt(so_items[so_no][item]) + already_indented > actual_so_qty: if flt(so_items[so_no][item]) + already_indented > actual_so_qty:
msgprint("You can raise indent of maximum qty: %s for item: %s against sales order: %s\n Anyway, you can add more qty in new row for the same item." % (actual_so_qty - already_indented, item, so_no), raise_exception=1) msgprint("You can raise indent of maximum qty: %s for item: %s against sales order: %s\n Anyway, you can add more qty in new row for the same item." % (actual_so_qty - already_indented, item, so_no), raise_exception=1)
# Validate fiscal year
# ----------------------------
def validate_fiscal_year(self):
get_obj(dt = 'Purchase Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.transaction_date,'Material Request Date')
# Validate Schedule Date
#--------------------------------
def validate_schedule_date(self): def validate_schedule_date(self):
#:::::::: validate schedule date v/s indent date :::::::::::: #:::::::: validate schedule date v/s indent date ::::::::::::
for d in getlist(self.doclist, 'indent_details'): for d in getlist(self.doclist, 'indent_details'):
@ -70,7 +60,6 @@ class DocType(BuyingController):
super(DocType, self).validate() super(DocType, self).validate()
self.validate_schedule_date() self.validate_schedule_date()
self.validate_fiscal_year()
if not self.doc.status: if not self.doc.status:
self.doc.status = "Draft" self.doc.status = "Draft"

View File

@ -63,9 +63,9 @@ class TestMaterialRequest(unittest.TestCase):
def _test_requested_qty(self, qty1, qty2): def _test_requested_qty(self, qty1, qty2):
self.assertEqual(flt(webnotes.conn.get_value("Bin", {"item_code": "_Test Item Home Desktop 100", self.assertEqual(flt(webnotes.conn.get_value("Bin", {"item_code": "_Test Item Home Desktop 100",
"warehouse": "_Test Warehouse"}, "indented_qty")), qty1) "warehouse": "_Test Warehouse - _TC"}, "indented_qty")), qty1)
self.assertEqual(flt(webnotes.conn.get_value("Bin", {"item_code": "_Test Item Home Desktop 200", self.assertEqual(flt(webnotes.conn.get_value("Bin", {"item_code": "_Test Item Home Desktop 200",
"warehouse": "_Test Warehouse"}, "indented_qty")), qty2) "warehouse": "_Test Warehouse - _TC"}, "indented_qty")), qty2)
def _insert_stock_entry(self, qty1, qty2): def _insert_stock_entry(self, qty1, qty2):
se = webnotes.bean([ se = webnotes.bean([
@ -87,7 +87,7 @@ class TestMaterialRequest(unittest.TestCase):
"stock_uom": "_Test UOM", "stock_uom": "_Test UOM",
"transfer_qty": qty1, "transfer_qty": qty1,
"uom": "_Test UOM", "uom": "_Test UOM",
"t_warehouse": "_Test Warehouse 1", "t_warehouse": "_Test Warehouse 1 - _TC",
}, },
{ {
"conversion_factor": 1.0, "conversion_factor": 1.0,
@ -99,7 +99,7 @@ class TestMaterialRequest(unittest.TestCase):
"stock_uom": "_Test UOM", "stock_uom": "_Test UOM",
"transfer_qty": qty2, "transfer_qty": qty2,
"uom": "_Test UOM", "uom": "_Test UOM",
"t_warehouse": "_Test Warehouse 1", "t_warehouse": "_Test Warehouse 1 - _TC",
}, },
]) ])
se.insert() se.insert()
@ -148,7 +148,7 @@ class TestMaterialRequest(unittest.TestCase):
po.cancel() po.cancel()
# check if per complete is as expected # check if per complete is as expected
mr.load_from_db() mr.load_from_db()
self._test_expected(mr.doclist, [{"per_ordered": 0}, {"ordered_qty": 0}, {"ordered_qty": 0}]) self._test_expected(mr.doclist, [{"per_ordered": None}, {"ordered_qty": None}, {"ordered_qty": None}])
self._test_requested_qty(54.0, 3.0) self._test_requested_qty(54.0, 3.0)
def test_completed_qty_for_transfer(self): def test_completed_qty_for_transfer(self):
@ -178,13 +178,13 @@ class TestMaterialRequest(unittest.TestCase):
se_doclist[1].update({ se_doclist[1].update({
"qty": 27.0, "qty": 27.0,
"transfer_qty": 27.0, "transfer_qty": 27.0,
"s_warehouse": "_Test Warehouse 1", "s_warehouse": "_Test Warehouse 1 - _TC",
"incoming_rate": 1.0 "incoming_rate": 1.0
}) })
se_doclist[2].update({ se_doclist[2].update({
"qty": 1.5, "qty": 1.5,
"transfer_qty": 1.5, "transfer_qty": 1.5,
"s_warehouse": "_Test Warehouse 1", "s_warehouse": "_Test Warehouse 1 - _TC",
"incoming_rate": 1.0 "incoming_rate": 1.0
}) })
@ -241,13 +241,13 @@ class TestMaterialRequest(unittest.TestCase):
se_doclist[1].update({ se_doclist[1].update({
"qty": 60.0, "qty": 60.0,
"transfer_qty": 60.0, "transfer_qty": 60.0,
"s_warehouse": "_Test Warehouse 1", "s_warehouse": "_Test Warehouse 1 - _TC",
"incoming_rate": 1.0 "incoming_rate": 1.0
}) })
se_doclist[2].update({ se_doclist[2].update({
"qty": 3.0, "qty": 3.0,
"transfer_qty": 3.0, "transfer_qty": 3.0,
"s_warehouse": "_Test Warehouse 1", "s_warehouse": "_Test Warehouse 1 - _TC",
"incoming_rate": 1.0 "incoming_rate": 1.0
}) })
@ -296,14 +296,14 @@ class TestMaterialRequest(unittest.TestCase):
se_doclist[1].update({ se_doclist[1].update({
"qty": 60.0, "qty": 60.0,
"transfer_qty": 60.0, "transfer_qty": 60.0,
"s_warehouse": "_Test Warehouse", "s_warehouse": "_Test Warehouse - _TC",
"t_warehouse": "_Test Warehouse 1", "t_warehouse": "_Test Warehouse 1 - _TC",
"incoming_rate": 1.0 "incoming_rate": 1.0
}) })
se_doclist[2].update({ se_doclist[2].update({
"qty": 3.0, "qty": 3.0,
"transfer_qty": 3.0, "transfer_qty": 3.0,
"s_warehouse": "_Test Warehouse 1", "s_warehouse": "_Test Warehouse 1 - _TC",
"incoming_rate": 1.0 "incoming_rate": 1.0
}) })
@ -336,7 +336,7 @@ test_records = [
"qty": 54.0, "qty": 54.0,
"schedule_date": "2013-02-18", "schedule_date": "2013-02-18",
"uom": "_Test UOM", "uom": "_Test UOM",
"warehouse": "_Test Warehouse" "warehouse": "_Test Warehouse - _TC"
}, },
{ {
"description": "_Test Item Home Desktop 200", "description": "_Test Item Home Desktop 200",
@ -347,7 +347,7 @@ test_records = [
"qty": 3.0, "qty": 3.0,
"schedule_date": "2013-02-19", "schedule_date": "2013-02-19",
"uom": "_Test UOM", "uom": "_Test UOM",
"warehouse": "_Test Warehouse" "warehouse": "_Test Warehouse - _TC"
} }
], ],
] ]

View File

@ -45,9 +45,6 @@ class DocType(BuyingController):
'percent_join_field': 'prevdoc_docname', 'percent_join_field': 'prevdoc_docname',
}] }]
def validate_fiscal_year(self):
get_obj(dt = 'Purchase Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.posting_date,'Transaction Date')
# get available qty at warehouse # get available qty at warehouse
def get_bin_details(self, arg = ''): def get_bin_details(self, arg = ''):
return get_obj(dt='Purchase Common').get_bin_details(arg) return get_obj(dt='Purchase Common').get_bin_details(arg)
@ -120,7 +117,6 @@ class DocType(BuyingController):
super(DocType, self).validate() super(DocType, self).validate()
self.po_required() self.po_required()
self.validate_fiscal_year()
if not self.doc.status: if not self.doc.status:
self.doc.status = "Draft" self.doc.status = "Draft"

View File

@ -120,7 +120,7 @@ test_records = [
"rejected_qty": 0.0, "rejected_qty": 0.0,
"import_rate": 50.0, "import_rate": 50.0,
"amount": 500.0, "amount": 500.0,
"warehouse": "_Test Warehouse", "warehouse": "_Test Warehouse - _TC",
"stock_uom": "Nos", "stock_uom": "Nos",
"uom": "_Test UOM", "uom": "_Test UOM",
}, },
@ -168,7 +168,7 @@ test_records = [
"posting_date": "2013-02-12", "posting_date": "2013-02-12",
"posting_time": "15:33:30", "posting_time": "15:33:30",
"is_subcontracted": "Yes", "is_subcontracted": "Yes",
"supplier_warehouse": "_Test Warehouse", "supplier_warehouse": "_Test Warehouse - _TC",
"supplier": "_Test Supplier", "supplier": "_Test Supplier",
"net_total": 5000.0, "net_total": 5000.0,
"grand_total": 5000.0, "grand_total": 5000.0,
@ -185,7 +185,7 @@ test_records = [
"rejected_qty": 0.0, "rejected_qty": 0.0,
"import_rate": 500.0, "import_rate": 500.0,
"amount": 5000.0, "amount": 5000.0,
"warehouse": "_Test Warehouse", "warehouse": "_Test Warehouse - _TC",
"stock_uom": "Nos", "stock_uom": "Nos",
"uom": "_Test UOM", "uom": "_Test UOM",
} }

View File

@ -22,7 +22,7 @@ class TestSerialNo(unittest.TestCase):
where voucher_type = 'Serial No' and voucher_no = %s""", sr.doc.name, as_dict=1)[0] where voucher_type = 'Serial No' and voucher_no = %s""", sr.doc.name, as_dict=1)[0]
self.assertTrue(sle) self.assertTrue(sle)
self.assertEquals([sle.item_code, sle.warehouse, sle.actual_qty], self.assertEquals([sle.item_code, sle.warehouse, sle.actual_qty],
["_Test Serialized Item", "_Test Warehouse", 1.0]) ["_Test Serialized Item", "_Test Warehouse - _TC", 1.0])
# check gl entries # check gl entries
gl_entries = webnotes.conn.sql("""select account, debit, credit gl_entries = webnotes.conn.sql("""select account, debit, credit
@ -92,7 +92,7 @@ test_records = [
"status": "In Store", "status": "In Store",
"item_code": "_Test Serialized Item", "item_code": "_Test Serialized Item",
"item_group": "_Test Item Group", "item_group": "_Test Item Group",
"warehouse": "_Test Warehouse", "warehouse": "_Test Warehouse - _TC",
"purchase_rate": 1000.0, "purchase_rate": 1000.0,
"purchase_time": "11:37:39", "purchase_time": "11:37:39",
"purchase_date": "2013-02-26", "purchase_date": "2013-02-26",

View File

@ -39,7 +39,7 @@ class TestStockEntry(unittest.TestCase):
def test_warehouse_company_validation(self): def test_warehouse_company_validation(self):
from stock.doctype.stock_ledger_entry.stock_ledger_entry import InvalidWarehouseCompany from stock.doctype.stock_ledger_entry.stock_ledger_entry import InvalidWarehouseCompany
st1 = webnotes.bean(copy=test_records[0]) st1 = webnotes.bean(copy=test_records[0])
st1.doclist[1].t_warehouse="_Test Warehouse 2" st1.doclist[1].t_warehouse="_Test Warehouse 2 - _TC1"
st1.insert() st1.insert()
self.assertRaises(InvalidWarehouseCompany, st1.submit) self.assertRaises(InvalidWarehouseCompany, st1.submit)
@ -55,7 +55,7 @@ class TestStockEntry(unittest.TestCase):
"stock_in_hand_account") "stock_in_hand_account")
self.check_stock_ledger_entries("Stock Entry", mr.doc.name, self.check_stock_ledger_entries("Stock Entry", mr.doc.name,
[["_Test Item", "_Test Warehouse", 50.0]]) [["_Test Item", "_Test Warehouse - _TC", 50.0]])
self.check_gl_entries("Stock Entry", mr.doc.name, self.check_gl_entries("Stock Entry", mr.doc.name,
sorted([ sorted([
@ -66,8 +66,8 @@ class TestStockEntry(unittest.TestCase):
mr.cancel() mr.cancel()
self.check_stock_ledger_entries("Stock Entry", mr.doc.name, self.check_stock_ledger_entries("Stock Entry", mr.doc.name,
sorted([["_Test Item", "_Test Warehouse", 50.0], sorted([["_Test Item", "_Test Warehouse - _TC", 50.0],
["_Test Item", "_Test Warehouse", -50.0]])) ["_Test Item", "_Test Warehouse - _TC", -50.0]]))
self.check_gl_entries("Stock Entry", mr.doc.name, self.check_gl_entries("Stock Entry", mr.doc.name,
sorted([ sorted([
@ -94,7 +94,7 @@ class TestStockEntry(unittest.TestCase):
"stock_in_hand_account") "stock_in_hand_account")
self.check_stock_ledger_entries("Stock Entry", mi.doc.name, self.check_stock_ledger_entries("Stock Entry", mi.doc.name,
[["_Test Item", "_Test Warehouse", -40.0]]) [["_Test Item", "_Test Warehouse - _TC", -40.0]])
self.check_gl_entries("Stock Entry", mi.doc.name, self.check_gl_entries("Stock Entry", mi.doc.name,
sorted([ sorted([
@ -106,8 +106,8 @@ class TestStockEntry(unittest.TestCase):
mi.cancel() mi.cancel()
self.check_stock_ledger_entries("Stock Entry", mi.doc.name, self.check_stock_ledger_entries("Stock Entry", mi.doc.name,
sorted([["_Test Item", "_Test Warehouse", -40.0], sorted([["_Test Item", "_Test Warehouse - _TC", -40.0],
["_Test Item", "_Test Warehouse", 40.0]])) ["_Test Item", "_Test Warehouse - _TC", 40.0]]))
self.check_gl_entries("Stock Entry", mi.doc.name, self.check_gl_entries("Stock Entry", mi.doc.name,
sorted([ sorted([
@ -131,7 +131,7 @@ class TestStockEntry(unittest.TestCase):
mtn.submit() mtn.submit()
self.check_stock_ledger_entries("Stock Entry", mtn.doc.name, self.check_stock_ledger_entries("Stock Entry", mtn.doc.name,
[["_Test Item", "_Test Warehouse", -45.0], ["_Test Item", "_Test Warehouse 1", 45.0]]) [["_Test Item", "_Test Warehouse - _TC", -45.0], ["_Test Item", "_Test Warehouse 1 - _TC", 45.0]])
# no gl entry # no gl entry
gl_entries = webnotes.conn.sql("""select * from `tabGL Entry` gl_entries = webnotes.conn.sql("""select * from `tabGL Entry`
@ -140,10 +140,10 @@ class TestStockEntry(unittest.TestCase):
mtn.cancel() mtn.cancel()
self.check_stock_ledger_entries("Stock Entry", mtn.doc.name, self.check_stock_ledger_entries("Stock Entry", mtn.doc.name,
sorted([["_Test Item", "_Test Warehouse", 45.0], sorted([["_Test Item", "_Test Warehouse - _TC", 45.0],
["_Test Item", "_Test Warehouse 1", -45.0], ["_Test Item", "_Test Warehouse 1 - _TC", -45.0],
["_Test Item", "_Test Warehouse", -45.0], ["_Test Item", "_Test Warehouse - _TC", -45.0],
["_Test Item", "_Test Warehouse 1", 45.0]])) ["_Test Item", "_Test Warehouse 1 - _TC", 45.0]]))
# no gl entry # no gl entry
gl_entries = webnotes.conn.sql("""select * from `tabGL Entry` gl_entries = webnotes.conn.sql("""select * from `tabGL Entry`
@ -196,7 +196,7 @@ class TestStockEntry(unittest.TestCase):
def _get_actual_qty(self): def _get_actual_qty(self):
return flt(webnotes.conn.get_value("Bin", {"item_code": "_Test Item", return flt(webnotes.conn.get_value("Bin", {"item_code": "_Test Item",
"warehouse": "_Test Warehouse"}, "actual_qty")) "warehouse": "_Test Warehouse - _TC"}, "actual_qty"))
def _test_sales_invoice_return(self, item_code, delivered_qty, returned_qty): def _test_sales_invoice_return(self, item_code, delivered_qty, returned_qty):
from stock.doctype.stock_entry.stock_entry import NotUpdateStockError from stock.doctype.stock_entry.stock_entry import NotUpdateStockError
@ -224,7 +224,7 @@ class TestStockEntry(unittest.TestCase):
# insert a pos invoice with update stock # insert a pos invoice with update stock
si = webnotes.bean(copy=sales_invoice_test_records[1]) si = webnotes.bean(copy=sales_invoice_test_records[1])
si.doc.is_pos = si.doc.update_stock = 1 si.doc.is_pos = si.doc.update_stock = 1
si.doclist[1].warehouse = "_Test Warehouse" si.doclist[1].warehouse = "_Test Warehouse - _TC"
si.doclist[1].item_code = item_code si.doclist[1].item_code = item_code
si.doclist[1].qty = 5.0 si.doclist[1].qty = 5.0
si.insert() si.insert()
@ -456,7 +456,7 @@ class TestStockEntry(unittest.TestCase):
se.doc.posting_date = "2013-03-01" se.doc.posting_date = "2013-03-01"
se.doc.fiscal_year = "_Test Fiscal Year 2013" se.doc.fiscal_year = "_Test Fiscal Year 2013"
se.doclist[1].qty = se.doclist[1].transfer_qty = 5 se.doclist[1].qty = se.doclist[1].transfer_qty = 5
se.doclist[1].s_warehouse = "_Test Warehouse" se.doclist[1].s_warehouse = "_Test Warehouse - _TC"
se.insert() se.insert()
se.submit() se.submit()
@ -481,7 +481,7 @@ class TestStockEntry(unittest.TestCase):
se.doc.posting_date = "2013-03-01" se.doc.posting_date = "2013-03-01"
se.doc.fiscal_year = "_Test Fiscal Year 2013" se.doc.fiscal_year = "_Test Fiscal Year 2013"
se.doclist[1].qty = se.doclist[1].transfer_qty = 6 se.doclist[1].qty = se.doclist[1].transfer_qty = 6
se.doclist[1].s_warehouse = "_Test Warehouse" se.doclist[1].s_warehouse = "_Test Warehouse - _TC"
self.assertRaises(StockOverReturnError, se.insert) self.assertRaises(StockOverReturnError, se.insert)
@ -556,7 +556,7 @@ class TestStockEntry(unittest.TestCase):
se.doc.posting_date = "2013-03-01" se.doc.posting_date = "2013-03-01"
se.doc.fiscal_year = "_Test Fiscal Year 2013" se.doc.fiscal_year = "_Test Fiscal Year 2013"
se.doclist[1].qty = se.doclist[1].transfer_qty = 5 se.doclist[1].qty = se.doclist[1].transfer_qty = 5
se.doclist[1].s_warehouse = "_Test Warehouse" se.doclist[1].s_warehouse = "_Test Warehouse - _TC"
se.insert() se.insert()
se.submit() se.submit()
@ -589,7 +589,7 @@ test_records = [
"stock_uom": "_Test UOM", "stock_uom": "_Test UOM",
"transfer_qty": 50.0, "transfer_qty": 50.0,
"uom": "_Test UOM", "uom": "_Test UOM",
"t_warehouse": "_Test Warehouse", "t_warehouse": "_Test Warehouse - _TC",
}, },
], ],
[ [
@ -612,7 +612,7 @@ test_records = [
"stock_uom": "_Test UOM", "stock_uom": "_Test UOM",
"transfer_qty": 40.0, "transfer_qty": 40.0,
"uom": "_Test UOM", "uom": "_Test UOM",
"s_warehouse": "_Test Warehouse", "s_warehouse": "_Test Warehouse - _TC",
}, },
], ],
[ [
@ -635,8 +635,8 @@ test_records = [
"stock_uom": "_Test UOM", "stock_uom": "_Test UOM",
"transfer_qty": 45.0, "transfer_qty": 45.0,
"uom": "_Test UOM", "uom": "_Test UOM",
"s_warehouse": "_Test Warehouse", "s_warehouse": "_Test Warehouse - _TC",
"t_warehouse": "_Test Warehouse 1", "t_warehouse": "_Test Warehouse 1 - _TC",
} }
] ]
] ]

View File

@ -34,14 +34,14 @@ class TestStockReconciliation(unittest.TestCase):
# check stock value # check stock value
res = webnotes.conn.sql("""select stock_value from `tabStock Ledger Entry` res = webnotes.conn.sql("""select stock_value from `tabStock Ledger Entry`
where item_code = '_Test Item' and warehouse = '_Test Warehouse' where item_code = '_Test Item' and warehouse = '_Test Warehouse - _TC'
and posting_date = %s and posting_time = %s order by name desc limit 1""", and posting_date = %s and posting_time = %s order by name desc limit 1""",
(d[2], d[3])) (d[2], d[3]))
self.assertEqual(res and flt(res[0][0]) or 0, d[4]) self.assertEqual(res and flt(res[0][0]) or 0, d[4])
# check bin qty and stock value # check bin qty and stock value
bin = webnotes.conn.sql("""select actual_qty, stock_value from `tabBin` bin = webnotes.conn.sql("""select actual_qty, stock_value from `tabBin`
where item_code = '_Test Item' and warehouse = '_Test Warehouse'""") where item_code = '_Test Item' and warehouse = '_Test Warehouse - _TC'""")
self.assertEqual(bin and [flt(bin[0][0]), flt(bin[0][1])] or [], [d[5], d[6]]) self.assertEqual(bin and [flt(bin[0][0]), flt(bin[0][1])] or [], [d[5], d[6]])
@ -79,7 +79,7 @@ class TestStockReconciliation(unittest.TestCase):
# check stock value in sle # check stock value in sle
res = webnotes.conn.sql("""select stock_value from `tabStock Ledger Entry` res = webnotes.conn.sql("""select stock_value from `tabStock Ledger Entry`
where item_code = '_Test Item' and warehouse = '_Test Warehouse' where item_code = '_Test Item' and warehouse = '_Test Warehouse - _TC'
and posting_date = %s and posting_time = %s order by name desc limit 1""", and posting_date = %s and posting_time = %s order by name desc limit 1""",
(d[2], d[3])) (d[2], d[3]))
@ -87,7 +87,7 @@ class TestStockReconciliation(unittest.TestCase):
# bin qty and stock value # bin qty and stock value
bin = webnotes.conn.sql("""select actual_qty, stock_value from `tabBin` bin = webnotes.conn.sql("""select actual_qty, stock_value from `tabBin`
where item_code = '_Test Item' and warehouse = '_Test Warehouse'""") where item_code = '_Test Item' and warehouse = '_Test Warehouse - _TC'""")
self.assertEqual(bin and [flt(bin[0][0]), flt(bin[0][1], 4)] or [], self.assertEqual(bin and [flt(bin[0][0]), flt(bin[0][1], 4)] or [],
[flt(d[5]), flt(d[6])]) [flt(d[5]), flt(d[6])])
@ -183,7 +183,7 @@ class TestStockReconciliation(unittest.TestCase):
"expense_account": "Stock Adjustment - _TC", "expense_account": "Stock Adjustment - _TC",
"reconciliation_json": json.dumps([ "reconciliation_json": json.dumps([
["Item Code", "Warehouse", "Quantity", "Valuation Rate"], ["Item Code", "Warehouse", "Quantity", "Valuation Rate"],
["_Test Item", "_Test Warehouse", qty, rate] ["_Test Item", "_Test Warehouse - _TC", qty, rate]
]), ]),
}]) }])
stock_reco.insert() stock_reco.insert()
@ -226,7 +226,7 @@ class TestStockReconciliation(unittest.TestCase):
{ {
"doctype": "Stock Ledger Entry", "__islocal": 1, "doctype": "Stock Ledger Entry", "__islocal": 1,
"voucher_type": "Stock Entry", "voucher_no": "TEST", "voucher_type": "Stock Entry", "voucher_no": "TEST",
"item_code": "_Test Item", "warehouse": "_Test Warehouse", "item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC",
"posting_date": "2012-12-12", "posting_time": "01:00", "posting_date": "2012-12-12", "posting_time": "01:00",
"actual_qty": 20, "incoming_rate": 1000, "company": "_Test Company", "actual_qty": 20, "incoming_rate": 1000, "company": "_Test Company",
"fiscal_year": "_Test Fiscal Year 2012", "fiscal_year": "_Test Fiscal Year 2012",
@ -234,7 +234,7 @@ class TestStockReconciliation(unittest.TestCase):
{ {
"doctype": "Stock Ledger Entry", "__islocal": 1, "doctype": "Stock Ledger Entry", "__islocal": 1,
"voucher_type": "Stock Entry", "voucher_no": "TEST", "voucher_type": "Stock Entry", "voucher_no": "TEST",
"item_code": "_Test Item", "warehouse": "_Test Warehouse", "item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC",
"posting_date": "2012-12-15", "posting_time": "02:00", "posting_date": "2012-12-15", "posting_time": "02:00",
"actual_qty": 10, "incoming_rate": 700, "company": "_Test Company", "actual_qty": 10, "incoming_rate": 700, "company": "_Test Company",
"fiscal_year": "_Test Fiscal Year 2012", "fiscal_year": "_Test Fiscal Year 2012",
@ -242,7 +242,7 @@ class TestStockReconciliation(unittest.TestCase):
{ {
"doctype": "Stock Ledger Entry", "__islocal": 1, "doctype": "Stock Ledger Entry", "__islocal": 1,
"voucher_type": "Stock Entry", "voucher_no": "TEST", "voucher_type": "Stock Entry", "voucher_no": "TEST",
"item_code": "_Test Item", "warehouse": "_Test Warehouse", "item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC",
"posting_date": "2012-12-25", "posting_time": "03:00", "posting_date": "2012-12-25", "posting_time": "03:00",
"actual_qty": -15, "company": "_Test Company", "actual_qty": -15, "company": "_Test Company",
"fiscal_year": "_Test Fiscal Year 2012", "fiscal_year": "_Test Fiscal Year 2012",
@ -250,7 +250,7 @@ class TestStockReconciliation(unittest.TestCase):
{ {
"doctype": "Stock Ledger Entry", "__islocal": 1, "doctype": "Stock Ledger Entry", "__islocal": 1,
"voucher_type": "Stock Entry", "voucher_no": "TEST", "voucher_type": "Stock Entry", "voucher_no": "TEST",
"item_code": "_Test Item", "warehouse": "_Test Warehouse", "item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC",
"posting_date": "2012-12-31", "posting_time": "08:00", "posting_date": "2012-12-31", "posting_time": "08:00",
"actual_qty": -20, "company": "_Test Company", "actual_qty": -20, "company": "_Test Company",
"fiscal_year": "_Test Fiscal Year 2012", "fiscal_year": "_Test Fiscal Year 2012",
@ -258,7 +258,7 @@ class TestStockReconciliation(unittest.TestCase):
{ {
"doctype": "Stock Ledger Entry", "__islocal": 1, "doctype": "Stock Ledger Entry", "__islocal": 1,
"voucher_type": "Stock Entry", "voucher_no": "TEST", "voucher_type": "Stock Entry", "voucher_no": "TEST",
"item_code": "_Test Item", "warehouse": "_Test Warehouse", "item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC",
"posting_date": "2013-01-05", "posting_time": "07:00", "posting_date": "2013-01-05", "posting_time": "07:00",
"actual_qty": 15, "incoming_rate": 1200, "company": "_Test Company", "actual_qty": 15, "incoming_rate": 1200, "company": "_Test Company",
"fiscal_year": "_Test Fiscal Year 2013", "fiscal_year": "_Test Fiscal Year 2013",

View File

@ -17,7 +17,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import cstr, flt, validate_email_add from webnotes.utils import flt, validate_email_add
from webnotes.model.code import get_obj from webnotes.model.code import get_obj
from webnotes import msgprint from webnotes import msgprint

View File

@ -50,7 +50,7 @@ def delete_masters():
'Supplier Type': ['Default Supplier Type'], 'Supplier Type': ['Default Supplier Type'],
'Supplier': '', 'Supplier': '',
'Serial No': '', 'Serial No': '',
'Sales Person': ['All Sales Persons'], 'Sales Person': ['Sales Team'],
'Sales Partner': '', 'Sales Partner': '',
'Sales BOM': '', 'Sales BOM': '',
'Salary Structure': '', 'Salary Structure': '',