refactor: item-wh wise reposting by default

This commit is contained in:
Ankush Menat 2021-10-28 15:53:18 +05:30 committed by Ankush Menat
parent a369094eca
commit 6dc9b822bc

View File

@ -544,7 +544,7 @@ class StockController(AccountsController):
"company": self.company
})
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()
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.save()
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