コード例 #1
0
def update_customer_address(bcommerce_customer, customer, setting):

    from bcommerce.utils import validate_resource
    for address in bcommerce_customer.addresses():

        if validate_resource(address):
            addr_type, addr_title = get_address_type_and_title(
                address, customer)
            addr_line1, addr_line2 = get_address_lines(address)
            addr_name = "{0}-{1}".format(addr_title, addr_type)
            update_flag = frappe.db.get_value("Address", {"name": addr_name},
                                              as_dict=True)
            if update_flag:
                doc = frappe.get_doc("Address", update_flag.get("name"))
                doc.update({
                    "phone": address.phone,
                    "city": address.city,
                    "state": address.state,
                    "country": address.country,
                    "email_id": bcommerce_customer.email,
                    "pincode": address.zip,
                    "address_line1": addr_line1,
                    "address_line2": addr_line2
                })
                doc.save(ignore_permissions=True)

            else:
                print "save customer address"
                save_customer_address(bcommerce_customer, customer, address,
                                      setting, addr_type, addr_title,
                                      addr_line1, addr_line2)
コード例 #2
0
def sync_bulk_brands():

    try:
        min_id = get_last_sync_id("bcommerce_brand_id", "Brand")
        max_id = min_id + 250  #250 is limit of resource list
        brands = get_connection().Brands.all(min_id=min_id,
                                             max_id=max_id,
                                             limit=250)
        if brands:
            for brand in brands:
                if validate_resource(brand):
                    if not frappe.db.get_value(
                            "Brand", {"bcommerce_brand_id": brand.id}):
                        doc = frappe.get_doc({
                            "doctype": "Brand",
                            "description": brand.meta_description,
                            "brand": brand.name,
                            "bcommerce_brand_id": brand.id
                        })
                        doc.flags.ignore_mandatory = 1
                        doc.save(ignore_permissions=True)

    except Exception as e:
        print "Exception  raised while syncing brand from bigcommerce"
        print frappe.get_traceback()
コード例 #3
0
def make_states(country):

    states = []
    for state in country.states():
        if validate_resource(state):
            name = frappe.db.get_value("Bcommerce State",
                                       {"state": state.state})
            doc = None
            if name:
                doc = frappe.get_doc("Bcommerce State", name.get("name"))
                doc.update({
                    "abbr": state.state_abbreviation,
                    "state": state.state,
                    "country": country.country
                })
            else:

                doc = frappe.get_doc({
                    "doctype": "Bcommerce State",
                    "abbr": state.state_abbreviation,
                    "state": state.state,
                    "country": country.country
                })
            if doc:
                doc.save(ignore_permissions=True)
                frappe.db.commit()
コード例 #4
0
def save_web_hook(webhook):

    if validate_resource(webhook):

        if not frappe.db.get_value("Bcommerce Webhook",
                                   filters={"webhook_id": webhook.id},
                                   as_dict=True):
            frappe.get_doc({
                "doctype": "Bcommerce Webhook",
                "webhook_id": webhook.id,
                "webhook_scope": webhook.scope,
                "webhook_destination": webhook.destination,
                "is_active": webhook.is_active,
            }).save(ignore_permissions=True)

            frappe.db.commit()
コード例 #5
0
def sync_currencies(setting, id=None):

    setting = frappe.get_doc("Bcommerce Setting", "Bcommerce Setting")

    if id and not frappe.db.get_value("Currency",
                                      {"bcommerce_currency_id": id}):

        currency = get_resource("Currencies", id)
        if not currency:
            return
        update_currency(currency, setting)

    else:
        currencies = get_connection().Currencies.all()
        for currency in currencies:
            if validate_resource(currency):
                update_currency(currency, setting)
コード例 #6
0
def sync_bulk_customer_group():

    try:
        customer_groups = get_connection().CustomerGroups.all(limit=250)
        if customer_groups:
            for cg in customer_groups:
                if validate_resource(cg):
                    doc = frappe.get_doc({
                        "doctype": "Customer Group",
                        "is_group": 0,
                        "parent_customer_group": setting.customer_group,
                        "customer_group_name": cg.name,
                        "bcommerce_customer_group_id": cg.id
                    })
                    doc.save(ignore_permissions=True)

    except Exception as e:
        print frappe.get_traceback()
コード例 #7
0
def delete_webhooks(id=None):

    if id:
        webhook = get_resource("Webhooks", id)
        flag = frappe.db.get_value("Bcommerce Webhook", {"webhook_id": id},
                                   as_dict=True)
        if flag:
            frappe.get_doc("Bcommerce Webhook", flag.get("name")).delete()
        webhook.delete()

    else:
        for webhook in get_connection().Webhooks.all(limit=250):
            if not validate_resource(webhook):
                continue
            flag = frappe.db.get("Bcommerce Webhook",
                                 {"webhook_id": webhook.id},
                                 as_dict=True)
            if flag:
                frappe.get_doc("Bcommerce Webhook", flag.get("name")).delete()
            webhook.delete()
コード例 #8
0
def save_customer(customer, setting, commit=False):

    if not validate_resource(customer):
        return
    full_name = get_customer_full_name(customer)
    doc = frappe.get_doc({
        "doctype": "Customer",
        "name": customer.id,
        "__islocal": 1,
        "customer_name": full_name,
        "bcommerce_customer_id": customer.id,
        "territory": setting.get("customer_territory"),
        "customer_type": setting.get("customer_type"),
        "customer_group": setting.get("customer_group")
    })
    doc.flags.ignore_mandatory = 1
    doc.save(ignore_permissions=True)
    update_customer_address(customer, doc, setting)
    if commit:
        frappe.db.commit()
    return full_name
コード例 #9
0
def sync_payments(setting):

    payment_methods = get_connection().PaymentMethods.all()

    for pay_method in payment_methods:
        if validate_resource(pay_method, "name"):
            flag = frappe.db.get_value("Mode of Payment",
                                       {"mode_of_payment": pay_method.name})
            doc = None
            if flag:
                doc = frappe.get_doc("Mode of Payment",
                                     {"mode_of_payment": pay_method.name})
                doc.update({"mode_of_payment": pay_method.name})
            else:
                doc = frappe.get_doc({
                    "doctype": "Mode of Payment",
                    "mode_of_payment": pay_method.name
                })

            if doc:
                doc.flags.ignore_mandatory = 1
                doc.save(ignore_permissions=True)
        frappe.db.commit()