mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-08 15:42:52 +00:00
Fix taxes and totals in party currency
This commit is contained in:
@@ -153,3 +153,4 @@ execute:frappe.delete_doc("Page", "stock-ledger")
|
|||||||
execute:frappe.delete_doc("Page","stock-level")
|
execute:frappe.delete_doc("Page","stock-level")
|
||||||
erpnext.patches.v5_0.reclculate_planned_operating_cost_in_production_order
|
erpnext.patches.v5_0.reclculate_planned_operating_cost_in_production_order
|
||||||
erpnext.patches.v5_0.repost_requested_qty
|
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))
|
||||||
@@ -47,16 +47,15 @@ def update_values(dt, tax_table):
|
|||||||
docstatus < 2
|
docstatus < 2
|
||||||
""".format(dt, net_total_precision))
|
""".format(dt, net_total_precision))
|
||||||
|
|
||||||
|
|
||||||
# update net_amount
|
# update net_amount
|
||||||
frappe.db.sql("""
|
frappe.db.sql("""
|
||||||
UPDATE
|
UPDATE
|
||||||
`tab{0}` par, `tab{1}` item
|
`tab{0}` par, `tab{1}` item
|
||||||
SET
|
SET
|
||||||
item.base_net_amount = item.base_amount,
|
item.base_net_amount = round(item.base_amount, {2}),
|
||||||
item.base_net_rate = item.base_rate,
|
item.base_net_rate = round(item.base_rate, {2}),
|
||||||
item.net_amount = round(item.base_net_amount / par.conversion_rate, {2}),
|
item.net_amount = round(item.base_amount / par.conversion_rate, {2}),
|
||||||
item.net_rate = round(item.base_net_rate / 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_amount = round(item.amount * par.conversion_rate, {2}),
|
||||||
item.base_rate = round(item.rate * par.conversion_rate, {2})
|
item.base_rate = round(item.rate * par.conversion_rate, {2})
|
||||||
WHERE
|
WHERE
|
||||||
@@ -69,12 +68,12 @@ def update_values(dt, tax_table):
|
|||||||
UPDATE
|
UPDATE
|
||||||
`tab{0}` par, `tab{1}` tax
|
`tab{0}` par, `tab{1}` tax
|
||||||
SET
|
SET
|
||||||
tax.base_tax_amount = tax.tax_amount,
|
tax.base_tax_amount = round(tax.tax_amount, {2}),
|
||||||
tax.tax_amount = round(tax.base_tax_amount / par.conversion_rate, {2}),
|
tax.tax_amount = round(tax.tax_amount / par.conversion_rate, {2}),
|
||||||
tax.base_total = round(tax.total, {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.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
|
WHERE
|
||||||
par.name = tax.parent
|
par.name = tax.parent
|
||||||
and par.docstatus < 2
|
and par.docstatus < 2
|
||||||
|
|||||||
Reference in New Issue
Block a user