Skip to content

Commit

Permalink
refactor: item-wh wise reposting by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Nov 25, 2021
1 parent a369094 commit 6dc9b82
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion erpnext/controllers/stock_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def repost_future_sle_and_gle(self):
"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):
Expand Down Expand Up @@ -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

0 comments on commit 6dc9b82

Please sign in to comment.