mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
Merge pull request #45335 from rohitwaghchaure/fixed-valuation-for-batch
fix: valuation for batch
This commit is contained in:
4
.github/workflows/server-tests-mariadb.yml
vendored
4
.github/workflows/server-tests-mariadb.yml
vendored
@@ -133,7 +133,7 @@ jobs:
|
|||||||
run: cat ~/frappe-bench/bench_start.log || true
|
run: cat ~/frappe-bench/bench_start.log || true
|
||||||
|
|
||||||
- name: Upload coverage data
|
- name: Upload coverage data
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
with:
|
with:
|
||||||
name: coverage-${{ matrix.container }}
|
name: coverage-${{ matrix.container }}
|
||||||
@@ -149,7 +149,7 @@ jobs:
|
|||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Download artifacts
|
- name: Download artifacts
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v4
|
||||||
|
|
||||||
- name: Upload coverage data
|
- name: Upload coverage data
|
||||||
uses: codecov/codecov-action@v4
|
uses: codecov/codecov-action@v4
|
||||||
|
|||||||
@@ -279,8 +279,9 @@ class DeprecatedBatchNoValuation:
|
|||||||
|
|
||||||
last_sle = self.get_last_sle_for_non_batch()
|
last_sle = self.get_last_sle_for_non_batch()
|
||||||
for d in batch_data:
|
for d in batch_data:
|
||||||
self.non_batchwise_balance_value[d.batch_no] += flt(last_sle.stock_value)
|
if self.available_qty.get(d.batch_no):
|
||||||
self.non_batchwise_balance_qty[d.batch_no] += flt(last_sle.qty_after_transaction)
|
self.non_batchwise_balance_value[d.batch_no] += flt(last_sle.stock_value)
|
||||||
|
self.non_batchwise_balance_qty[d.batch_no] += flt(last_sle.qty_after_transaction)
|
||||||
|
|
||||||
def get_last_sle_for_non_batch(self):
|
def get_last_sle_for_non_batch(self):
|
||||||
from erpnext.stock.utils import get_combine_datetime
|
from erpnext.stock.utils import get_combine_datetime
|
||||||
@@ -326,6 +327,57 @@ class DeprecatedBatchNoValuation:
|
|||||||
data = query.run(as_dict=True)
|
data = query.run(as_dict=True)
|
||||||
return data[0] if data else {}
|
return data[0] if data else {}
|
||||||
|
|
||||||
|
def get_last_sle_for_sabb_no_batchwise_valuation(self):
|
||||||
|
sabb = frappe.qb.DocType("Serial and Batch Bundle")
|
||||||
|
sabb_entry = frappe.qb.DocType("Serial and Batch Entry")
|
||||||
|
batch = frappe.qb.DocType("Batch")
|
||||||
|
|
||||||
|
posting_datetime = CombineDatetime(self.sle.posting_date, self.sle.posting_time)
|
||||||
|
timestamp_condition = CombineDatetime(sabb.posting_date, sabb.posting_time) < posting_datetime
|
||||||
|
|
||||||
|
if self.sle.creation:
|
||||||
|
timestamp_condition |= (
|
||||||
|
CombineDatetime(sabb.posting_date, sabb.posting_time) == posting_datetime
|
||||||
|
) & (sabb.creation < self.sle.creation)
|
||||||
|
|
||||||
|
query = (
|
||||||
|
frappe.qb.from_(sabb)
|
||||||
|
.inner_join(sabb_entry)
|
||||||
|
.on(sabb.name == sabb_entry.parent)
|
||||||
|
.inner_join(batch)
|
||||||
|
.on(sabb_entry.batch_no == batch.name)
|
||||||
|
.select(sabb.name)
|
||||||
|
.where(
|
||||||
|
(sabb.item_code == self.sle.item_code)
|
||||||
|
& (sabb.warehouse == self.sle.warehouse)
|
||||||
|
& (sabb_entry.batch_no.isnotnull())
|
||||||
|
& (batch.use_batchwise_valuation == 0)
|
||||||
|
& (sabb.is_cancelled == 0)
|
||||||
|
& (sabb.docstatus == 1)
|
||||||
|
)
|
||||||
|
.where(timestamp_condition)
|
||||||
|
.orderby(sabb.posting_date, order=Order.desc)
|
||||||
|
.orderby(sabb.posting_time, order=Order.desc)
|
||||||
|
.orderby(sabb.creation, order=Order.desc)
|
||||||
|
.limit(1)
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.sle.voucher_detail_no:
|
||||||
|
query = query.where(sabb.voucher_detail_no != self.sle.voucher_detail_no)
|
||||||
|
|
||||||
|
data = query.run(as_dict=True)
|
||||||
|
if not data:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
sle = frappe.db.get_value(
|
||||||
|
"Stock Ledger Entry",
|
||||||
|
{"serial_and_batch_bundle": data[0].name},
|
||||||
|
["stock_value", "qty_after_transaction"],
|
||||||
|
as_dict=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
return sle if sle else {}
|
||||||
|
|
||||||
@deprecated(
|
@deprecated(
|
||||||
"erpnext.stock.serial_batch_bundle.BatchNoValuation.set_balance_value_from_bundle",
|
"erpnext.stock.serial_batch_bundle.BatchNoValuation.set_balance_value_from_bundle",
|
||||||
"unknown",
|
"unknown",
|
||||||
@@ -377,7 +429,14 @@ class DeprecatedBatchNoValuation:
|
|||||||
|
|
||||||
query = query.where(bundle.voucher_type != "Pick List")
|
query = query.where(bundle.voucher_type != "Pick List")
|
||||||
|
|
||||||
for d in query.run(as_dict=True):
|
batch_data = query.run(as_dict=True)
|
||||||
self.non_batchwise_balance_value[d.batch_no] += flt(d.batch_value)
|
for d in batch_data:
|
||||||
self.non_batchwise_balance_qty[d.batch_no] += flt(d.batch_qty)
|
|
||||||
self.available_qty[d.batch_no] += flt(d.batch_qty)
|
self.available_qty[d.batch_no] += flt(d.batch_qty)
|
||||||
|
|
||||||
|
last_sle = self.get_last_sle_for_sabb_no_batchwise_valuation()
|
||||||
|
if not last_sle:
|
||||||
|
return
|
||||||
|
|
||||||
|
for batch_no in self.available_qty:
|
||||||
|
self.non_batchwise_balance_value[batch_no] = flt(last_sle.stock_value)
|
||||||
|
self.non_batchwise_balance_qty[batch_no] = flt(last_sle.qty_after_transaction)
|
||||||
|
|||||||
Reference in New Issue
Block a user