fix: Multiple issues in purchase invoice submission (#34600)
fix: Multiple issues in purchase invoice submission (#34600)
* fix: Multiple issues in purchase invoice submission
* fix: Base grand total calculation
* chore: Calculate base grand total separately only in multi currency docs
* fix: Add gl entry for round off
(cherry picked from commit 4c61ee30bb)
Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
This commit is contained in:
@@ -58,11 +58,11 @@ class TransactionBase(StatusUpdater):
|
||||
|
||||
def compare_values(self, ref_doc, fields, doc=None):
|
||||
for reference_doctype, ref_dn_list in ref_doc.items():
|
||||
prev_doc_detail_map = self.get_prev_doc_reference_details(
|
||||
ref_dn_list, reference_doctype, fields
|
||||
)
|
||||
for reference_name in ref_dn_list:
|
||||
prevdoc_values = frappe.db.get_value(
|
||||
reference_doctype, reference_name, [d[0] for d in fields], as_dict=1
|
||||
)
|
||||
|
||||
prevdoc_values = prev_doc_detail_map.get(reference_name)
|
||||
if not prevdoc_values:
|
||||
frappe.throw(_("Invalid reference {0} {1}").format(reference_doctype, reference_name))
|
||||
|
||||
@@ -70,6 +70,19 @@ class TransactionBase(StatusUpdater):
|
||||
if prevdoc_values[field] is not None and field not in self.exclude_fields:
|
||||
self.validate_value(field, condition, prevdoc_values[field], doc)
|
||||
|
||||
def get_prev_doc_reference_details(self, reference_names, reference_doctype, fields):
|
||||
prev_doc_detail_map = {}
|
||||
details = frappe.get_all(
|
||||
reference_doctype,
|
||||
filters={"name": ("in", reference_names)},
|
||||
fields=["name"] + [d[0] for d in fields],
|
||||
)
|
||||
|
||||
for d in details:
|
||||
prev_doc_detail_map.setdefault(d.name, d)
|
||||
|
||||
return prev_doc_detail_map
|
||||
|
||||
def validate_rate_with_reference_doc(self, ref_details):
|
||||
if self.get("is_internal_supplier"):
|
||||
return
|
||||
@@ -77,23 +90,23 @@ class TransactionBase(StatusUpdater):
|
||||
buying_doctypes = ["Purchase Order", "Purchase Invoice", "Purchase Receipt"]
|
||||
|
||||
if self.doctype in buying_doctypes:
|
||||
action = frappe.db.get_single_value("Buying Settings", "maintain_same_rate_action")
|
||||
settings_doc = "Buying Settings"
|
||||
action, role_allowed_to_override = frappe.get_cached_value(
|
||||
"Buying Settings", "None", ["maintain_same_rate_action", "role_to_override_stop_action"]
|
||||
)
|
||||
else:
|
||||
action = frappe.db.get_single_value("Selling Settings", "maintain_same_rate_action")
|
||||
settings_doc = "Selling Settings"
|
||||
action, role_allowed_to_override = frappe.get_cached_value(
|
||||
"Selling Settings", "None", ["maintain_same_rate_action", "role_to_override_stop_action"]
|
||||
)
|
||||
|
||||
for ref_dt, ref_dn_field, ref_link_field in ref_details:
|
||||
reference_names = [d.get(ref_link_field) for d in self.get("items") if d.get(ref_link_field)]
|
||||
reference_details = self.get_reference_details(reference_names, ref_dt + " Item")
|
||||
for d in self.get("items"):
|
||||
if d.get(ref_link_field):
|
||||
ref_rate = frappe.db.get_value(ref_dt + " Item", d.get(ref_link_field), "rate")
|
||||
ref_rate = reference_details.get(d.get(ref_link_field))
|
||||
|
||||
if abs(flt(d.rate - ref_rate, d.precision("rate"))) >= 0.01:
|
||||
if action == "Stop":
|
||||
role_allowed_to_override = frappe.db.get_single_value(
|
||||
settings_doc, "role_to_override_stop_action"
|
||||
)
|
||||
|
||||
if role_allowed_to_override not in frappe.get_roles():
|
||||
frappe.throw(
|
||||
_("Row #{0}: Rate must be same as {1}: {2} ({3} / {4})").format(
|
||||
@@ -109,6 +122,16 @@ class TransactionBase(StatusUpdater):
|
||||
indicator="orange",
|
||||
)
|
||||
|
||||
def get_reference_details(self, reference_names, reference_doctype):
|
||||
return frappe._dict(
|
||||
frappe.get_all(
|
||||
reference_doctype,
|
||||
filters={"name": ("in", reference_names)},
|
||||
fields=["name", "rate"],
|
||||
as_list=1,
|
||||
)
|
||||
)
|
||||
|
||||
def get_link_filters(self, for_doctype):
|
||||
if hasattr(self, "prev_link_mapper") and self.prev_link_mapper.get(for_doctype):
|
||||
fieldname = self.prev_link_mapper[for_doctype]["fieldname"]
|
||||
|
||||
Reference in New Issue
Block a user