Merge pull request #5325 from nabinhait/return_fix_2
In Purchase Return entry, make sle and gle as per actual inward entry's valuation rate
This commit is contained in:
commit
719504a0fe
@ -62,8 +62,8 @@ def validate_returned_items(doc):
|
||||
|
||||
|
||||
if doc.doctype in ("Delivery Note", "Sales Invoice"):
|
||||
for d in frappe.db.sql("""select item_code, sum(qty) as qty, serial_no, batch_no from `tabPacked Item`
|
||||
where parent = %s group by item_code""".format(doc.doctype), doc.return_against, as_dict=1):
|
||||
for d in frappe.db.sql("""select item_code, qty, serial_no, batch_no from `tabPacked Item`
|
||||
where parent = %s""".format(doc.doctype), doc.return_against, as_dict=1):
|
||||
valid_items = get_ref_item_dict(valid_items, d)
|
||||
|
||||
already_returned_items = get_already_returned_items(doc)
|
||||
|
@ -139,19 +139,24 @@ class PurchaseReceipt(BuyingController):
|
||||
pr_qty = flt(d.qty) * flt(d.conversion_factor)
|
||||
|
||||
if pr_qty:
|
||||
val_rate_db_precision = 6 if cint(self.precision("valuation_rate", d)) <= 6 else 9
|
||||
rate = flt(d.valuation_rate, val_rate_db_precision)
|
||||
|
||||
sle = self.get_sl_entries(d, {
|
||||
"actual_qty": flt(pr_qty),
|
||||
"serial_no": cstr(d.serial_no).strip()
|
||||
})
|
||||
if self.is_return:
|
||||
original_incoming_rate = frappe.db.get_value("Stock Ledger Entry",
|
||||
{"voucher_type": "Purchase Receipt", "voucher_no": self.return_against,
|
||||
"item_code": d.item_code}, "incoming_rate")
|
||||
|
||||
sle.update({
|
||||
"outgoing_rate": rate
|
||||
"outgoing_rate": original_incoming_rate
|
||||
})
|
||||
else:
|
||||
val_rate_db_precision = 6 if cint(self.precision("valuation_rate", d)) <= 6 else 9
|
||||
incoming_rate = flt(d.valuation_rate, val_rate_db_precision)
|
||||
sle.update({
|
||||
"incoming_rate": rate
|
||||
"incoming_rate": incoming_rate
|
||||
})
|
||||
sl_entries.append(sle)
|
||||
|
||||
@ -302,12 +307,9 @@ class PurchaseReceipt(BuyingController):
|
||||
for d in self.get("items"):
|
||||
if d.item_code in stock_items and flt(d.valuation_rate) and flt(d.qty):
|
||||
if warehouse_account.get(d.warehouse):
|
||||
|
||||
val_rate_db_precision = 6 if cint(d.precision("valuation_rate")) <= 6 else 9
|
||||
|
||||
# warehouse account
|
||||
stock_value_diff = flt(flt(d.valuation_rate, val_rate_db_precision) * flt(d.qty)
|
||||
* flt(d.conversion_factor), d.precision("base_net_amount"))
|
||||
stock_value_diff = frappe.db.get_value("Stock Ledger Entry",
|
||||
{"voucher_type": "Purchase Receipt", "voucher_no": self.name,
|
||||
"voucher_detail_no": d.name}, "stock_value_difference")
|
||||
|
||||
gl_entries.append(self.get_gl_dict({
|
||||
"account": warehouse_account[d.warehouse]["name"],
|
||||
@ -352,16 +354,20 @@ class PurchaseReceipt(BuyingController):
|
||||
}, warehouse_account[self.supplier_warehouse]["account_currency"]))
|
||||
|
||||
# divisional loss adjustment
|
||||
sle_valuation_amount = flt(flt(d.valuation_rate, val_rate_db_precision) * flt(d.qty) * flt(d.conversion_factor),
|
||||
self.precision("base_net_amount", d))
|
||||
|
||||
distributed_amount = flt(flt(d.base_net_amount, self.precision("base_net_amount", d))) + \
|
||||
valuation_amount_as_per_doc = flt(d.base_net_amount, d.precision("base_net_amount")) + \
|
||||
flt(d.landed_cost_voucher_amount) + flt(d.rm_supp_cost) + flt(d.item_tax_amount)
|
||||
|
||||
divisional_loss = flt(distributed_amount - sle_valuation_amount, self.precision("base_net_amount", d))
|
||||
divisional_loss = flt(valuation_amount_as_per_doc - stock_value_diff,
|
||||
d.precision("base_net_amount"))
|
||||
|
||||
if divisional_loss:
|
||||
if self.is_return or flt(d.item_tax_amount):
|
||||
loss_account = expenses_included_in_valuation
|
||||
else:
|
||||
loss_account = stock_rbnb
|
||||
|
||||
gl_entries.append(self.get_gl_dict({
|
||||
"account": stock_rbnb,
|
||||
"account": loss_account,
|
||||
"against": warehouse_account[d.warehouse]["name"],
|
||||
"cost_center": d.cost_center,
|
||||
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
||||
|
@ -215,8 +215,6 @@ class update_entries_after(object):
|
||||
stock_value_change = 0
|
||||
if incoming_rate:
|
||||
stock_value_change = actual_qty * incoming_rate
|
||||
elif flt(sle.outgoing_rate):
|
||||
stock_value_change = actual_qty * flt(sle.outgoing_rate)
|
||||
elif actual_qty < 0:
|
||||
# In case of delivery/stock issue, get average purchase rate
|
||||
# of serial nos of current entry
|
||||
|
Loading…
x
Reference in New Issue
Block a user