mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-23 05:04:52 +01:00
fix: patch to set discount percentange in case of mismatch
(cherry picked from commit f7eda8a156)
This commit is contained in:
committed by
Mergify
parent
7ecb4d3d6f
commit
039c47e3f2
56
erpnext/patches/v15_0/set_additional_discount_percentage.py
Normal file
56
erpnext/patches/v15_0/set_additional_discount_percentage.py
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import frappe
|
||||||
|
from frappe import scrub
|
||||||
|
from frappe.model.meta import get_field_precision
|
||||||
|
from frappe.utils import flt
|
||||||
|
|
||||||
|
from erpnext.accounts.report.calculated_discount_mismatch.calculated_discount_mismatch import (
|
||||||
|
DISCOUNT_DOCTYPES,
|
||||||
|
LAST_MODIFIED_DATE_THRESHOLD,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
for doctype in DISCOUNT_DOCTYPES:
|
||||||
|
documents = frappe.get_all(
|
||||||
|
doctype,
|
||||||
|
{
|
||||||
|
"docstatus": 0,
|
||||||
|
"modified": [">", LAST_MODIFIED_DATE_THRESHOLD],
|
||||||
|
"discount_amount": ["is", "set"],
|
||||||
|
},
|
||||||
|
[
|
||||||
|
"name",
|
||||||
|
"additional_discount_percentage",
|
||||||
|
"discount_amount",
|
||||||
|
"apply_discount_on",
|
||||||
|
"grand_total",
|
||||||
|
"net_total",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
if not documents:
|
||||||
|
continue
|
||||||
|
|
||||||
|
precision = get_field_precision(frappe.get_meta(doctype).get_field("additional_discount_percentage"))
|
||||||
|
mismatched_documents = []
|
||||||
|
|
||||||
|
for doc in documents:
|
||||||
|
discount_applied_on = scrub(doc.apply_discount_on)
|
||||||
|
|
||||||
|
calculated_discount_amount = flt(
|
||||||
|
doc.additional_discount_percentage * doc.get(discount_applied_on) / 100,
|
||||||
|
precision,
|
||||||
|
)
|
||||||
|
|
||||||
|
if calculated_discount_amount != doc.discount_amount:
|
||||||
|
mismatched_documents.append(doc.name)
|
||||||
|
|
||||||
|
if mismatched_documents:
|
||||||
|
frappe.db.set_value(
|
||||||
|
doctype,
|
||||||
|
{
|
||||||
|
"name": ["in", mismatched_documents],
|
||||||
|
},
|
||||||
|
"additional_discount_percentage",
|
||||||
|
0,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user