コード例 #1
0
def update_party(fullname, company_name=None, mobile_no=None, phone=None):
	party = get_lead_or_customer()

	if party.doctype == "Lead":
		party.company_name = company_name
		party.lead_name = fullname
		party.mobile_no = mobile_no
		party.phone = phone
	else:
		party.customer_name = company_name or fullname
		party.customer_type == "Company" if company_name else "Individual"
		
		contact_name = frappe.db.get_value("Contact", {"email_id": frappe.session.user,
			"customer": party.name})
		contact = frappe.bean("Contact", contact_name)
		contact.doc.first_name = fullname
		contact.doc.last_name = None
		contact.doc.customer_name = party.customer_name
		contact.doc.mobile_no = mobile_no
		contact.doc.phone = phone
		contact.ignore_permissions = True
		contact.save()
	
	party_bean = frappe.bean(party.fields)
	party_bean.ignore_permissions = True
	party_bean.save()
	
	qbean = _get_cart_quotation(party)
	if not qbean.doc.fields.get("__islocal"):
		qbean.doc.customer_name = company_name or fullname
		qbean.run_method("set_missing_lead_customer_details")
		qbean.ignore_permissions = True
		qbean.save()
コード例 #2
0
def _get_cart_quotation(party=None):
	if not party:
		party = get_lead_or_customer()
		
	quotation = frappe.db.get_value("Quotation", 
		{party.doctype.lower(): party.name, "order_type": "Shopping Cart", "docstatus": 0})
	
	if quotation:
		qbean = frappe.bean("Quotation", quotation)
	else:
		qbean = frappe.bean({
			"doctype": "Quotation",
			"naming_series": frappe.defaults.get_user_default("shopping_cart_quotation_series") or "QTN-CART-",
			"quotation_to": party.doctype,
			"company": frappe.defaults.get_user_default("company"),
			"order_type": "Shopping Cart",
			"status": "Draft",
			"docstatus": 0,
			"__islocal": 1,
			(party.doctype.lower()): party.name
		})
		
		if party.doctype == "Customer":
			qbean.doc.contact_person = frappe.db.get_value("Contact", {"email_id": frappe.session.user,
				"customer": party.name})
		
		qbean.run_method("onload_post_render")
		apply_cart_settings(party, qbean)
	
	return qbean
コード例 #3
0
	def test_exchange_rate_exists(self):
		frappe.db.sql("""delete from `tabCurrency Exchange`""")
		
		cart_settings = self.test_price_list_territory_overlap()
		controller = cart_settings.make_controller()
		self.assertRaises(ShoppingCartSetupError, controller.validate_exchange_rates_exist)
		
		from erpnext.setup.doctype.currency_exchange.test_currency_exchange import test_records as \
			currency_exchange_records
		frappe.bean(currency_exchange_records[0]).insert()
		controller.validate_exchange_rates_exist()
コード例 #4
0
def migrate_unit_to_website_group(unit):
	unit = frappe.bean("Unit", unit)
	
	if frappe.conn.get_value("Website Group", cleanup_page_name(unit.doc.name)):
		# already exists!
		return
	
	unit_name = cleanup_page_name(unit.doc.name)
	print unit_name
	
	# create website group
	group = frappe.new_bean("Website Group")
	group.doc.group_name = unit.doc.name
	group.doc.group_title = unit.doc.unit_title
	group.doc.group_type = unit.doc.unit_type
	group.doc.group_description = unit.doc.unit_description
	group.doc.public_read = unit.doc.public_read
	group.doc.public_write = unit.doc.public_write
	group.doc.upvotes = unit.doc.upvotes
	group.doc.replies = unit.doc.replies
	
	if unit.doc.parent_unit:
		parent_docname = cleanup_page_name(unit.doc.parent_unit)
		group.doc.parent_website_sitemap = frappe.conn.get_value("Website Sitemap",
			{"ref_doctype": "Website Group", "docname": parent_docname})
			
		# just making sure if my logic is correct!
		if not group.doc.parent_website_sitemap:
			if parent_docname.endswith("discussion"):
				print "ignoring", unit_name
				return
			
			raise Exception("Website Sitemap Not Found: {}".format(unit.doc.parent_unit))
	
	group.insert()
	
	# add website sitemap permissions
	for d in unit.doclist.get({"doctype": "Unit Profile"}):
		frappe.bean({
			"doctype": "Website Sitemap Permission",
			"website_sitemap": group.doc.page_name,
			"profile": d.profile,
			"read": d.read,
			"write": d.write,
			"admin": d.admin
		}).insert()
	
	# move posts
	frappe.conn.sql("""update `tabPost` set website_group=%s where unit=%s""", (group.doc.name,
		unit.doc.name))
	
	# WARNING - commit here to avoid too many writes error!
	frappe.conn.commit()
コード例 #5
0
def get_context(context):
	def _get_fields(fieldnames):
		return [frappe._dict(zip(["label", "fieldname", "fieldtype", "options"], 
				[df.label, df.fieldname, df.fieldtype, df.options]))
			for df in frappe.get_doctype("Address", processed=True).get({"fieldname": ["in", fieldnames]})]
	
	docname = doc = None
	title = "New Address"
	if frappe.form_dict.name:
		bean = frappe.bean("Address", frappe.form_dict.name)
		docname = bean.doc.name
		doc = bean.doc.fields
		title = bean.doc.name
	
	return {
		"doc": doc,
		"meta": frappe._dict({
			"left_fields": _get_fields(["address_title", "address_type", "address_line1", "address_line2",
				"city", "state", "pincode", "country"]),
			"right_fields": _get_fields(["email_id", "phone", "fax", "is_primary_address",
				"is_shipping_address"])
		}),
		"docname": docname,
		"title": title
	}
コード例 #6
0
	def enable_shopping_cart(self):
		settings = frappe.bean("Shopping Cart Settings", "Shopping Cart Settings")

		if len(settings.doclist) > 1:
			settings.doc.enabled = 1
		else:
			settings.doc.fields.update({
				"enabled": 1,
				"company": "_Test Company",
				"default_territory": "_Test Territory Rest Of The World",
				"default_customer_group": "_Test Customer Group",
				"quotation_series": "_T-Quotation-"
			})
			settings.doclist.extend([
				# price lists
				{"doctype": "Shopping Cart Price List", "parentfield": "price_lists", 
					"selling_price_list": "_Test Price List India"},
				{"doctype": "Shopping Cart Price List", "parentfield": "price_lists", 
					"selling_price_list": "_Test Price List Rest of the World"},
			
				# tax masters
				{"doctype": "Shopping Cart Taxes and Charges Master", "parentfield": "sales_taxes_and_charges_masters",
					"sales_taxes_and_charges_master": "_Test India Tax Master"},
				{"doctype": "Shopping Cart Taxes and Charges Master", "parentfield": "sales_taxes_and_charges_masters",
					"sales_taxes_and_charges_master": "_Test Sales Taxes and Charges Master - Rest of the World"},
			
				# shipping rules
				{"doctype": "Shopping Cart Shipping Rule", "parentfield": "shipping_rules",
					"shipping_rule": "_Test Shipping Rule - India"}
			])
		
		settings.save()
コード例 #7
0
	def enable_shopping_cart(self):
		return
		if not frappe.db.get_value("Shopping Cart Settings", None, "enabled"):
			cart_settings = frappe.bean("Shopping Cart Settings")
			cart_settings.ignore_permissions = True
			cart_settings.doc.enabled = 1
			cart_settings.save()
コード例 #8
0
def move_tasks_and_events():
	"""move tasks to tasks unit, events to events unit"""
	unit_tasks = dict(frappe.conn.sql("""select parent_unit, name from `tabUnit`
		where unit_type='Tasks'"""))
	unit_events = dict(frappe.conn.sql("""select parent_unit, name from `tabUnit`
		where unit_type='Events'"""))
	
	for post in frappe.conn.sql_list("""select name from `tabPost` 
		where is_task=1 or is_event=1"""):
		post = frappe.bean("Post", post)
		if post.doc.is_task:
			if not unit_tasks.get(post.doc.unit):
				# create unit of type Tasks
				new_unit = _add_unit(post.doc.unit, "Tasks", 1, 1, unit_type="Tasks")
				unit_tasks[post.doc.unit] = new_unit.doc.name
			
			post.doc.unit = unit_tasks.get(post.doc.unit)
			post.doc.is_event = 0
			
		elif post.doc.is_event:
			if not unit_events.get(post.doc.unit):
				# create unit of type Events
				new_unit = _add_unit(post.doc.unit, "Events", 1, 1, unit_type="Events")
				unit_events[post.doc.unit] = new_unit.doc.name
			
			post.doc.unit = unit_events.get(post.doc.unit)
			post.doc.is_task = 0
		
		print post.doc.name
		post.save()
コード例 #9
0
	def tearDown(self):
		return
		
		cart_settings = frappe.bean("Shopping Cart Settings")
		cart_settings.ignore_permissions = True
		cart_settings.doc.enabled = 0
		cart_settings.save()
コード例 #10
0
	def test_completed_qty_for_purchase(self):
		frappe.db.sql("""delete from `tabBin`""")
		
		# submit material request of type Purchase
		mr = frappe.bean(copy=test_records[0])
		mr.insert()
		mr.submit()
		
		# check if per complete is None
		self._test_expected(mr.doclist, [{"per_ordered": None}, {"ordered_qty": None}, {"ordered_qty": None}])
		
		self._test_requested_qty(54.0, 3.0)
		
		# map a purchase order
		from erpnext.stock.doctype.material_request.material_request import make_purchase_order
		po_doclist = make_purchase_order(mr.doc.name)
		po_doclist[0].supplier = "_Test Supplier"
		po_doclist[0].transaction_date = "2013-07-07"
		po_doclist[1].qty = 27.0
		po_doclist[2].qty = 1.5
		po_doclist[1].schedule_date = "2013-07-09"
		po_doclist[2].schedule_date = "2013-07-09"

		
		# check for stopped status of Material Request
		po = frappe.bean(copy=po_doclist)
		po.insert()
		mr.obj.update_status('Stopped')
		self.assertRaises(frappe.ValidationError, po.submit)
		self.assertRaises(frappe.ValidationError, po.cancel)

		mr.obj.update_status('Submitted')
		po = frappe.bean(copy=po_doclist)
		po.insert()
		po.submit()
		
		# check if per complete is as expected
		mr.load_from_db()
		self._test_expected(mr.doclist, [{"per_ordered": 50}, {"ordered_qty": 27.0}, {"ordered_qty": 1.5}])
		self._test_requested_qty(27.0, 1.5)
		
		po.cancel()
		# check if per complete is as expected
		mr.load_from_db()
		self._test_expected(mr.doclist, [{"per_ordered": None}, {"ordered_qty": None}, {"ordered_qty": None}])
		self._test_requested_qty(54.0, 3.0)
コード例 #11
0
ファイル: serial_no.py プロジェクト: ddimmich/erpnext
def validate_serial_no(sle, item_det):
    if item_det.has_serial_no == "No":
        if sle.serial_no:
            frappe.throw(
                _("Serial Number should be blank for Non Serialized Item" +
                  ": " + sle.item_code), SerialNoNotRequiredError)
    else:
        if sle.serial_no:
            serial_nos = get_serial_nos(sle.serial_no)
            if cint(sle.actual_qty) != flt(sle.actual_qty):
                frappe.throw(_("Serial No qty cannot be a fraction") + \
                 (": %s (%s)" % (sle.item_code, sle.actual_qty)))
            if len(serial_nos) and len(serial_nos) != abs(cint(
                    sle.actual_qty)):
                frappe.throw(_("Serial Nos do not match with qty") + \
                 (": %s (%s)" % (sle.item_code, sle.actual_qty)), SerialNoQtyError)

            if len(serial_nos) != len(set(serial_nos)):
                frappe.throw(
                    _("Duplicate Serial No entered against item") +
                    (": %s" % sle.item_code), SerialNoDuplicateError)

            for serial_no in serial_nos:
                if frappe.db.exists("Serial No", serial_no):
                    sr = frappe.bean("Serial No", serial_no)

                    if sr.doc.item_code != sle.item_code:
                        frappe.throw(
                            _("Serial No does not belong to Item") +
                            (": %s (%s)" % (sle.item_code, serial_no)),
                            SerialNoItemError)

                    if sr.doc.warehouse and sle.actual_qty > 0:
                        frappe.throw(
                            _("Same Serial No") + ": " + sr.doc.name +
                            _(" can not be received twice"),
                            SerialNoDuplicateError)

                    if sle.actual_qty < 0:
                        if sr.doc.warehouse != sle.warehouse:
                            frappe.throw(
                                _("Serial No") + ": " + serial_no +
                                _(" does not belong to Warehouse") + ": " +
                                sle.warehouse, SerialNoWarehouseError)

                        if sle.voucher_type in ("Delivery Note", "Sales Invoice") \
                         and sr.doc.status != "Available":
                            frappe.throw(
                                _("Serial No status must be 'Available' to Deliver"
                                  ) + ": " + serial_no, SerialNoStatusError)
                elif sle.actual_qty < 0:
                    # transfer out
                    frappe.throw(_("Serial No must exist to transfer out.") + \
                     ": " + serial_no, SerialNoNotExistsError)
        elif sle.actual_qty < 0 or not item_det.serial_no_series:
            frappe.throw(
                _("Serial Number Required for Serialized Item" + ": " +
                  sle.item_code), SerialNoRequiredError)
コード例 #12
0
	def test_delete(self):
		self.assertRaises(LinkExistsError, delete_doc, "Role", "_Test Role 2")
		frappe.db.sql("""delete from tabUserRole where role='_Test Role 2'""")
		delete_doc("Role","_Test Role 2")
		
		profile = frappe.bean(copy=test_records[1])
		profile.doc.email = "*****@*****.**"
		profile.insert()
		
		frappe.bean({"doctype": "ToDo", "description": "_Test"}).insert()
		
		delete_doc("Profile", "*****@*****.**")
		
		self.assertTrue(not frappe.db.sql("""select * from `tabToDo` where owner=%s""",
			("*****@*****.**",)))
		
		from frappe.core.doctype.role.test_role import test_records as role_records
		frappe.bean(copy=role_records[1]).insert()
コード例 #13
0
ファイル: test_sales_order.py プロジェクト: ddimmich/erpnext
    def create_so(self, so_doclist=None):
        if not so_doclist:
            so_doclist = test_records[0]

        w = frappe.bean(copy=so_doclist)
        w.insert()
        w.submit()

        return w
コード例 #14
0
def restore(version):
    if not "System Manager" in frappe.get_roles():
        raise frappe.PermissionError

    version = frappe.doc("Version", version)
    doclist = json.loads(version.doclist_json)

    # check if renamed
    if doclist[0].get("name") != version.docname:
        doclist[0]["name"] = version.docname
        for d in doclist[1:]:
            d["parent"] = version.docname

    doclist[0]["modified"] = frappe.db.get_value(version.ref_doctype,
                                                 version.docname, "modified")

    # overwrite
    frappe.bean(doclist).save()
コード例 #15
0
def set_value(doctype, name, fieldname, value):
    if fieldname != "idx" and fieldname in frappe.model.default_fields:
        frappe.throw(_("Cannot edit standard fields"))

    doc = frappe.db.get_value(doctype,
                              name, ["parenttype", "parent"],
                              as_dict=True)
    if doc and doc.parent:
        bean = frappe.bean(doc.parenttype, doc.parent)
        child = bean.doclist.getone({"doctype": doctype, "name": name})
        child.fields[fieldname] = value
    else:
        bean = frappe.bean(doctype, name)
        bean.doc.fields[fieldname] = value

    bean.save()

    return [d.fields for d in bean.doclist]
コード例 #16
0
ファイル: utils.py プロジェクト: akhileshdarjee/shopping-cart
def get_transaction_context(doctype, name):
	customer = frappe.conn.get_value("Contact", {"email_id": frappe.session.user}, 
		"customer")
	
	bean = frappe.bean(doctype, name)
	if bean.doc.customer != customer:
		return { "bean": frappe._dict({ "doc": frappe._dict({"name": _("Not Allowed")}) }) }
	else:
		return { "bean": bean }
コード例 #17
0
    def test_serialize_status(self):
        from erpnext.stock.doctype.serial_no.serial_no import SerialNoStatusError, get_serial_nos
        from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item

        se = make_serialized_item()
        serial_nos = get_serial_nos(se.doclist[1].serial_no)

        sr = frappe.bean("Serial No", serial_nos[0])
        sr.doc.status = "Not Available"
        sr.save()

        dn = frappe.bean(copy=test_records[0])
        dn.doclist[1].item_code = "_Test Serialized Item With Series"
        dn.doclist[1].qty = 1
        dn.doclist[1].serial_no = serial_nos[0]
        dn.insert()

        self.assertRaises(SerialNoStatusError, dn.submit)
コード例 #18
0
    def test_move_group_into_root(self):
        group_b = frappe.bean("Item Group", "_Test Item Group B")
        group_b.doc.parent_item_group = ""
        self.assertRaises(NestedSetMultipleRootsError, group_b.save)

        # trick! works because it hasn't been rolled back :D
        self.test_basic_tree()

        self.move_it_back()
コード例 #19
0
    def create_default_web_page(self):
        if not frappe.db.get_value("Website Settings", None, "home_page") and \
          not frappe.db.sql("select name from tabCompany where name!=%s", self.doc.name):
            import os
            with open(
                    os.path.join(os.path.dirname(__file__),
                                 "sample_home_page.html"), "r") as webfile:
                webpage = frappe.bean({
                    "doctype":
                    "Web Page",
                    "title":
                    self.doc.name + " Home",
                    "published":
                    1,
                    "description":
                    "Standard Home Page for " + self.doc.name,
                    "main_section":
                    webfile.read() % self.doc.fields
                }).insert()

                # update in home page in settings
                website_settings = frappe.bean("Website Settings",
                                               "Website Settings")
                website_settings.doc.home_page = webpage.doc.name
                website_settings.doc.brand_html = self.doc.name
                website_settings.doc.copyright = self.doc.name
                website_settings.doclist.append({
                    "doctype": "Top Bar Item",
                    "parentfield": "top_bar_items",
                    "label": "Contact",
                    "url": "contact"
                })
                website_settings.doclist.append({
                    "doctype": "Top Bar Item",
                    "parentfield": "top_bar_items",
                    "label": "Blog",
                    "url": "blog"
                })
                website_settings.save()
                style_settings = frappe.bean("Style Settings",
                                             "Style Settings")
                style_settings.doc.top_bar_background = "F2F2F2"
                style_settings.doc.font_size = "15px"
                style_settings.save()
コード例 #20
0
def get_party(user):
	customer = frappe.db.get_value("Contact", {"email_id": user}, "customer")
	if customer:
		return frappe.bean("Customer", customer)
	
	lead = frappe.db.get_value("Lead", {"email_id": user})
	if lead:
		return frappe.bean("Lead", lead)
	
	# create a lead
	lead = frappe.new_bean("Lead")
	lead.doc.fields.update({
		"email_id": user,
		"lead_name": get_fullname(user),
		"territory": guess_territory()
	})
	lead.insert(ignore_permissions=True)
	
	return lead
コード例 #21
0
	def cancel_pr(self, purchase_receipts):
		for pr in purchase_receipts:
			pr_bean = frappe.bean("Purchase Receipt", pr)
			
			pr_bean.run_method("update_ordered_qty")
			
			frappe.db.sql("""delete from `tabStock Ledger Entry` 
				where voucher_type='Purchase Receipt' and voucher_no=%s""", pr)
			frappe.db.sql("""delete from `tabGL Entry` where voucher_type='Purchase Receipt' 
				and voucher_no=%s""", pr)
コード例 #22
0
ファイル: utils.py プロジェクト: ddimmich/erpnext
def add_cc(args=None):
	if not args:
		args = frappe.local.form_dict
		args.pop("cmd")
		
	cc = frappe.bean(args)
	cc.doc.doctype = "Cost Center"
	cc.doc.old_parent = ""
	cc.insert()
	return cc.doc.name
コード例 #23
0
def create_suppliers(args):
    for i in xrange(1, 6):
        supplier = args.get("supplier_" + str(i))
        if supplier:
            frappe.bean({
                "doctype": "Supplier",
                "supplier_name": supplier,
                "supplier_type": "Local",
                "company": args.get("company_name")
            }).insert()

            if args.get("supplier_contact_" + str(i)):
                contact = args.get("supplier_contact_" + str(i)).split(" ")
                frappe.bean({
                    "doctype": "Contact",
                    "supplier": supplier,
                    "first_name": contact[0],
                    "last_name": len(contact) > 1 and contact[1] or ""
                }).insert()
コード例 #24
0
def execute():
	frappe.reload_doc("website", "doctype", "contact_us_settings")
	address = frappe.db.get_value("Contact Us Settings", None, "address")
	if address:
		address = frappe.doc("Address", address)
		contact = frappe.bean("Contact Us Settings", "Contact Us Settings")
		for f in ("address_title", "address_line1", "address_line2", "city", "state", "country", "pincode"):
			contact.doc.fields[f] = address.get(f)
		
		contact.save()
コード例 #25
0
    def add_calendar_event(self):
        # delete any earlier event for this project
        delete_events(self.doc.doctype, self.doc.name)

        # add events
        for milestone in self.doclist.get(
            {"parentfield": "project_milestones"}):
            if milestone.milestone_date:
                description = (milestone.milestone
                               or "Milestone") + " for " + self.doc.name
                frappe.bean({
                    "doctype": "Event",
                    "owner": self.doc.owner,
                    "subject": description,
                    "description": description,
                    "starts_on": milestone.milestone_date + " 10:00:00",
                    "event_type": "Private",
                    "ref_type": self.doc.doctype,
                    "ref_name": self.doc.name
                }).insert()
コード例 #26
0
ファイル: test_salary_slip.py プロジェクト: ddimmich/erpnext
 def test_salary_slip_with_holidays_excluded(self):
     ss = frappe.bean(copy=test_records[0])
     ss.insert()
     self.assertEquals(ss.doc.total_days_in_month, 30)
     self.assertEquals(ss.doc.payment_days, 29)
     self.assertEquals(ss.doclist[1].e_modified_amount, 14500)
     self.assertEquals(ss.doclist[2].e_modified_amount, 500)
     self.assertEquals(ss.doclist[3].d_modified_amount, 100)
     self.assertEquals(ss.doclist[4].d_modified_amount, 48.33)
     self.assertEquals(ss.doc.gross_pay, 15000)
     self.assertEquals(ss.doc.net_pay, 14851.67)
コード例 #27
0
ファイル: utils.py プロジェクト: ddimmich/erpnext
def add_ac(args=None):
	if not args:
		args = frappe.local.form_dict
		args.pop("cmd")
		
	ac = frappe.bean(args)
	ac.doc.doctype = "Account"
	ac.doc.old_parent = ""
	ac.doc.freeze_account = "No"
	ac.insert()
	return ac.doc.name
コード例 #28
0
def make_module_and_roles(doclist, perm_doctype="DocPerm"):
    try:
        if not frappe.db.exists("Module Def", doclist[0].module):
            m = frappe.bean({
                "doctype": "Module Def",
                "module_name": doclist[0].module
            })
            m.insert()

        default_roles = ["Administrator", "Guest", "All"]
        roles = [p.role for p in doclist.get({"doctype": perm_doctype})
                 ] + default_roles

        for role in list(set(roles)):
            if not frappe.db.exists("Role", role):
                r = frappe.bean({"doctype": "Role", "role_name": role})
                r.doc.role_name = role
                r.insert()
    except frappe.DoesNotExistError, e:
        pass
コード例 #29
0
    def test_make_purchase_receipt(self):
        from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt

        po = frappe.bean(copy=test_records[0]).insert()

        self.assertRaises(frappe.ValidationError, make_purchase_receipt,
                          po.doc.name)

        po = frappe.bean("Purchase Order", po.doc.name)
        po.submit()

        pr = make_purchase_receipt(po.doc.name)
        pr[0]["supplier_warehouse"] = "_Test Warehouse 1 - _TC"
        pr[0]["posting_date"] = "2013-05-12"
        self.assertEquals(pr[0]["doctype"], "Purchase Receipt")
        self.assertEquals(len(pr), len(test_records[0]))

        pr[0].naming_series = "_T-Purchase Receipt-"
        pr_bean = frappe.bean(pr)
        pr_bean.insert()
コード例 #30
0
def cancel(doctype=None, name=None):
    """cancel a doclist"""
    try:
        wrapper = frappe.bean(doctype, name)
        wrapper.cancel()
        send_updated_docs(wrapper)

    except Exception, e:
        frappe.errprint(frappe.utils.get_traceback())
        frappe.msgprint(frappe._("Did not cancel"))
        raise
コード例 #31
0
    def test_make_purchase_invoice(self):
        self._clear_stock_account_balance()
        set_perpetual_inventory(0)
        from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice

        pr = frappe.bean(copy=test_records[0]).insert()

        self.assertRaises(frappe.ValidationError, make_purchase_invoice,
                          pr.doc.name)

        pr = frappe.bean("Purchase Receipt", pr.doc.name)
        pr.submit()
        pi = make_purchase_invoice(pr.doc.name)

        self.assertEquals(pi[0]["doctype"], "Purchase Invoice")
        self.assertEquals(len(pi), len(pr.doclist))

        # modify rate
        pi[1].rate = 200
        self.assertRaises(frappe.ValidationError, frappe.bean(pi).submit)
コード例 #32
0
ファイル: test_stock_entry.py プロジェクト: ddimmich/erpnext
    def test_serial_duplicate(self):
        self._clear_stock_account_balance()
        self.test_serial_by_series()

        se = frappe.bean(copy=test_records[0])
        se.doclist[1].item_code = "_Test Serialized Item With Series"
        se.doclist[1].qty = 1
        se.doclist[1].serial_no = "ABCD00001"
        se.doclist[1].transfer_qty = 1
        se.insert()
        self.assertRaises(SerialNoDuplicateError, se.submit)
コード例 #33
0
ファイル: test_stock_entry.py プロジェクト: ddimmich/erpnext
    def test_freeze_stocks(self):
        self._clear_stock_account_balance()
        frappe.db.set_value('Stock Settings', None, 'stock_auth_role', '')

        # test freeze_stocks_upto
        date_newer_than_test_records = add_days(
            getdate(test_records[0][0]['posting_date']), 5)
        frappe.db.set_value("Stock Settings", None, "stock_frozen_upto",
                            date_newer_than_test_records)
        se = frappe.bean(copy=test_records[0]).insert()
        self.assertRaises(StockFreezeError, se.submit)
        frappe.db.set_value("Stock Settings", None, "stock_frozen_upto", '')

        # test freeze_stocks_upto_days
        frappe.db.set_value("Stock Settings", None, "stock_frozen_upto_days",
                            7)
        se = frappe.bean(copy=test_records[0]).insert()
        self.assertRaises(StockFreezeError, se.submit)
        frappe.db.set_value("Stock Settings", None, "stock_frozen_upto_days",
                            0)
コード例 #34
0
def create_fiscal_year_and_company(args):
    curr_fiscal_year = get_fy_details(args.get('fy_start_date'),
                                      args.get('fy_end_date'))
    frappe.bean([{
        "doctype": "Fiscal Year",
        'year': curr_fiscal_year,
        'year_start_date': args.get('fy_start_date'),
        'year_end_date': args.get('fy_end_date'),
    }]).insert()

    # Company
    frappe.bean([{
        "doctype": "Company",
        'domain': args.get("industry"),
        'company_name': args.get('company_name'),
        'abbr': args.get('company_abbr'),
        'default_currency': args.get('currency'),
    }]).insert()

    args["curr_fiscal_year"] = curr_fiscal_year
コード例 #35
0
def get_context(context):
	bean = frappe.bean("Support Ticket", frappe.form_dict.name)
	if bean.doc.raised_by == frappe.session.user:
		ticket_context = {
			"title": bean.doc.name,
			"bean": bean
		}
	else:
		ticket_context = {"title": "Not Allowed"}
		
	return ticket_context
コード例 #36
0
    def test_over_billing_against_dn(self):
        self.clear_stock_account_balance()
        _insert_purchase_receipt()

        from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_invoice
        _insert_purchase_receipt()
        dn = frappe.bean(copy=test_records[0]).insert()

        self.assertRaises(frappe.ValidationError, make_sales_invoice,
                          dn.doc.name)

        dn = frappe.bean("Delivery Note", dn.doc.name)
        dn.submit()
        si = make_sales_invoice(dn.doc.name)

        self.assertEquals(len(si), len(dn.doclist))

        # modify amount
        si[1].rate = 200
        self.assertRaises(frappe.ValidationError, frappe.bean(si).insert)
コード例 #37
0
    def update_web_page(self, route_details, fpath, priority,
                        parent_website_route):
        if str(cint(os.path.getmtime(fpath)))!= route_details.static_file_timestamp \
         or (cint(route_details.idx) != cint(priority) and (priority is not None)):

            page = frappe.bean("Web Page", route_details.docname)
            page.doc.fields.update(
                get_static_content(fpath, route_details.docname))
            page.doc.idx = priority
            page.save()

            route_bean = frappe.bean("Website Route", route_details.name)
            route_bean.doc.static_file_timestamp = cint(
                os.path.getmtime(fpath))
            route_bean.save()

            print route_bean.doc.name + " updated"
            self.updated += 1

        self.synced.append(route_details.name)
コード例 #38
0
ファイル: page.py プロジェクト: fogueri/frappe
def get(name):
    """
	   Return the :term:`doclist` of the `Page` specified by `name`
	"""
    page = frappe.bean("Page", name)
    if has_permission(page.doclist):
        page.run_method("get_from_files")
        return page.doclist
    else:
        frappe.response['403'] = 1
        raise frappe.PermissionError, 'No read permission for Page %s' % \
         (page.doclist[0].title or name,)
コード例 #39
0
ファイル: test_stock_entry.py プロジェクト: ddimmich/erpnext
 def test_serial_no_not_exists(self):
     self._clear_stock_account_balance()
     se = frappe.bean(copy=test_records[0])
     se.doc.purpose = "Material Issue"
     se.doclist[1].item_code = "_Test Serialized Item"
     se.doclist[1].qty = 2
     se.doclist[1].s_warehouse = "_Test Warehouse 1 - _TC"
     se.doclist[1].t_warehouse = None
     se.doclist[1].serial_no = "ABCD\nEFGH"
     se.doclist[1].transfer_qty = 2
     se.insert()
     self.assertRaises(SerialNoNotExistsError, se.submit)
コード例 #40
0
def create_customers(args):
    for i in xrange(1, 6):
        customer = args.get("customer_" + str(i))
        if customer:
            frappe.bean({
                "doctype": "Customer",
                "customer_name": customer,
                "customer_type": "Company",
                "customer_group": "Commercial",
                "territory": args.get("country"),
                "company": args.get("company_name")
            }).insert()

            if args.get("customer_contact_" + str(i)):
                contact = args.get("customer_contact_" + str(i)).split(" ")
                frappe.bean({
                    "doctype": "Contact",
                    "customer": customer,
                    "first_name": contact[0],
                    "last_name": len(contact) > 1 and contact[1] or ""
                }).insert()
コード例 #41
0
def create_taxes(args):
    for i in xrange(1, 6):
        if args.get("tax_" + str(i)):
            frappe.bean({
                "doctype":
                "Account",
                "company":
                args.get("company_name"),
                "parent_account":
                "Duties and Taxes - " + args.get("company_abbr"),
                "account_name":
                args.get("tax_" + str(i)),
                "group_or_ledger":
                "Ledger",
                "is_pl_account":
                "No",
                "account_type":
                "Tax",
                "tax_rate":
                args.get("tax_rate_" + str(i))
            }).insert()
コード例 #42
0
ファイル: workflow.py プロジェクト: fogueri/frappe
	def create_custom_field_for_workflow_state(self):
		frappe.clear_cache(doctype=self.doc.document_type)
		doctypeobj = frappe.get_doctype(self.doc.document_type)
		if not len(doctypeobj.get({"doctype":"DocField", 
			"fieldname":self.doc.workflow_state_field})):
			
			# create custom field
			frappe.bean([{
				"doctype":"Custom Field",
				"dt": self.doc.document_type,
				"__islocal": 1,
				"fieldname": self.doc.workflow_state_field,
				"label": self.doc.workflow_state_field.replace("_", " ").title(),
				"hidden": 1,
				"fieldtype": "Link",
				"options": "Workflow State",
				#"insert_after": doctypeobj.get({"doctype":"DocField"})[-1].fieldname
			}]).save()
			
			frappe.msgprint("Created Custom Field '%s' in '%s'" % (self.doc.workflow_state_field,
				self.doc.document_type))
コード例 #43
0
def add_reply(ticket, message):
	if not message:
		raise frappe.throw(_("Please write something"))
	
	bean = frappe.bean("Support Ticket", ticket)
	if bean.doc.raised_by != frappe.session.user:
		raise frappe.throw(_("You are not allowed to reply to this ticket."), frappe.PermissionError)
	
	from frappe.core.doctype.communication.communication import _make
	_make(content=message, sender=bean.doc.raised_by, subject = bean.doc.subject,
		doctype="Support Ticket", name=bean.doc.name,
		date=today())
コード例 #44
0
	def create_groups(group_name, group_title, parent_website_sitemap):
		group = frappe.bean({
			"doctype":"Website Group", 
			"group_name": group_name, 
			"group_title": group_title,
			"parent_website_sitemap": parent_website_sitemap, 
			"public_read":1, 
			"public_write":1,
			"group_type":"Forum"
		}).insert()
		
		return frappe.conn.get_value("Website Sitemap", {"ref_doctype":"Website Group", 
			"docname": group.doc.name})
コード例 #45
0
def save_address(fields, address_fieldname=None):
	party = get_lead_or_customer()
	fields = json.loads(fields)
	
	if fields.get("name"):
		bean = frappe.bean("Address", fields.get("name"))
	else:
		bean = frappe.bean({"doctype": "Address", "__islocal": 1})
	
	bean.doc.fields.update(fields)
	
	party_fieldname = party.doctype.lower()
	bean.doc.fields.update({
		party_fieldname: party.name,
		(party_fieldname + "_name"): party.fields[party_fieldname + "_name"]
	})
	bean.ignore_permissions = True
	bean.save()
	
	if address_fieldname:
		update_cart_address(address_fieldname, bean.doc.name)
	
	return bean.doc.name
コード例 #46
0
def place_order():
	quotation = _get_cart_quotation()
	controller = quotation.make_controller()
	for fieldname in ["customer_address", "shipping_address_name"]:
		if not quotation.doc.fields.get(fieldname):
			throw(_("Please select a") + " " + _(controller.meta.get_label(fieldname)))
	
	quotation.ignore_permissions = True
	quotation.submit()
	
	from erpnext.selling.doctype.quotation.quotation import _make_sales_order
	sales_order = frappe.bean(_make_sales_order(quotation.doc.name, ignore_permissions=True))
	sales_order.ignore_permissions = True
	sales_order.insert()
	sales_order.submit()
	frappe._response.set_cookie("cart_count", "")
	
	return sales_order.doc.name
コード例 #47
0
def get_quotation(user=None):
	if not user:
		user = frappe.session.user
	if user == "Guest":
		raise frappe.PermissionError
		
	is_shopping_cart_enabled()
	party = get_party(user)
	values = {
		"order_type": "Shopping Cart",
		party.doc.doctype.lower(): party.doc.name,
		"docstatus": 0,
	}

	try:
		quotation = frappe.bean("Quotation", values)
	except frappe.DoesNotExistError:
		quotation = frappe.new_bean("Quotation")
		quotation.doc.fields.update(values)
		quotation.insert(ignore_permissions=True)
		
	return quotation
コード例 #48
0
def get_lead_or_customer():
	customer = frappe.db.get_value("Contact", {"email_id": frappe.session.user}, "customer")
	if customer:
		return frappe.doc("Customer", customer)
	
	lead = frappe.db.get_value("Lead", {"email_id": frappe.session.user})
	if lead:
		return frappe.doc("Lead", lead)
	else:
		lead_bean = frappe.bean({
			"doctype": "Lead",
			"email_id": frappe.session.user,
			"lead_name": get_fullname(frappe.session.user),
			"territory": guess_territory(),
			"status": "Open" # TODO: set something better???
		})
		
		if frappe.session.user != "Guest":
			lead_bean.ignore_permissions = True
			lead_bean.insert()
			
		return lead_bean.doc
コード例 #49
0
	def disable_shopping_cart(self):
		settings = frappe.bean("Shopping Cart Settings", "Shopping Cart Settings")
		settings.doc.enabled = 0
		settings.save()
コード例 #50
0
	def get_cart_settings(self):
		return frappe.bean({"doctype": "Shopping Cart Settings",
			"company": "_Test Company"})
コード例 #51
0
def validate_cart_settings(bean, method):
	frappe.bean("Shopping Cart Settings", "Shopping Cart Settings").run_method("validate")
コード例 #52
0
	def test_place_order(self):
		quotation = self.test_update_cart()
		sales_order_name = place_order()
		sales_order = frappe.bean("Sales Order", sales_order_name)
		self.assertEquals(sales_order.doclist.getone({"item_code": "_Test Item"}).prevdoc_docname, quotation.doc.name)