mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 03:01:22 +00:00
model_wrapper is now bean, refactoring defaults
This commit is contained in:
@@ -17,10 +17,10 @@
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
|
||||
from webnotes.utils import add_days, cint, cstr, flt, get_defaults, now, nowdate
|
||||
from webnotes.utils import add_days, cint, cstr, flt, now, nowdate
|
||||
from webnotes.model import db_exists
|
||||
from webnotes.model.doc import Document, addchild
|
||||
from webnotes.model.wrapper import copy_doclist
|
||||
from webnotes.model.bean import copy_doclist
|
||||
from webnotes.model.code import get_obj
|
||||
from webnotes import msgprint
|
||||
sql = webnotes.conn.sql
|
||||
@@ -97,28 +97,34 @@ class DocType:
|
||||
|
||||
def reorder_item(self,doc_type,doc_name):
|
||||
""" Reorder item if stock reaches reorder level"""
|
||||
if not hasattr(webnotes, "auto_indent"):
|
||||
webnotes.auto_indent = webnotes.conn.get_value('Global Defaults', None, 'auto_indent')
|
||||
|
||||
if webnotes.conn.get_value('Global Defaults', None, 'auto_indent'):
|
||||
if webnotes.auto_indent:
|
||||
#check if re-order is required
|
||||
ret = sql("""select re_order_level, item_name, description, brand, item_group,
|
||||
lead_time_days, min_order_qty, email_notify, re_order_qty
|
||||
from tabItem where name = %s""", (self.doc.item_code), as_dict=1)
|
||||
item_reorder = webnotes.conn.get("Item Reorder",
|
||||
{"parent": self.doc.item_code, "warehouse": self.doc.warehouse}, as_dict=1)
|
||||
|
||||
current_qty = sql("""
|
||||
select sum(t1.actual_qty) + sum(t1.indented_qty) + sum(t1.ordered_qty) -sum(t1.reserved_qty)
|
||||
from tabBin t1, tabWarehouse t2
|
||||
where t1.item_code = %s
|
||||
and t1.warehouse = t2.name
|
||||
and t2.warehouse_type in ('Stores', 'Reserved', 'Default Warehouse Type')
|
||||
and t1.docstatus != 2
|
||||
""", self.doc.item_code)
|
||||
if item_reorder:
|
||||
reorder_level = item_reorder.warehouse_reorder_level
|
||||
reorder_qty = item_reorder.warehouse_reorder_qty
|
||||
else:
|
||||
reorder_level, reorder_qty = webnotes.conn.get_valuee("Item", self.doc.item_code,
|
||||
["re_order_level", "re_order_qty"])
|
||||
|
||||
if flt(reorder_qty) and flt(self.doc.projected_qty) < flt(reorder_level):
|
||||
self.create_material_request(doc_type, doc_name)
|
||||
|
||||
if ret[0]["re_order_level"] and current_qty and \
|
||||
(flt(ret[0]['re_order_level']) > flt(current_qty[0][0])):
|
||||
self.create_auto_indent(ret[0], doc_type, doc_name, current_qty[0][0])
|
||||
|
||||
def create_auto_indent(self, i , doc_type, doc_name, cur_qty):
|
||||
def create_material_request(self, doc_type, doc_name):
|
||||
""" Create indent on reaching reorder level """
|
||||
defaults = webnotes.conn.get_defaults()
|
||||
mr = webnotes.bean([{
|
||||
"doctype": "Material Request",
|
||||
"company": defaults.company,
|
||||
|
||||
}])
|
||||
|
||||
|
||||
indent = Document('Material Request')
|
||||
indent.transaction_date = nowdate()
|
||||
indent.naming_series = 'IDT'
|
||||
|
||||
@@ -18,7 +18,7 @@ from __future__ import unicode_literals
|
||||
import webnotes
|
||||
|
||||
from webnotes.utils import cstr, flt, getdate
|
||||
from webnotes.model.wrapper import getlist
|
||||
from webnotes.model.bean import getlist
|
||||
from webnotes.model.code import get_obj
|
||||
from webnotes import msgprint
|
||||
|
||||
@@ -312,9 +312,9 @@ class DocType(SellingController):
|
||||
""", self.doc.name)
|
||||
|
||||
if res and res[0][1]>0:
|
||||
from webnotes.model.wrapper import ModelWrapper
|
||||
from webnotes.model.bean import Bean
|
||||
for r in res:
|
||||
ps = ModelWrapper(dt='Packing Slip', dn=r[0])
|
||||
ps = Bean(dt='Packing Slip', dn=r[0])
|
||||
ps.cancel()
|
||||
webnotes.msgprint("%s Packing Slip(s) Cancelled" % res[0][1])
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import webnotes
|
||||
|
||||
from webnotes.utils import cstr, flt
|
||||
from webnotes.model.doc import addchild
|
||||
from webnotes.model.wrapper import getlist
|
||||
from webnotes.model.bean import getlist
|
||||
from webnotes import msgprint
|
||||
|
||||
sql = webnotes.conn.sql
|
||||
|
||||
@@ -19,7 +19,7 @@ import unittest
|
||||
import webnotes
|
||||
import copy
|
||||
|
||||
from webnotes.model.wrapper import ModelWrapper
|
||||
from webnotes.model.bean import Bean
|
||||
from webnotes.model.doc import Document
|
||||
from webnotes.utils import flt
|
||||
|
||||
@@ -34,7 +34,7 @@ class TestItem(unittest.TestCase):
|
||||
webnotes.conn.rollback()
|
||||
|
||||
def testInsert(self):
|
||||
d = ModelWrapper()
|
||||
d = Bean()
|
||||
|
||||
count_before = flt(sql("select count(*) from tab"+_doctype)[0][0])
|
||||
if docok:
|
||||
@@ -49,7 +49,7 @@ class TestItem(unittest.TestCase):
|
||||
def testFailAssert(self):
|
||||
if docnotok:
|
||||
with self.assertRaises(Exception) as context:
|
||||
d = ModelWrapper()
|
||||
d = Bean()
|
||||
d.doc = docnotok[0]
|
||||
d.children = None
|
||||
d.doc.fields['__islocal']=1
|
||||
@@ -77,6 +77,31 @@ docnotok = [Document(fielddata=r) for r in tabNotOK]
|
||||
|
||||
|
||||
test_records = [
|
||||
[{
|
||||
"doctype": "Item",
|
||||
"item_code": "_Test Item",
|
||||
"item_name": "_Test Item",
|
||||
"description": "_Test Item",
|
||||
"item_group": "_Test Item Group",
|
||||
"is_stock_item": "Yes",
|
||||
"is_asset_item": "No",
|
||||
"has_batch_no": "No",
|
||||
"has_serial_no": "No",
|
||||
"is_purchase_item": "Yes",
|
||||
"is_sales_item": "Yes",
|
||||
"is_service_item": "No",
|
||||
"is_sample_item": "No",
|
||||
"inspection_required": "No",
|
||||
"is_pro_applicable": "No",
|
||||
"is_sub_contracted_item": "No",
|
||||
"stock_uom": "_Test UOM"
|
||||
}, {
|
||||
"doctype": "Item Reorder",
|
||||
"parentfield": "item_reorder",
|
||||
"warehouse": "_Test Warehouse",
|
||||
"warehouse_reorder_level": 20,
|
||||
"warehouse_reorder_qty": 20
|
||||
}],
|
||||
[{
|
||||
"doctype": "Item",
|
||||
"item_code": "_Test Item Home Desktop 100",
|
||||
|
||||
@@ -18,7 +18,7 @@ from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes.utils import cint, cstr, flt
|
||||
from webnotes.model.doc import addchild
|
||||
from webnotes.model.wrapper import getlist
|
||||
from webnotes.model.bean import getlist
|
||||
from webnotes.model.code import get_obj
|
||||
from webnotes import msgprint
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ cur_frm.cscript.fname = "indent_details";
|
||||
wn.require('app/buying/doctype/purchase_common/purchase_common.js');
|
||||
wn.require('app/utilities/doctype/sms_control/sms_control.js');
|
||||
|
||||
erpnext.buying.PurchaseRequestController = erpnext.buying.BuyingController.extend({
|
||||
erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.extend({
|
||||
refresh: function(doc) {
|
||||
this._super();
|
||||
|
||||
@@ -39,7 +39,7 @@ erpnext.buying.PurchaseRequestController = erpnext.buying.BuyingController.exten
|
||||
}
|
||||
});
|
||||
|
||||
var new_cscript = new erpnext.buying.PurchaseRequestController({frm: cur_frm});
|
||||
var new_cscript = new erpnext.buying.MaterialRequestController({frm: cur_frm});
|
||||
|
||||
// for backward compatibility: combine new and previous states
|
||||
$.extend(cur_frm.cscript, new_cscript);
|
||||
|
||||
@@ -5,7 +5,7 @@ from __future__ import unicode_literals
|
||||
import webnotes
|
||||
|
||||
from webnotes.utils import cstr, flt, get_defaults
|
||||
from webnotes.model.wrapper import getlist
|
||||
from webnotes.model.bean import getlist
|
||||
from webnotes.model.code import get_obj
|
||||
from webnotes import msgprint
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-01-29 19:25:55",
|
||||
"creation": "2013-02-18 13:50:55",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-02-18 13:10:37",
|
||||
"modified": "2013-02-18 14:41:41",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@@ -37,6 +37,19 @@
|
||||
"doctype": "DocType",
|
||||
"name": "Material Request"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "material_request_type",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"label": "Material Request Type",
|
||||
"options": "Purchase\nTransfer"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "column_break_2",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"description": "To manage multiple series please go to Setup > Manage Series",
|
||||
"doctype": "DocField",
|
||||
@@ -46,25 +59,10 @@
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "naming_series",
|
||||
"oldfieldtype": "Select",
|
||||
"options": "MREQ\nIDT",
|
||||
"options": "MREQ-\nIDT",
|
||||
"print_hide": 1,
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"description": "The date at which current entry is made in system.",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "transaction_date",
|
||||
"fieldtype": "Date",
|
||||
"in_filter": 1,
|
||||
"label": "Transaction Date",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "transaction_date",
|
||||
"oldfieldtype": "Date",
|
||||
"print_width": "100px",
|
||||
"reqd": 1,
|
||||
"search_index": 1,
|
||||
"width": "100px"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "items",
|
||||
@@ -140,6 +138,21 @@
|
||||
"print_width": "50%",
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
"description": "The date at which current entry is made in system.",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "transaction_date",
|
||||
"fieldtype": "Date",
|
||||
"in_filter": 1,
|
||||
"label": "Transaction Date",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "transaction_date",
|
||||
"oldfieldtype": "Date",
|
||||
"print_width": "100px",
|
||||
"reqd": 1,
|
||||
"search_index": 1,
|
||||
"width": "100px"
|
||||
},
|
||||
{
|
||||
"description": "Select the relevant company name if you have multiple companies",
|
||||
"doctype": "DocField",
|
||||
@@ -276,7 +289,7 @@
|
||||
"doctype": "DocField",
|
||||
"fieldname": "remark",
|
||||
"fieldtype": "Small Text",
|
||||
"in_list_view": 1,
|
||||
"in_list_view": 0,
|
||||
"label": "Remarks",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "remark",
|
||||
|
||||
32
stock/doctype/material_request/test_material_request.py
Normal file
32
stock/doctype/material_request/test_material_request.py
Normal file
@@ -0,0 +1,32 @@
|
||||
test_records = [
|
||||
[
|
||||
{
|
||||
"company": "_Test Company",
|
||||
"doctype": "Material Request",
|
||||
"fiscal_year": "_Test Fiscal Year 2013",
|
||||
"transaction_date": "2013-02-18"
|
||||
},
|
||||
{
|
||||
"description": "A 6",
|
||||
"doctype": "Material Request Item",
|
||||
"item_code": "_Test Item Home Desktop 100",
|
||||
"item_name": "A 6",
|
||||
"parentfield": "indent_details",
|
||||
"qty": 54.0,
|
||||
"schedule_date": "2013-02-18",
|
||||
"uom": "_Test UOM",
|
||||
"warehouse": "_Test Warehouse"
|
||||
},
|
||||
{
|
||||
"description": "Value 3.5",
|
||||
"doctype": "Material Request Item",
|
||||
"item_code": "_Test Item Home Desktop 200",
|
||||
"item_name": "Valve 3.5",
|
||||
"parentfield": "indent_details",
|
||||
"qty": 3.0,
|
||||
"schedule_date": "2013-02-19",
|
||||
"uom": "_Test UOM",
|
||||
"warehouse": "_Test Warehouse"
|
||||
}
|
||||
]
|
||||
]
|
||||
@@ -19,7 +19,7 @@ import webnotes
|
||||
|
||||
from webnotes.utils import cstr, flt, get_defaults
|
||||
from webnotes.model.doc import addchild
|
||||
from webnotes.model.wrapper import getlist
|
||||
from webnotes.model.bean import getlist
|
||||
from webnotes.model.code import get_obj
|
||||
from webnotes import msgprint
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import webnotes
|
||||
from webnotes.utils import flt
|
||||
from webnotes.model import db_exists
|
||||
from webnotes.model.doc import addchild
|
||||
from webnotes.model.wrapper import copy_doclist
|
||||
from webnotes.model.bean import copy_doclist
|
||||
|
||||
sql = webnotes.conn.sql
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class TestSerialNo(unittest.TestCase):
|
||||
["2012-01-01", "02:00", "10006", 1200, 800],
|
||||
["2012-01-01", "06:00", "10007", 1500, 900]]
|
||||
for d in data:
|
||||
webnotes.model_wrapper([{
|
||||
webnotes.bean([{
|
||||
"doctype": "Serial No",
|
||||
"item_code": "Nebula 8",
|
||||
"warehouse": "Default Warehouse",
|
||||
|
||||
@@ -19,7 +19,7 @@ import webnotes
|
||||
|
||||
from webnotes.utils import cstr, cint, flt, comma_or
|
||||
from webnotes.model.doc import Document, addchild
|
||||
from webnotes.model.wrapper import getlist
|
||||
from webnotes.model.bean import getlist
|
||||
from webnotes.model.code import get_obj
|
||||
from webnotes import msgprint, _
|
||||
from stock.utils import get_incoming_rate
|
||||
|
||||
99
stock/doctype/stock_entry/test_stock_entry.py
Normal file
99
stock/doctype/stock_entry/test_stock_entry.py
Normal file
@@ -0,0 +1,99 @@
|
||||
import webnotes, unittest
|
||||
|
||||
class TestStockEntry(unittest.TestCase):
|
||||
def test_auto_material_request(self):
|
||||
webnotes.conn.sql("""delete from `tabMaterial Request Item`""")
|
||||
webnotes.conn.sql("""delete from `tabMaterial Request`""")
|
||||
|
||||
st1 = webnotes.bean(copy=test_records[0])
|
||||
st1.insert()
|
||||
st1.submit()
|
||||
|
||||
st2 = webnotes.bean(copy=test_records[0])
|
||||
st2.insert()
|
||||
st2.submit()
|
||||
|
||||
mr_name = webnotes.conn.sql("""select parent from `tabMaterial Request Item`
|
||||
where item_code='_Test Item'""")
|
||||
|
||||
self.assertTrue(mr_name)
|
||||
|
||||
test_records = [
|
||||
[
|
||||
{
|
||||
"company": "_Test Company",
|
||||
"doctype": "Stock Entry",
|
||||
"posting_date": "2013-01-25",
|
||||
"posting_time": "17:14:24",
|
||||
"purpose": "Material Receipt"
|
||||
},
|
||||
{
|
||||
"conversion_factor": 1.0,
|
||||
"doctype": "Stock Entry Detail",
|
||||
"item_code": "_Test Item",
|
||||
"parentfield": "mtn_details",
|
||||
"incoming_rate": 100,
|
||||
"qty": 50.0,
|
||||
"stock_uom": "_Test UOM",
|
||||
"transfer_qty": 50.0,
|
||||
"uom": "_Test UOM",
|
||||
"t_warehouse": "_Test Warehouse",
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
"company": "_Test Company",
|
||||
"doctype": "Stock Entry",
|
||||
"posting_date": "2013-01-25",
|
||||
"posting_time": "17:15",
|
||||
"purpose": "Material Issue"
|
||||
},
|
||||
{
|
||||
"conversion_factor": 1.0,
|
||||
"doctype": "Stock Entry Detail",
|
||||
"item_code": "_Test Item",
|
||||
"parentfield": "mtn_details",
|
||||
"incoming_rate": 100,
|
||||
"qty": 40.0,
|
||||
"stock_uom": "_Test UOM",
|
||||
"transfer_qty": 40.0,
|
||||
"uom": "_Test UOM",
|
||||
"s_warehouse": "_Test Warehouse",
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
"company": "_Test Company",
|
||||
"doctype": "Stock Entry",
|
||||
"posting_date": "2013-01-25",
|
||||
"posting_time": "17:14:24",
|
||||
"purpose": "Material Transfer"
|
||||
},
|
||||
{
|
||||
"conversion_factor": 1.0,
|
||||
"doctype": "Stock Entry Detail",
|
||||
"item_code": "_Test Item Home Desktop 100",
|
||||
"parentfield": "mtn_details",
|
||||
"incoming_rate": 100,
|
||||
"qty": 45.0,
|
||||
"stock_uom": "_Test UOM",
|
||||
"transfer_qty": 45.0,
|
||||
"uom": "_Test UOM",
|
||||
"s_warehouse": "_Test Warehouse",
|
||||
"t_warehouse": "_Test Warehouse 1",
|
||||
},
|
||||
{
|
||||
"conversion_factor": 1.0,
|
||||
"doctype": "Stock Entry Detail",
|
||||
"item_code": "_Test Item Home Desktop 100",
|
||||
"parentfield": "mtn_details",
|
||||
"qty": 45.0,
|
||||
"incoming_rate": 100,
|
||||
"stock_uom": "_Test UOM",
|
||||
"transfer_qty": 45.0,
|
||||
"uom": "_Test UOM",
|
||||
"s_warehouse": "_Test Warehouse",
|
||||
"t_warehouse": "_Test Warehouse 1",
|
||||
}
|
||||
]
|
||||
]
|
||||
@@ -19,7 +19,7 @@ import webnotes
|
||||
|
||||
from webnotes.utils import add_days, cstr, flt, nowdate, cint
|
||||
from webnotes.model.doc import Document
|
||||
from webnotes.model.wrapper import getlist
|
||||
from webnotes.model.bean import getlist
|
||||
from webnotes.model.code import get_obj
|
||||
from webnotes import session, msgprint
|
||||
from stock.utils import get_valid_serial_nos
|
||||
@@ -221,7 +221,7 @@ class DocType:
|
||||
if args.get("warehouse"):
|
||||
args["warehouse_type"] = webnotes.conn.get_value('Warehouse' , args["warehouse"],
|
||||
'warehouse_type')
|
||||
sle = webnotes.model_wrapper([args])
|
||||
sle = webnotes.bean([args])
|
||||
sle.ignore_permissions = 1
|
||||
sle.insert()
|
||||
return sle.doc.name
|
||||
|
||||
@@ -248,7 +248,7 @@ class DocType(DocListController):
|
||||
}
|
||||
args.update(opts)
|
||||
# create stock ledger entry
|
||||
sle_wrapper = webnotes.model_wrapper([args])
|
||||
sle_wrapper = webnotes.bean([args])
|
||||
sle_wrapper.ignore_permissions = 1
|
||||
sle_wrapper.insert()
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ class TestStockReconciliation(unittest.TestCase):
|
||||
self.setUp()
|
||||
|
||||
def submit_stock_reconciliation(self, qty, rate, posting_date, posting_time):
|
||||
return webnotes.model_wrapper([{
|
||||
return webnotes.bean([{
|
||||
"doctype": "Stock Reconciliation",
|
||||
"name": "RECO-001",
|
||||
"__islocal": 1,
|
||||
|
||||
@@ -19,7 +19,7 @@ import webnotes
|
||||
|
||||
from webnotes.utils import cstr, flt, now
|
||||
from webnotes.model import db_exists
|
||||
from webnotes.model.wrapper import copy_doclist
|
||||
from webnotes.model.bean import copy_doclist
|
||||
from webnotes.model.code import get_obj
|
||||
from webnotes import msgprint
|
||||
|
||||
|
||||
@@ -3,5 +3,10 @@ test_records = [
|
||||
"doctype": "Warehouse",
|
||||
"warehouse_name": "_Test Warehouse",
|
||||
"warehouse_type": "_Test Warehouse Type"
|
||||
}]
|
||||
}],
|
||||
[{
|
||||
"doctype": "Warehouse",
|
||||
"warehouse_name": "_Test Warehouse 1",
|
||||
"warehouse_type": "_Test Warehouse Type"
|
||||
}]
|
||||
]
|
||||
@@ -34,7 +34,7 @@ class DocType:
|
||||
warehouse = %s", (item_code, warehouse))
|
||||
bin = bin and bin[0][0] or ''
|
||||
if not bin:
|
||||
bin_wrapper = webnotes.model_wrapper([{
|
||||
bin_wrapper = webnotes.bean([{
|
||||
"doctype": "Bin",
|
||||
"item_code": item_code,
|
||||
"warehouse": warehouse,
|
||||
|
||||
@@ -6,6 +6,11 @@ wn.module_page["Stock"] = [
|
||||
title: wn._("Documents"),
|
||||
icon: "icon-copy",
|
||||
items: [
|
||||
{
|
||||
label: wn._("Material Request"),
|
||||
description: wn._("Request Material for Transfer or Purchase."),
|
||||
doctype:"Material Request"
|
||||
},
|
||||
{
|
||||
label: wn._("Stock Entry"),
|
||||
description: wn._("Transfer stock from one warehouse to another."),
|
||||
|
||||
@@ -86,7 +86,7 @@ def update_entries_after(args, verbose=1):
|
||||
# update bin
|
||||
if not webnotes.conn.exists({"doctype": "Bin", "item_code": args["item_code"],
|
||||
"warehouse": args["warehouse"]}):
|
||||
bin_wrapper = webnotes.model_wrapper([{
|
||||
bin_wrapper = webnotes.bean([{
|
||||
"doctype": "Bin",
|
||||
"item_code": args["item_code"],
|
||||
"warehouse": args["warehouse"],
|
||||
|
||||
Reference in New Issue
Block a user