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
This commit is contained in:
@@ -515,6 +515,8 @@ class AccountsController(TransactionBase):
|
||||
parent_dict.update({"customer": parent_dict.get("party_name")})
|
||||
|
||||
self.pricing_rules = []
|
||||
basic_item_details_map = {}
|
||||
|
||||
for item in self.get("items"):
|
||||
if item.get("item_code"):
|
||||
args = parent_dict.copy()
|
||||
@@ -533,7 +535,17 @@ class AccountsController(TransactionBase):
|
||||
if self.get("is_subcontracted"):
|
||||
args["is_subcontracted"] = self.is_subcontracted
|
||||
|
||||
ret = get_item_details(args, self, for_validate=True, overwrite_warehouse=False)
|
||||
basic_details = basic_item_details_map.get(item.item_code)
|
||||
ret, basic_item_details = get_item_details(
|
||||
args,
|
||||
self,
|
||||
for_validate=True,
|
||||
overwrite_warehouse=False,
|
||||
return_basic_details=True,
|
||||
basic_details=basic_details,
|
||||
)
|
||||
|
||||
basic_item_details_map.setdefault(item.item_code, basic_item_details)
|
||||
|
||||
for fieldname, value in ret.items():
|
||||
if item.meta.get_field(fieldname) and value is not None:
|
||||
@@ -1232,7 +1244,7 @@ class AccountsController(TransactionBase):
|
||||
)
|
||||
)
|
||||
|
||||
def validate_multiple_billing(self, ref_dt, item_ref_dn, based_on, parentfield):
|
||||
def validate_multiple_billing(self, ref_dt, item_ref_dn, based_on):
|
||||
from erpnext.controllers.status_updater import get_allowance_for
|
||||
|
||||
item_allowance = {}
|
||||
@@ -1245,17 +1257,20 @@ class AccountsController(TransactionBase):
|
||||
|
||||
total_overbilled_amt = 0.0
|
||||
|
||||
reference_names = [d.get(item_ref_dn) for d in self.get("items") if d.get(item_ref_dn)]
|
||||
reference_details = self.get_billing_reference_details(
|
||||
reference_names, ref_dt + " Item", based_on
|
||||
)
|
||||
|
||||
for item in self.get("items"):
|
||||
if not item.get(item_ref_dn):
|
||||
continue
|
||||
|
||||
ref_amt = flt(
|
||||
frappe.db.get_value(ref_dt + " Item", item.get(item_ref_dn), based_on),
|
||||
self.precision(based_on, item),
|
||||
)
|
||||
ref_amt = flt(reference_details.get(item.get(item_ref_dn)), self.precision(based_on, item))
|
||||
|
||||
if not ref_amt:
|
||||
frappe.msgprint(
|
||||
_("System will not check overbilling since amount for Item {0} in {1} is zero").format(
|
||||
_("System will not check over billing since amount for Item {0} in {1} is zero").format(
|
||||
item.item_code, ref_dt
|
||||
),
|
||||
title=_("Warning"),
|
||||
@@ -1302,6 +1317,16 @@ class AccountsController(TransactionBase):
|
||||
alert=True,
|
||||
)
|
||||
|
||||
def get_billing_reference_details(self, reference_names, reference_doctype, based_on):
|
||||
return frappe._dict(
|
||||
frappe.get_all(
|
||||
reference_doctype,
|
||||
filters={"name": ("in", reference_names)},
|
||||
fields=["name", based_on],
|
||||
as_list=1,
|
||||
)
|
||||
)
|
||||
|
||||
def get_billed_amount_for_item(self, item, item_ref_dn, based_on):
|
||||
"""
|
||||
Returns Sum of Amount of
|
||||
|
||||
Reference in New Issue
Block a user