def calculate_taxes_and_totals(self):
		from erpnext.controllers.taxes_and_totals import calculate_taxes_and_totals
		calculate_taxes_and_totals(self)

		if self.doctype in ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]:
			self.calculate_commission()
			self.calculate_contribution()
	def calculate_taxes_and_totals(self):
		from erpnext.controllers.taxes_and_totals import calculate_taxes_and_totals
		calculate_taxes_and_totals(self)

		if self.doctype in ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]:
			self.calculate_commission()
			self.calculate_contribution()
Beispiel #3
0
def set_tcs(doc, action):
	if action == "validate":
		settings = frappe.get_single("India TCS 206C_1H App Settings")
		if not cint(settings.enable_tcs):
			return
		if doc.docstatus != 0:
			return
		if len(doc.taxes) < 1:
			return
		if doc.taxes[-1].account_head == settings.tcs_account:
			return
		from erpnext.accounts.party import get_dashboard_info
		info = get_dashboard_info("Customer", doc.customer)
		customer_turnover = 0
		for company_info in info:
			if company_info['company'] == doc.company:
				customer_turnover = company_info['billing_this_year']
		if settings.tcs_trigger_amount >= customer_turnover + flt(doc.rounded_total):
			return
		tcs_row = frappe.new_doc('Sales Taxes and Charges')
		tcs_row.update({
						"charge_type": "On Previous Row Total",
						"row_id": str(len(doc.taxes)),
						"account_head": settings.tcs_account,
						"rate": settings.tcs_percentage,
						"description": settings.tcs_invoice_description,
						"parenttype": "Sales Invoice",
						"parentfield": "taxes",
						"parent": doc.name,
						"idx": len(doc.taxes) + 1
					})
		doc.taxes.append(tcs_row)
		from erpnext.controllers.taxes_and_totals import calculate_taxes_and_totals
		calculate_taxes_and_totals(doc)
def execute():
    frappe.reload_doc('selling', 'doctype', 'quotation')
    frappe.reload_doc('selling', 'doctype', 'quotation_item')
    frappe.reload_doc('selling', 'doctype', 'sales_order')
    frappe.reload_doc('selling', 'doctype', 'sales_order_item')
    frappe.reload_doc('stock', 'doctype', 'delivery_note')
    frappe.reload_doc('stock', 'doctype', 'delivery_note_item')
    frappe.reload_doc('accounts', 'doctype', 'sales_invoice')
    frappe.reload_doc('accounts', 'doctype', 'sales_invoice_item')
    frappe.reload_doc('buying', 'doctype', 'supplier_quotation')
    frappe.reload_doc('buying', 'doctype', 'supplier_quotation_item')
    frappe.reload_doc('buying', 'doctype', 'purchase_order')
    frappe.reload_doc('buying', 'doctype', 'purchase_order_item')
    frappe.reload_doc('stock', 'doctype', 'purchase_receipt')
    frappe.reload_doc('stock', 'doctype', 'purchase_receipt_item')
    frappe.reload_doc('accounts', 'doctype', 'purchase_invoice')
    frappe.reload_doc('accounts', 'doctype', 'purchase_invoice_item')
    frappe.reload_doc('accounts', 'doctype', 'sales_taxes_and_charges')
    frappe.reload_doc('accounts', 'doctype', 'purchase_taxes_and_charges')

    doctypes = [
        'Sales Order', 'Delivery Note', 'Sales Invoice', 'Purchase Order',
        'Purchase Receipt', 'Purchase Invoice', 'Quotation',
        'Supplier Quotation'
    ]

    new_transaction_fields = [
        'total_before_discount',
        'tax_exclusive_total_before_discount',
        'total_discount',
        'tax_exclusive_total_discount',
        'taxable_total',
        'net_total',
        'total_after_taxes',
        'total_discount_after_taxes',
    ]
    new_transaction_fields += ['base_' + f for f in new_transaction_fields]
    new_transaction_fields = set(new_transaction_fields)

    new_item_fields = [
        'tax_exclusive_price_list_rate',
        'tax_exclusive_rate',
        'tax_exclusive_amount',
        'tax_exclusive_discount_amount',
        'tax_exclusive_rate_with_margin',
        'amount_before_discount',
        'tax_exclusive_amount_before_discount',
        'total_discount',
        'tax_exclusive_total_discount',
        'taxable_rate',
        'taxable_amount',
        'net_rate',
        'net_amount',
        'item_taxes_and_charges',
        'tax_inclusive_amount',
        'tax_inclusive_rate',
    ]
    new_item_fields += ['base_' + f for f in new_item_fields]
    new_item_fields = set(new_item_fields)

    # Calculate and update database
    for dt in doctypes:
        docnames = frappe.get_all(dt)
        for dn in docnames:
            dn = dn.name
            doc = frappe.get_doc(dt, dn)
            calculate_taxes_and_totals(doc)

            values_to_update = [doc.get(f) for f in new_transaction_fields]
            update_dict = dict(zip(new_transaction_fields, values_to_update))
            frappe.db.set_value(dt,
                                doc.name,
                                update_dict,
                                None,
                                update_modified=False)

            for item in doc.items:
                item_fields = set([f.fieldname for f in item.meta.fields])
                fields_to_update = list(
                    new_item_fields.intersection(item_fields))
                values_to_update = [item.get(f) for f in fields_to_update]
                update_dict = dict(zip(fields_to_update, values_to_update))
                frappe.db.set_value(dt + " Item",
                                    item.name,
                                    update_dict,
                                    None,
                                    update_modified=False)

            for tax in doc.taxes:
                frappe.db.set_value(tax.doctype,
                                    tax.name,
                                    "displayed_total",
                                    tax.displayed_total,
                                    update_modified=False)