Exemplo n.º 1
0
    def test_party_details_tax_category(self):
        from erpnext.accounts.party import get_party_details

        frappe.delete_doc_if_exists("Address",
                                    "_Test Address With Tax Category-Billing")

        # Tax Category without Address
        details = get_party_details("_Test Supplier With Tax Category",
                                    party_type="Supplier")
        self.assertEqual(details.tax_category, "_Test Tax Category 1")

        address = frappe.get_doc(
            dict(doctype='Address',
                 address_title='_Test Address With Tax Category',
                 tax_category='_Test Tax Category 2',
                 address_type='Billing',
                 address_line1='Station Road',
                 city='_Test City',
                 country='India',
                 links=[
                     dict(link_doctype='Supplier',
                          link_name='_Test Supplier With Tax Category')
                 ])).insert()

        # Tax Category with Address
        details = get_party_details("_Test Supplier With Tax Category",
                                    party_type="Supplier")
        self.assertEqual(details.tax_category, "_Test Tax Category 2")

        # Rollback
        address.delete()
Exemplo n.º 2
0
    def test_party_details_tax_category(self):
        from erpnext.accounts.party import get_party_details

        frappe.delete_doc_if_exists("Address",
                                    "_Test Address With Tax Category-Billing")
        frappe.delete_doc_if_exists(
            "Address", "_Test Address With Tax Category-Shipping")

        # Tax Category without Address
        details = get_party_details("_Test Customer With Tax Category")
        self.assertEqual(details.tax_category, "_Test Tax Category 1")

        billing_address = frappe.get_doc(
            dict(doctype='Address',
                 address_title='_Test Address With Tax Category',
                 tax_category='_Test Tax Category 2',
                 address_type='Billing',
                 address_line1='Station Road',
                 city='_Test City',
                 country='India',
                 phone='+91 0000000000',
                 links=[
                     dict(link_doctype='Customer',
                          link_name='_Test Customer With Tax Category')
                 ])).insert()
        shipping_address = frappe.get_doc(
            dict(doctype='Address',
                 address_title='_Test Address With Tax Category',
                 tax_category='_Test Tax Category 3',
                 address_type='Shipping',
                 address_line1='Station Road',
                 city='_Test City',
                 country='India',
                 phone='+91 0000000000',
                 links=[
                     dict(link_doctype='Customer',
                          link_name='_Test Customer With Tax Category')
                 ])).insert()

        settings = frappe.get_single("Accounts Settings")
        rollback_setting = settings.determine_address_tax_category_from

        # Tax Category from Billing Address
        settings.determine_address_tax_category_from = "Billing Address"
        settings.save()
        details = get_party_details("_Test Customer With Tax Category")
        self.assertEqual(details.tax_category, "_Test Tax Category 2")

        # Tax Category from Shipping Address
        settings.determine_address_tax_category_from = "Shipping Address"
        settings.save()
        details = get_party_details("_Test Customer With Tax Category")
        self.assertEqual(details.tax_category, "_Test Tax Category 3")

        # Rollback
        settings.determine_address_tax_category_from = rollback_setting
        settings.save()
        billing_address.delete()
        shipping_address.delete()
Exemplo n.º 3
0
def create_sales_invoice(doc):
    if not frappe.has_permission('Sales Invoice', "create"):
        frappe.throw("Unsufficient Permission To Create Sales Invoice")
    try:
        customer_details = get_party_details(party=doc.ic_customer,
                                             party_type="Customer")
        frappe.errprint(customer_details)
        sinv_doc = frappe.get_doc(
            dict(doctype="Sales Invoice",
                 company=doc.seller_company,
                 posting_date=doc.date,
                 set_posting_time=1,
                 due_date=add_days(doc.date, 2),
                 selling_price_list=customer_details.get('selling_price_list'),
                 fiscal_year=get_fiscal_year(doc.date,
                                             company=doc.seller_company)[0],
                 naming_series="SINV .######",
                 customer=doc.ic_customer,
                 update_stock=doc.update_stock,
                 letter_head=frappe.db.get_value("Company",
                                                 str(doc.seller_company),
                                                 "default_letter_head"),
                 items=get_item_object(doc.items, doc.from_warehouse),
                 ic_invoice=1)).insert()
        doc.ic_sales_invoice_no = sinv_doc.name
        doc.ic_sales_inv_status = sinv_doc.status
        # frappe.db.set_value(doc.doctype,doc.name,"ic_sales_invoice_no",sinv_doc.name)
        # frappe.db.set_value(doc.doctype,doc.name,"ic_sales_invoice_status",sinv_doc.status)
    except Exception:
        frappe.log_error(frappe.get_traceback())
        frappe.throw(frappe.get_traceback())
Exemplo n.º 4
0
def create_purchase_invoice(doc):
    if not frappe.has_permission('Purchase Invoice', "create"):
        frappe.throw("Unsufficient Permission To Create Purchase Invoice")
    try:
        supplier_details = get_party_details(party=doc.ic_supplier,
                                             party_type="Supplier")
        pinv_doc = frappe.get_doc(
            dict(doctype="Purchase Invoice",
                 company=doc.buyer_company,
                 posting_date=doc.date,
                 buying_price_list=supplier_details.get("buying_price_list"),
                 set_posting_time=1,
                 due_date=add_days(doc.date, 2),
                 supplier=doc.ic_supplier,
                 update_stock=doc.update_stock,
                 items=get_item_object(doc.items, doc.to_warehouse),
                 ic_invoice=1,
                 sales_invoice_no=doc.ic_sales_invoice_no)).insert()
        doc.ic_pur_invoice_no = pinv_doc.name
        doc.ic_pur_inv_status = pinv_doc.status
        if pinv_doc.sales_invoice_no:
            frappe.db.set_value("Sales Invoice", pinv_doc.sales_invoice_no,
                                "purchase_invoice_no", pinv_doc.name)
        # frappe.db.set_value(doc.doctype,doc.name,"ic_purchase_invoice_no",pinv_doc.name)
        # frappe.db.set_value(doc.doctype,doc.name,"ic_purchase_inv_status",pinv_doc.status)
    except Exception:
        frappe.log_error(frappe.get_traceback())
        sales_invoice_no = frappe.db.get_value(doc.doctype, doc.name,
                                               "ic_sales_invoice_no")
        delete_or_cancel_sales_invocie("Sales Invoice", sales_invoice_no, doc)
        frappe.throw(frappe.get_traceback())
Exemplo n.º 5
0
def get_item_rate(customer, item_code, out):
    if out.get((customer, item_code)):
        return out.get((customer, item_code))
    default_price_list = frappe.db.sql("""
        select cu.name,
        COALESCE(cu.default_price_list,cug.default_price_list,sing.value) price_list
        from tabCustomer cu
        inner join `tabCustomer Group` cug on cug.name = cu.customer_group
        cross join tabSingles sing on sing.field = 'selling_price_list'
        and sing.doctype = 'Selling Settings'
        where cu.name=%s""", (customer, ),
                                       as_dict=True)

    customer_details = get_party_details(party=customer, party_type="Customer")
    customer_details.update({
        "company":
        get_default_company(),
        "price_list":
        [d["price_list"] for d in default_price_list if d.name == customer][0],
        "transaction_date":
        getdate()
    })
    rate = get_price_list_rate_for(customer_details, item_code) or 0.0
    out.setdefault((customer, item_code), rate)
    return rate
Exemplo n.º 6
0
    def test_party_details(self):
        from erpnext.accounts.party import get_party_details

        to_check = {
            "selling_price_list": None,
            "customer_group": "_Test Customer Group",
            "contact_designation": None,
            "customer_address": "_Test Address for Customer-Office",
            "contact_department": None,
            "contact_email": "*****@*****.**",
            "contact_mobile": None,
            "sales_team": [],
            "contact_display": "_Test Contact for _Test Customer",
            "contact_person":
            "_Test Contact for _Test Customer-_Test Customer",
            "territory": "_Test Territory",
            "contact_phone": "+91 0000000000",
            "customer_name": "_Test Customer",
        }

        create_test_contact_and_address()

        frappe.db.set_value("Contact",
                            "_Test Contact for _Test Customer-_Test Customer",
                            "is_primary_contact", 1)

        details = get_party_details("_Test Customer")

        for key, value in to_check.items():
            val = details.get(key)
            if not val and not isinstance(val, list):
                val = None

            self.assertEqual(value, val)
Exemplo n.º 7
0
	def test_party_details(self):
		from erpnext.accounts.party import get_party_details

		to_check = {
			'selling_price_list': None,
			'customer_group': '_Test Customer Group',
			'contact_designation': None,
			'customer_address': '_Test Address-Office',
			'contact_department': None,
			'contact_email': '*****@*****.**',
			'contact_mobile': None,
			'sales_team': [],
			'contact_display': '_Test Contact For _Test Customer',
			'contact_person': '_Test Contact For _Test Customer-_Test Customer',
			'territory': u'_Test Territory',
			'contact_phone': '+91 0000000000',
			'customer_name': '_Test Customer'
		}

		make_test_records("Address")
		make_test_records("Contact")
		frappe.db.set_value("Contact", "_Test Contact For _Test Customer-_Test Customer", 
			"is_primary_contact", 1)
		
		details = get_party_details("_Test Customer")

		for key, value in to_check.iteritems():
			self.assertEquals(value, details.get(key))
Exemplo n.º 8
0
    def test_party_details(self):
        from erpnext.accounts.party import get_party_details

        to_check = {
            'selling_price_list': None,
            'customer_group': '_Test Customer Group',
            'contact_designation': None,
            'customer_address': '_Test Address for Customer-Office',
            'contact_department': None,
            'contact_email': '*****@*****.**',
            'contact_mobile': None,
            'sales_team': [],
            'contact_display': '_Test Contact for _Test Customer',
            'contact_person':
            '_Test Contact for _Test Customer-_Test Customer',
            'territory': u'_Test Territory',
            'contact_phone': '+91 0000000000',
            'customer_name': '_Test Customer'
        }

        create_test_contact_and_address()

        frappe.db.set_value("Contact",
                            "_Test Contact for _Test Customer-_Test Customer",
                            "is_primary_contact", 1)

        details = get_party_details("_Test Customer")

        for key, value in iteritems(to_check):
            val = details.get(key)
            if not val and not isinstance(val, list):
                val = None

            self.assertEqual(value, val)
Exemplo n.º 9
0
def get_customer_details(filters):
	customer_details = get_party_details(party=filters.get("customer"), party_type="Customer")
	customer_details.update(
		{"company": get_default_company(), "price_list": customer_details.get("selling_price_list")}
	)

	return customer_details
Exemplo n.º 10
0
 def postprocess(source, target_doc):
     target_doc.supplier = for_supplier
     args = get_party_details(for_supplier, party_type="Supplier", ignore_permissions=True)
     target_doc.currency = args.currency or get_party_account_currency("Supplier", for_supplier, source.company)
     target_doc.buying_price_list = args.buying_price_list or frappe.db.get_value(
         "Buying Settings", None, "buying_price_list"
     )
     set_missing_values(source, target_doc)
Exemplo n.º 11
0
 def postprocess(source, target_doc):
     target_doc.supplier = for_supplier
     args = get_party_details(for_supplier,
                              party_type="Supplier",
                              ignore_permissions=True)
     target_doc.currency = args.currency or get_party_account_currency(
         'Supplier', for_supplier, source.company)
     target_doc.buying_price_list = args.buying_price_list or frappe.db.get_value(
         'Buying Settings', None, 'buying_price_list')
     set_missing_values(source, target_doc)
Exemplo n.º 12
0
	def set_missing_values(self, for_validate=False):
		super(BuyingController, self).set_missing_values(for_validate)

		self.set_supplier_from_item_default()
		self.set_price_list_currency("Buying")

		# set contact and address details for supplier, if they are not mentioned
		if getattr(self, "supplier", None):
			self.update_if_missing(get_party_details(self.supplier, party_type="Supplier", ignore_permissions=self.flags.ignore_permissions, doctype=self.doctype, company=self.company))

		self.set_missing_item_details(for_validate)
Exemplo n.º 13
0
	def set_missing_values(self, for_validate=False):
		super(BuyingController, self).set_missing_values(for_validate)

		self.set_supplier_from_item_default()
		self.set_price_list_currency("Buying")

		# set contact and address details for supplier, if they are not mentioned
		if getattr(self, "supplier", None):
			self.update_if_missing(get_party_details(self.supplier, party_type="Supplier", ignore_permissions=self.flags.ignore_permissions, doctype=self.doctype, company=self.company))

		self.set_missing_item_details(for_validate)
Exemplo n.º 14
0
	def set_missing_values(self, for_validate=False):
		super(BuyingController, self).set_missing_values(for_validate)

		self.set_supplier_from_item_default()
		self.set_price_list_currency("Buying")

		# set contact and address details for supplier, if they are not mentioned
		if getattr(self, "supplier", None):
			self.update_if_missing(get_party_details(self.supplier, party_type="Supplier"))

		self.set_missing_item_details()
		if self.get("__islocal"):
			self.set_taxes("other_charges", "taxes_and_charges")
Exemplo n.º 15
0
def set_missing_values(source, target_doc, for_validate=False):
	if target_doc.doctype == "Purchase Order" and getdate(target_doc.schedule_date) <  getdate(nowdate()):
		target_doc.schedule_date = None
	super(BuyingController, target_doc).set_missing_values(for_validate)

	target_doc.set_supplier_from_item_default()
	target_doc.set_price_list_currency("Buying")

	# set contact and address details for supplier, if they are not mentioned
	if getattr(target_doc, "supplier", None):
		target_doc.update_if_missing(get_party_details(target_doc.supplier, party_type="Supplier", ignore_permissions=target_doc.flags.ignore_permissions,
		doctype=target_doc.doctype, company=target_doc.company, party_address=target_doc.supplier_address, shipping_address=target_doc.get('shipping_address')))
	target_doc.run_method("calculate_taxes_and_totals")
Exemplo n.º 16
0
def update_sales_invoice(self):
    #frappe.errprint(self)
    if self.ic_sales_invoice_no:
        customer_details = get_party_details(party=self.ic_customer,
                                             party_type="Customer")
        doc = frappe.get_doc("Sales Invoice", self.ic_sales_invoice_no)
        doc.posting_date = self.date
        doc.due_date = add_days(self.date, 2)
        doc.update_stock = self.update_stock
        doc.selling_price_list = customer_details.get("selling_price_list")
        doc.set("items", [])
        for item in self.items:
            new_item = doc.append("items")
            new_item.item_code = item.item
            new_item.qty = item.qty
            new_item.warehouse = self.from_warehouse
        doc.save()
Exemplo n.º 17
0
def update_purchase_invoice(self):
    #frappe.errprint(self)
    if self.ic_pur_invoice_no:
        supplier_details = get_party_details(party=self.ic_supplier,
                                             party_type="Supplier")
        doc = frappe.get_doc("Purchase Invoice", self.ic_pur_invoice_no)
        doc.posting_date = self.date
        doc.due_date = add_days(self.date, 2)
        doc.update_stock = self.update_stock
        doc.buying_price_list = supplier_details.get("buying_price_list")
        doc.set("items", [])
        for item in self.items:
            new_item = doc.append("items")
            new_item.item_code = item.item
            new_item.qty = item.qty
            new_item.warehouse = self.to_warehouse
        doc.save()
	def get_address(self):
		from erpnext.accounts.party import get_party_details
		customer_details = get_party_details(self.customer, party_type="Customer")
		supplier_details = get_party_details(self.supplier, party_type="Supplier")
		self.address_display = customer_details["address_display"]
		self.supplier_address_display = supplier_details["address_display"]
Exemplo n.º 19
0
	def get_address(self):
		from erpnext.accounts.party import get_party_details
		customer_details = get_party_details(self.customer, party_type="Customer")
		supplier_details = get_party_details(self.supplier, party_type="Supplier")
		self.address_display = customer_details["address_display"]
		self.supplier_address_display = supplier_details["address_display"]