model_wrapper is now bean, refactoring defaults

This commit is contained in:
Rushabh Mehta 2013-02-18 18:24:28 +05:30
parent 9c880da381
commit c53231a841
104 changed files with 351 additions and 163 deletions

View File

@ -20,7 +20,7 @@ import webnotes
from webnotes.utils import cstr, flt, getdate, now, nowdate
from webnotes.model import db_exists
from webnotes.model.doc import addchild
from webnotes.model.wrapper import getlist, copy_doclist
from webnotes.model.bean import getlist, copy_doclist
from webnotes import msgprint
sql = webnotes.conn.sql

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import flt
from webnotes.model.doc import addchild
from webnotes.model.wrapper import getlist
from webnotes.model.bean import getlist
from webnotes import msgprint
class DocType:

View File

@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes.utils import flt, getdate
from webnotes.model.doc import make_autoname
from webnotes.model.wrapper import getlist
from webnotes.model.bean import getlist
class DocType:
def __init__(self,d,dl):

View File

@ -16,7 +16,7 @@
from __future__ import unicode_literals
import webnotes
from webnotes.model.wrapper import getlist
from webnotes.model.bean import getlist
from webnotes import msgprint
from webnotes.utils.nestedset import DocTypeNestedSet

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import cint, cstr, flt, fmt_money, formatdate, getdate
from webnotes.model.doc import addchild, make_autoname
from webnotes.model.wrapper import getlist
from webnotes.model.bean import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint
from setup.utils import get_company_currency

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import cint, cstr, flt, get_defaults, get_first_day, get_last_day, has_common
from webnotes.model import db_exists
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
from webnotes import session, msgprint
sql = webnotes.conn.sql

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import flt
from webnotes.model.doc import addchild
from webnotes.model.wrapper import getlist
from webnotes.model.bean import getlist
from webnotes import msgprint
class DocType:

View File

@ -20,7 +20,7 @@ import webnotes
from webnotes.utils import cstr, flt, getdate
from webnotes.model import db_exists
from webnotes.model.doc import Document
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

View File

@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes.model import db_exists
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
from webnotes import msgprint
sql = webnotes.conn.sql

View File

@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes.utils import add_days, cint, cstr, flt, formatdate, 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, _
from setup.utils import get_company_currency

View File

@ -25,7 +25,7 @@ test_dependencies = ["Item", "Cost Center"]
class TestPurchaseInvoice(unittest.TestCase):
def test_gl_entries(self):
wrapper = webnotes.model_wrapper(self.get_test_doclist())
wrapper = webnotes.bean(self.get_test_doclist())
# circumvent the disabled calculation call
obj = webnotes.get_obj(doc=wrapper.doc, doclist=wrapper.doclist)
@ -54,7 +54,7 @@ class TestPurchaseInvoice(unittest.TestCase):
self.assertEqual([d.debit, d.credit], expected_gl_entries.get(d.account))
def test_purchase_invoice_calculation(self):
wrapper = webnotes.model_wrapper(self.get_test_doclist())
wrapper = webnotes.bean(self.get_test_doclist())
# circumvent the disabled calculation call
obj = webnotes.get_obj(doc=wrapper.doc, doclist=wrapper.doclist)

View File

@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes
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
sql = webnotes.conn.sql

View File

@ -20,7 +20,7 @@ import webnotes
from webnotes.utils import add_days, cint, cstr, date_diff, flt, getdate, nowdate, sendmail
from webnotes.utils import comma_and
from webnotes.model.doc import make_autoname
from webnotes.model.wrapper import getlist
from webnotes.model.bean import getlist
from webnotes.model.code import get_obj
from webnotes import _, msgprint
@ -858,7 +858,7 @@ def manage_recurring_invoices(next_date=None):
where posting_date=%s and recurring_id=%s and docstatus=1""",
(next_date, recurring_id)):
try:
ref_wrapper = webnotes.model_wrapper('Sales Invoice', ref_invoice)
ref_wrapper = webnotes.bean('Sales Invoice', ref_invoice)
new_invoice_wrapper = make_new_invoice(ref_wrapper, next_date)
send_notification(new_invoice_wrapper)
webnotes.conn.commit()
@ -880,7 +880,7 @@ def manage_recurring_invoices(next_date=None):
raise Exception, exception_message
def make_new_invoice(ref_wrapper, posting_date):
from webnotes.model.wrapper import clone
from webnotes.model.bean import clone
from accounts.utils import get_fiscal_year
new_invoice = clone(ref_wrapper)

View File

@ -3,7 +3,7 @@ import unittest
class TestSalesInvoice(unittest.TestCase):
def make(self):
w = webnotes.model_wrapper(webnotes.copy_doclist(test_records[0]))
w = webnotes.bean(webnotes.copy_doclist(test_records[0]))
w.insert()
w.submit()
return w
@ -17,7 +17,7 @@ class TestSalesInvoice(unittest.TestCase):
from accounts.doctype.journal_voucher.test_journal_voucher \
import test_records as jv_test_records
jv = webnotes.model_wrapper(webnotes.copy_doclist(jv_test_records[0]))
jv = webnotes.bean(webnotes.copy_doclist(jv_test_records[0]))
jv.doclist[1].against_invoice = w.doc.name
jv.insert()
jv.submit()

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import add_days, add_months, cint, cstr
from webnotes.model import db_exists
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
sql = webnotes.conn.sql

View File

@ -65,7 +65,7 @@ def map_fields(field_list, source, target):
def import_vouchers(common_values, data, start_idx, import_type):
from webnotes.model.doc import Document
from webnotes.model.wrapper import ModelWrapper
from webnotes.model.bean import Bean
from accounts.utils import get_fiscal_year
from webnotes.utils.dateutils import parse_date
@ -159,7 +159,7 @@ def import_vouchers(common_values, data, start_idx, import_type):
If you entered accounts correctly, please check template once"""]
raise Exception
doclist = ModelWrapper([jv]+details)
doclist = Bean([jv]+details)
doclist.submit()
messages.append("""<p style='color: green'>[row #%s]

View File

@ -121,7 +121,7 @@ def add_ac(args=None):
args = webnotes.form_dict
args.pop("cmd")
ac = webnotes.model_wrapper(args)
ac = webnotes.bean(args)
ac.doc.doctype = "Account"
ac.doc.old_parent = ""
ac.doc.freeze_account = "No"
@ -135,7 +135,7 @@ def add_cc(args=None):
args = webnotes.form_dict
args.pop("cmd")
cc = webnotes.model_wrapper(args)
cc = webnotes.bean(args)
cc.doc.doctype = "Cost Center"
cc.doc.old_parent = ""
cc.ignore_permissions = 1

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import add_days, 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, _

View File

@ -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
from buying.utils import get_last_purchase_details

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.model import db_exists
from webnotes.model.doc import addchild, make_autoname
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
sql = webnotes.conn.sql

View File

@ -57,7 +57,7 @@ class DocType(BuyingController):
self.doc, self.doclist, """[['Material Request', 'Supplier Quotation'],
['Material Request Item', 'Supplier Quotation Item']]""")
from webnotes.model.wrapper import getlist
from webnotes.model.bean import getlist
for d in getlist(self.doclist, self.fname):
if d.item_code and not d.purchase_rate:
d.purchase_ref_rate = d.discount_rate = d.purchase_rate = 0.0

View File

@ -37,7 +37,7 @@ def get_item_details(args):
args = webnotes._dict(args)
item_wrapper = webnotes.model_wrapper("Item", args.item_code)
item_wrapper = webnotes.bean("Item", args.item_code)
item = item_wrapper.doc
from stock.utils import validate_end_of_life
@ -98,7 +98,7 @@ def get_item_details(args):
def get_rates_as_per_price_list(args, item_doclist=None):
if not item_doclist:
item_doclist = webnotes.model_wrapper("Item", args.item_code).doclist
item_doclist = webnotes.bean("Item", args.item_code).doclist
result = item_doclist.get({"parentfield": "ref_rate_details",
"price_list_name": args.price_list_name, "ref_currency": args.price_list_currency,

View File

@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes.model import db_exists
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
sql = webnotes.conn.sql

View File

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

View File

@ -20,7 +20,7 @@ import webnotes
from webnotes.utils import add_days, getdate, now
from webnotes.model import db_exists
from webnotes.model.doc import make_autoname
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
from webnotes import msgprint
sql = webnotes.conn.sql

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import cint, cstr, date_diff, formatdate, get_defaults, getdate, now
from webnotes.model import db_exists
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
from webnotes import form, msgprint
sql = webnotes.conn.sql

View File

@ -79,7 +79,7 @@ class DocType:
from webnotes.profile import add_role
add_role(self.doc.user_id, "HR User")
profile_wrapper = webnotes.model_wrapper("Profile", self.doc.user_id)
profile_wrapper = webnotes.bean("Profile", self.doc.user_id)
# copy details like Fullname, DOB and Image to Profile
if self.doc.employee_name:

View File

@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes.utils import add_days
from webnotes.model.wrapper import getlist
from webnotes.model.bean import getlist
from webnotes import form, msgprint
from webnotes.model.code import get_obj

View File

@ -20,7 +20,7 @@ import webnotes
from webnotes.utils import add_days, add_years, cint, getdate
from webnotes.model import db_exists
from webnotes.model.doc import addchild, make_autoname
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
from webnotes import msgprint
sql = webnotes.conn.sql

View File

@ -31,14 +31,14 @@ class JobsMailbox(POP3Mailbox):
name = webnotes.conn.get_value("Job Applicant", {"email_id": mail.from_email},
"name")
if name:
applicant = webnotes.model_wrapper("Job Applicant", name)
applicant = webnotes.bean("Job Applicant", name)
if applicant.doc.status!="Rejected":
applicant.doc.status = "Open"
applicant.doc.save()
else:
name = (mail.from_real_name and (mail.from_real_name + " - ") or "") \
+ mail.from_email
applicant = webnotes.model_wrapper({
applicant = webnotes.bean({
"creation": mail.date,
"doctype":"Job Applicant",
"applicant_name": name,

View File

@ -5,18 +5,18 @@ from hr.doctype.leave_application.leave_application import LeaveDayBlockedError
class TestLeaveApplication(unittest.TestCase):
def get_application(self, doclist):
application = webnotes.model_wrapper(doclist)
application = webnotes.bean(copy=doclist)
application.doc.from_date = "2013-01-01"
application.doc.to_date = "2013-01-05"
return application
def test_block_list(self):
import webnotes
webnotes.conn.set_value("Employee", "_T-Employee-0001", "department",
"_Test Department with Block List")
webnotes.conn.set_value("Department", "_Test Department", "leave_block_list", "_Test Leave Block List")
application = self.get_application(test_records[1])
application.insert()
application.doc.status = "Approved"
self.assertRaises(LeaveDayBlockedError, application.submit)
webnotes.session.user = "test1@example.com"
@ -45,6 +45,7 @@ class TestLeaveApplication(unittest.TestCase):
from webnotes.profile import add_role
add_role("test@example.com", "Leave Approver")
application.doc.status = "Approved"
self.assertRaises(LeaveDayBlockedError, application.submit)

View File

@ -20,7 +20,7 @@ import webnotes
from webnotes.utils import cint, cstr, flt, now, nowdate
from webnotes.model import db_exists
from webnotes.model.doc import Document
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

View File

@ -20,7 +20,7 @@ import webnotes
from webnotes.utils import cint, flt
from webnotes.model import db_exists
from webnotes.model.doc import Document
from webnotes.model.wrapper import getlist, copy_doclist
from webnotes.model.bean import getlist, copy_doclist
from webnotes.model.code import get_obj
from webnotes import msgprint

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import add_days, cint, cstr, flt, getdate
from webnotes.model.doc import make_autoname
from webnotes.model.wrapper import getlist
from webnotes.model.bean import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint
from setup.utils import get_company_currency

View File

@ -20,7 +20,7 @@ import webnotes
from webnotes.utils import cstr, flt
from webnotes.model import db_exists
from webnotes.model.doc import addchild, make_autoname
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
from webnotes import msgprint
sql = webnotes.conn.sql

View File

@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes.utils import cint, cstr, flt, now, nowdate
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, _

View File

@ -20,7 +20,7 @@ import webnotes
from webnotes.utils import cstr, flt, now, nowdate
from webnotes.model import db_exists
from webnotes.model.doc import make_autoname
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

View File

@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes.utils import cstr, flt, cint, nowdate, add_days
from webnotes.model.doc import addchild, Document
from webnotes.model.wrapper import getlist
from webnotes.model.bean import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint
@ -339,7 +339,7 @@ class DocType:
purchase_request_list = []
if items_to_be_requested:
for item in items_to_be_requested:
item_wrapper = webnotes.model_wrapper("Item", item)
item_wrapper = webnotes.bean("Item", item)
pr_doclist = [
{
"doctype": "Material Request",
@ -367,7 +367,7 @@ class DocType:
"warehouse": self.doc.purchase_request_for_warehouse
}
]
pr_wrapper = webnotes.model_wrapper(pr_doclist)
pr_wrapper = webnotes.bean(pr_doclist)
pr_wrapper.ignore_permissions = 1
pr_wrapper.submit()
purchase_request_list.append(pr_wrapper.doc.name)

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import flt
from webnotes.model import db_exists
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
sql = webnotes.conn.sql

View File

@ -1,5 +1,5 @@
from __future__ import unicode_literals
def execute():
import webnotes
from webnotes.model.wrapper import ModelWrapper
ModelWrapper("Website Settings", "Website Settings").save()
from webnotes.model.bean import Bean
Bean("Website Settings", "Website Settings").save()

View File

@ -4,10 +4,10 @@ def execute():
# new roles
roles = [r[0] for r in webnotes.conn.sql("""select name from tabRole""")]
if not "Leave Approver" in roles:
webnotes.model_wrapper([{"doctype":"Role", "role_name":"Leave Approver",
webnotes.bean([{"doctype":"Role", "role_name":"Leave Approver",
"__islocal":1, "module":"HR"}]).save()
if not "Expense Approver" in roles:
webnotes.model_wrapper([{"doctype":"Role", "role_name":"Expense Approver",
webnotes.bean([{"doctype":"Role", "role_name":"Expense Approver",
"__islocal":1, "module":"HR"}]).save()
# reload

View File

@ -6,6 +6,8 @@ def execute():
webnotes.rename_doc("DocType", "Purchase Request", "Material Request", force=True)
webnotes.reload_doc("buying", "search_criteria", "pending_po_items_to_bill")
webnotes.reload_doc("buying", "search_criteria", "pending_po_items_to_receive")
webnotes.conn.sql("""update `tabMaterial Request` set material_request_type='Purchase'""")
os.system("rm -rf app/buying/doctype/purchase_request")
os.system("rm -rf app/buying/doctype/purchase_request_item")

View File

@ -1,7 +1,7 @@
import webnotes
def execute():
for name in webnotes.conn.sql("""select name from `tabHoliday List`"""):
holiday_list_wrapper = webnotes.model_wrapper("Holiday List", name[0])
holiday_list_wrapper = webnotes.bean("Holiday List", name[0])
desc_count = _count([d.description for d in
holiday_list_wrapper.doclist.get({"doctype": "Holiday"})])

View File

@ -5,7 +5,7 @@ def execute():
webnotes.conn.sql("""update tabDocPerm set report = 0 where parent = %s""", dt[0])
doctype = webnotes.model_wrapper("DocType", dt[0])
doctype = webnotes.bean("DocType", dt[0])
for pl in [1, 2, 3]:
if not doctype.doclist.get({"doctype": "DocField", "permlevel": pl}):
if doctype.doclist.get({"doctype":"DocPerm", "permlevel":pl}):

View File

@ -23,7 +23,7 @@ def move_remarks_to_comments():
where ifnull(remark, '')!=''""")
fullname_map = {}
for reco, remark, modified_by in result:
webnotes.model_wrapper([{
webnotes.bean([{
"doctype": "Comment",
"comment": remark,
"comment_by": modified_by,

View File

@ -67,13 +67,13 @@ def save_pages():
}
import webnotes
from webnotes.model.wrapper import ModelWrapper
from webnotes.model.bean import Bean
import webnotes.modules.patch_handler
for dt in query_map:
for result in webnotes.conn.sql(query_map[dt], as_dict=1):
try:
ModelWrapper(dt, result['name'].encode('utf-8')).save()
Bean(dt, result['name'].encode('utf-8')).save()
except Exception, e:
webnotes.modules.patch_handler.log(unicode(e))

View File

@ -20,7 +20,7 @@ import webnotes
from webnotes.utils import flt, getdate
from webnotes.model import db_exists
from webnotes.model.doc import Document
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
from webnotes import msgprint
sql = webnotes.conn.sql

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import add_days, cint, cstr, date_diff, flt, now, nowdate, add_days
from webnotes.model import db_exists
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
from webnotes import msgprint
from webnotes.utils.email_lib import sendmail
sql = webnotes.conn.sql

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import getdate, today
from webnotes.model import db_exists
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
from webnotes import msgprint
sql = webnotes.conn.sql

View File

@ -20,7 +20,7 @@ import time, datetime
from webnotes.utils import cint, cstr, getdate, now, nowdate
from webnotes.model import db_exists
from webnotes.model.wrapper import getlist, copy_doclist
from webnotes.model.bean import getlist, copy_doclist
from webnotes import msgprint
sql = webnotes.conn.sql

View File

@ -20,7 +20,7 @@ import webnotes
from webnotes.utils import cstr, getdate
from webnotes.model import db_exists
from webnotes.model.doc import make_autoname
from webnotes.model.wrapper import getlist, copy_doclist
from webnotes.model.bean import getlist, copy_doclist
from webnotes.model.code import get_obj
from webnotes import msgprint
from stock.utils import get_valid_serial_nos

View File

@ -23,7 +23,7 @@ from core.doctype.communication.communication import make
def add_sales_communication(subject, content, sender, real_name, mail=None,
status="Open", date=None):
def set_status(doctype, name):
w = webnotes.model_wrapper(doctype, name)
w = webnotes.bean(doctype, name)
w.ignore_permissions = True
w.doc.status = is_system_user and "Replied" or status
w.doc.save()
@ -36,7 +36,7 @@ def add_sales_communication(subject, content, sender, real_name, mail=None,
if not (lead_name or contact_name):
# none, create a new Lead
lead = webnotes.model_wrapper({
lead = webnotes.bean({
"doctype":"Lead",
"lead_name": real_name or sender,
"email_id": sender,

View File

@ -20,7 +20,7 @@ import webnotes
from webnotes.utils import add_days, cstr, getdate
from webnotes.model import db_exists
from webnotes.model.doc import Document, addchild
from webnotes.model.wrapper import getlist
from webnotes.model.bean import getlist
from webnotes import msgprint
sql = webnotes.conn.sql

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import cint, cstr, get_defaults, now
from webnotes.model import db_exists
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
sql = webnotes.conn.sql

View File

@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes.utils import cstr, getdate
from webnotes.model.wrapper import getlist
from webnotes.model.bean import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import cint, cstr, flt, getdate, nowdate, formatdate
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, _
from setup.utils import get_company_currency

View File

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

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import cstr
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

View File

@ -30,4 +30,4 @@ def add_node():
parent_field: webnotes.form_dict['parent'],
"is_group": webnotes.form_dict['is_group']
}]
webnotes.model_wrapper(doclist).save()
webnotes.bean(doclist).save()

View File

@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes.utils import cstr, flt, has_common, make_esc
from webnotes.model.wrapper import getlist
from webnotes.model.bean import getlist
from webnotes import session, msgprint
from setup.utils import get_company_currency

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import cint, cstr, flt, has_common
from webnotes.model import db_exists
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
from webnotes import msgprint
sql = webnotes.conn.sql

View File

@ -5,7 +5,7 @@ import webnotes
from webnotes.utils import set_default
from webnotes.model import db_exists
from webnotes.model.doc import Document
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

View File

@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes.model import db_exists
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
sql = webnotes.conn.sql

View File

@ -20,7 +20,7 @@ import webnotes
from webnotes.utils import cstr
from webnotes.model import db_exists
from webnotes.model.doc import Document
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

View File

@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes.model import db_exists
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
sql = webnotes.conn.sql

View File

@ -17,7 +17,7 @@
from __future__ import unicode_literals
import webnotes
from webnotes.model.wrapper import getlist
from webnotes.model.bean import getlist
from webnotes.utils import flt
from webnotes.utils.nestedset import DocTypeNestedSet

View File

@ -17,7 +17,7 @@
from __future__ import unicode_literals
import webnotes
from webnotes.model.wrapper import getlist
from webnotes.model.bean import getlist
from webnotes.utils import flt
from webnotes.utils.nestedset import DocTypeNestedSet

View File

@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes.model import db_exists
from webnotes.model.wrapper import getlist, copy_doclist
from webnotes.model.bean import getlist, copy_doclist
from webnotes.model.code import get_obj
from webnotes import form, msgprint

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import cstr
from webnotes.model import db_exists
from webnotes.model.wrapper import getlist, copy_doclist
from webnotes.model.bean import getlist, copy_doclist
from webnotes import form, msgprint
sql = webnotes.conn.sql

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View 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"
}
]
]

View File

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

View File

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

View File

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

View File

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

View 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",
}
]
]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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."),

View File

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

View File

@ -19,7 +19,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes.model import db_exists
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
from webnotes import session, msgprint
from webnotes.utils import today

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import add_days, cstr, getdate
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

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import cstr
from webnotes.model import db_exists
from webnotes.model.wrapper import getlist, copy_doclist
from webnotes.model.bean import getlist, copy_doclist
from webnotes.model.code import get_obj
from webnotes import msgprint

View File

@ -2,7 +2,7 @@ import webnotes, unittest
class TestNewsletter(unittest.TestCase):
def test_get_recipients_lead(self):
w = webnotes.model_wrapper(test_records[0])
w = webnotes.bean(test_records[0])
w.insert()
self.assertTrue("test_lead@example.com" in w.controller.get_recipients())
webnotes.conn.sql("""delete from `tabBulk Email`""")
@ -10,24 +10,24 @@ class TestNewsletter(unittest.TestCase):
self.assertTrue(webnotes.conn.get_value("Bulk Email", {"recipient": "test_lead@example.com"}))
def test_get_recipients_lead_by_status(self):
w = webnotes.model_wrapper(test_records[0])
w = webnotes.bean(test_records[0])
w.doc.lead_status="Converted"
w.insert()
self.assertTrue("test_lead3@example.com" in w.controller.get_recipients())
def test_get_recipients_contact_customer(self):
w = webnotes.model_wrapper(test_records[1])
w = webnotes.bean(test_records[1])
w.insert()
self.assertTrue("test_contact_customer@example.com" in w.controller.get_recipients())
def test_get_recipients_contact_supplier(self):
w = webnotes.model_wrapper(test_records[1])
w = webnotes.bean(test_records[1])
w.doc.contact_type="Supplier"
w.insert()
self.assertTrue("test_contact_supplier@example.com" in w.controller.get_recipients())
def test_get_recipients_custom(self):
w = webnotes.model_wrapper(test_records[2])
w = webnotes.bean(test_records[2])
w.insert()
self.assertTrue("test_custom2@example.com" in w.controller.get_recipients())
self.assertTrue(webnotes.conn.get("Lead",

View File

@ -38,12 +38,12 @@ class SupportMailbox(POP3Mailbox):
ticket = None
if thread_id and webnotes.conn.exists("Support Ticket", thread_id):
ticket = webnotes.model_wrapper("Support Ticket", thread_id)
ticket = webnotes.bean("Support Ticket", thread_id)
ticket.doc.status = 'Open'
ticket.doc.save()
else:
ticket = webnotes.model_wrapper([{
ticket = webnotes.bean([{
"doctype":"Support Ticket",
"description": mail.content,
"subject": mail.mail["Subject"],

View File

@ -67,7 +67,7 @@ class DocType(TransactionBase):
@webnotes.whitelist()
def set_status(name, status):
st = webnotes.model_wrapper("Support Ticket", name)
st = webnotes.bean("Support Ticket", name)
st.doc.status = status
st.save()

View File

@ -20,7 +20,7 @@ import webnotes
from webnotes.utils import cstr
from webnotes.model import db_exists
from webnotes.model.doc import Document
from webnotes.model.wrapper import copy_doclist
from webnotes.model.bean import copy_doclist
sql = webnotes.conn.sql

View File

@ -21,7 +21,7 @@ from webnotes.utils import load_json, nowdate, cstr
from webnotes.model.code import get_obj
from webnotes.model.doc import Document
from webnotes import msgprint
from webnotes.model.wrapper import getlist, copy_doclist
from webnotes.model.bean import getlist, copy_doclist
sql = webnotes.conn.sql

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import 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
sql = webnotes.conn.sql

Some files were not shown because too many files have changed in this diff Show More