Fix taxes and totals in party currency
This commit is contained in:
parent
73249551e8
commit
8719c1a6b8
@ -153,3 +153,4 @@ execute:frappe.delete_doc("Page", "stock-ledger")
|
||||
execute:frappe.delete_doc("Page","stock-level")
|
||||
erpnext.patches.v5_0.reclculate_planned_operating_cost_in_production_order
|
||||
erpnext.patches.v5_0.repost_requested_qty
|
||||
erpnext.patches.v5_0.fix_taxes_and_totals_in_party_currency
|
@ -0,0 +1,63 @@
|
||||
|
||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.model.meta import get_field_precision
|
||||
|
||||
def execute():
|
||||
selling_doctypes = ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]
|
||||
buying_doctypes = ["Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice"]
|
||||
|
||||
for dt in selling_doctypes:
|
||||
update_values(dt, "Sales Taxes and Charges")
|
||||
|
||||
for dt in buying_doctypes:
|
||||
update_values(dt, "Purchase Taxes and Charges")
|
||||
|
||||
def update_values(dt, tax_table):
|
||||
rate_field_precision = get_field_precision(frappe.get_meta(dt + " Item").get_field("rate"))
|
||||
tax_amount_precision = get_field_precision(frappe.get_meta(tax_table).get_field("tax_amount"))
|
||||
|
||||
# update net_total, discount_on
|
||||
frappe.db.sql("""
|
||||
UPDATE
|
||||
`tab{0}`
|
||||
SET
|
||||
total_taxes_and_charges = round(base_total_taxes_and_charges / conversion_rate, {1})
|
||||
WHERE
|
||||
docstatus < 2
|
||||
and ifnull(base_total_taxes_and_charges, 0) != 0
|
||||
and ifnull(total_taxes_and_charges, 0) = 0
|
||||
""".format(dt, tax_amount_precision))
|
||||
|
||||
# update net_amount
|
||||
frappe.db.sql("""
|
||||
UPDATE
|
||||
`tab{0}` par, `tab{1}` item
|
||||
SET
|
||||
item.net_amount = round(item.base_net_amount / par.conversion_rate, {2}),
|
||||
item.net_rate = round(item.base_net_rate / par.conversion_rate, {2})
|
||||
WHERE
|
||||
par.name = item.parent
|
||||
and par.docstatus < 2
|
||||
and ((ifnull(item.base_net_amount, 0) != 0 and ifnull(item.net_amount, 0) = 0)
|
||||
or (ifnull(item.base_net_rate, 0) != 0 and ifnull(item.net_rate, 0) = 0))
|
||||
""".format(dt, dt + " Item", rate_field_precision))
|
||||
|
||||
# update tax in party currency
|
||||
frappe.db.sql("""
|
||||
UPDATE
|
||||
`tab{0}` par, `tab{1}` tax
|
||||
SET
|
||||
tax.tax_amount = round(tax.base_tax_amount / par.conversion_rate, {2}),
|
||||
tax.total = round(tax.base_total / conversion_rate, {2}),
|
||||
tax.tax_amount_after_discount_amount = round(tax.base_tax_amount_after_discount_amount / conversion_rate, {2})
|
||||
WHERE
|
||||
par.name = tax.parent
|
||||
and par.docstatus < 2
|
||||
and ((ifnull(tax.base_tax_amount, 0) != 0 and ifnull(tax.tax_amount, 0) = 0)
|
||||
or (ifnull(tax.base_total, 0) != 0 and ifnull(tax.total, 0) = 0)
|
||||
or (ifnull(tax.base_tax_amount_after_discount_amount, 0) != 0 and
|
||||
ifnull(tax.tax_amount_after_discount_amount, 0) = 0))
|
||||
""".format(dt, tax_table, tax_amount_precision))
|
@ -46,17 +46,16 @@ def update_values(dt, tax_table):
|
||||
WHERE
|
||||
docstatus < 2
|
||||
""".format(dt, net_total_precision))
|
||||
|
||||
|
||||
|
||||
# update net_amount
|
||||
frappe.db.sql("""
|
||||
UPDATE
|
||||
`tab{0}` par, `tab{1}` item
|
||||
SET
|
||||
item.base_net_amount = item.base_amount,
|
||||
item.base_net_rate = item.base_rate,
|
||||
item.net_amount = round(item.base_net_amount / par.conversion_rate, {2}),
|
||||
item.net_rate = round(item.base_net_rate / par.conversion_rate, {2}),
|
||||
item.base_net_amount = round(item.base_amount, {2}),
|
||||
item.base_net_rate = round(item.base_rate, {2}),
|
||||
item.net_amount = round(item.base_amount / par.conversion_rate, {2}),
|
||||
item.net_rate = round(item.base_rate / par.conversion_rate, {2}),
|
||||
item.base_amount = round(item.amount * par.conversion_rate, {2}),
|
||||
item.base_rate = round(item.rate * par.conversion_rate, {2})
|
||||
WHERE
|
||||
@ -69,12 +68,12 @@ def update_values(dt, tax_table):
|
||||
UPDATE
|
||||
`tab{0}` par, `tab{1}` tax
|
||||
SET
|
||||
tax.base_tax_amount = tax.tax_amount,
|
||||
tax.tax_amount = round(tax.base_tax_amount / par.conversion_rate, {2}),
|
||||
tax.base_tax_amount = round(tax.tax_amount, {2}),
|
||||
tax.tax_amount = round(tax.tax_amount / par.conversion_rate, {2}),
|
||||
tax.base_total = round(tax.total, {2}),
|
||||
tax.total = round(tax.base_total / conversion_rate, {2}),
|
||||
tax.total = round(tax.total / conversion_rate, {2}),
|
||||
tax.base_tax_amount_after_discount_amount = round(tax.tax_amount_after_discount_amount, {2}),
|
||||
tax.tax_amount_after_discount_amount = round(tax.base_tax_amount_after_discount_amount / conversion_rate, {2})
|
||||
tax.tax_amount_after_discount_amount = round(tax.tax_amount_after_discount_amount / conversion_rate, {2})
|
||||
WHERE
|
||||
par.name = tax.parent
|
||||
and par.docstatus < 2
|
||||
|
Loading…
x
Reference in New Issue
Block a user