feat(batch): Add total quantity and dashboard to Batch
This commit is contained in:
parent
6c36cddbd3
commit
658ed14e40
@ -663,3 +663,4 @@ erpnext.patches.v12_0.move_bank_account_swift_number_to_bank
|
||||
erpnext.patches.v12_0.rename_bank_reconciliation_fields # 2020-01-22
|
||||
erpnext.patches.v12_0.set_received_qty_in_material_request_as_per_stock_uom
|
||||
erpnext.patches.v12_0.recalculate_requested_qty_in_bin
|
||||
erpnext.patches.v12_0.set_total_batch_quantity
|
||||
|
7
erpnext/patches/v12_0/set_total_batch_quantity.py
Normal file
7
erpnext/patches/v12_0/set_total_batch_quantity.py
Normal file
@ -0,0 +1,7 @@
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
for batch in frappe.get_all("Batch", fields=["name", "batch_id"]):
|
||||
batch_qty = frappe.db.get_value("Stock Ledger Entry", {"docstatus": 1, "batch_no": batch.batch_id}, "sum(actual_qty)")
|
||||
frappe.db.set_value("Batch", batch.name, "batch_qty", batch_qty, update_modified=False)
|
File diff suppressed because it is too large
Load Diff
@ -111,11 +111,15 @@ class Batch(Document):
|
||||
|
||||
def validate(self):
|
||||
self.item_has_batch_enabled()
|
||||
self.calculate_batch_qty()
|
||||
|
||||
def item_has_batch_enabled(self):
|
||||
if frappe.db.get_value("Item", self.item, "has_batch_no") == 0:
|
||||
frappe.throw(_("The selected item cannot have Batch"))
|
||||
|
||||
def calculate_batch_qty(self):
|
||||
self.batch_qty = frappe.db.get_value("Stock Ledger Entry", {"batch_no": self.batch_id}, "sum(actual_qty)")
|
||||
|
||||
def before_save(self):
|
||||
has_expiry_date, shelf_life_in_days = frappe.db.get_value('Item', self.item, ['has_expiry_date', 'shelf_life_in_days'])
|
||||
if not self.expiry_date and has_expiry_date and shelf_life_in_days:
|
||||
|
27
erpnext/stock/doctype/batch/batch_dashboard.py
Normal file
27
erpnext/stock/doctype/batch/batch_dashboard.py
Normal file
@ -0,0 +1,27 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from frappe import _
|
||||
|
||||
|
||||
def get_data():
|
||||
return {
|
||||
'fieldname': 'batch_no',
|
||||
'transactions': [
|
||||
{
|
||||
'label': _('Buy'),
|
||||
'items': ['Purchase Invoice', 'Purchase Receipt']
|
||||
},
|
||||
{
|
||||
'label': _('Sell'),
|
||||
'items': ['Sales Invoice', 'Delivery Note']
|
||||
},
|
||||
{
|
||||
'label': _('Move'),
|
||||
'items': ['Stock Entry']
|
||||
},
|
||||
{
|
||||
'label': _('Quality'),
|
||||
'items': ['Quality Inspection']
|
||||
}
|
||||
]
|
||||
}
|
@ -1,12 +1,18 @@
|
||||
frappe.listview_settings['Batch'] = {
|
||||
add_fields: ["item", "expiry_date"],
|
||||
get_indicator: function(doc) {
|
||||
if(doc.expiry_date && frappe.datetime.get_diff(doc.expiry_date, frappe.datetime.nowdate()) <= 0) {
|
||||
return [__("Expired"), "red", "expiry_date,>=,Today"]
|
||||
} else if(doc.expiry_date) {
|
||||
return [__("Not Expired"), "green", "expiry_date,<,Today"]
|
||||
add_fields: ["item", "expiry_date", "batch_qty"],
|
||||
get_indicator: function (doc) {
|
||||
if (!doc.batch_qty) {
|
||||
return ["Empty", "darkgrey", "batch_qty,=,0"];
|
||||
} else {
|
||||
return ["Not Set", "darkgrey", ""];
|
||||
}
|
||||
if (doc.expiry_date) {
|
||||
if (frappe.datetime.get_diff(doc.expiry_date, frappe.datetime.nowdate()) <= 0) {
|
||||
return [__("Expired"), "red", "expiry_date,>=,Today|batch_qty,>,0"]
|
||||
} else {
|
||||
return [__("Not Expired"), "green", "expiry_date,<,Today|batch_qty,>,0"]
|
||||
}
|
||||
} else {
|
||||
return ["Active", "green", "batch_qty,>,0"];
|
||||
};
|
||||
};
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user