コード例 #1
0
ファイル: customer.py プロジェクト: libermatic/leiteng
def get(token):
    decoded_token = get_decoded_token(token)
    customer_id = frappe.db.exists(
        "Customer", {"le_firebase_uid": decoded_token["uid"]}
    )
    if not customer_id:
        return None
    doc = frappe.get_doc("Customer", customer_id)
    orders = frappe.db.exists("Sales Order", {"customer": customer_id})
    return merge(
        pick(["name", "customer_name"], doc.as_dict()),
        {"can_register_messaging": bool(orders)},
    )
コード例 #2
0
ファイル: customer.py プロジェクト: libermatic/leiteng
def _make_sales_order(customer_id, **kwargs):
    args = pick(["transaction_date", "delivery_date", "customer_address"], kwargs)

    doc = frappe.get_doc(
        merge(
            {
                "doctype": "Sales Order",
                "customer": customer_id,
                "order_type": "Shopping Cart",
                "company": frappe.defaults.get_user_default("company"),
                "currency": frappe.defaults.get_user_default("currency"),
                "selling_price_list": frappe.db.get_single_value(
                    "Selling Settings", "selling_price_list"
                ),
            },
            args,
            {"le_delivery_time": kwargs.get("delivery_time")},
        )
    )

    warehouse = frappe.db.get_single_value("Stock Settings", "default_warehouse")
    for item_args in json.loads(kwargs.get("items", "[]")):
        doc.append(
            "items",
            merge(
                pick(["item_code", "qty", "rate"], item_args),
                {
                    "warehouse": warehouse,
                    "uom": frappe.db.get_value(
                        "Item", item_args.get("item_code"), "stock_uom"
                    ),
                },
            ),
        )

    doc.set_missing_values()
    return doc
コード例 #3
0
ファイル: customer.py プロジェクト: libermatic/leiteng
def create(token, **kwargs):
    decoded_token = get_decoded_token(token)
    session_user = frappe.session.user
    settings = frappe.get_single("Leiteng Website Settings")
    if not settings.user:
        frappe.throw(frappe._("Site setup not complete"))
    frappe.set_user(settings.user)

    uid = decoded_token["uid"]
    customer_id = frappe.db.exists("Customer", {"le_firebase_uid": uid})
    if customer_id:
        frappe.throw(frappe._("Customer already created"))

    args = keyfilter(
        lambda x: x
        in [
            "customer_name",
            "mobile_no",
            "email",
            "address_line1",
            "address_line2",
            "city",
            "state",
            "country",
            "pincode",
        ],
        kwargs,
    )

    doc = frappe.get_doc(
        merge(
            {
                "doctype": "Customer",
                "le_firebase_uid": uid,
                "customer_type": "Individual",
                "customer_group": frappe.db.get_single_value(
                    "Selling Settings", "customer_group"
                ),
                "territory": frappe.db.get_single_value(
                    "Selling Settings", "territory"
                ),
            },
            args,
        )
    ).insert()
    auth.set_custom_user_claims(uid, {"customer": True}, app=app)

    frappe.set_user(session_user)
    return pick(["name", "customer_name"], doc.as_dict())
コード例 #4
0
ファイル: customer.py プロジェクト: libermatic/leiteng
def _get_formatted_sales_order(doc):
    return merge(
        pick(
            [
                "name",
                "transaction_date",
                "delivery_date",
                "total",
                "grand_total",
                "rounding_adjustment",
                "rounded_total",
            ],
            doc.as_dict(),
        ),
        {
            "delivery_time": doc.le_delivery_time,
            "items": [
                pick(
                    [
                        "item_code",
                        "item_name",
                        "item_group",
                        "qty",
                        "rate",
                        "amount",
                        "net_amount",
                    ],
                    x.as_dict(),
                )
                for x in doc.items
            ],
            "taxes": [
                pick(["description", "tax_amount"], x.as_dict()) for x in doc.taxes
            ],
        },
    )
コード例 #5
0
ファイル: customer.py プロジェクト: libermatic/leiteng
def create_address(token, **kwargs):
    decoded_token = get_decoded_token(token)
    customer_id = frappe.db.exists(
        "Customer", {"le_firebase_uid": decoded_token["uid"]}
    )
    if not customer_id:
        frappe.throw(frappe._("Customer does not exist on backend"))

    session_user = frappe.session.user
    settings = frappe.get_single("Leiteng Website Settings")
    if not settings.user:
        frappe.throw(frappe._("Site setup not complete"))
    frappe.set_user(settings.user)

    fields = ["address_line1", "address_line2", "city", "state", "country", "pincode"]

    args = pick(fields, kwargs,)
    doc = frappe.get_doc(
        merge({"doctype": "Address", "address_type": "Billing"}, args,)
    )
    doc.append("links", {"link_doctype": "Customer", "link_name": customer_id})
    doc.insert()
    frappe.set_user(session_user)
    return pick(["name"] + fields, doc.as_dict())
コード例 #6
0
ファイル: item.py プロジェクト: libermatic/leiteng
def get_product_info(route):
    item_code = frappe.db.exists("Item", {
        "route": route.replace("__", "/"),
        "show_in_website": 1
    })
    if not item_code:
        frappe.throw(frappe._("Item does not exist at this route"))

    item_for_website = get_product_info_for_website(item_code)
    return {
        "price":
        pick(
            ["currency", "price_list_rate"],
            item_for_website.get("product_info", {}).get("price", {}),
        )
    }
コード例 #7
0
ファイル: website.py プロジェクト: libermatic/leiteng
def _get_slideshow_settings(settings):
    if not settings.slideshow:
        return None

    def get_route(item):
        ref_doctype, ref_name = item.get("le_ref_doctype"), item.get(
            "le_ref_docname")
        if ref_doctype and ref_name:
            route, show_in__website = frappe.get_cached_value(
                ref_doctype, ref_name, ["route", "show_in_website"])
            if route and show_in__website:
                if ref_doctype == "Item Group":
                    return transform_route({"route": route})
                if ref_doctype == "Item":
                    item_group = frappe.get_cached_value(
                        "Item", ref_name, "item_group")
                    group_route, show_in__website = frappe.get_cached_value(
                        "Item Group",
                        item_group,
                        ["route", "show_in_website"],
                    )
                    if group_route and show_in__website:
                        return "/".join([
                            transform_route({"route": group_route}),
                            transform_route({"route": route}),
                        ])
        return None

    return [
        merge(pick(["image", "heading", "description"], x),
              {"route": get_route(x)}) for x in frappe.get_all(
                  "Website Slideshow Item",
                  filters={"parent": settings.slideshow},
                  fields=[
                      "image",
                      "heading",
                      "description",
                      "le_ref_doctype",
                      "le_ref_docname",
                  ],
              )
    ]
コード例 #8
0
ファイル: website.py プロジェクト: libermatic/leiteng
def get_settings():
    from frappe.website.doctype.website_settings.website_settings import (
        get_website_settings, )

    leiteng_settings = frappe.get_single("Leiteng Website Settings")
    allcat_groups = [x.item_group for x in leiteng_settings.allcat_groups]
    slideshow = _get_slideshow_settings(leiteng_settings)

    settings = get_website_settings()

    return merge(
        pick(["copyright", "footer_address"], settings),
        {
            "root_groups": _get_root_groups(),
            "allcat_groups": allcat_groups,
            "slideshow": slideshow,
            "privacy": bool(leiteng_settings.privacy),
            "terms": bool(leiteng_settings.terms),
            "show_about_us": bool(leiteng_settings.show_about_us),
            "hide_build_info": bool(leiteng_settings.hide_build_info),
        },
    )
コード例 #9
0
ファイル: website.py プロジェクト: libermatic/leiteng
def get_about_us():
    about = frappe.get_cached_doc("About Us Settings")
    return pick(["company_introduction"], about.as_dict())