[minor] fixes after merge with master

This commit is contained in:
Anand Doshi 2013-10-10 18:43:34 +05:30
parent 2eec1eb9a6
commit 9106221ea4
14 changed files with 64 additions and 60 deletions

View File

@ -641,8 +641,8 @@ class TestSalesInvoice(unittest.TestCase):
return new_si return new_si
# if yearly, test 3 repetitions, else test 13 repetitions # if yearly, test 1 repetition, else test 5 repetitions
count = 3 if no_of_months == 12 else 13 count = 1 if (no_of_months == 12) else 5
for i in xrange(count): for i in xrange(count):
base_si = _test(i) base_si = _test(i)
@ -653,7 +653,7 @@ class TestSalesInvoice(unittest.TestCase):
def test_serialized(self): def test_serialized(self):
from stock.doctype.stock_entry.test_stock_entry import make_serialized_item from stock.doctype.stock_entry.test_stock_entry import make_serialized_item
from stock.doctype.stock_ledger_entry.stock_ledger_entry import get_serial_nos from stock.doctype.serial_no.serial_no import get_serial_nos
se = make_serialized_item() se = make_serialized_item()
serial_nos = get_serial_nos(se.doclist[1].serial_no) serial_nos = get_serial_nos(se.doclist[1].serial_no)
@ -674,7 +674,7 @@ class TestSalesInvoice(unittest.TestCase):
return si return si
def test_serialized_cancel(self): def test_serialized_cancel(self):
from stock.doctype.stock_ledger_entry.stock_ledger_entry import get_serial_nos from stock.doctype.serial_no.serial_no import get_serial_nos
si = self.test_serialized() si = self.test_serialized()
si.cancel() si.cancel()
@ -686,7 +686,7 @@ class TestSalesInvoice(unittest.TestCase):
"delivery_document_no")) "delivery_document_no"))
def test_serialize_status(self): def test_serialize_status(self):
from stock.doctype.stock_ledger_entry.stock_ledger_entry import SerialNoStatusError, get_serial_nos from stock.doctype.serial_no.serial_no import SerialNoStatusError, get_serial_nos
from stock.doctype.stock_entry.test_stock_entry import make_serialized_item from stock.doctype.stock_entry.test_stock_entry import make_serialized_item
se = make_serialized_item() se = make_serialized_item()

View File

@ -64,10 +64,10 @@ def upload():
data, start_idx = get_data(rows, company_abbr, rows[0][0]) data, start_idx = get_data(rows, company_abbr, rows[0][0])
except Exception, e: except Exception, e:
err_msg = webnotes.message_log and "<br>".join(webnotes.message_log) or cstr(e) err_msg = webnotes.local.message_log and "<br>".join(webnotes.local.message_log) or cstr(e)
messages.append("""<p style='color: red'>%s</p>""" % (err_msg or "No message")) messages.append("""<p style='color: red'>%s</p>""" % (err_msg or "No message"))
webnotes.errprint(webnotes.getTraceback()) webnotes.errprint(webnotes.getTraceback())
webnotes.message_log = [] webnotes.local.message_log = []
return messages return messages
return import_vouchers(common_values, data, start_idx, rows[0][0]) return import_vouchers(common_values, data, start_idx, rows[0][0])
@ -117,11 +117,11 @@ def import_vouchers(common_values, data, start_idx, import_type):
d = data[i][0] d = data[i][0]
if import_type == "Voucher Import: Two Accounts" and flt(d.get("amount")) == 0: if import_type == "Voucher Import: Two Accounts" and flt(d.get("amount")) == 0:
webnotes.message_log = ["Amount not specified"] webnotes.local.message_log = ["Amount not specified"]
raise Exception raise Exception
elif import_type == "Voucher Import: Multiple Accounts" and \ elif import_type == "Voucher Import: Multiple Accounts" and \
(flt(d.get("total_debit")) == 0 or flt(d.get("total_credit")) == 0): (flt(d.get("total_debit")) == 0 or flt(d.get("total_credit")) == 0):
webnotes.message_log = ["Total Debit and Total Credit amount can not be zero"] webnotes.local.message_log = ["Total Debit and Total Credit amount can not be zero"]
raise Exception raise Exception
else: else:
d.posting_date = parse_date(d.posting_date) d.posting_date = parse_date(d.posting_date)
@ -174,7 +174,7 @@ def import_vouchers(common_values, data, start_idx, import_type):
details.append(detail) details.append(detail)
if not details: if not details:
webnotes.message_log = ["""No accounts found. webnotes.local.message_log = ["""No accounts found.
If you entered accounts correctly, please check template once"""] If you entered accounts correctly, please check template once"""]
raise Exception raise Exception
@ -193,12 +193,12 @@ def import_vouchers(common_values, data, start_idx, import_type):
webnotes.conn.commit() webnotes.conn.commit()
except Exception, e: except Exception, e:
webnotes.conn.rollback() webnotes.conn.rollback()
err_msg = webnotes.message_log and "<br>".join(webnotes.message_log) or cstr(e) err_msg = webnotes.local.message_log and "<br>".join(webnotes.local.message_log) or cstr(e)
messages.append("""<p style='color: red'>[row #%s] %s failed: %s</p>""" messages.append("""<p style='color: red'>[row #%s] %s failed: %s</p>"""
% ((start_idx + 1) + i, jv.name or "", err_msg or "No message")) % ((start_idx + 1) + i, jv.name or "", err_msg or "No message"))
messages.append("<p style='color: red'>All transactions rolled back</p>") messages.append("<p style='color: red'>All transactions rolled back</p>")
webnotes.errprint(webnotes.getTraceback()) webnotes.errprint(webnotes.getTraceback())
webnotes.message_log = [] webnotes.local.message_log = []
return messages return messages

View File

@ -98,12 +98,12 @@ class TestPurchaseOrder(unittest.TestCase):
self.assertEquals(len(po.doclist.get({"parentfield": "po_raw_material_details"})), 2) self.assertEquals(len(po.doclist.get({"parentfield": "po_raw_material_details"})), 2)
def test_warehouse_company_validation(self): def test_warehouse_company_validation(self):
from controllers.buying_controller import WrongWarehouseCompany from stock.utils import InvalidWarehouseCompany
po = webnotes.bean(copy=test_records[0]) po = webnotes.bean(copy=test_records[0])
po.doc.company = "_Test Company 1" po.doc.company = "_Test Company 1"
po.doc.conversion_rate = 0.0167 po.doc.conversion_rate = 0.0167
self.assertRaises(WrongWarehouseCompany, po.insert) self.assertRaises(InvalidWarehouseCompany, po.insert)
def test_uom_integer_validation(self): def test_uom_integer_validation(self):
from utilities.transaction_base import UOMMustBeIntegerError from utilities.transaction_base import UOMMustBeIntegerError
po = webnotes.bean(copy=test_records[0]) po = webnotes.bean(copy=test_records[0])

View File

@ -11,8 +11,6 @@ from setup.utils import get_company_currency
from controllers.stock_controller import StockController from controllers.stock_controller import StockController
class WrongWarehouseCompany(Exception): pass
class BuyingController(StockController): class BuyingController(StockController):
def onload_post_render(self): def onload_post_render(self):

View File

@ -61,8 +61,8 @@ def dropbox_callback(oauth_token=None, not_approved=False):
allowed = 0 allowed = 0
message = "Dropbox Access not approved." message = "Dropbox Access not approved."
webnotes.message_title = "Dropbox Approval" webnotes.local.message_title = "Dropbox Approval"
webnotes.message = "<h3>%s</h3><p>Please close this window.</p>" % message webnotes.local.message = "<h3>%s</h3><p>Please close this window.</p>" % message
webnotes.conn.commit() webnotes.conn.commit()
webnotes.response['type'] = 'page' webnotes.response['type'] = 'page'

View File

@ -160,7 +160,7 @@ class TestDeliveryNote(unittest.TestCase):
def test_serialized(self): def test_serialized(self):
from stock.doctype.stock_entry.test_stock_entry import make_serialized_item from stock.doctype.stock_entry.test_stock_entry import make_serialized_item
from stock.doctype.stock_ledger_entry.stock_ledger_entry import get_serial_nos from stock.doctype.serial_no.serial_no import get_serial_nos
se = make_serialized_item() se = make_serialized_item()
serial_nos = get_serial_nos(se.doclist[1].serial_no) serial_nos = get_serial_nos(se.doclist[1].serial_no)
@ -180,7 +180,7 @@ class TestDeliveryNote(unittest.TestCase):
return dn return dn
def test_serialized_cancel(self): def test_serialized_cancel(self):
from stock.doctype.stock_ledger_entry.stock_ledger_entry import get_serial_nos from stock.doctype.serial_no.serial_no import get_serial_nos
dn = self.test_serialized() dn = self.test_serialized()
dn.cancel() dn.cancel()
@ -192,7 +192,7 @@ class TestDeliveryNote(unittest.TestCase):
"delivery_document_no")) "delivery_document_no"))
def test_serialize_status(self): def test_serialize_status(self):
from stock.doctype.stock_ledger_entry.stock_ledger_entry import SerialNoStatusError, get_serial_nos from stock.doctype.serial_no.serial_no import SerialNoStatusError, get_serial_nos
from stock.doctype.stock_entry.test_stock_entry import make_serialized_item from stock.doctype.stock_entry.test_stock_entry import make_serialized_item
se = make_serialized_item() se = make_serialized_item()

View File

@ -315,10 +315,10 @@ class TestMaterialRequest(unittest.TestCase):
self.assertRaises(webnotes.MappingMismatchError, se.insert) self.assertRaises(webnotes.MappingMismatchError, se.insert)
def test_warehouse_company_validation(self): def test_warehouse_company_validation(self):
from controllers.buying_controller import WrongWarehouseCompany from stock.utils import InvalidWarehouseCompany
mr = webnotes.bean(copy=test_records[0]) mr = webnotes.bean(copy=test_records[0])
mr.doc.company = "_Test Company 1" mr.doc.company = "_Test Company 1"
self.assertRaises(WrongWarehouseCompany, mr.insert) self.assertRaises(InvalidWarehouseCompany, mr.insert)
test_dependencies = ["Currency Exchange"] test_dependencies = ["Currency Exchange"]
test_records = [ test_records = [

View File

@ -242,7 +242,7 @@ class DocType(BuyingController):
self.update_stock() self.update_stock()
from stock.doctype.serial_no.serial_no import update_serial_nos_after_submit from stock.doctype.serial_no.serial_no import update_serial_nos_after_submit
update_serial_nos_after_submit(self, "Purchase Receipt", "purchase_receipt_details") update_serial_nos_after_submit(self, "purchase_receipt_details")
purchase_controller.update_last_purchase_rate(self, 1) purchase_controller.update_last_purchase_rate(self, 1)

View File

@ -104,6 +104,7 @@ class TestPurchaseReceipt(unittest.TestCase):
pr.doclist[1].received_qty = 1 pr.doclist[1].received_qty = 1
pr.insert() pr.insert()
pr.submit() pr.submit()
self.assertEquals(webnotes.conn.get_value("Serial No", pr.doclist[1].serial_no, self.assertEquals(webnotes.conn.get_value("Serial No", pr.doclist[1].serial_no,
"supplier"), pr.doc.supplier) "supplier"), pr.doc.supplier)
@ -112,7 +113,7 @@ class TestPurchaseReceipt(unittest.TestCase):
def test_serial_no_cancel(self): def test_serial_no_cancel(self):
pr = self.test_serial_no_supplier() pr = self.test_serial_no_supplier()
pr.cancel() pr.cancel()
self.assertFalse(webnotes.conn.get_value("Serial No", pr.doclist[1].serial_no, self.assertFalse(webnotes.conn.get_value("Serial No", pr.doclist[1].serial_no,
"warehouse")) "warehouse"))

View File

@ -37,11 +37,8 @@ class DocType(StockController):
self.validate_warehouse() self.validate_warehouse()
self.validate_item() self.validate_item()
if self.via_stock_ledger: self.on_stock_ledger_entry()
self.set_status()
self.set_purchase_details()
self.set_sales_details()
def validate_amc_status(self): def validate_amc_status(self):
""" """
validate amc status validate amc status
@ -118,7 +115,7 @@ class DocType(StockController):
and ifnull(is_cancelled, 'No')='No' order by name asc limit 1""", and ifnull(is_cancelled, 'No')='No' order by name asc limit 1""",
("%%%s%%" % (self.doc.name+"\n"), "%%%s%%" % ("\n"+self.doc.name), self.doc.name, ("%%%s%%" % (self.doc.name+"\n"), "%%%s%%" % ("\n"+self.doc.name), self.doc.name,
self.doc.item_code), as_dict=1) self.doc.item_code), as_dict=1)
if purchase_sle: if purchase_sle:
self.doc.purchase_document_type = purchase_sle[0].voucher_type self.doc.purchase_document_type = purchase_sle[0].voucher_type
self.doc.purchase_document_no = purchase_sle[0].voucher_no self.doc.purchase_document_no = purchase_sle[0].voucher_no
@ -181,6 +178,12 @@ class DocType(StockController):
webnotes.conn.sql("""update `tab%s` set serial_no = %s webnotes.conn.sql("""update `tab%s` set serial_no = %s
where name=%s""" % (dt[0], '%s', '%s'), where name=%s""" % (dt[0], '%s', '%s'),
('\n'.join(serial_nos), item[0])) ('\n'.join(serial_nos), item[0]))
def on_stock_ledger_entry(self):
if self.via_stock_ledger and not self.doc.fields.get("__islocal"):
self.set_status()
self.set_purchase_details()
self.set_sales_details()
def process_serial_no(sle): def process_serial_no(sle):
item_det = get_item_details(sle.item_code) item_det = get_item_details(sle.item_code)
@ -233,6 +236,14 @@ def validate_serial_no(sle, item_det):
+ sle.item_code), SerialNoRequiredError) + sle.item_code), SerialNoRequiredError)
def update_serial_nos(sle, item_det): def update_serial_nos(sle, item_det):
if not sle.serial_no and sle.actual_qty > 0 and item_det.serial_no_series:
from webnotes.model.doc import make_autoname
serial_nos = []
for i in xrange(cint(sle.actual_qty)):
serial_nos.append(make_autoname(item_det.serial_no_series))
webnotes.conn.set(sle, "serial_no", "\n".join(serial_nos))
if sle.serial_no: if sle.serial_no:
serial_nos = get_serial_nos(sle.serial_no) serial_nos = get_serial_nos(sle.serial_no)
for serial_no in serial_nos: for serial_no in serial_nos:
@ -243,12 +254,6 @@ def update_serial_nos(sle, item_det):
sr.save() sr.save()
elif sle.actual_qty > 0: elif sle.actual_qty > 0:
make_serial_no(serial_no, sle) make_serial_no(serial_no, sle)
elif sle.actual_qty > 0 and item_det.serial_no_series:
from webnotes.model.doc import make_autoname
serial_nos = []
for i in xrange(cint(sle.actual_qty)):
serial_nos.append(make_serial_no(make_autoname(item_det.serial_no_series), sle))
sle.serial_no = "\n".join(serial_nos)
def get_item_details(item_code): def get_item_details(item_code):
return webnotes.conn.sql("""select name, has_batch_no, docstatus, return webnotes.conn.sql("""select name, has_batch_no, docstatus,
@ -270,13 +275,16 @@ def make_serial_no(serial_no, sle):
webnotes.msgprint(_("Serial No created") + ": " + sr.doc.name) webnotes.msgprint(_("Serial No created") + ": " + sr.doc.name)
return sr.doc.name return sr.doc.name
def update_serial_nos_after_submit(controller, parenttype, parentfield): def update_serial_nos_after_submit(controller, parentfield):
if not hasattr(webnotes, "new_stock_ledger_entries"): stock_ledger_entries = webnotes.conn.sql("""select voucher_detail_no, serial_no
return from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s""",
(controller.doc.doctype, controller.doc.name), as_dict=True)
if not stock_ledger_entries: return
for d in controller.doclist.get({"parentfield": parentfield}): for d in controller.doclist.get({"parentfield": parentfield}):
serial_no = None serial_no = None
for sle in webnotes.new_stock_ledger_entries: for sle in stock_ledger_entries:
if sle.voucher_detail_no==d.name: if sle.voucher_detail_no==d.name:
serial_no = sle.serial_no serial_no = sle.serial_no
break break

View File

@ -53,7 +53,7 @@ class DocType(StockController):
self.update_stock_ledger() self.update_stock_ledger()
from stock.doctype.serial_no.serial_no import update_serial_nos_after_submit from stock.doctype.serial_no.serial_no import update_serial_nos_after_submit
update_serial_nos_after_submit(self, "Stock Entry", "mtn_details") update_serial_nos_after_submit(self, "mtn_details")
self.update_production_order(1) self.update_production_order(1)
self.make_gl_entries() self.make_gl_entries()

View File

@ -44,9 +44,10 @@ class TestStockEntry(unittest.TestCase):
def test_warehouse_company_validation(self): def test_warehouse_company_validation(self):
self._clear_stock_account_balance() self._clear_stock_account_balance()
webnotes.session.user = "test2@example.com"
webnotes.bean("Profile", "test2@example.com").get_controller()\ webnotes.bean("Profile", "test2@example.com").get_controller()\
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager") .add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
webnotes.session.user = "test2@example.com"
from stock.utils import InvalidWarehouseCompany from stock.utils import InvalidWarehouseCompany
st1 = webnotes.bean(copy=test_records[0]) st1 = webnotes.bean(copy=test_records[0])
@ -59,13 +60,13 @@ class TestStockEntry(unittest.TestCase):
def test_warehouse_user(self): def test_warehouse_user(self):
from stock.utils import UserNotAllowedForWarehouse from stock.utils import UserNotAllowedForWarehouse
webnotes.session.user = "test@example.com"
webnotes.bean("Profile", "test@example.com").get_controller()\ webnotes.bean("Profile", "test@example.com").get_controller()\
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager") .add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
webnotes.bean("Profile", "test2@example.com").get_controller()\ webnotes.bean("Profile", "test2@example.com").get_controller()\
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager") .add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
webnotes.session.user = "test@example.com"
st1 = webnotes.bean(copy=test_records[0]) st1 = webnotes.bean(copy=test_records[0])
st1.doc.company = "_Test Company 1" st1.doc.company = "_Test Company 1"
st1.doclist[1].t_warehouse="_Test Warehouse 2 - _TC1" st1.doclist[1].t_warehouse="_Test Warehouse 2 - _TC1"

View File

@ -14,10 +14,6 @@ class DocType(DocListController):
def validate(self): def validate(self):
from stock.utils import validate_warehouse_user, validate_warehouse_company from stock.utils import validate_warehouse_user, validate_warehouse_company
if not hasattr(webnotes, "new_stock_ledger_entries"):
webnotes.new_stock_ledger_entries = []
webnotes.new_stock_ledger_entries.append(self.doc)
self.validate_mandatory() self.validate_mandatory()
self.validate_item() self.validate_item()
validate_warehouse_user(self.doc.warehouse) validate_warehouse_user(self.doc.warehouse)
@ -52,7 +48,7 @@ class DocType(DocListController):
<b>%(item_code)s</b> at Warehouse <b>%(warehouse)s</b> \ <b>%(item_code)s</b> at Warehouse <b>%(warehouse)s</b> \
as on %(posting_date)s %(posting_time)s""" % self.doc.fields) as on %(posting_date)s %(posting_time)s""" % self.doc.fields)
sself.doc.fields.pop('batch_bal') self.doc.fields.pop('batch_bal')
def validate_mandatory(self): def validate_mandatory(self):
mandatory = ['warehouse','posting_date','voucher_type','voucher_no','actual_qty','company'] mandatory = ['warehouse','posting_date','voucher_type','voucher_no','actual_qty','company']

View File

@ -252,10 +252,10 @@ def get_buying_amount(voucher_type, voucher_no, item_row, stock_ledger_entries):
def reorder_item(): def reorder_item():
""" Reorder item if stock reaches reorder level""" """ Reorder item if stock reaches reorder level"""
if not hasattr(webnotes, "auto_indent"): if getattr(webnotes.local, "auto_indent", None) is None:
webnotes.auto_indent = cint(webnotes.conn.get_value('Stock Settings', None, 'auto_indent')) webnotes.local.auto_indent = cint(webnotes.conn.get_value('Stock Settings', None, 'auto_indent'))
if webnotes.auto_indent: if webnotes.local.auto_indent:
material_requests = {} material_requests = {}
bin_list = webnotes.conn.sql("""select item_code, warehouse, projected_qty bin_list = webnotes.conn.sql("""select item_code, warehouse, projected_qty
from tabBin where ifnull(item_code, '') != '' and ifnull(warehouse, '') != '' from tabBin where ifnull(item_code, '') != '' and ifnull(warehouse, '') != ''
@ -340,18 +340,18 @@ def create_material_request(material_requests):
mr_list.append(mr_bean) mr_list.append(mr_bean)
except: except:
if webnotes.message_log: if webnotes.local.message_log:
exceptions_list.append([] + webnotes.message_log) exceptions_list.append([] + webnotes.local.message_log)
webnotes.message_log = [] webnotes.local.message_log = []
else: else:
exceptions_list.append(webnotes.getTraceback()) exceptions_list.append(webnotes.getTraceback())
if mr_list: if mr_list:
if not hasattr(webnotes, "reorder_email_notify"): if getattr(webnotes.local, "reorder_email_notify", None) is None:
webnotes.reorder_email_notify = cint(webnotes.conn.get_value('Stock Settings', None, webnotes.local.reorder_email_notify = cint(webnotes.conn.get_value('Stock Settings', None,
'reorder_email_notify')) 'reorder_email_notify'))
if(webnotes.reorder_email_notify): if(webnotes.local.reorder_email_notify):
send_email_notification(mr_list) send_email_notification(mr_list)
if exceptions_list: if exceptions_list: