Example #1
0
def get_tax_template_based_on_category(master_doctype, company, party_details):
	if not party_details.get('tax_category'):
		return

	default_tax = frappe.db.get_value(master_doctype, {'company': company, 'tax_category': party_details.get('tax_category')},
		'name')

	if default_tax:
		party_details["taxes_and_charges"] = default_tax
		party_details.taxes = get_taxes_and_charges(master_doctype, default_tax)
Example #2
0
	def set_missing_values(source, target):
		target.run_method("set_missing_values")

		if target.doctype == 'Purchase Receipt':
			master_doctype = 'Purchase Taxes and Charges Template'
		else:
			master_doctype = 'Sales Taxes and Charges Template'

		if not target.get('taxes') and target.get('taxes_and_charges'):
			for tax in get_taxes_and_charges(master_doctype, target.get('taxes_and_charges')):
				target.append('taxes', tax)
Example #3
0
def get_regional_address_details(party_details, doctype, company):
	if isinstance(party_details, string_types):
		party_details = json.loads(party_details)
		party_details = frappe._dict(party_details)

	update_party_details(party_details, doctype)

	party_details.place_of_supply = get_place_of_supply(party_details, doctype)

	if is_internal_transfer(party_details, doctype):
		party_details.taxes_and_charges = ''
		party_details.taxes = ''
		return party_details

	if doctype in ("Sales Invoice", "Delivery Note", "Sales Order"):
		master_doctype = "Sales Taxes and Charges Template"

		get_tax_template_for_sez(party_details, master_doctype, company, 'Customer')
		get_tax_template_based_on_category(master_doctype, company, party_details)

		if party_details.get('taxes_and_charges'):
			return party_details

		if not party_details.company_gstin:
			return party_details

	elif doctype in ("Purchase Invoice", "Purchase Order", "Purchase Receipt"):
		master_doctype = "Purchase Taxes and Charges Template"
		get_tax_template_for_sez(party_details, master_doctype, company, 'Supplier')
		get_tax_template_based_on_category(master_doctype, company, party_details)

		if party_details.get('taxes_and_charges'):
			return party_details

		if not party_details.supplier_gstin:
			return party_details

	if not party_details.place_of_supply: return party_details

	if not party_details.company_gstin: return party_details

	if ((doctype in ("Sales Invoice", "Delivery Note", "Sales Order") and party_details.company_gstin
		and party_details.company_gstin[:2] != party_details.place_of_supply[:2]) or (doctype in ("Purchase Invoice",
		"Purchase Order", "Purchase Receipt") and party_details.supplier_gstin and party_details.supplier_gstin[:2] != party_details.place_of_supply[:2])):
		default_tax = get_tax_template(master_doctype, company, 1, party_details.company_gstin[:2])
	else:
		default_tax = get_tax_template(master_doctype, company, 0, party_details.company_gstin[:2])

	if not default_tax:
		return party_details
	party_details["taxes_and_charges"] = default_tax
	party_details.taxes = get_taxes_and_charges(master_doctype, default_tax)

	return party_details
Example #4
0
def get_tax_template_for_sez(party_details, master_doctype, company, party_type):

	gst_details = frappe.db.get_value(party_type, {'name': party_details.get(frappe.scrub(party_type))},
			['gst_category', 'export_type'], as_dict=1)

	if gst_details:
		if gst_details.gst_category == 'SEZ' and gst_details.export_type == 'With Payment of Tax':
			default_tax = frappe.db.get_value(master_doctype, {"company": company, "is_inter_state":1, "disabled":0,
				"gst_state": number_state_mapping[party_details.company_gstin[:2]]})

			party_details["taxes_and_charges"] = default_tax
			party_details.taxes = get_taxes_and_charges(master_doctype, default_tax)
Example #5
0
    def set_missing_lead_customer_details(self, for_validate=False):
        customer, lead = None, None
        if getattr(self, "customer", None):
            customer = self.customer
        elif self.doctype == "Opportunity" and self.party_name:
            if self.opportunity_from == "Customer":
                customer = self.party_name
            else:
                lead = self.party_name
        elif self.doctype == "Quotation" and self.party_name:
            if self.quotation_to == "Customer":
                customer = self.party_name
            else:
                lead = self.party_name

        if customer:
            from erpbee.accounts.party import _get_party_details
            fetch_payment_terms_template = False
            if (self.get("__islocal") or self.company != frappe.db.get_value(
                    self.doctype, self.name, 'company')):
                fetch_payment_terms_template = True

            party_details = _get_party_details(
                customer,
                ignore_permissions=self.flags.ignore_permissions,
                doctype=self.doctype,
                company=self.company,
                posting_date=self.get('posting_date'),
                fetch_payment_terms_template=fetch_payment_terms_template,
                party_address=self.customer_address,
                shipping_address=self.shipping_address_name)
            if not self.meta.get_field("sales_team"):
                party_details.pop("sales_team")
            self.update_if_missing(party_details)

        elif lead:
            from erpbee.crm.doctype.lead.lead import get_lead_details
            self.update_if_missing(
                get_lead_details(lead,
                                 posting_date=self.get('transaction_date')
                                 or self.get('posting_date'),
                                 company=self.company))

        if self.get('taxes_and_charges'
                    ) and not self.get('taxes') and not for_validate:
            taxes = get_taxes_and_charges('Sales Taxes and Charges Template',
                                          self.taxes_and_charges)
            for tax in taxes:
                self.append('taxes', tax)