mergify[bot] da5bf501eb
feat: auto reserve stock for Sales Order on purchase (backport #37603) (#37648)
* chore: make `Reserve Stock` checkbox visible in SO

(cherry picked from commit 36a996d70499a8bc4cf9c28853c2b5606d73f81d)

* refactor: rename field `Auto Reserve Stock for Sales Order`

(cherry picked from commit 2b4fa98941817966b8a936e4076be84406ad035a)

* feat: add fields to hold SO and SO Item ref in PR Item

(cherry picked from commit 188175be84b5eaa0be73face69f4f2b58b80dd64)

* feat: reserve stock for SO on PR submission

(cherry picked from commit 64497c922892d19ca378b5da75cf6b528f5e52d9)

# Conflicts:
#	erpnext/stock/doctype/purchase_receipt/purchase_receipt.py

* feat: add field `From Voucher Type` in SRE

(cherry picked from commit 5ae9c2f62b741d64da4ce74b3b251339711e8256)

* refactor: rename field `against_pick_list_item`

(cherry picked from commit 78fe56741931ad2c253bf9acca2896c2411f4ac6)

* refactor: rename field `against_pick_list`

(cherry picked from commit 961d2d9926a1a9c0396c3292d431d3bad6865e62)

* fix: incorrect serial and batch get reserved

(cherry picked from commit 45395027d3b5c51ac3ccdbebb1f0d23d5ffd2ec1)

* fix: partial reservation against SBB

(cherry picked from commit 4f363f5bf3da286999966f10d0cca22264f42199)

* fix: ignore qty msg if From Voucher is set

(cherry picked from commit a432290a828478265a8a463d05aea818c2b75914)

* test: add test case for auto-reservation from PR

(cherry picked from commit adf313a6d3308f957b4876574e455ca750b22106)

* chore: add SRE link in PR Connections

(cherry picked from commit 24788ddcc085fb825d2b14145a82ced02842f512)

* chore: patch to update `From Voucher` details

(cherry picked from commit 6942ab10125cfaf07c526df53a7c88bffcc5b9da)

* chore: `conflicts`

* fix(patch): `update_sre_from_voucher_details`

---------

Co-authored-by: s-aga-r <sagarsharma.s312@gmail.com>
2023-10-24 12:39:05 +05:30

199 lines
3.9 KiB
Python

# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
import frappe
from frappe import _
from frappe.query_builder.functions import Date
def execute(filters=None):
columns, data = [], []
validate_filters(filters)
columns = get_columns()
data = get_data(filters)
return columns, data
def validate_filters(filters):
if not filters:
frappe.throw(_("Please set filters"))
for field in ["company", "from_date", "to_date"]:
if not filters.get(field):
frappe.throw(_("Please set {0}").format(field))
if filters.get("from_date") > filters.get("to_date"):
frappe.throw(_("From Date cannot be greater than To Date"))
def get_data(filters):
sre = frappe.qb.DocType("Stock Reservation Entry")
query = (
frappe.qb.from_(sre)
.select(
sre.creation,
sre.warehouse,
sre.item_code,
sre.stock_uom,
sre.voucher_qty,
sre.reserved_qty,
sre.delivered_qty,
(sre.available_qty - sre.reserved_qty).as_("available_qty"),
sre.voucher_type,
sre.voucher_no,
sre.from_voucher_type,
sre.from_voucher_no,
sre.name.as_("stock_reservation_entry"),
sre.status,
sre.project,
sre.company,
)
.where(
(sre.docstatus == 1)
& (sre.company == filters.get("company"))
& (
(Date(sre.creation) >= filters.get("from_date"))
& (Date(sre.creation) <= filters.get("to_date"))
)
)
)
for field in [
"item_code",
"warehouse",
"voucher_type",
"voucher_no",
"from_voucher_type",
"from_voucher_no",
"reservation_based_on",
"status",
"project",
]:
if value := filters.get(field):
query = query.where((sre[field] == value))
if value := filters.get("stock_reservation_entry"):
query = query.where((sre.name == value))
data = query.run(as_list=True)
return data
def get_columns():
columns = [
{
"label": _("Date"),
"fieldname": "date",
"fieldtype": "Datetime",
"width": 150,
},
{
"fieldname": "warehouse",
"label": _("Warehouse"),
"fieldtype": "Link",
"options": "Warehouse",
"width": 150,
},
{
"fieldname": "item_code",
"label": _("Item"),
"fieldtype": "Link",
"options": "Item",
"width": 100,
},
{
"fieldname": "stock_uom",
"label": _("Stock UOM"),
"fieldtype": "Link",
"options": "UOM",
"width": 100,
},
{
"fieldname": "voucher_qty",
"label": _("Voucher Qty"),
"fieldtype": "Float",
"width": 110,
"convertible": "qty",
},
{
"fieldname": "reserved_qty",
"label": _("Reserved Qty"),
"fieldtype": "Float",
"width": 110,
"convertible": "qty",
},
{
"fieldname": "delivered_qty",
"label": _("Delivered Qty"),
"fieldtype": "Float",
"width": 110,
"convertible": "qty",
},
{
"fieldname": "available_qty",
"label": _("Available Qty to Reserve"),
"fieldtype": "Float",
"width": 120,
"convertible": "qty",
},
{
"fieldname": "voucher_type",
"label": _("Voucher Type"),
"fieldtype": "Data",
"width": 110,
},
{
"fieldname": "voucher_no",
"label": _("Voucher No"),
"fieldtype": "Dynamic Link",
"options": "voucher_type",
"width": 120,
},
{
"fieldname": "from_voucher_type",
"label": _("From Voucher Type"),
"fieldtype": "Data",
"width": 110,
},
{
"fieldname": "from_voucher_no",
"label": _("From Voucher No"),
"fieldtype": "Dynamic Link",
"options": "from_voucher_type",
"width": 120,
},
{
"fieldname": "stock_reservation_entry",
"label": _("Stock Reservation Entry"),
"fieldtype": "Link",
"options": "Stock Reservation Entry",
"width": 150,
},
{
"fieldname": "status",
"label": _("Status"),
"fieldtype": "Data",
"width": 120,
},
{
"fieldname": "project",
"label": _("Project"),
"fieldtype": "Link",
"options": "Project",
"width": 100,
},
{
"fieldname": "company",
"label": _("Company"),
"fieldtype": "Link",
"options": "Company",
"width": 110,
},
]
return columns