From 6465711ca65923c83752c97fc9f1ed07a7d56061 Mon Sep 17 00:00:00 2001 From: robert schouten Date: Mon, 12 Sep 2016 11:17:14 +0800 Subject: [PATCH 1/3] [fix] missing gl entries warnings --- erpnext/controllers/stock_controller.py | 16 ++++++--- .../stock/doctype/stock_entry/stock_entry.py | 33 +++++++++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 3f25e0222f..aa849295f3 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -276,12 +276,18 @@ def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for def compare_existing_and_expected_gle(existing_gle, expected_gle): matched = True for entry in expected_gle: + account_existed = False for e in existing_gle: - if entry.account==e.account and entry.against_account==e.against_account \ - and (not entry.cost_center or not e.cost_center or entry.cost_center==e.cost_center) \ - and (entry.debit != e.debit or entry.credit != e.credit): - matched = False - break + if entry.account == e.account: + account_existed = True + if entry.account == e.account and entry.against_account == e.against_account \ + and (not entry.cost_center or not e.cost_center or entry.cost_center == e.cost_center) \ + and (entry.debit != e.debit or entry.credit != e.credit): + matched = False + break + if not account_existed: + matched = False + break return matched def get_future_stock_vouchers(posting_date, posting_time, for_warehouses=None, for_items=None): diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index e35f3d2965..bf0782f7c5 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -36,6 +36,7 @@ class StockEntry(StockController): self.pro_doc = frappe.get_doc('Production Order', self.production_order) self.validate_posting_time() + self.validate_posting_date() self.validate_purpose() self.validate_item() self.set_transfer_qty() @@ -65,6 +66,38 @@ class StockEntry(StockController): self.update_production_order() self.make_gl_entries_on_cancel() + def validate_posting_date(self): + allow_negative_stock = cint(frappe.db.get_value("Stock Settings", None, "allow_negative_stock")) + items, warehouses = self.get_items_and_warehouses() + previous_stock_vouchers = self.get_previous_stock_vouchers(self.posting_date, self.posting_time, warehouses, + items) + + if allow_negative_stock and previous_stock_vouchers: + for voucher_type, voucher_no in previous_stock_vouchers: + frappe.msgprint( + _("The posting date is after {0}: {1}, this will cause missing data in the General Ledger").format( + voucher_type, voucher_no)) + + def get_previous_stock_vouchers(self, posting_date, posting_time, for_warehouses=None, for_items=None): + previous_stock_vouchers = [] + + values = [] + condition = "" + + if for_items: + condition += " and item_code in ({})".format(", ".join(["%s"] * len(for_items))) + values += for_items + + for d in frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no + from `tabStock Ledger Entry` sle + where timestamp(sle.posting_date, sle.posting_time) <= timestamp(%s, %s) {condition} + and warehouse = "Finished Goods - IAG" + order by timestamp(sle.posting_date, sle.posting_time) asc, name asc""".format(condition=condition), + tuple([posting_date, posting_time] + values), as_dict=True): + previous_stock_vouchers.append([d.voucher_type, d.voucher_no]) + + return previous_stock_vouchers + def validate_purpose(self): valid_purposes = ["Material Issue", "Material Receipt", "Material Transfer", "Material Transfer for Manufacture", "Manufacture", "Repack", "Subcontract"] From 7157b2f286a829b8bfb2e36001841978d8111b23 Mon Sep 17 00:00:00 2001 From: robert schouten Date: Mon, 12 Sep 2016 11:17:14 +0800 Subject: [PATCH 2/3] warnings for prevent stock entries after sales invoice --- erpnext/stock/doctype/stock_entry/stock_entry.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index bf0782f7c5..d44ef57a8f 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -85,15 +85,15 @@ class StockEntry(StockController): condition = "" if for_items: - condition += " and item_code in ({})".format(", ".join(["%s"] * len(for_items))) + condition += " and item_code in ({})".format(", ".join(["%(item_code)s"] * len(for_items))) values += for_items for d in frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no from `tabStock Ledger Entry` sle - where timestamp(sle.posting_date, sle.posting_time) <= timestamp(%s, %s) {condition} - and warehouse = "Finished Goods - IAG" + where timestamp(sle.posting_date, sle.posting_time) <= timestamp(%(date)s, %(time)s) {condition} + and warehouse = %(warehouse)s order by timestamp(sle.posting_date, sle.posting_time) asc, name asc""".format(condition=condition), - tuple([posting_date, posting_time] + values), as_dict=True): + {"warehouse":for_warehouses,"date":posting_date,"time":posting_time,"item_code":values}, as_dict=1): previous_stock_vouchers.append([d.voucher_type, d.voucher_no]) return previous_stock_vouchers From e5eed00aa5b496ab1ddc1b82a0b869a6a268c4dc Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 17 Oct 2016 17:37:35 +0530 Subject: [PATCH 3/3] Update stock_entry.py --- .../stock/doctype/stock_entry/stock_entry.py | 33 ------------------- 1 file changed, 33 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index d44ef57a8f..e35f3d2965 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -36,7 +36,6 @@ class StockEntry(StockController): self.pro_doc = frappe.get_doc('Production Order', self.production_order) self.validate_posting_time() - self.validate_posting_date() self.validate_purpose() self.validate_item() self.set_transfer_qty() @@ -66,38 +65,6 @@ class StockEntry(StockController): self.update_production_order() self.make_gl_entries_on_cancel() - def validate_posting_date(self): - allow_negative_stock = cint(frappe.db.get_value("Stock Settings", None, "allow_negative_stock")) - items, warehouses = self.get_items_and_warehouses() - previous_stock_vouchers = self.get_previous_stock_vouchers(self.posting_date, self.posting_time, warehouses, - items) - - if allow_negative_stock and previous_stock_vouchers: - for voucher_type, voucher_no in previous_stock_vouchers: - frappe.msgprint( - _("The posting date is after {0}: {1}, this will cause missing data in the General Ledger").format( - voucher_type, voucher_no)) - - def get_previous_stock_vouchers(self, posting_date, posting_time, for_warehouses=None, for_items=None): - previous_stock_vouchers = [] - - values = [] - condition = "" - - if for_items: - condition += " and item_code in ({})".format(", ".join(["%(item_code)s"] * len(for_items))) - values += for_items - - for d in frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no - from `tabStock Ledger Entry` sle - where timestamp(sle.posting_date, sle.posting_time) <= timestamp(%(date)s, %(time)s) {condition} - and warehouse = %(warehouse)s - order by timestamp(sle.posting_date, sle.posting_time) asc, name asc""".format(condition=condition), - {"warehouse":for_warehouses,"date":posting_date,"time":posting_time,"item_code":values}, as_dict=1): - previous_stock_vouchers.append([d.voucher_type, d.voucher_no]) - - return previous_stock_vouchers - def validate_purpose(self): valid_purposes = ["Material Issue", "Material Receipt", "Material Transfer", "Material Transfer for Manufacture", "Manufacture", "Repack", "Subcontract"]