def create_quotation(self): quotation = frappe.new_doc("Quotation") values = { "doctype": "Quotation", "quotation_to": "Customer", "order_type": "Shopping Cart", "customer": get_party(frappe.session.user).name, "docstatus": 0, "contact_email": frappe.session.user, "selling_price_list": "_Test Price List Rest of the World", "currency": "USD", "taxes_and_charges" : "_Test Tax 1", "items": [{ "item_code": "_Test Item", "qty": 1 }], "taxes": frappe.get_doc("Sales Taxes and Charges Template", "_Test Tax 1").taxes, "company": "_Test Company" } quotation.update(values) quotation.insert(ignore_permissions=True) return quotation
def create_quotation(self): quotation = frappe.new_doc("Quotation") values = { "doctype": "Quotation", "quotation_to": "Customer", "order_type": "Shopping Cart", "customer": get_party(frappe.session.user).name, "docstatus": 0, "contact_email": frappe.session.user, "selling_price_list": "_Test Price List Rest of the World", "currency": "USD", "taxes_and_charges" : "_Test Tax 1", "items": [{ "item_code": "_Test Item", "qty": 1 }], "taxes": frappe.get_doc("Sales Taxes and Charges Template", "_Test Tax 1").taxes, "company": "_Test Company" } quotation.update(values) quotation.insert(ignore_permissions=True) return quotation
def clear_existing_quotations(self): quotations = frappe.get_all("Quotation", filters={ "party_name": get_party().name, "order_type": "Shopping Cart", "docstatus": 0 }, order_by="modified desc", pluck="name") for quotation in quotations: frappe.delete_doc("Quotation", quotation, ignore_permissions=True, force=True)
def initialise_order_for(): """Initializes the "order for" feature which allows a backend user to use the shopping cart in behalf of another user""" cart_settings = frappe.get_single("Shopping Cart Settings") if not (cart_settings.enabled and cart_settings.allow_order_for): return # Initialize frappe.session.data.order_for frappe.session.data["order_for"] = _dict(frappe.session.data.get("order_for", {})) order_for = frappe.session.data.order_for if frappe.session.user in ("Guest", "Administrator"): return # Guard against customers set to order for which are removed after initializing if order_for.get("customer_name") and not frappe.db.exists("Customer", order_for.get("customer_name")): order_for.pop("customer_name", None) order_for.pop("customer_primary_contact_name", None) if not order_for.get("customer_name") and order_for.get("enabled"): order_for.pop("enabled", None) # Set default customer if not order_for.get("customer_name") and frappe.session.user not in ("Guest", "Administrator"): contact = frappe.get_doc("Contact", {"email_id": frappe.session.user}) customer_links = [] for link in contact.links: if link.link_doctype == "Customer" and frappe.db.exists(link.link_doctype, link.link_name): customer_links.append(link) if len(customer_links) == 1: order_for["customer_name"] = customer_links[0].link_name order_for["customer_primary_contact_name"] = contact.name # Keep customer info up to date on every session start customer = get_party() if customer and customer.doctype == "Customer": # no reason to set customer_name again as get_party expects # customer_name to exists to set user from the "order for" feature # otherwise vanilla path is executed and the true customer is returned. if order_for.get("customer_name"): order_for["customer_name"] = customer.name order_for["customer_group"] = customer.customer_group
def export_query(): """export from query reports""" data = frappe._dict(frappe.local.form_dict) del data["cmd"] if "csrf_token" in data: del data["csrf_token"] if isinstance(data.get("filters"), string_types): filters = json.loads(data["filters"]) if isinstance(data.get("report_name"), string_types): report_name = data["report_name"] frappe.permissions.can_export(frappe.get_cached_value( 'Report', report_name, 'ref_doctype'), raise_exception=True) if isinstance(data.get("file_format_type"), string_types): file_format_type = data["file_format_type"] if isinstance(data.get("visible_idx"), string_types): visible_idx = json.loads(data.get("visible_idx")) else: visible_idx = None # add filter this customer party = get_party() filters["customer"] = party.name or "" if file_format_type == "Excel": data = run(report_name, filters) data = frappe._dict(data) columns = get_columns_dict(data.columns) from frappe.utils.xlsxutils import make_xlsx xlsx_data = build_xlsx_data(columns, data) xlsx_file = make_xlsx(xlsx_data, "Query Report") frappe.response['filename'] = report_name + '.xlsx' frappe.response['filecontent'] = xlsx_file.getvalue() frappe.response['type'] = 'binary'