refactor: item-wh wise reposting by default
(cherry picked from commit 6dc9b822bc)
This commit is contained in:
committed by
mergify-bot
parent
80d0b6ddc8
commit
0032ee46be
@@ -544,7 +544,7 @@ class StockController(AccountsController):
|
|||||||
"company": self.company
|
"company": self.company
|
||||||
})
|
})
|
||||||
if future_sle_exists(args):
|
if future_sle_exists(args):
|
||||||
create_repost_item_valuation_entry(args)
|
create_item_wise_repost_entries(voucher_type=self.doctype, voucher_no=self.name)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_quality_inspections(doctype, docname, items):
|
def make_quality_inspections(doctype, docname, items):
|
||||||
@@ -679,3 +679,39 @@ def create_repost_item_valuation_entry(args):
|
|||||||
repost_entry.flags.ignore_permissions = True
|
repost_entry.flags.ignore_permissions = True
|
||||||
repost_entry.save()
|
repost_entry.save()
|
||||||
repost_entry.submit()
|
repost_entry.submit()
|
||||||
|
|
||||||
|
|
||||||
|
def create_item_wise_repost_entries(voucher_type, voucher_no, allow_zero_rate=False):
|
||||||
|
"""Using a voucher create repost item valuation records for all item-warehouse pairs."""
|
||||||
|
|
||||||
|
stock_ledger_entries = frappe.db.get_all("Stock Ledger Entry",
|
||||||
|
filters={"voucher_type": voucher_type, "voucher_no": voucher_no},
|
||||||
|
fields=["item_code", "warehouse", "posting_date", "posting_time", "creation", "company"],
|
||||||
|
order_by="creation asc",
|
||||||
|
group_by="item_code, warehouse"
|
||||||
|
)
|
||||||
|
distinct_item_warehouses = set()
|
||||||
|
|
||||||
|
repost_entries = []
|
||||||
|
|
||||||
|
for sle in stock_ledger_entries:
|
||||||
|
item_wh = (sle.item_code, sle.warehouse)
|
||||||
|
if item_wh in distinct_item_warehouses:
|
||||||
|
continue
|
||||||
|
distinct_item_warehouses.add(item_wh)
|
||||||
|
|
||||||
|
repost_entry = frappe.new_doc("Repost Item Valuation")
|
||||||
|
repost_entry.based_on = "Item and Warehouse"
|
||||||
|
repost_entry.voucher_type = voucher_type
|
||||||
|
repost_entry.voucher_no = voucher_no
|
||||||
|
|
||||||
|
repost_entry.item_code = sle.item_code
|
||||||
|
repost_entry.warehouse = sle.warehouse
|
||||||
|
repost_entry.posting_date = sle.posting_date
|
||||||
|
repost_entry.posting_time = sle.posting_time
|
||||||
|
repost_entry.allow_zero_rate = allow_zero_rate
|
||||||
|
repost_entry.flags.ignore_links = True
|
||||||
|
repost_entry.submit()
|
||||||
|
repost_entries.append(repost_entry)
|
||||||
|
|
||||||
|
return repost_entries
|
||||||
|
|||||||
Reference in New Issue
Block a user