Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add running stock value difference in invariant report (backport #29012) #29013

Merged
merged 1 commit into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const DIFFERNCE_FIELD_NAMES = [
"fifo_value_diff",
"fifo_valuation_diff",
"valuation_diff",
"fifo_difference_diff"
"fifo_difference_diff",
"diff_value_diff"
];

frappe.query_reports["Stock Ledger Invariant Check"] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def get_stock_ledger_entries(filters):

def add_invariant_check_fields(sles):
balance_qty = 0.0
balance_stock_value = 0.0
for idx, sle in enumerate(sles):
queue = json.loads(sle.stock_queue)

Expand All @@ -60,6 +61,7 @@ def add_invariant_check_fields(sles):
fifo_value += qty * rate

balance_qty += sle.actual_qty
balance_stock_value += sle.stock_value_difference
if sle.voucher_type == "Stock Reconciliation" and not sle.batch_no:
balance_qty = sle.qty_after_transaction

Expand All @@ -70,6 +72,7 @@ def add_invariant_check_fields(sles):
sle.stock_value / sle.qty_after_transaction if sle.qty_after_transaction else None
)
sle.expected_qty_after_transaction = balance_qty
sle.stock_value_from_diff = balance_stock_value

# set difference fields
sle.difference_in_qty = sle.qty_after_transaction - sle.expected_qty_after_transaction
Expand All @@ -81,6 +84,7 @@ def add_invariant_check_fields(sles):
sle.valuation_diff = (
sle.valuation_rate - sle.balance_value_by_qty if sle.balance_value_by_qty else None
)
sle.diff_value_diff = sle.stock_value_from_diff - sle.stock_value

if idx > 0:
sle.fifo_stock_diff = sle.fifo_stock_value - sles[idx - 1].fifo_stock_value
Expand Down Expand Up @@ -191,12 +195,21 @@ def get_columns():
"fieldtype": "Float",
"label": "D - E",
},

{
"fieldname": "stock_value_difference",
"fieldtype": "Float",
"label": "(F) Stock Value Difference",
},
{
"fieldname": "stock_value_from_diff",
"fieldtype": "Float",
"label": "Balance Stock Value using (F)",
},
{
"fieldname": "diff_value_diff",
"fieldtype": "Float",
"label": "K - D",
},
{
"fieldname": "fifo_stock_diff",
"fieldtype": "Float",
Expand Down