mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
refactor: set actual and projected qty in Packed Item and Sales Invoice Item
This commit is contained in:
@@ -1025,23 +1025,11 @@ class SalesInvoice(SellingController):
|
|||||||
frappe.throw(_("Could not update stock, invoice contains drop shipping item."))
|
frappe.throw(_("Could not update stock, invoice contains drop shipping item."))
|
||||||
|
|
||||||
def update_current_stock(self):
|
def update_current_stock(self):
|
||||||
for d in self.get("items"):
|
for item in self.items:
|
||||||
if d.item_code and d.warehouse:
|
item.set_actual_qty()
|
||||||
bin = frappe.db.sql(
|
|
||||||
"select actual_qty from `tabBin` where item_code = %s and warehouse = %s",
|
|
||||||
(d.item_code, d.warehouse),
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
d.actual_qty = bin and flt(bin[0]["actual_qty"]) or 0
|
|
||||||
|
|
||||||
for d in self.get("packed_items"):
|
for packed_item in self.packed_items:
|
||||||
bin = frappe.db.sql(
|
packed_item.set_actual_and_projected_qty()
|
||||||
"select actual_qty, projected_qty from `tabBin` where item_code = %s and warehouse = %s",
|
|
||||||
(d.item_code, d.warehouse),
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
d.actual_qty = bin and flt(bin[0]["actual_qty"]) or 0
|
|
||||||
d.projected_qty = bin and flt(bin[0]["projected_qty"]) or 0
|
|
||||||
|
|
||||||
def update_packing_list(self):
|
def update_packing_list(self):
|
||||||
if cint(self.update_stock) == 1:
|
if cint(self.update_stock) == 1:
|
||||||
|
|||||||
@@ -102,3 +102,12 @@ class SalesInvoiceItem(Document):
|
|||||||
frappe.bold(self.idx), frappe.bold(self.cost_center), frappe.bold(company)
|
frappe.bold(self.idx), frappe.bold(self.cost_center), frappe.bold(company)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def set_actual_qty(self):
|
||||||
|
if self.item_code and self.warehouse:
|
||||||
|
self.actual_qty = (
|
||||||
|
frappe.db.get_value(
|
||||||
|
"Bin", {"item_code": self.item_code, "warehouse": self.warehouse}, "actual_qty"
|
||||||
|
)
|
||||||
|
or 0
|
||||||
|
)
|
||||||
|
|||||||
@@ -51,7 +51,16 @@ class PackedItem(Document):
|
|||||||
warehouse: DF.Link | None
|
warehouse: DF.Link | None
|
||||||
# end: auto-generated types
|
# end: auto-generated types
|
||||||
|
|
||||||
pass
|
def set_actual_and_projected_qty(self):
|
||||||
|
"Set actual and projected qty based on warehouse and item_code"
|
||||||
|
_bin = frappe.db.get_value(
|
||||||
|
"Bin",
|
||||||
|
{"item_code": self.item_code, "warehouse": self.warehouse},
|
||||||
|
["actual_qty", "projected_qty"],
|
||||||
|
as_dict=True,
|
||||||
|
)
|
||||||
|
self.actual_qty = _bin.actual_qty if _bin else 0
|
||||||
|
self.projected_qty = _bin.projected_qty if _bin else 0
|
||||||
|
|
||||||
|
|
||||||
def make_packing_list(doc):
|
def make_packing_list(doc):
|
||||||
|
|||||||
Reference in New Issue
Block a user