def selco_stock_entry_validate(doc, method):
    from frappe.contacts.doctype.address.address import get_address_display
    if doc.selco_type_of_stock_entry == "Outward DC":
        local_warehouse = frappe.db.get_value("Branch",
                                              doc.selco_being_dispatched_to,
                                              "selco_warehouse")
        doc.selco_recipient_address_link = frappe.db.get_value(
            "Warehouse", local_warehouse, "address")
        doc.selco_recipient_address = "<b>" + doc.selco_being_dispatched_to.upper(
        ) + " BRANCH</b><br>"
        doc.selco_recipient_address += "SELCO SOLAR LIGHT PVT. LTD.<br>"
        doc.selco_recipient_address += str(
            get_address_display(doc.selco_recipient_address_link))
    elif doc.selco_type_of_stock_entry == "GRN":
        sender = frappe.db.get_value("Stock Entry", doc.selco_suppliers_ref,
                                     "selco_branch")
        frappe.msgprint(doc.selco_suppliers_ref)
        sender_warehouse = frappe.db.get_value("Branch", sender,
                                               "selco_warehouse")
        doc.sender_address_link = frappe.db.get_value("Warehouse",
                                                      sender_warehouse,
                                                      "address")
        doc.sender_address = "<b>" + str(sender) + " SELCO BRANCH</b><br>"
        doc.sender_address += "SELCO SOLAR LIGHT PVT. LTD.<br>"
        doc.sender_address += str(get_address_display(doc.sender_address_link))
Esempio n. 2
0
def set_address_details(out, party, party_type, doctype=None, company=None):
    billing_address_field = "customer_address" if party_type == "Lead" \
     else party_type.lower() + "_address"
    out[billing_address_field] = get_default_address(party_type, party.name)
    out.update(
        get_fetch_values(doctype, billing_address_field,
                         out[billing_address_field]))

    # address display
    out.address_display = get_address_display(out[billing_address_field])

    # shipping address
    if party_type in ["Customer", "Lead"]:
        out.shipping_address_name = get_default_address(
            party_type, party.name, 'is_shipping_address')
        out.shipping_address = get_address_display(
            out["shipping_address_name"])
        out.update(
            get_fetch_values(doctype, 'shipping_address_name',
                             out.shipping_address_name))

    if doctype and doctype in ['Sales Invoice']:
        out.update(get_company_address(company))
        if out.company_address:
            out.update(
                get_fetch_values(doctype, 'company_address',
                                 out.company_address))
Esempio n. 3
0
def set_address_details(out, party, party_type, doctype=None, company=None, party_address=None, shipping_address=None):
	billing_address_field = "customer_address" if party_type == "Lead" \
		else party_type.lower() + "_address"
	out[billing_address_field] = party_address or get_default_address(party_type, party.name)
	if doctype:
		out.update(get_fetch_values(doctype, billing_address_field, out[billing_address_field]))
	# address display
	out.address_display = get_address_display(out[billing_address_field])
	# shipping address
	if party_type in ["Customer", "Lead"]:
		out.shipping_address_name = shipping_address or get_party_shipping_address(party_type, party.name)
		out.shipping_address = get_address_display(out["shipping_address_name"])
		if doctype:
			out.update(get_fetch_values(doctype, 'shipping_address_name', out.shipping_address_name))

	if doctype and doctype in ['Delivery Note', 'Sales Invoice']:
		out.update(get_company_address(company))
		if out.company_address:
			out.update(get_fetch_values(doctype, 'company_address', out.company_address))
		get_regional_address_details(out, doctype, company)

	elif doctype and doctype == "Purchase Invoice":
		out.update(get_company_address(company))
		if out.company_address:
			out["shipping_address"] = shipping_address or out["company_address"]
			out.shipping_address_display = get_address_display(out["shipping_address"])
			out.update(get_fetch_values(doctype, 'shipping_address', out.shipping_address))
		get_regional_address_details(out, doctype, company)
Esempio n. 4
0
def set_address_details(party_details, party, party_type, doctype=None, company=None, party_address=None, company_address=None, shipping_address=None):
	billing_address_field = "customer_address" if party_type == "Lead" \
		else party_type.lower() + "_address"
	party_details[billing_address_field] = party_address or get_default_address(party_type, party.name)
	if doctype:
		party_details.update(get_fetch_values(doctype, billing_address_field, party_details[billing_address_field]))
	# address display
	party_details.address_display = get_address_display(party_details[billing_address_field])
	# shipping address
	if party_type in ["Customer", "Lead"]:
		party_details.shipping_address_name = shipping_address or get_party_shipping_address(party_type, party.name)
		party_details.shipping_address = get_address_display(party_details["shipping_address_name"])
		if doctype:
			party_details.update(get_fetch_values(doctype, 'shipping_address_name', party_details.shipping_address_name))

	if company_address:
		party_details.update({'company_address': company_address})
	else:
		party_details.update(get_company_address(company))

	if doctype and doctype in ['Delivery Note', 'Sales Invoice', 'Sales Order']:
		if party_details.company_address:
			party_details.update(get_fetch_values(doctype, 'company_address', party_details.company_address))
		get_regional_address_details(party_details, doctype, company)

	elif doctype and doctype in ["Purchase Invoice", "Purchase Order", "Purchase Receipt"]:
		if party_details.company_address:
			party_details["shipping_address"] = shipping_address or party_details["company_address"]
			party_details.shipping_address_display = get_address_display(party_details["shipping_address"])
			party_details.update(get_fetch_values(doctype, 'shipping_address', party_details.shipping_address))
		get_regional_address_details(party_details, doctype, company)

	return party_details.get(billing_address_field), party_details.shipping_address_name
Esempio n. 5
0
def set_transporter_address(doc, method=None):
    country = frappe.get_cached_value('Company', doc.company, 'country')
    if country != 'India':
        return

    if doc.get("transporter_address"):
        # once supplier is set, address can be selected from multiple transporter addresses
        doc.transporter_address_display = get_address_display(
            doc.get("transporter_address"))
        return

    transporter_address = frappe.db.get_value(
        "Dynamic Link", {
            'link_doctype': 'Supplier',
            'link_name': doc.get('transporter'),
            'parenttype': 'Address'
        }, "parent")

    if not transporter_address:
        doc.transporter_address = ""
        doc.transporter_address_display = ""
        return

    doc.transporter_address = transporter_address
    doc.transporter_address_display = get_address_display(transporter_address)
Esempio n. 6
0
def validate_gst_state(doc, method):
	parser = HTMLParser.HTMLParser()
	ship_state = frappe.db.get_value("Address", doc.shipping_address_name, "gst_state")
	if not ship_state:
		frappe.throw("""Please update Correct GST State in Shipping Address and then Try Again""")

	bill_state = frappe.db.get_value("Address", doc.customer_address, "gst_state")
	if not bill_state:
		frappe.throw("""Please update Correct GST State in Billing Address and then Try Again""")

	from frappe.contacts.doctype.address.address import get_address_display
	da = get_address_display(doc.customer_address)
	if da != parser.unescape(doc.address_display):
		frappe.throw("""Please use 'Update Address' under Address to update the correct Billing Address in the Document""")

	da = get_address_display(doc.shipping_address_name)
	if da != parser.unescape(doc.shipping_address):
		frappe.throw("""Please use 'Update Address' under Address to update the correct Shipping Address in the Document""")


	if doc.taxes_and_charges == 'Out of State GST' and ship_state == 'Madhya Pradesh':
		if doc.special_invoice and doc.special_invoice == 'SEZ Supply':
			return
		frappe.throw("""Please Check Correct Shipping Address/Taxes""")

	if doc.taxes_and_charges == 'In State GST' and ship_state != 'Madhya Pradesh':
		frappe.throw("""Please Check Correct Shipping Address/Taxes""")
Esempio n. 7
0
def update_address_display(doctype,
                           doc_name,
                           fields,
                           addresses,
                           as_list=False):
    if as_list:
        if isinstance(fields, six.string_types):
            fields = json.loads(fields)
        if isinstance(addresses, six.string_types):
            addresses = json.loads(addresses)
        count = 0
        response = []
        for field in fields:
            address = addresses[count]
            address_html = get_address_display(address)
            old_display = frappe.db.sql(
                """SELECT `{field}` FROM `tab{doctype}` WHERE `name` = '{doc_name}'"""
                .format(field=field, doctype=doctype, doc_name=doc_name),
                as_dict=True)
            count += 1
            if len(old_display) >= 1:
                if old_display[0][field] != address_html:
                    frappe.db.sql(
                        """UPDATE `tab{doctype}` SET `{field}` = '{address_html}' WHERE `name` = '{doc_name}'"""
                        .format(field=field,
                                doctype=doctype,
                                doc_name=doc_name,
                                address_html=address_html),
                        as_list=True)
                    frappe.db.commit()
                    response.append('updated')
                else:
                    response.append('passed')
            else:
                response.append('no address')
        return response
    else:
        field = fields
        address = addresses
        address_html = get_address_display(address)
        old_display = frappe.db.sql(
            """SELECT `{field}` FROM `tab{doctype}` WHERE `name` = '{doc_name}'"""
            .format(field=field, doctype=doctype, doc_name=doc_name),
            as_dict=True)
        if len(old_display) >= 1:
            if old_display[0][field] != address_html:
                frappe.db.sql(
                    """UPDATE `tab{doctype}` SET `{field}` = '{address_html}' WHERE `name` = '{doc_name}'"""
                    .format(field=field,
                            doctype=doctype,
                            doc_name=doc_name,
                            address_html=address_html),
                    as_list=True)
                frappe.db.commit()
                return 'updated'
            else:
                return 'passed'
        else:
            return 'no address'
Esempio n. 8
0
def set_address_details(out, party, party_type):
	billing_address_field = "customer_address" if party_type == "Lead" \
		else party_type.lower() + "_address"
	out[billing_address_field] = get_default_address(party_type, party.name)

	# address display
	out.address_display = get_address_display(out[billing_address_field])

	# shipping address
	if party_type in ["Customer", "Lead"]:
		out.shipping_address_name = get_default_address(party_type, party.name, 'is_shipping_address')
		out.shipping_address = get_address_display(out["shipping_address_name"])
Esempio n. 9
0
def get_rates_for_doc(doc, address=None, address_obj=None):
    doc = json.loads(doc)
    from frappe.contacts.doctype.address.address import get_address_display
    if not address_obj:
        to_address = frappe.get_doc(
            "Address", address or doc.get("shipping_address_name"))
        frappe.local.response["address"] = get_address_display(
            to_address.as_dict())
    else:
        to_address = json.loads(address_obj)
        frappe.local.response["address"] = get_address_display(to_address)

    from_address = frappe.get_doc("Address", {"is_your_company_address": 1})
    return get_rates(from_address, to_address, doc=doc)
Esempio n. 10
0
def get_primary_address(suppname):
    add = get_address_display(get_default_address('Supplier', suppname))

    if add is not None:
        return add.replace("<br>", '&nbsp;')
    else:
        return add
Esempio n. 11
0
def get_address_docs(doctype=None,
                     txt=None,
                     filters=None,
                     limit_start=0,
                     limit_page_length=20,
                     party=None):
    if not party:
        party = get_party()

    if not party:
        return []

    address_names = frappe.db.get_all('Dynamic Link',
                                      fields=('parent'),
                                      filters=dict(parenttype='Address',
                                                   link_doctype=party.doctype,
                                                   link_name=party.name))

    out = []

    for a in address_names:
        address = frappe.get_doc('Address', a.parent)
        address.display = get_address_display(address.as_dict())
        out.append(address)

    return out
Esempio n. 12
0
def update_cart_address(address_type, address_name):
    quotation = _get_cart_quotation()
    address_doc = frappe.get_doc("Address", address_name).as_dict()
    address_display = get_address_display(address_doc)

    if address_type.lower() == "billing":
        quotation.customer_address = address_name
        quotation.address_display = address_display
        quotation.shipping_address_name = quotation.shipping_address_name or address_name
        address_doc = next((doc for doc in get_billing_addresses()
                            if doc["name"] == address_name), None)
    elif address_type.lower() == "shipping":
        quotation.shipping_address_name = address_name
        quotation.shipping_address = address_display
        quotation.customer_address = quotation.customer_address or address_name
        address_doc = next((doc for doc in get_shipping_addresses()
                            if doc["name"] == address_name), None)
    apply_cart_settings(quotation=quotation)

    quotation.flags.ignore_permissions = True
    quotation.save()

    context = get_cart_quotation(quotation)
    context["address"] = address_doc

    return {
        "taxes":
        frappe.render_template("templates/includes/order/order_taxes.html",
                               context),
        "address":
        frappe.render_template("templates/includes/cart/address_card.html",
                               context),
    }
Esempio n. 13
0
def set_address_details(out, party, party_type):
	billing_address_field = "customer_address" if party_type == "Lead" \
		else party_type.lower() + "_address"
	out[billing_address_field] = get_default_address(party_type, party.name)
	
	# address display
	out.address_display = get_address_display(out[billing_address_field])
Esempio n. 14
0
def get_address_docs(doctype=None,
                     txt=None,
                     filters=None,
                     limit_start=0,
                     limit_page_length=20,
                     party=None):
    if not party:
        party = get_party()

    if not party:
        return []

    address_names = frappe.get_all(
        "Address",
        filters=[
            ["Address", "disabled", "=", 0],
            ["Dynamic Link", "link_doctype", "=", party.doctype],
            ["Dynamic Link", "link_name", "=", party.name],
            ["Dynamic Link", "parenttype", "=", "Address"],
        ])

    out = []

    for a in address_names:
        address = frappe.get_doc('Address', a.name)
        address.display = get_address_display(address.as_dict())
        out.append(address)

    return out
Esempio n. 15
0
def update_cart_address(address_fieldname, address_name):
	quotation = _get_cart_quotation()
	address_display = get_address_display(frappe.get_doc("Address", address_name).as_dict())

	if address_fieldname == "shipping_address_name":
		quotation.shipping_address_name = address_name
		quotation.shipping_address = address_display

		if not quotation.customer_address:
			address_fieldname == "customer_address"

	if address_fieldname == "customer_address":
		quotation.customer_address = address_name
		quotation.address_display = address_display


	apply_cart_settings(quotation=quotation)

	quotation.flags.ignore_permissions = True
	quotation.save()

	context = get_cart_quotation(quotation)
	return {
		"taxes": frappe.render_template("templates/includes/order/order_taxes.html",
			context),
		}
Esempio n. 16
0
    def test_template_works(self):
        if not frappe.db.exists('Address Template', 'India'):
            frappe.get_doc({
                "doctype": "Address Template",
                "country": 'India',
                "is_default": 1
            }).insert()

        if not frappe.db.exists('Address', '_Test Address-Office'):
            frappe.get_doc({
                "address_line1": "_Test Address Line 1",
                "address_title": "_Test Address",
                "address_type": "Office",
                "city": "_Test City",
                "state": "Test State",
                "country": "India",
                "doctype": "Address",
                "is_primary_address": 1,
                "phone": "+91 0000000000"
            }).insert()

        address = frappe.get_list("Address")[0].name
        display = get_address_display(
            frappe.get_doc("Address", address).as_dict())
        self.assertTrue(display)
Esempio n. 17
0
def load_address_and_contact(doc, key=None):
	"""Loads address list and contact list in `__onload`"""
	from frappe.contacts.doctype.address.address import get_address_display

	filters = [
		["Dynamic Link", "link_doctype", "=", doc.doctype],
		["Dynamic Link", "link_name", "=", doc.name],
		["Dynamic Link", "parenttype", "=", "Address"],
	]
	address_list = frappe.get_all("Address", filters=filters, fields=["*"])

	address_list = [a.update({"display": get_address_display(a)})
		for a in address_list]

	address_list = sorted(address_list,
		key = functools.cmp_to_key(lambda a, b:
			(int(a.is_primary_address - b.is_primary_address)) or
			(1 if a.modified - b.modified else 0)), reverse=True)

	doc.set_onload('addr_list', address_list)

	contact_list = []
	filters = [
		["Dynamic Link", "link_doctype", "=", doc.doctype],
		["Dynamic Link", "link_name", "=", doc.name],
		["Dynamic Link", "parenttype", "=", "Contact"],
	]
	contact_list = frappe.get_all("Contact", filters=filters, fields=["*"])

	contact_list = sorted(contact_list,
		key = functools.cmp_to_key(lambda a, b:
			(int(a.is_primary_contact - b.is_primary_contact)) or
			(1 if a.modified - b.modified else 0)), reverse=True)

	doc.set_onload('contact_list', contact_list)
Esempio n. 18
0
def update_cart_address(address_fieldname, address_name):
    quotation = _get_cart_quotation()
    address_display = get_address_display(
        frappe.get_doc("Address", address_name).as_dict())

    if address_fieldname == "shipping_address_name":
        quotation.shipping_address_name = address_name
        quotation.shipping_address = address_display

        if not quotation.customer_address:
            address_fieldname == "customer_address"

    if address_fieldname == "customer_address":
        quotation.customer_address = address_name
        quotation.address_display = address_display

    apply_cart_settings(quotation=quotation)

    quotation.flags.ignore_permissions = True
    quotation.save()

    context = get_cart_quotation(quotation)
    return {
        "taxes":
        frappe.render_template("templates/includes/order/order_taxes.html",
                               context),
    }
Esempio n. 19
0
def load_address_and_contact(doc, key=None):
	"""Loads address list and contact list in `__onload`"""
	from frappe.contacts.doctype.address.address import get_address_display

	filters = [
		["Dynamic Link", "link_doctype", "=", doc.doctype],
		["Dynamic Link", "link_name", "=", doc.name],
		["Dynamic Link", "parenttype", "=", "Address"],
	]
	address_list = frappe.get_all("Address", filters=filters, fields=["*"])

	address_list = [a.update({"display": get_address_display(a)})
		for a in address_list]

	address_list = sorted(address_list,
		lambda a, b:
			(int(a.is_primary_address - b.is_primary_address)) or
			(1 if a.modified - b.modified else 0), reverse=True)

	doc.set_onload('addr_list', address_list)

	contact_list = []
	filters = [
		["Dynamic Link", "link_doctype", "=", doc.doctype],
		["Dynamic Link", "link_name", "=", doc.name],
		["Dynamic Link", "parenttype", "=", "Contact"],
	]
	contact_list = frappe.get_all("Contact", filters=filters, fields=["*"])

	contact_list = sorted(contact_list,
		lambda a, b:
			(int(a.is_primary_contact - b.is_primary_contact)) or
			(1 if a.modified - b.modified else 0), reverse=True)

	doc.set_onload('contact_list', contact_list)
def set_primary_address(cust_id, add_id):
    add_doc = frappe.get_doc("Address", add_id)
    frappe.db.set_value("Customer", cust_id, "customer_primary_address",
                        add_id)
    from frappe.contacts.doctype.address.address import get_address_display
    frappe.db.set_value("Customer", cust_id, "primary_address",
                        get_address_display(add_id))
    print("Customer " + cust_id + " Updated with Primary Address of " + add_id)
Esempio n. 21
0
    def get_customer_address(self, customer):
        if frappe.get_value("Address",
                            customer.customer_primary_address) is not None:
            from frappe.contacts.doctype.address.address import get_address_display

            return get_address_display(customer.customer_primary_address)
        else:
            return ''
Esempio n. 22
0
	def set_supplier_address(self):
		address_dict = {
			"supplier_address": "address_display",
			"shipping_address": "shipping_address_display",
		}

		for address_field, address_display_field in address_dict.items():
			if self.get(address_field):
				self.set(address_display_field, get_address_display(self.get(address_field)))
Esempio n. 23
0
	def set_supplier_address(self):
		address_dict = {
			'supplier_address': 'address_display',
			'shipping_address': 'shipping_address_display'
		}

		for address_field, address_display_field in address_dict.items():
			if self.get(address_field):
				self.set(address_display_field, get_address_display(self.get(address_field)))
Esempio n. 24
0
	def create_primary_address(self):
		from frappe.contacts.doctype.address.address import get_address_display

		if self.flags.is_new_doc and self.get("address_line1"):
			address = make_address(self)
			address_display = get_address_display(address.name)

			self.db_set("customer_primary_address", address.name)
			self.db_set("primary_address", address_display)
Esempio n. 25
0
	def set_supplier_address(self):
		address_dict = {
			'supplier_address': 'address_display',
			'shipping_address': 'shipping_address_display'
		}

		for address_field, address_display_field in address_dict.items():
			if self.get(address_field):
				self.set(address_display_field, get_address_display(self.get(address_field)))
Esempio n. 26
0
	def set_customer_address(self):
		address_dict = {
			'customer_address': 'address_display',
			'shipping_address_name': 'shipping_address',
			'company_address': 'company_address_display'
		}

		for address_field, address_display_field in address_dict.items():
			if self.get(address_field):
				self.set(address_display_field, get_address_display(self.get(address_field)))
Esempio n. 27
0
def make_transfer_dn(company, customer, source_name, project=None):
    try:
        current_dn = frappe.get_doc("Delivery Note", source_name)

        new_dn = frappe.copy_doc(current_dn, ignore_no_copy=True)

        new_dn.company = company
        new_dn.company_trn = frappe.db.get_value("Company", company, "tax_id")

        new_dn.customer = customer
        new_dn.project = project

        from erpnext.selling.doctype.customer.customer import get_customer_details
        from frappe.contacts.doctype.address.address import get_default_address, get_address_display

        customer_details = get_customer_details(customer)

        if customer_details:
            new_dn.tax_id = customer_details.tax_id
            new_dn.customer_name_in_arabic = customer_details.customer_name_in_arabic

        new_dn.shipping_address_name = get_default_address(
            'Customer', customer)
        new_dn.shipping_address = get_address_display(
            new_dn.shipping_address_name)
        new_dn.customer_address = get_default_address('Customer', customer)
        new_dn.address_display = get_address_display(new_dn.customer_address)

        if not new_dn.company == current_dn.company:
            from erpnext.stock.utils import get_default_warehouse

            default_warehouse = get_default_warehouse(
                company=new_dn.company).get("source_warehouse")

            for d in new_dn.get("items"):
                d.warehouse = default_warehouse

        new_dn.insert(ignore_permissions=True)

        return new_dn.name

    except:
        return False
Esempio n. 28
0
def set_address_details(out, party, party_type, doctype=None, company=None):
	billing_address_field = "customer_address" if party_type == "Lead" \
		else party_type.lower() + "_address"
	out[billing_address_field] = get_default_address(party_type, party.name)
	out.update(get_fetch_values(doctype, billing_address_field, out[billing_address_field]))

	# address display
	out.address_display = get_address_display(out[billing_address_field])

	# shipping address
	if party_type in ["Customer", "Lead"]:
		out.shipping_address_name = get_default_address(party_type, party.name, 'is_shipping_address')
		out.shipping_address = get_address_display(out["shipping_address_name"])
		out.update(get_fetch_values(doctype, 'shipping_address_name', out.shipping_address_name))

	if doctype and doctype in ['Sales Invoice']:
		out.update(get_company_address(company))
		if out.company_address:
			out.update(get_fetch_values(doctype, 'company_address', out.company_address))
Esempio n. 29
0
    def update_address(self):
        # exit if one of the two fields are not present
        if not self.party_type or not self.party: return

        self.party_address = get_default_address(self.party_type, self.party)

        if self.party_address:
            self.display_address = get_address_display(self.party_address)
        else:
            self.display_address = None
Esempio n. 30
0
	def set_customer_address(self):
		address_dict = {
			'customer_address': 'address_display',
			'shipping_address_name': 'shipping_address',
			'company_address': 'company_address_display'
		}

		for address_field, address_display_field in address_dict.items():
			if self.get(address_field):
				self.set(address_display_field, get_address_display(self.get(address_field)))
Esempio n. 31
0
    def set_customer_address(self):
        address_dict = {
            "customer_address": "address_display",
            "shipping_address_name": "shipping_address",
            "company_address": "company_address_display",
        }

        for address_field, address_display_field in address_dict.items():
            if self.get(address_field):
                self.set(address_display_field,
                         get_address_display(self.get(address_field)))
Esempio n. 32
0
    def create_primary_address(self):
        from frappe.contacts.doctype.address.address import get_address_display

        from erpnext.selling.doctype.customer.customer import make_address

        if self.flags.is_new_doc and self.get('address_line1'):
            address = make_address(self)
            address_display = get_address_display(address.name)

            self.db_set("supplier_primary_address", address.name)
            self.db_set("primary_address", address_display)
Esempio n. 33
0
    def on_update(self):
        """
		After Address is updated, update the related 'Primary Address' on Customer.
		"""
        address_display = get_address_display(self.as_dict())
        filters = {"customer_primary_address": self.name}
        customers = frappe.db.get_all("Customer",
                                      filters=filters,
                                      as_list=True)
        for customer_name in customers:
            frappe.db.set_value("Customer", customer_name[0],
                                "primary_address", address_display)
Esempio n. 34
0
 def onload(self):
     filters = [
         ['Dynamic Link', 'link_doctype', '=', 'Customer'],
         ['Dynamic Link', 'link_name', '=', self.customer],
         ['Dynamic Link', 'parenttype', '=', 'Address'],
     ]
     address_list = sorted([
         a.update({'display': get_address_display(a)})
         for a in frappe.get_all('Address', filters=filters, fields=["*"])
     ],
                           key=cmp_to_key(lambda a, b: (int(
                               a.is_primary_address - b.is_primary_address
                           )) or (1 if a.modified - b.modified else 0)),
                           reverse=True)
     self.set_onload('addr_list', address_list)
Esempio n. 35
0
def selco_add_new_address(selco_branch, address_type, address_line1,
                          address_line2, city, selco_district, country,
                          customer, address_title):
    from frappe.contacts.doctype.address.address import get_address_display
    local_address = frappe.new_doc("Address")
    local_address.selco_branch = selco_branch
    local_address.address_type = address_type
    local_address.address_line1 = address_line1
    local_address_line2 = address_line2
    local_address.city = city
    local_address.selco_district = selco_district
    local_address.country = country
    local_address.customer = customer

    local_address.address_title = address_title
    local_address.insert()
    return local_address.name, str(get_address_display(local_address.name))
Esempio n. 36
0
def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20,
	party=None):
	if not party:
		party = get_party()

	if not party:
		return []

	address_names = frappe.db.get_all('Dynamic Link', fields=('parent'),
		filters=dict(parenttype='Address', link_doctype=party.doctype, link_name=party.name))

	out = []

	for a in address_names:
		address = frappe.get_doc('Address', a.parent)
		address.display = get_address_display(address.as_dict())
		out.append(address)

	return out