From f1dd923a501989d0718a7ddc84b1f10397e77711 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Thu, 26 Jan 2023 12:51:58 +0530 Subject: [PATCH 01/53] fix: `amount` in `Material Request` (cherry picked from commit 6b781d78e0cfb256621d8b40bc21ed144b75f501) --- erpnext/stock/doctype/material_request/material_request.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js index 5f05de6991b2..156e5917f23c 100644 --- a/erpnext/stock/doctype/material_request/material_request.js +++ b/erpnext/stock/doctype/material_request/material_request.js @@ -366,10 +366,11 @@ frappe.ui.form.on('Material Request', { frappe.ui.form.on("Material Request Item", { qty: function (frm, doctype, name) { - var d = locals[doctype][name]; - if (flt(d.qty) < flt(d.min_order_qty)) { + const item = locals[doctype][name]; + if (flt(item.qty) < flt(item.min_order_qty)) { frappe.msgprint(__("Warning: Material Requested Qty is less than Minimum Order Qty")); } + frm.events.get_item_data(frm, item, false); }, from_warehouse: function(frm, doctype, name) { From a5d09270cbeb118afcea4d362c2d8ac91b1d955b Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Sat, 21 Jan 2023 11:28:23 +0530 Subject: [PATCH 02/53] refactor: rewrite `get_picked_items_qty` query in `QB` (cherry picked from commit 29bf787313092e7a261479af36110613c7d0357b) --- erpnext/stock/doctype/pick_list/pick_list.py | 39 +++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index 808f19e2740e..caafcdda3319 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -347,28 +347,23 @@ def _compute_picked_qty_for_bundle(self, bundle_row, bundle_items) -> int: def get_picked_items_qty(items) -> List[Dict]: - return frappe.db.sql( - f""" - SELECT - sales_order_item, - item_code, - sales_order, - SUM(stock_qty) AS stock_qty, - SUM(picked_qty) AS picked_qty - FROM - `tabPick List Item` - WHERE - sales_order_item IN ( - {", ".join(frappe.db.escape(d) for d in items)} - ) - AND docstatus = 1 - GROUP BY - sales_order_item, - sales_order - FOR UPDATE - """, - as_dict=1, - ) + pi_item = frappe.qb.DocType("Pick List Item") + return ( + frappe.qb.from_(pi_item) + .select( + pi_item.sales_order_item, + pi_item.item_code, + pi_item.sales_order, + Sum(pi_item.stock_qty).as_("stock_qty"), + Sum(pi_item.picked_qty).as_("picked_qty"), + ) + .where((pi_item.docstatus == 1) & (pi_item.sales_order_item.isin(items))) + .groupby( + pi_item.sales_order_item, + pi_item.sales_order, + ) + .for_update() + ).run(as_dict=True) def validate_item_locations(pick_list): From 167a5596cbfb485ea0567994765eae2715325c4f Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Sat, 21 Jan 2023 12:15:45 +0530 Subject: [PATCH 03/53] refactor: rewrite `get_available_item_locations_for_other_item` query in `QB` (cherry picked from commit 58dd40a2d7915c6b4ae99b72e8d35915394b57f6) --- erpnext/stock/doctype/pick_list/pick_list.py | 25 ++++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index caafcdda3319..4f111a2aa951 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -555,23 +555,22 @@ def get_available_item_locations_for_serial_and_batched_item( def get_available_item_locations_for_other_item(item_code, from_warehouses, required_qty, company): - # gets all items available in different warehouses - warehouses = [x.get("name") for x in frappe.get_list("Warehouse", {"company": company}, "name")] - - filters = frappe._dict( - {"item_code": item_code, "warehouse": ["in", warehouses], "actual_qty": [">", 0]} + bin = frappe.qb.DocType("Bin") + query = ( + frappe.qb.from_(bin) + .select(bin.warehouse, bin.actual_qty.as_("qty")) + .where((bin.item_code == item_code) & (bin.actual_qty > 0)) + .orderby(bin.creation) + .limit(cint(required_qty)) ) if from_warehouses: - filters.warehouse = ["in", from_warehouses] + query = query.where(bin.warehouse.isin(from_warehouses)) + else: + wh = frappe.qb.DocType("Warehouse") + query = query.from_(wh).where((bin.warehouse == wh.name) & (wh.company == company)) - item_locations = frappe.get_all( - "Bin", - fields=["warehouse", "actual_qty as qty"], - filters=filters, - limit=required_qty, - order_by="creation", - ) + item_locations = query.run(as_dict=True) return item_locations From d9d986a5123aaca2c1afeffd45c38d0739e43d17 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Sat, 21 Jan 2023 12:45:39 +0530 Subject: [PATCH 04/53] refactor: rewrite `get_available_item_locations_for_serialized_item` query in `QB` (cherry picked from commit 5b76e8b19370eb76471f6b59873900d9f2977959) --- erpnext/stock/doctype/pick_list/pick_list.py | 26 +++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index 4f111a2aa951..f053474b28f1 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -11,7 +11,7 @@ from frappe.model.document import Document from frappe.model.mapper import map_child_doc from frappe.query_builder import Case -from frappe.query_builder.functions import IfNull, Locate, Sum +from frappe.query_builder.functions import Coalesce, IfNull, Locate, Sum from frappe.utils import cint, floor, flt, today from frappe.utils.nestedset import get_descendants_of @@ -470,19 +470,21 @@ def get_available_item_locations( def get_available_item_locations_for_serialized_item( item_code, from_warehouses, required_qty, company ): - filters = frappe._dict({"item_code": item_code, "company": company, "warehouse": ["!=", ""]}) + sn = frappe.qb.DocType("Serial No") + query = ( + frappe.qb.from_(sn) + .select(sn.name, sn.warehouse) + .where((sn.item_code == item_code) & (sn.company == company)) + .orderby(sn.purchase_date) + .limit(cint(required_qty)) + ) if from_warehouses: - filters.warehouse = ["in", from_warehouses] - - serial_nos = frappe.get_all( - "Serial No", - fields=["name", "warehouse"], - filters=filters, - limit=required_qty, - order_by="purchase_date", - as_list=1, - ) + query = query.where(sn.warehouse.isin(from_warehouses)) + else: + query = query.where(Coalesce(sn.warehouse, "") != "") + + serial_nos = query.run(as_list=True) warehouse_serial_nos_map = frappe._dict() for serial_no, warehouse in serial_nos: From 6166a6e64f143d6b4f41b48a91b08d85b11abaea Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Sat, 21 Jan 2023 14:05:51 +0530 Subject: [PATCH 05/53] refactor: rewrite `get_available_item_locations_for_serial_and_batched_item` query in `QB` (cherry picked from commit 57c32166831912603b283208ff08c9fdffcb0d95) --- erpnext/stock/doctype/pick_list/pick_list.py | 37 +++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index f053474b28f1..4e5705710051 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -534,24 +534,27 @@ def get_available_item_locations_for_serial_and_batched_item( item_code, from_warehouses, required_qty, company ) - filters = frappe._dict( - {"item_code": item_code, "company": company, "warehouse": ["!=", ""], "batch_no": ""} - ) - - # Get Serial Nos by FIFO for Batch No - for location in locations: - filters.batch_no = location.batch_no - filters.warehouse = location.warehouse - location.qty = ( - required_qty if location.qty > required_qty else location.qty - ) # if extra qty in batch - - serial_nos = frappe.get_list( - "Serial No", fields=["name"], filters=filters, limit=location.qty, order_by="purchase_date" - ) + if locations: + sn = frappe.qb.DocType("Serial No") + conditions = (sn.item_code == item_code) & (sn.company == company) + + for location in locations: + location.qty = ( + required_qty if location.qty > required_qty else location.qty + ) # if extra qty in batch + + serial_nos = ( + frappe.qb.from_(sn) + .select(sn.name) + .where( + (conditions) & (sn.batch_no == location.batch_no) & (sn.warehouse == location.warehouse) + ) + .orderby(sn.purchase_date) + .limit(cint(location.qty)) + ).run(as_dict=True) - serial_nos = [sn.name for sn in serial_nos] - location.serial_no = serial_nos + serial_nos = [sn.name for sn in serial_nos] + location.serial_no = serial_nos return locations From 140be10060a27e299b1bc5738f6a14d8ffbbb049 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Sat, 21 Jan 2023 20:58:47 +0530 Subject: [PATCH 06/53] chore: add method `get_picked_items_details()` (cherry picked from commit 9ae3a54ce96e1bce5d32fadb25fbc3da399f838a) --- erpnext/stock/doctype/pick_list/pick_list.py | 44 ++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index 4e5705710051..e572540a04c2 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -162,6 +162,7 @@ def validate_picked_qty(self, data): def set_item_locations(self, save=False): self.validate_for_qty() items = self.aggregate_item_qty() + picked_items_details = self.get_picked_items_details(items) self.item_location_map = frappe._dict() from_warehouses = None @@ -309,6 +310,49 @@ def update_bundle_picked_qty(self): already_picked + (picked_qty * (1 if self.docstatus == 1 else -1)), ) + def get_picked_items_details(self, items): + picked_items = frappe._dict() + + pi_item = frappe.qb.DocType("Pick List Item") + query = ( + frappe.qb.from_(pi_item) + .select( + pi_item.item_code, + pi_item.warehouse, + pi_item.batch_no, + pi_item.serial_no, + Sum(pi_item.picked_qty).as_("picked_qty"), + ) + .where( + (pi_item.item_code.isin([x.item_code for x in items])) + & (pi_item.docstatus != 2) + & (pi_item.picked_qty > 0) + ) + .groupby( + pi_item.item_code, + pi_item.warehouse, + pi_item.batch_no, + ) + ) + + if self.name: + query = query.where(pi_item.parent != self.name) + + items_data = query.run(as_dict=True) + + for item_data in items_data: + key = (item_data.warehouse, item_data.batch_no) if item_data.batch_no else item_data.warehouse + serial_no = [x for x in item_data.serial_no.split("\n") if x] if item_data.serial_no else None + data = {"picked_qty": item_data.picked_qty} + if serial_no: + data["serial_no"] = serial_no + if item_data.item_code not in picked_items: + picked_items[item_data.item_code] = {key: data} + else: + picked_items[item_data.item_code][key] = data + + return picked_items + def _get_product_bundles(self) -> Dict[str, str]: # Dict[so_item_row: item_code] product_bundles = {} From 466a791f68643cae1d2f1323039e786aace9be77 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Mon, 23 Jan 2023 13:51:07 +0530 Subject: [PATCH 07/53] fix: consider existing pick list (cherry picked from commit b642718f08472294b6cc1cbdd5d344dcc0f5059d) --- erpnext/stock/doctype/pick_list/pick_list.py | 76 ++++++++++++++++---- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index e572540a04c2..7b75bb0ffd3a 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -181,7 +181,11 @@ def set_item_locations(self, save=False): self.item_location_map.setdefault( item_code, get_available_item_locations( - item_code, from_warehouses, self.item_count_map.get(item_code), self.company + item_code, + from_warehouses, + self.item_count_map.get(item_code), + self.company, + picked_item_details=picked_items_details.get(item_code), ), ) @@ -473,31 +477,38 @@ def get_items_with_location_and_quantity(item_doc, item_location_map, docstatus) def get_available_item_locations( - item_code, from_warehouses, required_qty, company, ignore_validation=False + item_code, + from_warehouses, + required_qty, + company, + ignore_validation=False, + picked_item_details=None, ): locations = [] + total_picked_qty = ( + sum([v.get("picked_qty") for k, v in picked_item_details.items()]) if picked_item_details else 0 + ) has_serial_no = frappe.get_cached_value("Item", item_code, "has_serial_no") has_batch_no = frappe.get_cached_value("Item", item_code, "has_batch_no") if has_batch_no and has_serial_no: locations = get_available_item_locations_for_serial_and_batched_item( - item_code, from_warehouses, required_qty, company + item_code, from_warehouses, required_qty, company, total_picked_qty ) elif has_serial_no: locations = get_available_item_locations_for_serialized_item( - item_code, from_warehouses, required_qty, company + item_code, from_warehouses, required_qty, company, total_picked_qty ) elif has_batch_no: locations = get_available_item_locations_for_batched_item( - item_code, from_warehouses, required_qty, company + item_code, from_warehouses, required_qty, company, total_picked_qty ) else: locations = get_available_item_locations_for_other_item( - item_code, from_warehouses, required_qty, company + item_code, from_warehouses, required_qty, company, total_picked_qty ) total_qty_available = sum(location.get("qty") for location in locations) - remaining_qty = required_qty - total_qty_available if remaining_qty > 0 and not ignore_validation: @@ -508,11 +519,44 @@ def get_available_item_locations( title=_("Insufficient Stock"), ) + if picked_item_details: + for location in list(locations): + key = ( + (location["warehouse"], location["batch_no"]) + if location.get("batch_no") + else location["warehouse"] + ) + + if key in picked_item_details: + picked_detail = picked_item_details[key] + + if picked_detail.get("serial_no") and location.get("serial_no"): + location["serial_no"] = list( + set(location["serial_no"]).difference(set(picked_detail["serial_no"])) + ) + location["qty"] = len(location["serial_no"]) + else: + location["qty"] -= picked_detail.get("picked_qty") + + if location["qty"] < 1: + locations.remove(location) + + total_qty_available = sum(location.get("qty") for location in locations) + remaining_qty = required_qty - total_qty_available + + if remaining_qty > 0 and not ignore_validation: + frappe.msgprint( + _("{0} units of Item {1} is picked in another Pick List.").format( + remaining_qty, frappe.get_desk_link("Item", item_code) + ), + title=_("Already Picked"), + ) + return locations def get_available_item_locations_for_serialized_item( - item_code, from_warehouses, required_qty, company + item_code, from_warehouses, required_qty, company, total_picked_qty=0 ): sn = frappe.qb.DocType("Serial No") query = ( @@ -520,7 +564,7 @@ def get_available_item_locations_for_serialized_item( .select(sn.name, sn.warehouse) .where((sn.item_code == item_code) & (sn.company == company)) .orderby(sn.purchase_date) - .limit(cint(required_qty)) + .limit(cint(required_qty + total_picked_qty)) ) if from_warehouses: @@ -542,7 +586,7 @@ def get_available_item_locations_for_serialized_item( def get_available_item_locations_for_batched_item( - item_code, from_warehouses, required_qty, company + item_code, from_warehouses, required_qty, company, total_picked_qty=0 ): sle = frappe.qb.DocType("Stock Ledger Entry") batch = frappe.qb.DocType("Batch") @@ -562,6 +606,7 @@ def get_available_item_locations_for_batched_item( .groupby(sle.warehouse, sle.batch_no, sle.item_code) .having(Sum(sle.actual_qty) > 0) .orderby(IfNull(batch.expiry_date, "2200-01-01"), batch.creation, sle.batch_no, sle.warehouse) + .limit(cint(required_qty + total_picked_qty)) ) if from_warehouses: @@ -571,7 +616,7 @@ def get_available_item_locations_for_batched_item( def get_available_item_locations_for_serial_and_batched_item( - item_code, from_warehouses, required_qty, company + item_code, from_warehouses, required_qty, company, total_picked_qty=0 ): # Get batch nos by FIFO locations = get_available_item_locations_for_batched_item( @@ -594,23 +639,26 @@ def get_available_item_locations_for_serial_and_batched_item( (conditions) & (sn.batch_no == location.batch_no) & (sn.warehouse == location.warehouse) ) .orderby(sn.purchase_date) - .limit(cint(location.qty)) + .limit(cint(location.qty + total_picked_qty)) ).run(as_dict=True) serial_nos = [sn.name for sn in serial_nos] location.serial_no = serial_nos + location.qty = len(serial_nos) return locations -def get_available_item_locations_for_other_item(item_code, from_warehouses, required_qty, company): +def get_available_item_locations_for_other_item( + item_code, from_warehouses, required_qty, company, total_picked_qty=0 +): bin = frappe.qb.DocType("Bin") query = ( frappe.qb.from_(bin) .select(bin.warehouse, bin.actual_qty.as_("qty")) .where((bin.item_code == item_code) & (bin.actual_qty > 0)) .orderby(bin.creation) - .limit(cint(required_qty)) + .limit(cint(required_qty + total_picked_qty)) ) if from_warehouses: From e8d617ada216dc699e6c68bc75106f3602056e0b Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Tue, 24 Jan 2023 11:10:29 +0530 Subject: [PATCH 08/53] chore: add `status` field in `Pick List` (cherry picked from commit be41052dc80e731bc058bcc4ca3ea0632658b3ea) # Conflicts: # erpnext/patches.txt --- erpnext/patches.txt | 4 ++ erpnext/patches/v14_0/set_pick_list_status.py | 40 +++++++++++++++++++ .../doctype/delivery_note/delivery_note.py | 6 +++ .../stock/doctype/pick_list/pick_list.json | 22 ++++++++-- erpnext/stock/doctype/pick_list/pick_list.py | 23 +++++++++++ .../stock/doctype/pick_list/pick_list_list.js | 14 +++++++ .../stock/doctype/stock_entry/stock_entry.py | 6 +++ 7 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 erpnext/patches/v14_0/set_pick_list_status.py create mode 100644 erpnext/stock/doctype/pick_list/pick_list_list.js diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 9dcb9c1bcae5..d9734c90fe4f 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -325,4 +325,8 @@ erpnext.patches.v14_0.setup_clear_repost_logs erpnext.patches.v14_0.create_accounting_dimensions_for_payment_request erpnext.patches.v14_0.update_entry_type_for_journal_entry erpnext.patches.v14_0.change_autoname_for_tax_withheld_vouchers +<<<<<<< HEAD erpnext.patches.v14_0.update_asset_value_for_manual_depr_entries +======= +erpnext.patches.v14_0.set_pick_list_status +>>>>>>> be41052dc8 (chore: add `status` field in `Pick List`) diff --git a/erpnext/patches/v14_0/set_pick_list_status.py b/erpnext/patches/v14_0/set_pick_list_status.py new file mode 100644 index 000000000000..eea5745c23a9 --- /dev/null +++ b/erpnext/patches/v14_0/set_pick_list_status.py @@ -0,0 +1,40 @@ +# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors +# License: MIT. See LICENSE + + +import frappe +from pypika.terms import ExistsCriterion + + +def execute(): + pl = frappe.qb.DocType("Pick List") + se = frappe.qb.DocType("Stock Entry") + dn = frappe.qb.DocType("Delivery Note") + + ( + frappe.qb.update(pl).set( + pl.status, + ( + frappe.qb.terms.Case() + .when(pl.docstatus == 0, "Draft") + .when(pl.docstatus == 2, "Cancelled") + .else_("Completed") + ), + ) + ).run() + + ( + frappe.qb.update(pl) + .set(pl.status, "Open") + .where( + ( + ExistsCriterion( + frappe.qb.from_(se).select(se.name).where((se.docstatus == 1) & (se.pick_list == pl.name)) + ) + | ExistsCriterion( + frappe.qb.from_(dn).select(dn.name).where((dn.docstatus == 1) & (dn.pick_list == pl.name)) + ) + ).negate() + & (pl.docstatus == 1) + ) + ).run() diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index a1df764ea9d2..9f9f5cbe2a4c 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -228,6 +228,7 @@ def update_current_stock(self): def on_submit(self): self.validate_packed_qty() + self.update_pick_list_status() # Check for Approving Authority frappe.get_doc("Authorization Control").validate_approving_authority( @@ -313,6 +314,11 @@ def validate_packed_qty(self): if has_error: raise frappe.ValidationError + def update_pick_list_status(self): + from erpnext.stock.doctype.pick_list.pick_list import update_pick_list_status + + update_pick_list_status(self.pick_list) + def check_next_docstatus(self): submit_rv = frappe.db.sql( """select t1.name diff --git a/erpnext/stock/doctype/pick_list/pick_list.json b/erpnext/stock/doctype/pick_list/pick_list.json index e1c3f0f50618..7259dc00a81b 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.json +++ b/erpnext/stock/doctype/pick_list/pick_list.json @@ -26,7 +26,8 @@ "locations", "amended_from", "print_settings_section", - "group_same_items" + "group_same_items", + "status" ], "fields": [ { @@ -168,11 +169,26 @@ "fieldtype": "Data", "label": "Customer Name", "read_only": 1 + }, + { + "default": "Draft", + "fieldname": "status", + "fieldtype": "Select", + "hidden": 1, + "in_standard_filter": 1, + "label": "Status", + "no_copy": 1, + "options": "Draft\nOpen\nCompleted\nCancelled", + "print_hide": 1, + "read_only": 1, + "report_hide": 1, + "reqd": 1, + "search_index": 1 } ], "is_submittable": 1, "links": [], - "modified": "2022-07-19 11:03:04.442174", + "modified": "2023-01-24 10:33:43.244476", "modified_by": "Administrator", "module": "Stock", "name": "Pick List", @@ -244,4 +260,4 @@ "sort_order": "DESC", "states": [], "track_changes": 1 -} +} \ No newline at end of file diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index 7b75bb0ffd3a..07961d035361 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -77,15 +77,32 @@ def validate_picked_items(self): ) def on_submit(self): + self.update_status() self.update_bundle_picked_qty() self.update_reference_qty() self.update_sales_order_picking_status() def on_cancel(self): + self.update_status() self.update_bundle_picked_qty() self.update_reference_qty() self.update_sales_order_picking_status() + def update_status(self, status=None, update_modified=True): + if not status: + if self.docstatus == 0: + status = "Draft" + elif self.docstatus == 1: + if self.status == "Draft": + status = "Open" + elif target_document_exists(self.name, self.purpose): + status = "Completed" + elif self.docstatus == 2: + status = "Cancelled" + + if status: + frappe.db.set_value("Pick List", self.name, "status", status, update_modified=update_modified) + def update_reference_qty(self): packed_items = [] so_items = [] @@ -394,6 +411,12 @@ def _compute_picked_qty_for_bundle(self, bundle_row, bundle_items) -> int: return int(flt(min(possible_bundles), precision or 6)) +def update_pick_list_status(pick_list): + if pick_list: + doc = frappe.get_doc("Pick List", pick_list) + doc.run_method("update_status") + + def get_picked_items_qty(items) -> List[Dict]: pi_item = frappe.qb.DocType("Pick List Item") return ( diff --git a/erpnext/stock/doctype/pick_list/pick_list_list.js b/erpnext/stock/doctype/pick_list/pick_list_list.js new file mode 100644 index 000000000000..ad88b0a682f5 --- /dev/null +++ b/erpnext/stock/doctype/pick_list/pick_list_list.js @@ -0,0 +1,14 @@ +// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.listview_settings['Pick List'] = { + get_indicator: function (doc) { + const status_colors = { + "Draft": "grey", + "Open": "orange", + "Completed": "green", + "Cancelled": "red", + }; + return [__(doc.status), status_colors[doc.status], "status,=," + doc.status]; + }, +}; \ No newline at end of file diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index d90a74f7b4ad..9a2473170458 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -161,6 +161,7 @@ def on_submit(self): self.validate_subcontract_order() self.update_subcontract_order_supplied_items() self.update_subcontracting_order_status() + self.update_pick_list_status() self.make_gl_entries() @@ -2279,6 +2280,11 @@ def update_subcontracting_order_status(self): update_subcontracting_order_status(self.subcontracting_order) + def update_pick_list_status(self): + from erpnext.stock.doctype.pick_list.pick_list import update_pick_list_status + + update_pick_list_status(self.pick_list) + def set_missing_values(self): "Updates rate and availability of all the items of mapped doc." self.set_transfer_qty() From 7afbd9201d328fa13170453bd120c6c04a7cec04 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Tue, 24 Jan 2023 14:45:19 +0530 Subject: [PATCH 09/53] fix: `get_picked_items_details` (cherry picked from commit 7b3d496ce0d8e9fba103e2df281709e7aa3c750f) --- erpnext/stock/doctype/pick_list/pick_list.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index 07961d035361..38878484495c 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -11,7 +11,8 @@ from frappe.model.document import Document from frappe.model.mapper import map_child_doc from frappe.query_builder import Case -from frappe.query_builder.functions import Coalesce, IfNull, Locate, Sum +from frappe.query_builder.custom import GROUP_CONCAT +from frappe.query_builder.functions import Coalesce, IfNull, Locate, Replace, Sum from frappe.utils import cint, floor, flt, today from frappe.utils.nestedset import get_descendants_of @@ -334,20 +335,24 @@ def update_bundle_picked_qty(self): def get_picked_items_details(self, items): picked_items = frappe._dict() + pi = frappe.qb.DocType("Pick List") pi_item = frappe.qb.DocType("Pick List Item") query = ( - frappe.qb.from_(pi_item) + frappe.qb.from_(pi) + .inner_join(pi_item) + .on(pi.name == pi_item.parent) .select( pi_item.item_code, pi_item.warehouse, pi_item.batch_no, - pi_item.serial_no, Sum(pi_item.picked_qty).as_("picked_qty"), + Replace(GROUP_CONCAT(pi_item.serial_no), ",", "\n").as_("serial_no"), ) .where( (pi_item.item_code.isin([x.item_code for x in items])) & (pi_item.docstatus != 2) & (pi_item.picked_qty > 0) + & (pi.status != "Completed") ) .groupby( pi_item.item_code, From aa3dd33f5626b8cbae54ba4f9ca97e1acefc9779 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Thu, 26 Jan 2023 18:10:05 +0530 Subject: [PATCH 10/53] fix: `pymysql.err.ProgrammingError` (cherry picked from commit 5138ef0160a72e19dfa3b11b4d662c68e79badb1) --- erpnext/stock/doctype/pick_list/pick_list.py | 75 ++++++++++---------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index 38878484495c..79c6891f5d2b 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -335,47 +335,48 @@ def update_bundle_picked_qty(self): def get_picked_items_details(self, items): picked_items = frappe._dict() - pi = frappe.qb.DocType("Pick List") - pi_item = frappe.qb.DocType("Pick List Item") - query = ( - frappe.qb.from_(pi) - .inner_join(pi_item) - .on(pi.name == pi_item.parent) - .select( - pi_item.item_code, - pi_item.warehouse, - pi_item.batch_no, - Sum(pi_item.picked_qty).as_("picked_qty"), - Replace(GROUP_CONCAT(pi_item.serial_no), ",", "\n").as_("serial_no"), - ) - .where( - (pi_item.item_code.isin([x.item_code for x in items])) - & (pi_item.docstatus != 2) - & (pi_item.picked_qty > 0) - & (pi.status != "Completed") - ) - .groupby( - pi_item.item_code, - pi_item.warehouse, - pi_item.batch_no, + if items: + pi = frappe.qb.DocType("Pick List") + pi_item = frappe.qb.DocType("Pick List Item") + query = ( + frappe.qb.from_(pi) + .inner_join(pi_item) + .on(pi.name == pi_item.parent) + .select( + pi_item.item_code, + pi_item.warehouse, + pi_item.batch_no, + Sum(pi_item.picked_qty).as_("picked_qty"), + Replace(GROUP_CONCAT(pi_item.serial_no), ",", "\n").as_("serial_no"), + ) + .where( + (pi_item.item_code.isin([x.item_code for x in items])) + & (pi_item.docstatus != 2) + & (pi_item.picked_qty > 0) + & (pi.status != "Completed") + ) + .groupby( + pi_item.item_code, + pi_item.warehouse, + pi_item.batch_no, + ) ) - ) - if self.name: - query = query.where(pi_item.parent != self.name) + if self.name: + query = query.where(pi_item.parent != self.name) - items_data = query.run(as_dict=True) + items_data = query.run(as_dict=True) - for item_data in items_data: - key = (item_data.warehouse, item_data.batch_no) if item_data.batch_no else item_data.warehouse - serial_no = [x for x in item_data.serial_no.split("\n") if x] if item_data.serial_no else None - data = {"picked_qty": item_data.picked_qty} - if serial_no: - data["serial_no"] = serial_no - if item_data.item_code not in picked_items: - picked_items[item_data.item_code] = {key: data} - else: - picked_items[item_data.item_code][key] = data + for item_data in items_data: + key = (item_data.warehouse, item_data.batch_no) if item_data.batch_no else item_data.warehouse + serial_no = [x for x in item_data.serial_no.split("\n") if x] if item_data.serial_no else None + data = {"picked_qty": item_data.picked_qty} + if serial_no: + data["serial_no"] = serial_no + if item_data.item_code not in picked_items: + picked_items[item_data.item_code] = {key: data} + else: + picked_items[item_data.item_code][key] = data return picked_items From 7124c0ca30f26c715766b6d1363a4f041e082fac Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Fri, 27 Jan 2023 10:09:20 +0530 Subject: [PATCH 11/53] fix(test): `test_pick_list_for_items_with_multiple_UOM()` (cherry picked from commit 207eeefc857a6e4c136c7971d9a637452adcc395) --- erpnext/stock/doctype/pick_list/test_pick_list.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/stock/doctype/pick_list/test_pick_list.py b/erpnext/stock/doctype/pick_list/test_pick_list.py index 43acdf083601..c93b8ce87da5 100644 --- a/erpnext/stock/doctype/pick_list/test_pick_list.py +++ b/erpnext/stock/doctype/pick_list/test_pick_list.py @@ -414,6 +414,7 @@ def test_pick_list_for_items_with_multiple_UOM(self): pick_list.submit() delivery_note = create_delivery_note(pick_list.name) + pick_list.load_from_db() self.assertEqual(pick_list.locations[0].qty, delivery_note.items[0].qty) self.assertEqual(pick_list.locations[1].qty, delivery_note.items[1].qty) From cdb6abf569b498897dfa56bce9dbe94d2933e167 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Sat, 28 Jan 2023 13:22:10 +0530 Subject: [PATCH 12/53] test: add test cases (cherry picked from commit bb7fe795fe0117cf042f22807f4827f6b027772b) --- .../stock/doctype/pick_list/test_pick_list.py | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/erpnext/stock/doctype/pick_list/test_pick_list.py b/erpnext/stock/doctype/pick_list/test_pick_list.py index c93b8ce87da5..9f8d2d71106b 100644 --- a/erpnext/stock/doctype/pick_list/test_pick_list.py +++ b/erpnext/stock/doctype/pick_list/test_pick_list.py @@ -664,3 +664,138 @@ def test_picklist_with_partial_bundles(self): self.assertEqual(dn.items[0].rate, 42) so.reload() self.assertEqual(so.per_delivered, 100) + + def test_pick_list_status(self): + warehouse = "_Test Warehouse - _TC" + item = make_item(properties={"maintain_stock": 1}).name + make_stock_entry(item=item, to_warehouse=warehouse, qty=10) + + so = make_sales_order(item_code=item, qty=10, rate=100) + + pl = create_pick_list(so.name) + pl.save() + pl.reload() + self.assertEqual(pl.status, "Draft") + + pl.submit() + pl.reload() + self.assertEqual(pl.status, "Open") + + dn = create_delivery_note(pl.name) + dn.save() + pl.reload() + self.assertEqual(pl.status, "Open") + + dn.submit() + pl.reload() + self.assertEqual(pl.status, "Completed") + + dn.cancel() + pl.reload() + self.assertEqual(pl.status, "Completed") + + pl.cancel() + pl.reload() + self.assertEqual(pl.status, "Cancelled") + + def test_consider_existing_pick_list(self): + # Step - 1: Setup - Create Items and Stock Entries + items_properties = [ + { + "valuation_rate": 100, + }, + { + "valuation_rate": 200, + "has_batch_no": 1, + "create_new_batch": 1, + }, + { + "valuation_rate": 300, + "has_serial_no": 1, + "serial_no_series": "SNO.###", + }, + { + "valuation_rate": 400, + "has_batch_no": 1, + "create_new_batch": 1, + "has_serial_no": 1, + "serial_no_series": "SNO.###", + }, + ] + + items = [] + for properties in items_properties: + properties.update({"maintain_stock": 1}) + item_code = make_item(properties=properties).name + properties.update({"item_code": item_code}) + items.append(properties) + + warehouses = ["Stores - _TC", "Finished Goods - _TC"] + for item in items: + for warehouse in warehouses: + se = make_stock_entry( + item=item.get("item_code"), + to_warehouse=warehouse, + qty=5, + ) + + # Step - 2: Create Sales Order [1] + item_list = [ + { + "item_code": item.get("item_code"), + "qty": 6, + "warehouse": "All Warehouses - _TC", + } + for item in items + ] + so1 = make_sales_order(item_list=item_list) + + # Step - 3: Create and Submit Pick List [1] for Sales Order [1] + pl1 = create_pick_list(so1.name) + pl1.submit() + + # Step - 4: Create Sales Order [2] with same Item(s) as Sales Order [1] + item_list = [ + { + "item_code": item.get("item_code"), + "qty": 4, + "warehouse": "All Warehouses - _TC", + } + for item in items + ] + so2 = make_sales_order(item_list=item_list) + + # Step - 5: Create Pick List [2] for Sales Order [2] + pl2 = create_pick_list(so2.name) + pl2.save() + + # Step - 6: Assert + items_data = {} + for location in pl1.locations: + key = (location.warehouse, location.batch_no) if location.batch_no else location.warehouse + serial_no = [x for x in location.serial_no.split("\n") if x] if location.serial_no else None + data = {"picked_qty": location.picked_qty} + if serial_no: + data["serial_no"] = serial_no + if location.item_code not in items_data: + items_data[location.item_code] = {key: data} + else: + items_data[location.item_code][key] = data + + for location in pl2.locations: + key = (location.warehouse, location.batch_no) if location.batch_no else location.warehouse + item_data = items_data.get(location.item_code, {}).get(key, {}) + picked_qty = item_data.get("picked_qty", 0) + picked_serial_no = items_data.get("serial_no", []) + bin_actual_qty = frappe.db.get_value( + "Bin", {"item_code": location.item_code, "warehouse": location.warehouse}, "actual_qty" + ) + + # Available Qty to pick should be equal to [Actual Qty - Picked Qty] + self.assertEqual(location.stock_qty, bin_actual_qty - picked_qty) + + # Serial No should not be in the Picked Serial No list + if location.serial_no: + a = set(picked_serial_no) + b = set([x for x in location.serial_no.split("\n") if x]) + self.assertSetEqual(b, b.difference(a)) From 4f56c72bedafb8e802abfef4a7aaf34db24f9af7 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Sat, 28 Jan 2023 17:45:08 +0530 Subject: [PATCH 13/53] refactor: `test_consider_existing_pick_list()` (cherry picked from commit 0b76a26c8a660f21f38b2511586a6ea5d816fb0e) --- .../stock/doctype/pick_list/test_pick_list.py | 101 ++++++++++-------- 1 file changed, 55 insertions(+), 46 deletions(-) diff --git a/erpnext/stock/doctype/pick_list/test_pick_list.py b/erpnext/stock/doctype/pick_list/test_pick_list.py index 9f8d2d71106b..1254fe3927fa 100644 --- a/erpnext/stock/doctype/pick_list/test_pick_list.py +++ b/erpnext/stock/doctype/pick_list/test_pick_list.py @@ -699,6 +699,54 @@ def test_pick_list_status(self): self.assertEqual(pl.status, "Cancelled") def test_consider_existing_pick_list(self): + def create_items(items_properties): + items = [] + + for properties in items_properties: + properties.update({"maintain_stock": 1}) + item_code = make_item(properties=properties).name + properties.update({"item_code": item_code}) + items.append(properties) + + return items + + def create_stock_entries(items): + warehouses = ["Stores - _TC", "Finished Goods - _TC"] + + for item in items: + for warehouse in warehouses: + se = make_stock_entry( + item=item.get("item_code"), + to_warehouse=warehouse, + qty=5, + ) + + def get_item_list(items, qty, warehouse="All Warehouses - _TC"): + return [ + { + "item_code": item.get("item_code"), + "qty": qty, + "warehouse": warehouse, + } + for item in items + ] + + def get_picked_items_details(pick_list_doc): + items_data = {} + + for location in pick_list_doc.locations: + key = (location.warehouse, location.batch_no) if location.batch_no else location.warehouse + serial_no = [x for x in location.serial_no.split("\n") if x] if location.serial_no else None + data = {"picked_qty": location.picked_qty} + if serial_no: + data["serial_no"] = serial_no + if location.item_code not in items_data: + items_data[location.item_code] = {key: data} + else: + items_data[location.item_code][key] = data + + return items_data + # Step - 1: Setup - Create Items and Stock Entries items_properties = [ { @@ -723,70 +771,31 @@ def test_consider_existing_pick_list(self): }, ] - items = [] - for properties in items_properties: - properties.update({"maintain_stock": 1}) - item_code = make_item(properties=properties).name - properties.update({"item_code": item_code}) - items.append(properties) - - warehouses = ["Stores - _TC", "Finished Goods - _TC"] - for item in items: - for warehouse in warehouses: - se = make_stock_entry( - item=item.get("item_code"), - to_warehouse=warehouse, - qty=5, - ) + items = create_items(items_properties) + create_stock_entries(items) # Step - 2: Create Sales Order [1] - item_list = [ - { - "item_code": item.get("item_code"), - "qty": 6, - "warehouse": "All Warehouses - _TC", - } - for item in items - ] - so1 = make_sales_order(item_list=item_list) + so1 = make_sales_order(item_list=get_item_list(items, qty=6)) # Step - 3: Create and Submit Pick List [1] for Sales Order [1] pl1 = create_pick_list(so1.name) pl1.submit() # Step - 4: Create Sales Order [2] with same Item(s) as Sales Order [1] - item_list = [ - { - "item_code": item.get("item_code"), - "qty": 4, - "warehouse": "All Warehouses - _TC", - } - for item in items - ] - so2 = make_sales_order(item_list=item_list) + so2 = make_sales_order(item_list=get_item_list(items, qty=4)) # Step - 5: Create Pick List [2] for Sales Order [2] pl2 = create_pick_list(so2.name) pl2.save() # Step - 6: Assert - items_data = {} - for location in pl1.locations: - key = (location.warehouse, location.batch_no) if location.batch_no else location.warehouse - serial_no = [x for x in location.serial_no.split("\n") if x] if location.serial_no else None - data = {"picked_qty": location.picked_qty} - if serial_no: - data["serial_no"] = serial_no - if location.item_code not in items_data: - items_data[location.item_code] = {key: data} - else: - items_data[location.item_code][key] = data + picked_items_details = get_picked_items_details(pl1) for location in pl2.locations: key = (location.warehouse, location.batch_no) if location.batch_no else location.warehouse - item_data = items_data.get(location.item_code, {}).get(key, {}) + item_data = picked_items_details.get(location.item_code, {}).get(key, {}) picked_qty = item_data.get("picked_qty", 0) - picked_serial_no = items_data.get("serial_no", []) + picked_serial_no = picked_items_details.get("serial_no", []) bin_actual_qty = frappe.db.get_value( "Bin", {"item_code": location.item_code, "warehouse": location.warehouse}, "actual_qty" ) From df72e4a2217337d3815808a7bf7fba75eab643ea Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Tue, 31 Jan 2023 14:33:21 +0530 Subject: [PATCH 14/53] fix: consider `stock_qty` if `picked_qty` is zero (cherry picked from commit 6ffdeb1af8dc9debf63f15d8f1844a7fb1a35d40) --- erpnext/stock/doctype/pick_list/pick_list.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index 79c6891f5d2b..bf3b5ddc54a4 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -346,14 +346,16 @@ def get_picked_items_details(self, items): pi_item.item_code, pi_item.warehouse, pi_item.batch_no, - Sum(pi_item.picked_qty).as_("picked_qty"), + Sum(Case().when(pi_item.picked_qty > 0, pi_item.picked_qty).else_(pi_item.stock_qty)).as_( + "picked_qty" + ), Replace(GROUP_CONCAT(pi_item.serial_no), ",", "\n").as_("serial_no"), ) .where( (pi_item.item_code.isin([x.item_code for x in items])) - & (pi_item.docstatus != 2) - & (pi_item.picked_qty > 0) + & ((pi_item.picked_qty > 0) | (pi_item.stock_qty > 0)) & (pi.status != "Completed") + & (pi_item.docstatus != 2) ) .groupby( pi_item.item_code, From 3aca84c43f4e843802f94ee1e44e57090385c50b Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 31 Jan 2023 14:19:14 +0530 Subject: [PATCH 15/53] feat: mandatory and mandatory depends on in inventory dimension (cherry picked from commit 423f2b5627ce2fc20424665aec0a3d4321d013e5) --- .../inventory_dimension.js | 2 +- .../inventory_dimension.json | 22 ++++++++++++++++++- .../inventory_dimension.py | 4 ++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/inventory_dimension/inventory_dimension.js b/erpnext/stock/doctype/inventory_dimension/inventory_dimension.js index ba1023ac691f..0310682a2c17 100644 --- a/erpnext/stock/doctype/inventory_dimension/inventory_dimension.js +++ b/erpnext/stock/doctype/inventory_dimension/inventory_dimension.js @@ -37,7 +37,7 @@ frappe.ui.form.on('Inventory Dimension', { if (frm.doc.__onload && frm.doc.__onload.has_stock_ledger && frm.doc.__onload.has_stock_ledger.length) { let allow_to_edit_fields = ['disabled', 'fetch_from_parent', - 'type_of_transaction', 'condition']; + 'type_of_transaction', 'condition', 'mandatory_depends_on']; frm.fields.forEach((field) => { if (!in_list(allow_to_edit_fields, field.df.fieldname)) { diff --git a/erpnext/stock/doctype/inventory_dimension/inventory_dimension.json b/erpnext/stock/doctype/inventory_dimension/inventory_dimension.json index 4397e11f540c..eb6102a436e3 100644 --- a/erpnext/stock/doctype/inventory_dimension/inventory_dimension.json +++ b/erpnext/stock/doctype/inventory_dimension/inventory_dimension.json @@ -24,6 +24,9 @@ "istable", "applicable_condition_example_section", "condition", + "conditional_mandatory_section", + "reqd", + "mandatory_depends_on", "conditional_rule_examples_section", "html_19" ], @@ -153,11 +156,28 @@ "fieldname": "conditional_rule_examples_section", "fieldtype": "Section Break", "label": "Conditional Rule Examples" + }, + { + "description": "To apply condition on parent field use parent.field_name and to apply condition on child table use doc.field_name. Here field_name could be based on the actual column name of the respective field.", + "fieldname": "mandatory_depends_on", + "fieldtype": "Small Text", + "label": "Mandatory Depends On" + }, + { + "fieldname": "conditional_mandatory_section", + "fieldtype": "Section Break", + "label": "Mandatory Section" + }, + { + "default": "0", + "fieldname": "reqd", + "fieldtype": "Check", + "label": "Mandatory" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2022-11-15 15:50:16.767105", + "modified": "2023-01-31 13:44:38.507698", "modified_by": "Administrator", "module": "Stock", "name": "Inventory Dimension", diff --git a/erpnext/stock/doctype/inventory_dimension/inventory_dimension.py b/erpnext/stock/doctype/inventory_dimension/inventory_dimension.py index 009548abf26d..db2b5d0a6b60 100644 --- a/erpnext/stock/doctype/inventory_dimension/inventory_dimension.py +++ b/erpnext/stock/doctype/inventory_dimension/inventory_dimension.py @@ -126,6 +126,8 @@ def add_custom_fields(self): insert_after="inventory_dimension", options=self.reference_document, label=self.dimension_name, + reqd=self.reqd, + mandatory_depends_on=self.mandatory_depends_on, ), ] @@ -142,6 +144,8 @@ def add_custom_fields(self): "Custom Field", {"dt": "Stock Ledger Entry", "fieldname": self.target_fieldname} ) and not field_exists("Stock Ledger Entry", self.target_fieldname): dimension_field = dimension_fields[1] + dimension_field["mandatory_depends_on"] = "" + dimension_field["reqd"] = 0 dimension_field["fieldname"] = self.target_fieldname custom_fields["Stock Ledger Entry"] = dimension_field From f47b05f58c02020ae2c08f6730dbf8c8d2c81685 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 31 Jan 2023 14:36:26 +0530 Subject: [PATCH 16/53] test: added test case (cherry picked from commit 22d0e1373b0b8b4e457c936eb2383723f931a9cb) --- .../test_inventory_dimension.py | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/erpnext/stock/doctype/inventory_dimension/test_inventory_dimension.py b/erpnext/stock/doctype/inventory_dimension/test_inventory_dimension.py index edff3fd556c1..28b1ed96f0d4 100644 --- a/erpnext/stock/doctype/inventory_dimension/test_inventory_dimension.py +++ b/erpnext/stock/doctype/inventory_dimension/test_inventory_dimension.py @@ -85,6 +85,9 @@ def test_inventory_dimension(self): condition="parent.purpose == 'Material Issue'", ) + inv_dim1.reqd = 0 + inv_dim1.save() + create_inventory_dimension( reference_document="Shelf", type_of_transaction="Inward", @@ -205,6 +208,48 @@ def test_check_standard_dimensions(self): ) ) + def test_check_mandatory_dimensions(self): + doc = create_inventory_dimension( + reference_document="Pallet", + type_of_transaction="Outward", + dimension_name="Pallet", + apply_to_all_doctypes=0, + document_type="Stock Entry Detail", + ) + + doc.reqd = 1 + doc.save() + + self.assertTrue( + frappe.db.get_value( + "Custom Field", {"fieldname": "pallet", "dt": "Stock Entry Detail", "reqd": 1}, "name" + ) + ) + + doc.load_from_db + doc.reqd = 0 + doc.save() + + def test_check_mandatory_depends_on_dimensions(self): + doc = create_inventory_dimension( + reference_document="Pallet", + type_of_transaction="Outward", + dimension_name="Pallet", + apply_to_all_doctypes=0, + document_type="Stock Entry Detail", + ) + + doc.mandatory_depends_on = "t_warehouse" + doc.save() + + self.assertTrue( + frappe.db.get_value( + "Custom Field", + {"fieldname": "pallet", "dt": "Stock Entry Detail", "mandatory_depends_on": "t_warehouse"}, + "name", + ) + ) + def prepare_test_data(): if not frappe.db.exists("DocType", "Shelf"): @@ -251,6 +296,22 @@ def prepare_test_data(): create_warehouse("Rack Warehouse") + if not frappe.db.exists("DocType", "Pallet"): + frappe.get_doc( + { + "doctype": "DocType", + "name": "Pallet", + "module": "Stock", + "custom": 1, + "naming_rule": "By fieldname", + "autoname": "field:pallet_name", + "fields": [{"label": "Pallet Name", "fieldname": "pallet_name", "fieldtype": "Data"}], + "permissions": [ + {"role": "System Manager", "permlevel": 0, "read": 1, "write": 1, "create": 1, "delete": 1} + ], + } + ).insert(ignore_permissions=True) + def create_inventory_dimension(**args): args = frappe._dict(args) From 075c547184daa2754e2a64a9f45a68cec3f3c39e Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Tue, 31 Jan 2023 16:14:45 +0530 Subject: [PATCH 17/53] chore: conflicts --- erpnext/patches.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index d9734c90fe4f..54957cd22283 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -325,8 +325,5 @@ erpnext.patches.v14_0.setup_clear_repost_logs erpnext.patches.v14_0.create_accounting_dimensions_for_payment_request erpnext.patches.v14_0.update_entry_type_for_journal_entry erpnext.patches.v14_0.change_autoname_for_tax_withheld_vouchers -<<<<<<< HEAD erpnext.patches.v14_0.update_asset_value_for_manual_depr_entries -======= -erpnext.patches.v14_0.set_pick_list_status ->>>>>>> be41052dc8 (chore: add `status` field in `Pick List`) +erpnext.patches.v14_0.set_pick_list_status \ No newline at end of file From 68a1615eae49a0d237bb358d650b3c8e80806da2 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Tue, 31 Jan 2023 23:23:54 +0100 Subject: [PATCH 18/53] feat: add incoterm named place to RFQ (cherry picked from commit 7156184933fb80b1c7f9a68914126e31ee352a55) --- .../request_for_quotation/request_for_quotation.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json index 019d45b5683e..bd65b0c805e8 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json @@ -29,6 +29,7 @@ "message_for_supplier", "terms_section_break", "incoterm", + "named_place", "tc_name", "terms", "printing_settings", @@ -278,13 +279,19 @@ "fieldtype": "Link", "label": "Incoterm", "options": "Incoterm" + }, + { + "depends_on": "incoterm", + "fieldname": "named_place", + "fieldtype": "Data", + "label": "Named Place" } ], "icon": "fa fa-shopping-cart", "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2022-11-17 17:26:33.770993", + "modified": "2023-01-31 23:22:06.684694", "modified_by": "Administrator", "module": "Buying", "name": "Request for Quotation", From 01ff6a1f1995e619de90ba861c7b6dd0bf79af94 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 1 Feb 2023 15:38:12 +0530 Subject: [PATCH 19/53] fix: incorrect actual qty in Bin (cherry picked from commit f8c852c54ccf7a33d26e15378b76557ceffd77e5) --- erpnext/stock/doctype/bin/bin.py | 7 ++++++- erpnext/stock/stock_ledger.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py index 9f409d4b96a0..72654e6f8168 100644 --- a/erpnext/stock/doctype/bin/bin.py +++ b/erpnext/stock/doctype/bin/bin.py @@ -159,13 +159,18 @@ def update_qty(bin_name, args): last_sle_qty = ( frappe.qb.from_(sle) .select(sle.qty_after_transaction) - .where((sle.item_code == args.get("item_code")) & (sle.warehouse == args.get("warehouse"))) + .where( + (sle.item_code == args.get("item_code")) + & (sle.warehouse == args.get("warehouse")) + & (sle.is_cancelled == 0) + ) .orderby(CombineDatetime(sle.posting_date, sle.posting_time), order=Order.desc) .orderby(sle.creation, order=Order.desc) .limit(1) .run() ) + actual_qty = 0.0 if last_sle_qty: actual_qty = last_sle_qty[0][0] diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 5d75bfd05a3f..d8b12ed5b92a 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -1179,7 +1179,7 @@ def get_stock_ledger_entries( def get_sle_by_voucher_detail_no(voucher_detail_no, excluded_sle=None): return frappe.db.get_value( "Stock Ledger Entry", - {"voucher_detail_no": voucher_detail_no, "name": ["!=", excluded_sle]}, + {"voucher_detail_no": voucher_detail_no, "name": ["!=", excluded_sle], "is_cancelled": 0}, [ "item_code", "warehouse", From c191a3f7c6ec48269f9b0b6c774297ced9db129a Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Sat, 21 Jan 2023 13:28:22 +0530 Subject: [PATCH 20/53] perf: reduce memory usage while migrating remarks Page through records using primary key (cherry picked from commit 9bb64107c568bf64a121bf31596d69e9d1910f09) --- ...grate_remarks_from_gl_to_payment_ledger.py | 151 ++++++++++-------- 1 file changed, 84 insertions(+), 67 deletions(-) diff --git a/erpnext/patches/v14_0/migrate_remarks_from_gl_to_payment_ledger.py b/erpnext/patches/v14_0/migrate_remarks_from_gl_to_payment_ledger.py index fd2a2a39cc68..9d216c4028c5 100644 --- a/erpnext/patches/v14_0/migrate_remarks_from_gl_to_payment_ledger.py +++ b/erpnext/patches/v14_0/migrate_remarks_from_gl_to_payment_ledger.py @@ -1,81 +1,98 @@ import frappe from frappe import qb -from frappe.utils import create_batch - - -def remove_duplicate_entries(pl_entries): - unique_vouchers = set() - for x in pl_entries: - unique_vouchers.add( - (x.company, x.account, x.party_type, x.party, x.voucher_type, x.voucher_no, x.gle_remarks) - ) - - entries = [] - for x in unique_vouchers: - entries.append( - frappe._dict( - company=x[0], - account=x[1], - party_type=x[2], - party=x[3], - voucher_type=x[4], - voucher_no=x[5], - gle_remarks=x[6], - ) - ) - return entries +from frappe.query_builder import CustomFunction +from frappe.query_builder.functions import Count, IfNull +from frappe.utils import flt def execute(): + """ + Migrate 'remarks' field from 'tabGL Entry' to 'tabPayment Ledger Entry' + """ + if frappe.reload_doc("accounts", "doctype", "payment_ledger_entry"): gle = qb.DocType("GL Entry") ple = qb.DocType("Payment Ledger Entry") - # get ple and their remarks from GL Entry - pl_entries = ( - qb.from_(ple) - .left_join(gle) - .on( - (ple.account == gle.account) - & (ple.party_type == gle.party_type) - & (ple.party == gle.party) - & (ple.voucher_type == gle.voucher_type) - & (ple.voucher_no == gle.voucher_no) - & (ple.company == gle.company) - ) - .select( - ple.company, - ple.account, - ple.party_type, - ple.party, - ple.voucher_type, - ple.voucher_no, - gle.remarks.as_("gle_remarks"), - ) - .where((ple.delinked == 0) & (gle.is_cancelled == 0)) - .run(as_dict=True) - ) - - pl_entries = remove_duplicate_entries(pl_entries) - - if pl_entries: - # split into multiple batches, update and commit for each batch + # Get empty PLE records + un_processed = ( + qb.from_(ple).select(Count(ple.name)).where((ple.remarks.isnull()) & (ple.delinked == 0)).run() + )[0][0] + + if un_processed: + print(f"Remarks for {un_processed} Payment Ledger records will be updated from GL Entry") + + ifelse = CustomFunction("IF", ["condition", "then", "else"]) + + processed = 0 + last_percent_update = 0 batch_size = 1000 - for batch in create_batch(pl_entries, batch_size): - for entry in batch: - query = ( - qb.update(ple) - .set(ple.remarks, entry.gle_remarks) - .where( - (ple.company == entry.company) - & (ple.account == entry.account) - & (ple.party_type == entry.party_type) - & (ple.party == entry.party) - & (ple.voucher_type == entry.voucher_type) - & (ple.voucher_no == entry.voucher_no) + last_name = None + + while True: + if last_name: + where_clause = (ple.name.gt(last_name)) & (ple.remarks.isnull()) & (ple.delinked == 0) + else: + where_clause = (ple.remarks.isnull()) & (ple.delinked == 0) + + # results are deterministic + names = ( + qb.from_(ple).select(ple.name).where(where_clause).orderby(ple.name).limit(batch_size).run() + ) + + if names: + last_name = names[-1][0] + + pl_entries = ( + qb.from_(ple) + .left_join(gle) + .on( + (ple.account == gle.account) + & (ple.party_type == gle.party_type) + & (ple.party == gle.party) + & (ple.voucher_type == gle.voucher_type) + & (ple.voucher_no == gle.voucher_no) + & ( + ple.against_voucher_type + == IfNull( + ifelse(gle.against_voucher_type == "", None, gle.against_voucher_type), gle.voucher_type + ) + ) + & ( + ple.against_voucher_no + == IfNull(ifelse(gle.against_voucher == "", None, gle.against_voucher), gle.voucher_no) + ) + & (ple.company == gle.company) + & ( + ((ple.account_type == "Receivable") & (ple.amount == (gle.debit - gle.credit))) + | (ple.account_type == "Payable") & (ple.amount == (gle.credit - gle.debit)) + ) + & (gle.remarks.notnull()) + & (gle.is_cancelled == 0) + ) + .select(ple.name) + .distinct() + .select( + gle.remarks.as_("gle_remarks"), ) + .where(ple.name.isin(names)) + .run(as_dict=True) ) - query.run() - frappe.db.commit() + if pl_entries: + for entry in pl_entries: + query = qb.update(ple).set(ple.remarks, entry.gle_remarks).where((ple.name == entry.name)) + query.run() + + frappe.db.commit() + + processed += len(pl_entries) + percentage = flt((processed / un_processed) * 100, 2) + if percentage - last_percent_update > 1: + print(f"{percentage}% ({processed}) PLE records updated") + last_percent_update = percentage + + else: + break + print("Remarks succesfully migrated") From 3ce8dc70cbdfab46789480b1e70f818bc6a328a3 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 20 Jan 2023 15:32:16 +0530 Subject: [PATCH 21/53] perf: reduce memory usage by paging through records While migrating GL entries to Payment Ledger, page through records using primary key to reduce memory usage. (cherry picked from commit fee0ca8cd9a629389335af7b12fc80bf3cebf7fb) --- .../v14_0/migrate_gl_to_payment_ledger.py | 147 ++++++++++++------ 1 file changed, 97 insertions(+), 50 deletions(-) diff --git a/erpnext/patches/v14_0/migrate_gl_to_payment_ledger.py b/erpnext/patches/v14_0/migrate_gl_to_payment_ledger.py index e15aa4a1f41e..853a99a48959 100644 --- a/erpnext/patches/v14_0/migrate_gl_to_payment_ledger.py +++ b/erpnext/patches/v14_0/migrate_gl_to_payment_ledger.py @@ -2,7 +2,8 @@ from frappe import qb from frappe.query_builder import Case, CustomFunction from frappe.query_builder.custom import ConstantColumn -from frappe.query_builder.functions import IfNull +from frappe.query_builder.functions import Count, IfNull +from frappe.utils import flt from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import ( get_dimensions, @@ -17,9 +18,9 @@ def create_accounting_dimension_fields(): make_dimension_in_accounting_doctypes(dimension, ["Payment Ledger Entry"]) -def generate_name_for_payment_ledger_entries(gl_entries): - for index, entry in enumerate(gl_entries, 1): - entry.name = index +def generate_name_for_payment_ledger_entries(gl_entries, start): + for index, entry in enumerate(gl_entries, 0): + entry.name = start + index def get_columns(): @@ -81,6 +82,14 @@ def insert_chunk_into_payment_ledger(insert_query, gl_entries): def execute(): + """ + Description: + Migrate records from `tabGL Entry` to `tabPayment Ledger Entry`. + Patch is non-resumable. if patch failed or is terminatted abnormally, clear 'tabPayment Ledger Entry' table manually before re-running. Re-running is safe only during V13->V14 update. + + Note: Post successful migration to V14, re-running is NOT-SAFE and SHOULD NOT be attempted. + """ + if frappe.reload_doc("accounts", "doctype", "payment_ledger_entry"): # create accounting dimension fields in Payment Ledger create_accounting_dimension_fields() @@ -89,52 +98,90 @@ def execute(): account = qb.DocType("Account") ifelse = CustomFunction("IF", ["condition", "then", "else"]) - gl_entries = ( + # Get Records Count + accounts = ( + qb.from_(account) + .select(account.name) + .where((account.account_type == "Receivable") | (account.account_type == "Payable")) + .orderby(account.name) + ) + un_processed = ( qb.from_(gl) - .inner_join(account) - .on((gl.account == account.name) & (account.account_type.isin(["Receivable", "Payable"]))) - .select( - gl.star, - ConstantColumn(1).as_("docstatus"), - account.account_type.as_("account_type"), - IfNull( - ifelse(gl.against_voucher_type == "", None, gl.against_voucher_type), gl.voucher_type - ).as_("against_voucher_type"), - IfNull(ifelse(gl.against_voucher == "", None, gl.against_voucher), gl.voucher_no).as_( - "against_voucher_no" - ), - # convert debit/credit to amount - Case() - .when(account.account_type == "Receivable", gl.debit - gl.credit) - .else_(gl.credit - gl.debit) - .as_("amount"), - # convert debit/credit in account currency to amount in account currency - Case() - .when( - account.account_type == "Receivable", - gl.debit_in_account_currency - gl.credit_in_account_currency, + .select(Count(gl.name)) + .where((gl.is_cancelled == 0) & (gl.account.isin(accounts))) + .run() + )[0][0] + + if un_processed: + print(f"Migrating {un_processed} GL Entries to Payment Ledger") + + processed = 0 + last_update_percent = 0 + batch_size = 5000 + last_name = None + + while True: + if last_name: + where_clause = gl.name.gt(last_name) & (gl.is_cancelled == 0) + else: + where_clause = gl.is_cancelled == 0 + + gl_entries = ( + qb.from_(gl) + .inner_join(account) + .on((gl.account == account.name) & (account.account_type.isin(["Receivable", "Payable"]))) + .select( + gl.star, + ConstantColumn(1).as_("docstatus"), + account.account_type.as_("account_type"), + IfNull( + ifelse(gl.against_voucher_type == "", None, gl.against_voucher_type), gl.voucher_type + ).as_("against_voucher_type"), + IfNull(ifelse(gl.against_voucher == "", None, gl.against_voucher), gl.voucher_no).as_( + "against_voucher_no" + ), + # convert debit/credit to amount + Case() + .when(account.account_type == "Receivable", gl.debit - gl.credit) + .else_(gl.credit - gl.debit) + .as_("amount"), + # convert debit/credit in account currency to amount in account currency + Case() + .when( + account.account_type == "Receivable", + gl.debit_in_account_currency - gl.credit_in_account_currency, + ) + .else_(gl.credit_in_account_currency - gl.debit_in_account_currency) + .as_("amount_in_account_currency"), + ) + .where(where_clause) + .orderby(gl.name) + .limit(batch_size) + .run(as_dict=True) ) - .else_(gl.credit_in_account_currency - gl.debit_in_account_currency) - .as_("amount_in_account_currency"), - ) - .where(gl.is_cancelled == 0) - .orderby(gl.creation) - .run(as_dict=True) - ) - # primary key(name) for payment ledger records - generate_name_for_payment_ledger_entries(gl_entries) - - # split data into chunks - chunk_size = 1000 - try: - for i in range(0, len(gl_entries), chunk_size): - insert_query = build_insert_query() - insert_chunk_into_payment_ledger(insert_query, gl_entries[i : i + chunk_size]) - frappe.db.commit() - except Exception as err: - frappe.db.rollback() - ple = qb.DocType("Payment Ledger Entry") - qb.from_(ple).delete().where(ple.docstatus >= 0).run() - frappe.db.commit() - raise err + if gl_entries: + last_name = gl_entries[-1].name + + # primary key(name) for payment ledger records + generate_name_for_payment_ledger_entries(gl_entries, processed) + + try: + insert_query = build_insert_query() + insert_chunk_into_payment_ledger(insert_query, gl_entries) + frappe.db.commit() + + processed += len(gl_entries) + + # Progress message + percent = flt((processed / un_processed) * 100, 2) + if percent - last_update_percent > 1: + print(f"{percent}% ({processed}) records processed") + last_update_percent = percent + + except Exception as err: + print("Migration Failed. Clear `tabPayment Ledger Entry` table before re-running") + raise err + else: + break + print(f"{processed} records have been sucessfully migrated") From 9f3bb849906c2fe95cc65502411aa9b25404446b Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Sun, 29 Jan 2023 11:52:25 +0530 Subject: [PATCH 22/53] chore: column width in `Warehouse wise Item Balance Age and Value` report (cherry picked from commit d7a665cb8478c72efbb7046ec1432eaa04ecc247) --- .../warehouse_wise_item_balance_age_and_value.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py b/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py index b5c6764224bd..55454ded71e1 100644 --- a/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py +++ b/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py @@ -89,10 +89,10 @@ def get_columns(filters): """return columns""" columns = [ - _("Item") + ":Link/Item:180", - _("Item Group") + "::100", + _("Item") + ":Link/Item:150", + _("Item Group") + "::120", _("Value") + ":Currency:120", - _("Age") + ":Float:80", + _("Age") + ":Float:120", ] return columns @@ -123,7 +123,7 @@ def get_warehouse_list(filters): def add_warehouse_column(columns, warehouse_list): if len(warehouse_list) > 1: - columns += [_("Total Qty") + ":Int:90"] + columns += [_("Total Qty") + ":Int:120"] for wh in warehouse_list: - columns += [_(wh.name) + ":Int:120"] + columns += [_(wh.name) + ":Int:100"] From 00e93dc0761794316da99284d5e061794515ff7c Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Sun, 29 Jan 2023 12:22:01 +0530 Subject: [PATCH 23/53] chore: add `Item Name` column in `Warehouse wise Item Balance Age and Value` report (cherry picked from commit 56356ffbb9302d36c6b206102fda94fc5997f2a6) --- .../warehouse_wise_item_balance_age_and_value.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py b/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py index 55454ded71e1..abbb33b2f16c 100644 --- a/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py +++ b/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py @@ -62,7 +62,7 @@ def execute(filters=None): continue total_stock_value = sum(item_value[(item, item_group)]) - row = [item, item_group, total_stock_value] + row = [item, item_map[item]["item_name"], item_group, total_stock_value] fifo_queue = item_ageing[item]["fifo_queue"] average_age = 0.00 @@ -90,6 +90,7 @@ def get_columns(filters): columns = [ _("Item") + ":Link/Item:150", + _("Item Name") + ":Link/Item:150", _("Item Group") + "::120", _("Value") + ":Currency:120", _("Age") + ":Float:120", From c8c9c509932c6ccdc8350d3b77d94244fa3a515b Mon Sep 17 00:00:00 2001 From: developsessions Date: Fri, 3 Feb 2023 11:30:29 +0100 Subject: [PATCH 24/53] fix: default due_date was wrong calculated on template "_Test Payment Term Template 1" (last day of next month) (cherry picked from commit ce8a1086a7b4cc3c6f0a9d460fe7abd742faa5d8) --- erpnext/accounts/party.py | 2 +- erpnext/buying/doctype/purchase_order/test_purchase_order.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index bfe73f02cdc5..078e51c905f3 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -550,7 +550,7 @@ def get_due_date_from_template(template_name, posting_date, bill_date): elif term.due_date_based_on == "Day(s) after the end of the invoice month": due_date = max(due_date, add_days(get_last_day(due_date), term.credit_days)) else: - due_date = max(due_date, add_months(get_last_day(due_date), term.credit_months)) + due_date = max(due_date, get_last_day(add_months(due_date, term.credit_months))) return due_date diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index f0360b27dc04..3c08d53288be 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -23,6 +23,7 @@ from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( make_purchase_invoice as make_pi_from_pr, ) +from erpnext.accounts.party import get_due_date_from_template class TestPurchaseOrder(FrappeTestCase): @@ -685,6 +686,10 @@ def test_po_for_blocked_supplier_payments_past_date(self): else: raise Exception + def test_default_payment_terms(self): + due_date = get_due_date_from_template("_Test Payment Term Template 1", "2023-02-03") + self.assertEqual(due_date, "2023-03-31") + def test_terms_are_not_copied_if_automatically_fetch_payment_terms_is_unchecked(self): po = create_purchase_order(do_not_save=1) po.payment_terms_template = "_Test Payment Term Template" From 76c4dc81771dff5e0394c22ae7262ebe101fef7d Mon Sep 17 00:00:00 2001 From: developsessions Date: Fri, 3 Feb 2023 13:55:36 +0100 Subject: [PATCH 25/53] style: lint wrong from position (cherry picked from commit c80aaad437e5b080d9bd929cbd5d22afcbbe77c6) --- erpnext/buying/doctype/purchase_order/test_purchase_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index 3c08d53288be..14c54e92fa69 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -10,6 +10,7 @@ from frappe.utils.data import today from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry +from erpnext.accounts.party import get_due_date_from_template from erpnext.buying.doctype.purchase_order.purchase_order import make_inter_company_sales_order from erpnext.buying.doctype.purchase_order.purchase_order import ( make_purchase_invoice as make_pi_from_po, @@ -23,7 +24,6 @@ from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( make_purchase_invoice as make_pi_from_pr, ) -from erpnext.accounts.party import get_due_date_from_template class TestPurchaseOrder(FrappeTestCase): From ced9274d1b394a3be8c83f47db1b5d2bace36ad9 Mon Sep 17 00:00:00 2001 From: developsessions Date: Fri, 3 Feb 2023 14:50:44 +0100 Subject: [PATCH 26/53] fix: Add missing 1 required positional argument: 'bill_date' (cherry picked from commit be1f94199681a785173fef20be5ce9cc6932c134) --- erpnext/buying/doctype/purchase_order/test_purchase_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index 14c54e92fa69..f3881bd2ecc5 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -687,7 +687,7 @@ def test_po_for_blocked_supplier_payments_past_date(self): raise Exception def test_default_payment_terms(self): - due_date = get_due_date_from_template("_Test Payment Term Template 1", "2023-02-03") + due_date = get_due_date_from_template("_Test Payment Term Template 1", "2023-02-03", None) self.assertEqual(due_date, "2023-03-31") def test_terms_are_not_copied_if_automatically_fetch_payment_terms_is_unchecked(self): From 7228a492ef2390b2acb08426b363633690098ecf Mon Sep 17 00:00:00 2001 From: developsessions Date: Fri, 3 Feb 2023 21:21:43 +0100 Subject: [PATCH 27/53] fix: failed test, convert date time to string (cherry picked from commit 9d0096ad9ea17565d8ba692bb1c36ad7a64e96d5) --- erpnext/buying/doctype/purchase_order/test_purchase_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index f3881bd2ecc5..4615b695d114 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -687,7 +687,7 @@ def test_po_for_blocked_supplier_payments_past_date(self): raise Exception def test_default_payment_terms(self): - due_date = get_due_date_from_template("_Test Payment Term Template 1", "2023-02-03", None) + due_date = get_due_date_from_template("_Test Payment Term Template 1", "2023-02-03", None).strftime("%Y-%m-%d") self.assertEqual(due_date, "2023-03-31") def test_terms_are_not_copied_if_automatically_fetch_payment_terms_is_unchecked(self): From d2836c16a7d0c945fbea23191a9441e67732efe2 Mon Sep 17 00:00:00 2001 From: developsessions Date: Sat, 4 Feb 2023 09:12:29 +0100 Subject: [PATCH 28/53] style: apply results of lint run (cherry picked from commit c8cd351b39e57295fb477b70c29dba14c13bb4dd) --- erpnext/buying/doctype/purchase_order/test_purchase_order.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index 4615b695d114..920486a78ef9 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -687,7 +687,9 @@ def test_po_for_blocked_supplier_payments_past_date(self): raise Exception def test_default_payment_terms(self): - due_date = get_due_date_from_template("_Test Payment Term Template 1", "2023-02-03", None).strftime("%Y-%m-%d") + due_date = get_due_date_from_template( + "_Test Payment Term Template 1", "2023-02-03", None + ).strftime("%Y-%m-%d") self.assertEqual(due_date, "2023-03-31") def test_terms_are_not_copied_if_automatically_fetch_payment_terms_is_unchecked(self): From e0cd6c20a3a317f567778e22c8f8b0df19c1891c Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 2 Feb 2023 18:40:15 +0530 Subject: [PATCH 29/53] fix: negative stock error (cherry picked from commit 6d513e2519e3c0d4ffe6a5c9b2620ab0bee1b347) --- erpnext/stock/stock_ledger.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index d8b12ed5b92a..08fc6fbd42fb 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -1050,7 +1050,7 @@ def update_bin(self): frappe.db.set_value("Bin", bin_name, updated_values, update_modified=True) -def get_previous_sle_of_current_voucher(args, exclude_current_voucher=False): +def get_previous_sle_of_current_voucher(args, operator="<", exclude_current_voucher=False): """get stock ledger entries filtered by specific posting datetime conditions""" args["time_format"] = "%H:%i:%s" @@ -1076,13 +1076,13 @@ def get_previous_sle_of_current_voucher(args, exclude_current_voucher=False): posting_date < %(posting_date)s or ( posting_date = %(posting_date)s and - time_format(posting_time, %(time_format)s) < time_format(%(posting_time)s, %(time_format)s) + time_format(posting_time, %(time_format)s) {operator} time_format(%(posting_time)s, %(time_format)s) ) ) order by timestamp(posting_date, posting_time) desc, creation desc limit 1 for update""".format( - voucher_condition=voucher_condition + operator=operator, voucher_condition=voucher_condition ), args, as_dict=1, @@ -1375,7 +1375,7 @@ def get_stock_reco_qty_shift(args): stock_reco_qty_shift = flt(args.actual_qty) else: # reco is being submitted - last_balance = get_previous_sle_of_current_voucher(args, exclude_current_voucher=True).get( + last_balance = get_previous_sle_of_current_voucher(args, "<=", exclude_current_voucher=True).get( "qty_after_transaction" ) From 388cc31e9e4f1b11d4f7af53bfd647b279d4dba8 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 2 Feb 2023 18:54:28 +0530 Subject: [PATCH 30/53] test: test case (cherry picked from commit 9ae7578b078fd9809ad3f04a62d7025d104b706f) --- .../doctype/stock_entry/test_stock_entry.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index 38bf0a5f9e58..cc06bd709ad4 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -1662,6 +1662,48 @@ def test_batch_expiry(self): self.assertRaises(BatchExpiredError, se.save) + def test_negative_stock_reco(self): + from erpnext.controllers.stock_controller import BatchExpiredError + from erpnext.stock.doctype.batch.test_batch import make_new_batch + + frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 0) + + item_code = "Test Negative Item - 001" + item_doc = create_item(item_code=item_code, is_stock_item=1, valuation_rate=10) + + make_stock_entry( + item_code=item_code, + posting_date=add_days(today(), -3), + posting_time="00:00:00", + purpose="Material Receipt", + qty=10, + to_warehouse="_Test Warehouse - _TC", + do_not_save=True, + ) + + make_stock_entry( + item_code=item_code, + posting_date=today(), + posting_time="00:00:00", + purpose="Material Receipt", + qty=8, + from_warehouse="_Test Warehouse - _TC", + do_not_save=True, + ) + + sr_doc = create_stock_reconciliation( + purpose="Stock Reconciliation", + posting_date=add_days(today(), -3), + posting_time="00:00:00", + item_code=item_code, + warehouse="_Test Warehouse - _TC", + valuation_rate=10, + qty=7, + do_not_submit=True, + ) + + self.assertRaises(frappe.ValidationError, sr_doc.submit) + def make_serialized_item(**args): args = frappe._dict(args) From 04a474d0a12fa51211b5878a19ada7f8e7848475 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Fri, 3 Feb 2023 18:08:34 +0530 Subject: [PATCH 31/53] fix: stock entry from item dashboard (stock levels) (cherry picked from commit dc0ddf8d7eb41e4aeaa364c3b0d00dac5b2c9370) --- erpnext/stock/dashboard/item_dashboard.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/dashboard/item_dashboard.js b/erpnext/stock/dashboard/item_dashboard.js index 6e7622c067f0..bef438f9fd72 100644 --- a/erpnext/stock/dashboard/item_dashboard.js +++ b/erpnext/stock/dashboard/item_dashboard.js @@ -42,7 +42,7 @@ erpnext.stock.ItemDashboard = class ItemDashboard { let warehouse = unescape(element.attr('data-warehouse')); let actual_qty = unescape(element.attr('data-actual_qty')); let disable_quick_entry = Number(unescape(element.attr('data-disable_quick_entry'))); - let entry_type = action === "Move" ? "Material Transfer" : null; + let entry_type = action === "Move" ? "Material Transfer" : "Material Receipt"; if (disable_quick_entry) { open_stock_entry(item, warehouse, entry_type); @@ -63,11 +63,19 @@ erpnext.stock.ItemDashboard = class ItemDashboard { function open_stock_entry(item, warehouse, entry_type) { frappe.model.with_doctype('Stock Entry', function () { var doc = frappe.model.get_new_doc('Stock Entry'); - if (entry_type) doc.stock_entry_type = entry_type; + if (entry_type) { + doc.stock_entry_type = entry_type; + } var row = frappe.model.add_child(doc, 'items'); row.item_code = item; - row.s_warehouse = warehouse; + + if (entry_type === "Material Transfer") { + row.s_warehouse = warehouse; + } + else { + row.t_warehouse = warehouse; + } frappe.set_route('Form', doc.doctype, doc.name); }); From c98b2b59181546f246912fcd8c649ae773b68fab Mon Sep 17 00:00:00 2001 From: anandbaburajan Date: Fri, 3 Feb 2023 22:58:22 +0530 Subject: [PATCH 32/53] fix: allow PI cancel if linked asset is cancelled (cherry picked from commit b961321de5447fe8049472f51ae89f1a3ff76665) --- erpnext/controllers/buying_controller.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 445620a1246f..31e5dd777f30 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -716,6 +716,8 @@ def update_fixed_asset(self, field, delete_asset=False): asset.purchase_date = self.posting_date asset.supplier = self.supplier elif self.docstatus == 2: + if asset.docstatus == 2: + break if asset.docstatus == 0: asset.set(field, None) asset.supplier = None From 68df9ad83c7bb1b2042a700c229157b9f848436f Mon Sep 17 00:00:00 2001 From: anandbaburajan Date: Sat, 4 Feb 2023 11:20:26 +0530 Subject: [PATCH 33/53] chore: use continue, not break (cherry picked from commit 3380dc5deaac8df145f424153254466b35ddd02b) --- erpnext/controllers/buying_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 31e5dd777f30..cf267716d585 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -717,7 +717,7 @@ def update_fixed_asset(self, field, delete_asset=False): asset.supplier = self.supplier elif self.docstatus == 2: if asset.docstatus == 2: - break + continue if asset.docstatus == 0: asset.set(field, None) asset.supplier = None From 6e8a985bc6e532371fd12fc485a8540e5586b66f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 10 Feb 2023 20:55:03 +0530 Subject: [PATCH 34/53] chore: typo in stock_entry get_uom_details (backport #33998) (#34003) chore: typo in stock_entry get_uom_details (#33998) fix: typo in stock_entry get_uom_details (cherry picked from commit 185c543b7308bbf7b525f6c269ff023cfd08e6bb) Co-authored-by: Akshay <60477442+akshayitzme@users.noreply.github.com> --- erpnext/stock/doctype/stock_entry/stock_entry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 9a2473170458..e263a278bef9 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -2497,7 +2497,7 @@ def get_uom_details(item_code, uom, qty): if not conversion_factor: frappe.msgprint( - _("UOM coversion factor required for UOM: {0} in Item: {1}").format(uom, item_code) + _("UOM conversion factor required for UOM: {0} in Item: {1}").format(uom, item_code) ) ret = {"uom": ""} else: From 52bfb667294b39bcd621b536459f0d2b0e43a824 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:20:10 +0530 Subject: [PATCH 35/53] feat: Add filters in Loan Interest Report (#33907) * feat: Add filters in Loan Interest Report (#33907) (cherry picked from commit e478a5d0ceb092c0b05849189e89b5cadc16afb8) * chore: remove flaky tests --------- Co-authored-by: Deepesh Garg --- .../test_bulk_transaction_log.py | 11 - .../test_procurement_tracker.py | 58 +--- .../loan_interest_report.js | 36 +- .../loan_interest_report.py | 51 ++- .../workspace/loans/loans.json | 315 ++++++++++++++++++ 5 files changed, 392 insertions(+), 79 deletions(-) create mode 100644 erpnext/loan_management/workspace/loans/loans.json diff --git a/erpnext/bulk_transaction/doctype/bulk_transaction_log/test_bulk_transaction_log.py b/erpnext/bulk_transaction/doctype/bulk_transaction_log/test_bulk_transaction_log.py index 646dba51ce96..c673be89b3f6 100644 --- a/erpnext/bulk_transaction/doctype/bulk_transaction_log/test_bulk_transaction_log.py +++ b/erpnext/bulk_transaction/doctype/bulk_transaction_log/test_bulk_transaction_log.py @@ -15,17 +15,6 @@ def setUp(self): create_customer() create_item() - def test_for_single_record(self): - so_name = create_so() - transaction_processing([{"name": so_name}], "Sales Order", "Sales Invoice") - data = frappe.db.get_list( - "Sales Invoice", - filters={"posting_date": date.today(), "customer": "Bulk Customer"}, - fields=["*"], - ) - if not data: - self.fail("No Sales Invoice Created !") - def test_entry_in_log(self): so_name = create_so() transaction_processing([{"name": so_name}], "Sales Order", "Sales Invoice") diff --git a/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py b/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py index 47a66ad46f2a..9b53421319d9 100644 --- a/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py +++ b/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py @@ -15,60 +15,4 @@ class TestProcurementTracker(FrappeTestCase): - def test_result_for_procurement_tracker(self): - filters = {"company": "_Test Procurement Company", "cost_center": "Main - _TPC"} - expected_data = self.generate_expected_data() - report = execute(filters) - - length = len(report[1]) - self.assertEqual(expected_data, report[1][length - 1]) - - def generate_expected_data(self): - if not frappe.db.exists("Company", "_Test Procurement Company"): - frappe.get_doc( - dict( - doctype="Company", - company_name="_Test Procurement Company", - abbr="_TPC", - default_currency="INR", - country="Pakistan", - ) - ).insert() - warehouse = create_warehouse("_Test Procurement Warehouse", company="_Test Procurement Company") - mr = make_material_request( - company="_Test Procurement Company", warehouse=warehouse, cost_center="Main - _TPC" - ) - po = make_purchase_order(mr.name) - po.supplier = "_Test Supplier" - po.get("items")[0].cost_center = "Main - _TPC" - po.submit() - pr = make_purchase_receipt(po.name) - pr.get("items")[0].cost_center = "Main - _TPC" - pr.submit() - date_obj = datetime.date(datetime.now()) - - po.load_from_db() - - expected_data = { - "material_request_date": date_obj, - "cost_center": "Main - _TPC", - "project": None, - "requesting_site": "_Test Procurement Warehouse - _TPC", - "requestor": "Administrator", - "material_request_no": mr.name, - "item_code": "_Test Item", - "quantity": 10.0, - "unit_of_measurement": "_Test UOM", - "status": "To Bill", - "purchase_order_date": date_obj, - "purchase_order": po.name, - "supplier": "_Test Supplier", - "estimated_cost": 0.0, - "actual_cost": 0.0, - "purchase_order_amt": po.net_total, - "purchase_order_amt_in_company_currency": po.base_net_total, - "expected_delivery_date": date_obj, - "actual_delivery_date": date_obj, - } - - return expected_data + pass diff --git a/erpnext/loan_management/report/loan_interest_report/loan_interest_report.js b/erpnext/loan_management/report/loan_interest_report/loan_interest_report.js index a227b6d79733..458c79a1ea8f 100644 --- a/erpnext/loan_management/report/loan_interest_report/loan_interest_report.js +++ b/erpnext/loan_management/report/loan_interest_report/loan_interest_report.js @@ -11,6 +11,40 @@ frappe.query_reports["Loan Interest Report"] = { "options": "Company", "default": frappe.defaults.get_user_default("Company"), "reqd": 1 - } + }, + { + "fieldname":"applicant_type", + "label": __("Applicant Type"), + "fieldtype": "Select", + "options": ["Customer", "Employee"], + "reqd": 1, + "default": "Customer", + on_change: function() { + frappe.query_report.set_filter_value('applicant', ""); + } + }, + { + "fieldname": "applicant", + "label": __("Applicant"), + "fieldtype": "Dynamic Link", + "get_options": function() { + var applicant_type = frappe.query_report.get_filter_value('applicant_type'); + var applicant = frappe.query_report.get_filter_value('applicant'); + if(applicant && !applicant_type) { + frappe.throw(__("Please select Applicant Type first")); + } + return applicant_type; + } + }, + { + "fieldname":"from_date", + "label": __("From Date"), + "fieldtype": "Date", + }, + { + "fieldname":"to_date", + "label": __("From Date"), + "fieldtype": "Date", + }, ] }; diff --git a/erpnext/loan_management/report/loan_interest_report/loan_interest_report.py b/erpnext/loan_management/report/loan_interest_report/loan_interest_report.py index 9186ce617439..58a7880a4592 100644 --- a/erpnext/loan_management/report/loan_interest_report/loan_interest_report.py +++ b/erpnext/loan_management/report/loan_interest_report/loan_interest_report.py @@ -13,12 +13,12 @@ def execute(filters=None): - columns = get_columns(filters) + columns = get_columns() data = get_active_loan_details(filters) return columns, data -def get_columns(filters): +def get_columns(): columns = [ {"label": _("Loan"), "fieldname": "loan", "fieldtype": "Link", "options": "Loan", "width": 160}, {"label": _("Status"), "fieldname": "status", "fieldtype": "Data", "width": 160}, @@ -70,6 +70,13 @@ def get_columns(filters): "options": "currency", "width": 120, }, + { + "label": _("Accrued Principal"), + "fieldname": "accrued_principal", + "fieldtype": "Currency", + "options": "currency", + "width": 120, + }, { "label": _("Total Repayment"), "fieldname": "total_repayment", @@ -137,11 +144,16 @@ def get_columns(filters): def get_active_loan_details(filters): - - filter_obj = {"status": ("!=", "Closed")} + filter_obj = { + "status": ("!=", "Closed"), + "docstatus": 1, + } if filters.get("company"): filter_obj.update({"company": filters.get("company")}) + if filters.get("applicant"): + filter_obj.update({"applicant": filters.get("applicant")}) + loan_details = frappe.get_all( "Loan", fields=[ @@ -167,8 +179,8 @@ def get_active_loan_details(filters): sanctioned_amount_map = get_sanctioned_amount_map() penal_interest_rate_map = get_penal_interest_rate_map() - payments = get_payments(loan_list) - accrual_map = get_interest_accruals(loan_list) + payments = get_payments(loan_list, filters) + accrual_map = get_interest_accruals(loan_list, filters) currency = erpnext.get_company_currency(filters.get("company")) for loan in loan_details: @@ -183,6 +195,7 @@ def get_active_loan_details(filters): - flt(loan.written_off_amount), "total_repayment": flt(payments.get(loan.loan)), "accrued_interest": flt(accrual_map.get(loan.loan, {}).get("accrued_interest")), + "accrued_principal": flt(accrual_map.get(loan.loan, {}).get("accrued_principal")), "interest_outstanding": flt(accrual_map.get(loan.loan, {}).get("interest_outstanding")), "penalty": flt(accrual_map.get(loan.loan, {}).get("penalty")), "penalty_interest": penal_interest_rate_map.get(loan.loan_type), @@ -212,20 +225,35 @@ def get_sanctioned_amount_map(): ) -def get_payments(loans): +def get_payments(loans, filters): + query_filters = {"against_loan": ("in", loans)} + + if filters.get("from_date"): + query_filters.update({"posting_date": (">=", filters.get("from_date"))}) + + if filters.get("to_date"): + query_filters.update({"posting_date": ("<=", filters.get("to_date"))}) + return frappe._dict( frappe.get_all( "Loan Repayment", fields=["against_loan", "sum(amount_paid)"], - filters={"against_loan": ("in", loans)}, + filters=query_filters, group_by="against_loan", as_list=1, ) ) -def get_interest_accruals(loans): +def get_interest_accruals(loans, filters): accrual_map = {} + query_filters = {"loan": ("in", loans)} + + if filters.get("from_date"): + query_filters.update({"posting_date": (">=", filters.get("from_date"))}) + + if filters.get("to_date"): + query_filters.update({"posting_date": ("<=", filters.get("to_date"))}) interest_accruals = frappe.get_all( "Loan Interest Accrual", @@ -236,8 +264,9 @@ def get_interest_accruals(loans): "penalty_amount", "paid_interest_amount", "accrual_type", + "payable_principal_amount", ], - filters={"loan": ("in", loans)}, + filters=query_filters, order_by="posting_date desc", ) @@ -246,6 +275,7 @@ def get_interest_accruals(loans): entry.loan, { "accrued_interest": 0.0, + "accrued_principal": 0.0, "undue_interest": 0.0, "interest_outstanding": 0.0, "last_accrual_date": "", @@ -270,6 +300,7 @@ def get_interest_accruals(loans): accrual_map[entry.loan]["undue_interest"] += entry.interest_amount - entry.paid_interest_amount accrual_map[entry.loan]["accrued_interest"] += entry.interest_amount + accrual_map[entry.loan]["accrued_principal"] += entry.payable_principal_amount if last_accrual_date and getdate(entry.posting_date) == last_accrual_date: accrual_map[entry.loan]["penalty"] = entry.penalty_amount diff --git a/erpnext/loan_management/workspace/loans/loans.json b/erpnext/loan_management/workspace/loans/loans.json new file mode 100644 index 000000000000..c65be4efae9d --- /dev/null +++ b/erpnext/loan_management/workspace/loans/loans.json @@ -0,0 +1,315 @@ +{ + "charts": [], + "content": "[{\"id\":\"_38WStznya\",\"type\":\"header\",\"data\":{\"text\":\"Your Shortcuts\",\"col\":12}},{\"id\":\"t7o_K__1jB\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Loan Application\",\"col\":3}},{\"id\":\"IRiNDC6w1p\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Loan\",\"col\":3}},{\"id\":\"xbbo0FYbq0\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Dashboard\",\"col\":3}},{\"id\":\"7ZL4Bro-Vi\",\"type\":\"spacer\",\"data\":{\"col\":12}},{\"id\":\"yhyioTViZ3\",\"type\":\"header\",\"data\":{\"text\":\"Reports & Masters\",\"col\":12}},{\"id\":\"oYFn4b1kSw\",\"type\":\"card\",\"data\":{\"card_name\":\"Loan\",\"col\":4}},{\"id\":\"vZepJF5tl9\",\"type\":\"card\",\"data\":{\"card_name\":\"Loan Processes\",\"col\":4}},{\"id\":\"k-393Mjhqe\",\"type\":\"card\",\"data\":{\"card_name\":\"Disbursement and Repayment\",\"col\":4}},{\"id\":\"6crJ0DBiBJ\",\"type\":\"card\",\"data\":{\"card_name\":\"Loan Security\",\"col\":4}},{\"id\":\"Um5YwxVLRJ\",\"type\":\"card\",\"data\":{\"card_name\":\"Reports\",\"col\":4}}]", + "creation": "2020-03-12 16:35:55.299820", + "docstatus": 0, + "doctype": "Workspace", + "for_user": "", + "hide_custom": 0, + "icon": "loan", + "idx": 0, + "is_hidden": 0, + "label": "Loans", + "links": [ + { + "hidden": 0, + "is_query_report": 0, + "label": "Loan", + "link_count": 0, + "onboard": 0, + "type": "Card Break" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan Type", + "link_count": 0, + "link_to": "Loan Type", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan Application", + "link_count": 0, + "link_to": "Loan Application", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan", + "link_count": 0, + "link_to": "Loan", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Loan Processes", + "link_count": 0, + "onboard": 0, + "type": "Card Break" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Process Loan Security Shortfall", + "link_count": 0, + "link_to": "Process Loan Security Shortfall", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Process Loan Interest Accrual", + "link_count": 0, + "link_to": "Process Loan Interest Accrual", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Disbursement and Repayment", + "link_count": 0, + "onboard": 0, + "type": "Card Break" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan Disbursement", + "link_count": 0, + "link_to": "Loan Disbursement", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan Repayment", + "link_count": 0, + "link_to": "Loan Repayment", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan Write Off", + "link_count": 0, + "link_to": "Loan Write Off", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan Interest Accrual", + "link_count": 0, + "link_to": "Loan Interest Accrual", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Loan Security", + "link_count": 0, + "onboard": 0, + "type": "Card Break" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan Security Type", + "link_count": 0, + "link_to": "Loan Security Type", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan Security Price", + "link_count": 0, + "link_to": "Loan Security Price", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan Security", + "link_count": 0, + "link_to": "Loan Security", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan Security Pledge", + "link_count": 0, + "link_to": "Loan Security Pledge", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan Security Unpledge", + "link_count": 0, + "link_to": "Loan Security Unpledge", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan Security Shortfall", + "link_count": 0, + "link_to": "Loan Security Shortfall", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Reports", + "link_count": 6, + "onboard": 0, + "type": "Card Break" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 1, + "label": "Loan Repayment and Closure", + "link_count": 0, + "link_to": "Loan Repayment and Closure", + "link_type": "Report", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 1, + "label": "Loan Security Status", + "link_count": 0, + "link_to": "Loan Security Status", + "link_type": "Report", + "onboard": 0, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 1, + "label": "Loan Interest Report", + "link_count": 0, + "link_to": "Loan Interest Report", + "link_type": "Report", + "onboard": 0, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 1, + "label": "Loan Security Exposure", + "link_count": 0, + "link_to": "Loan Security Exposure", + "link_type": "Report", + "onboard": 0, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 1, + "label": "Applicant-Wise Loan Security Exposure", + "link_count": 0, + "link_to": "Applicant-Wise Loan Security Exposure", + "link_type": "Report", + "onboard": 0, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 1, + "label": "Loan Security Status", + "link_count": 0, + "link_to": "Loan Security Status", + "link_type": "Report", + "onboard": 0, + "type": "Link" + } + ], + "modified": "2023-01-31 19:47:13.114415", + "modified_by": "Administrator", + "module": "Loan Management", + "name": "Loans", + "owner": "Administrator", + "parent_page": "", + "public": 1, + "quick_lists": [], + "restrict_to_domain": "", + "roles": [], + "sequence_id": 16.0, + "shortcuts": [ + { + "color": "Green", + "format": "{} Open", + "label": "Loan Application", + "link_to": "Loan Application", + "stats_filter": "{ \"status\": \"Open\" }", + "type": "DocType" + }, + { + "label": "Loan", + "link_to": "Loan", + "type": "DocType" + }, + { + "doc_view": "", + "label": "Dashboard", + "link_to": "Loan Dashboard", + "type": "Dashboard" + } + ], + "title": "Loans" +} \ No newline at end of file From bb8e232aea98db7158c64e8f5a0ef9bdc57293a9 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:53:27 +0530 Subject: [PATCH 36/53] fix: list view for Terms and Conditions (#33925) fix: list view for Terms and Conditions (#33925) Co-authored-by: Deepesh Garg (cherry picked from commit ab7293bcd367c287ee2663a58cce38c591783304) Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> --- .../terms_and_conditions/terms_and_conditions.js | 13 +++---------- .../terms_and_conditions/terms_and_conditions.json | 9 ++++++--- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.js b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.js index 3680906057fa..c3605bf0e8bc 100644 --- a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.js +++ b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.js @@ -1,13 +1,6 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt - - -//--------- ONLOAD ------------- -cur_frm.cscript.onload = function(doc, cdt, cdn) { - -} - -cur_frm.cscript.refresh = function(doc, cdt, cdn) { - -} +// frappe.ui.form.on("Terms and Conditions", { +// refresh(frm) {} +// }); diff --git a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json index f14b243512f5..f884864acfa7 100644 --- a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json +++ b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json @@ -33,7 +33,6 @@ "default": "0", "fieldname": "disabled", "fieldtype": "Check", - "in_list_view": 1, "label": "Disabled" }, { @@ -60,12 +59,14 @@ "default": "1", "fieldname": "selling", "fieldtype": "Check", + "in_list_view": 1, "label": "Selling" }, { "default": "1", "fieldname": "buying", "fieldtype": "Check", + "in_list_view": 1, "label": "Buying" }, { @@ -76,10 +77,11 @@ "icon": "icon-legal", "idx": 1, "links": [], - "modified": "2022-06-16 15:07:38.094844", + "modified": "2023-02-01 14:33:39.246532", "modified_by": "Administrator", "module": "Setup", "name": "Terms and Conditions", + "naming_rule": "By fieldname", "owner": "Administrator", "permissions": [ { @@ -133,5 +135,6 @@ "quick_entry": 1, "show_name_in_global_search": 1, "sort_field": "modified", - "sort_order": "ASC" + "sort_order": "ASC", + "states": [] } \ No newline at end of file From 87a8c17314c0268109d1a60d8a90c470e2548c3f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:53:47 +0530 Subject: [PATCH 37/53] fix: Amount for debit and credit notes with 0 qty line items (#33902) fix: Amount for debit and credit notes with 0 qty line items (#33902) (cherry picked from commit 47c91324b13217db83670c97a6e0488ae78b8b14) Co-authored-by: Deepesh Garg --- erpnext/public/js/controllers/taxes_and_totals.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 2ce0c7eb00dd..a87c3ec9514b 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -126,7 +126,16 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { frappe.model.round_floats_in(item); item.net_rate = item.rate; item.qty = item.qty === undefined ? (me.frm.doc.is_return ? -1 : 1) : item.qty; - item.net_amount = item.amount = flt(item.rate * item.qty, precision("amount", item)); + + if (!(me.frm.doc.is_return || me.frm.doc.is_debit_note)) { + item.net_amount = item.amount = flt(item.rate * item.qty, precision("amount", item)); + } + else { + let qty = item.qty || 1; + qty = me.frm.doc.is_return ? -1 * qty : qty; + item.net_amount = item.amount = flt(item.rate * qty, precision("amount", item)); + } + item.item_tax_amount = 0.0; item.total_weight = flt(item.weight_per_unit * item.stock_qty); From 8e2d7bb44a383ed4c7770a2e5c8de2930c0ffc10 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:54:12 +0530 Subject: [PATCH 38/53] fix: currency formatting in item-wise sales history (#33903) fix: currency formatting in item-wise sales history (#33903) * fix(item-sales-history): currency formatting * chore: linting issues * fix: convert raw sql to qb (cherry picked from commit 2cc7239dd580499f71c01d6647ab852827adf394) Co-authored-by: Dany Robert Co-authored-by: Deepesh Garg --- .../item_wise_sales_history.py | 110 +++++++++++------- 1 file changed, 66 insertions(+), 44 deletions(-) diff --git a/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.py b/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.py index e10df2acbb5e..44c4d5497bad 100644 --- a/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.py +++ b/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.py @@ -41,8 +41,20 @@ def get_columns(filters): {"label": _("Description"), "fieldtype": "Data", "fieldname": "description", "width": 150}, {"label": _("Quantity"), "fieldtype": "Float", "fieldname": "quantity", "width": 150}, {"label": _("UOM"), "fieldtype": "Link", "fieldname": "uom", "options": "UOM", "width": 100}, - {"label": _("Rate"), "fieldname": "rate", "options": "Currency", "width": 120}, - {"label": _("Amount"), "fieldname": "amount", "options": "Currency", "width": 120}, + { + "label": _("Rate"), + "fieldname": "rate", + "fieldtype": "Currency", + "options": "currency", + "width": 120, + }, + { + "label": _("Amount"), + "fieldname": "amount", + "fieldtype": "Currency", + "options": "currency", + "width": 120, + }, { "label": _("Sales Order"), "fieldtype": "Link", @@ -93,8 +105,9 @@ def get_columns(filters): }, { "label": _("Billed Amount"), - "fieldtype": "currency", + "fieldtype": "Currency", "fieldname": "billed_amount", + "options": "currency", "width": 120, }, { @@ -104,6 +117,13 @@ def get_columns(filters): "options": "Company", "width": 100, }, + { + "label": _("Currency"), + "fieldtype": "Link", + "fieldname": "currency", + "options": "Currency", + "hidden": 1, + }, ] @@ -141,31 +161,12 @@ def get_data(filters): "billed_amount": flt(record.get("billed_amt")), "company": record.get("company"), } + row["currency"] = frappe.get_cached_value("Company", row["company"], "default_currency") data.append(row) return data -def get_conditions(filters): - conditions = "" - if filters.get("item_group"): - conditions += "AND so_item.item_group = %s" % frappe.db.escape(filters.item_group) - - if filters.get("from_date"): - conditions += "AND so.transaction_date >= '%s'" % filters.from_date - - if filters.get("to_date"): - conditions += "AND so.transaction_date <= '%s'" % filters.to_date - - if filters.get("item_code"): - conditions += "AND so_item.item_code = %s" % frappe.db.escape(filters.item_code) - - if filters.get("customer"): - conditions += "AND so.customer = %s" % frappe.db.escape(filters.customer) - - return conditions - - def get_customer_details(): details = frappe.get_all("Customer", fields=["name", "customer_name", "customer_group"]) customer_details = {} @@ -187,29 +188,50 @@ def get_item_details(): def get_sales_order_details(company_list, filters): - conditions = get_conditions(filters) - - return frappe.db.sql( - """ - SELECT - so_item.item_code, so_item.description, so_item.qty, - so_item.uom, so_item.base_rate, so_item.base_amount, - so.name, so.transaction_date, so.customer,so.territory, - so.project, so_item.delivered_qty, - so_item.billed_amt, so.company - FROM - `tabSales Order` so, `tabSales Order Item` so_item - WHERE - so.name = so_item.parent - AND so.company in ({0}) - AND so.docstatus = 1 {1} - """.format( - ",".join(["%s"] * len(company_list)), conditions - ), - tuple(company_list), - as_dict=1, + db_so = frappe.qb.DocType("Sales Order") + db_so_item = frappe.qb.DocType("Sales Order Item") + + query = ( + frappe.qb.from_(db_so) + .inner_join(db_so_item) + .on(db_so_item.parent == db_so.name) + .select( + db_so.name, + db_so.customer, + db_so.transaction_date, + db_so.territory, + db_so.project, + db_so.company, + db_so_item.item_code, + db_so_item.description, + db_so_item.qty, + db_so_item.uom, + db_so_item.base_rate, + db_so_item.base_amount, + db_so_item.delivered_qty, + (db_so_item.billed_amt * db_so.conversion_rate).as_("billed_amt"), + ) + .where(db_so.docstatus == 1) + .where(db_so.company.isin(tuple(company_list))) ) + if filters.get("item_group"): + query = query.where(db_so_item.item_group == frappe.db.escape(filters.item_group)) + + if filters.get("from_date"): + query = query.where(db_so.transaction_date >= filters.from_date) + + if filters.get("to_date"): + query = query.where(db_so.transaction_date <= filters.to_date) + + if filters.get("item_code"): + query = query.where(db_so_item.item_group == frappe.db.escape(filters.item_code)) + + if filters.get("customer"): + query = query.where(db_so.customer == filters.customer) + + return query.run(as_dict=1) + def get_chart_data(data): item_wise_sales_map = {} From 02c4c55adc87aa7423fcf2fff05568eccf135cd2 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:59:23 +0530 Subject: [PATCH 39/53] fix: german chart of accounts "SKR03" (#33909) fix: german chart of accounts "SKR03" (#33909) * fix: german chart of accounts "SKR03" - Added some missing account types and tax rates - Added some missing accounts * style: convert indentation to tabs * fix: space before percentage sign * feat: add some expense accounts * refactor: replace unicode characters with utf-8 for better readability * revert: add back groups for Bank and Cash accounts Removed in 7d0d9c690068481a9730e0132c7aff34c1f56100 (cherry picked from commit 3c7b460fd8ec9e9bdc00669bbae6353b731a12eb) Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> Co-authored-by: Deepesh Garg --- .../verified/de_kontenplan_SKR03_gnucash.json | 666 +++++++++--------- 1 file changed, 347 insertions(+), 319 deletions(-) diff --git a/erpnext/accounts/doctype/account/chart_of_accounts/verified/de_kontenplan_SKR03_gnucash.json b/erpnext/accounts/doctype/account/chart_of_accounts/verified/de_kontenplan_SKR03_gnucash.json index ee501f664b67..741d4283e2f1 100644 --- a/erpnext/accounts/doctype/account/chart_of_accounts/verified/de_kontenplan_SKR03_gnucash.json +++ b/erpnext/accounts/doctype/account/chart_of_accounts/verified/de_kontenplan_SKR03_gnucash.json @@ -1,38 +1,38 @@ { - "country_code": "de", - "name": "SKR03 mit Kontonummern", - "tree": { - "Aktiva": { - "is_group": 1, + "country_code": "de", + "name": "SKR03 mit Kontonummern", + "tree": { + "Aktiva": { + "is_group": 1, "root_type": "Asset", - "A - Anlagevermögen": { - "is_group": 1, - "EDV-Software": { - "account_number": "0027", - "account_type": "Fixed Asset" - }, - "Gesch\u00e4ftsausstattung": { - "account_number": "0410", - "account_type": "Fixed Asset" - }, - "B\u00fcroeinrichtung": { - "account_number": "0420", - "account_type": "Fixed Asset" - }, - "Darlehen": { - "account_number": "0565" - }, - "Maschinen": { - "account_number": "0210", - "account_type": "Fixed Asset" - }, - "Betriebsausstattung": { - "account_number": "0400", - "account_type": "Fixed Asset" - }, - "Ladeneinrichtung": { - "account_number": "0430", - "account_type": "Fixed Asset" + "A - Anlagevermögen": { + "is_group": 1, + "EDV-Software": { + "account_number": "0027", + "account_type": "Fixed Asset" + }, + "Geschäftsausstattung": { + "account_number": "0410", + "account_type": "Fixed Asset" + }, + "Büroeinrichtung": { + "account_number": "0420", + "account_type": "Fixed Asset" + }, + "Darlehen": { + "account_number": "0565" + }, + "Maschinen": { + "account_number": "0210", + "account_type": "Fixed Asset" + }, + "Betriebsausstattung": { + "account_number": "0400", + "account_type": "Fixed Asset" + }, + "Ladeneinrichtung": { + "account_number": "0430", + "account_type": "Fixed Asset" }, "Accumulated Depreciation": { "account_type": "Accumulated Depreciation" @@ -60,36 +60,46 @@ "Durchlaufende Posten": { "account_number": "1590" }, - "Gewinnermittlung \u00a74/3 nicht Ergebniswirksam": { + "Verrechnungskonto Gewinnermittlung § 4 Abs. 3 EStG, nicht ergebniswirksam": { "account_number": "1371" }, "Abziehbare Vorsteuer": { - "account_type": "Tax", "is_group": 1, - "Abziehbare Vorsteuer 7%": { - "account_number": "1571" - }, - "Abziehbare Vorsteuer 19%": { - "account_number": "1576" + "Abziehbare Vorsteuer 7 %": { + "account_number": "1571", + "account_type": "Tax", + "tax_rate": 7.0 }, - "Abziehbare Vorsteuer nach \u00a713b UStG 19%": { - "account_number": "1577" + "Abziehbare Vorsteuer 19 %": { + "account_number": "1576", + "account_type": "Tax", + "tax_rate": 19.0 }, - "Leistungen \u00a713b UStG 19% Vorsteuer, 19% Umsatzsteuer": { - "account_number": "3120" + "Abziehbare Vorsteuer nach § 13b UStG 19 %": { + "account_number": "1577", + "account_type": "Tax", + "tax_rate": 19.0 } } }, "III. Wertpapiere": { - "is_group": 1 + "is_group": 1, + "Anteile an verbundenen Unternehmen (Umlaufvermögen)": { + "account_number": "1340" + }, + "Anteile an herrschender oder mit Mehrheit beteiligter Gesellschaft": { + "account_number": "1344" + }, + "Sonstige Wertpapiere": { + "account_number": "1348" + } }, "IV. Kassenbestand, Bundesbankguthaben, Guthaben bei Kreditinstituten und Schecks.": { "is_group": 1, "Kasse": { - "account_type": "Cash", "is_group": 1, + "account_type": "Cash", "Kasse": { - "is_group": 1, "account_number": "1000", "account_type": "Cash" } @@ -111,21 +121,21 @@ "C - Rechnungsabgrenzungsposten": { "is_group": 1, "Aktive Rechnungsabgrenzung": { - "account_number": "0980" + "account_number": "0980" } }, "D - Aktive latente Steuern": { "is_group": 1, "Aktive latente Steuern": { - "account_number": "0983" + "account_number": "0983" } }, "E - Aktiver Unterschiedsbetrag aus der Vermögensverrechnung": { "is_group": 1 } - }, - "Passiva": { - "is_group": 1, + }, + "Passiva": { + "is_group": 1, "root_type": "Liability", "A. Eigenkapital": { "is_group": 1, @@ -200,26 +210,32 @@ }, "Umsatzsteuer": { "is_group": 1, - "account_type": "Tax", - "Umsatzsteuer 7%": { - "account_number": "1771" + "Umsatzsteuer 7 %": { + "account_number": "1771", + "account_type": "Tax", + "tax_rate": 7.0 }, - "Umsatzsteuer 19%": { - "account_number": "1776" + "Umsatzsteuer 19 %": { + "account_number": "1776", + "account_type": "Tax", + "tax_rate": 19.0 }, "Umsatzsteuer-Vorauszahlung": { - "account_number": "1780" + "account_number": "1780", + "account_type": "Tax" }, "Umsatzsteuer-Vorauszahlung 1/11": { "account_number": "1781" }, - "Umsatzsteuer \u00a7 13b UStG 19%": { - "account_number": "1787" + "Umsatzsteuer nach § 13b UStG 19 %": { + "account_number": "1787", + "account_type": "Tax", + "tax_rate": 19.0 }, "Umsatzsteuer Vorjahr": { "account_number": "1790" }, - "Umsatzsteuer fr\u00fchere Jahre": { + "Umsatzsteuer frühere Jahre": { "account_number": "1791" } } @@ -234,44 +250,56 @@ "E. Passive latente Steuern": { "is_group": 1 } - }, - "Erl\u00f6se u. Ertr\u00e4ge 2/8": { - "is_group": 1, - "root_type": "Income", - "Erl\u00f6skonten 8": { + }, + "Erlöse u. Erträge 2/8": { + "is_group": 1, + "root_type": "Income", + "Erlöskonten 8": { + "is_group": 1, + "Erlöse": { + "account_number": "8200", + "account_type": "Income Account" + }, + "Erlöse USt. 19 %": { + "account_number": "8400", + "account_type": "Income Account" + }, + "Erlöse USt. 7 %": { + "account_number": "8300", + "account_type": "Income Account" + } + }, + "Ertragskonten 2": { "is_group": 1, - "Erl\u00f6se": { - "account_number": "8200", - "account_type": "Income Account" - }, - "Erl\u00f6se USt. 19%": { - "account_number": "8400", - "account_type": "Income Account" - }, - "Erl\u00f6se USt. 7%": { - "account_number": "8300", - "account_type": "Income Account" - } - }, - "Ertragskonten 2": { - "is_group": 1, - "sonstige Zinsen und \u00e4hnliche Ertr\u00e4ge": { - "account_number": "2650", - "account_type": "Income Account" - }, - "Au\u00dferordentliche Ertr\u00e4ge": { - "account_number": "2500", - "account_type": "Income Account" - }, - "Sonstige Ertr\u00e4ge": { - "account_number": "2700", - "account_type": "Income Account" - } - } - }, - "Aufwendungen 2/4": { - "is_group": 1, + "sonstige Zinsen und ähnliche Erträge": { + "account_number": "2650", + "account_type": "Income Account" + }, + "Außerordentliche Erträge": { + "account_number": "2500", + "account_type": "Income Account" + }, + "Sonstige Erträge": { + "account_number": "2700", + "account_type": "Income Account" + } + } + }, + "Aufwendungen 2/4": { + "is_group": 1, "root_type": "Expense", + "Fremdleistungen": { + "account_number": "3100", + "account_type": "Expense Account" + }, + "Fremdleistungen ohne Vorsteuer": { + "account_number": "3109", + "account_type": "Expense Account" + }, + "Bauleistungen eines im Inland ansässigen Unternehmers 19 % Vorsteuer und 19 % Umsatzsteuer": { + "account_number": "3120", + "account_type": "Expense Account" + }, "Wareneingang": { "account_number": "3200" }, @@ -298,234 +326,234 @@ "Gegenkonto 4996-4998": { "account_number": "4999" }, - "Abschreibungen": { - "is_group": 1, + "Abschreibungen": { + "is_group": 1, "Abschreibungen auf Sachanlagen (ohne AfA auf Kfz und Gebäude)": { - "account_number": "4830", - "account_type": "Accumulated Depreciation" + "account_number": "4830", + "account_type": "Accumulated Depreciation" }, "Abschreibungen auf Gebäude": { - "account_number": "4831", - "account_type": "Depreciation" + "account_number": "4831", + "account_type": "Depreciation" }, "Abschreibungen auf Kfz": { - "account_number": "4832", - "account_type": "Depreciation" + "account_number": "4832", + "account_type": "Depreciation" }, "Sofortabschreibung GWG": { - "account_number": "4855", - "account_type": "Expense Account" + "account_number": "4855", + "account_type": "Expense Account" + } + }, + "Kfz-Kosten": { + "is_group": 1, + "Kfz-Steuer": { + "account_number": "4510", + "account_type": "Expense Account" + }, + "Kfz-Versicherungen": { + "account_number": "4520", + "account_type": "Expense Account" + }, + "laufende Kfz-Betriebskosten": { + "account_number": "4530", + "account_type": "Expense Account" + }, + "Kfz-Reparaturen": { + "account_number": "4540", + "account_type": "Expense Account" + }, + "Fremdfahrzeuge": { + "account_number": "4570", + "account_type": "Expense Account" + }, + "sonstige Kfz-Kosten": { + "account_number": "4580", + "account_type": "Expense Account" + } + }, + "Personalkosten": { + "is_group": 1, + "Gehälter": { + "account_number": "4120", + "account_type": "Expense Account" + }, + "gesetzliche soziale Aufwendungen": { + "account_number": "4130", + "account_type": "Expense Account" + }, + "Aufwendungen für Altersvorsorge": { + "account_number": "4165", + "account_type": "Expense Account" + }, + "Vermögenswirksame Leistungen": { + "account_number": "4170", + "account_type": "Expense Account" + }, + "Aushilfslöhne": { + "account_number": "4190", + "account_type": "Expense Account" } - }, - "Kfz-Kosten": { - "is_group": 1, - "Kfz-Steuer": { - "account_number": "4510", - "account_type": "Expense Account" - }, - "Kfz-Versicherungen": { - "account_number": "4520", - "account_type": "Expense Account" - }, - "laufende Kfz-Betriebskosten": { - "account_number": "4530", - "account_type": "Expense Account" - }, - "Kfz-Reparaturen": { - "account_number": "4540", - "account_type": "Expense Account" - }, - "Fremdfahrzeuge": { - "account_number": "4570", - "account_type": "Expense Account" - }, - "sonstige Kfz-Kosten": { - "account_number": "4580", - "account_type": "Expense Account" - } - }, - "Personalkosten": { - "is_group": 1, - "Geh\u00e4lter": { - "account_number": "4120", - "account_type": "Expense Account" - }, - "gesetzliche soziale Aufwendungen": { - "account_number": "4130", - "account_type": "Expense Account" - }, - "Aufwendungen f\u00fcr Altersvorsorge": { - "account_number": "4165", - "account_type": "Expense Account" - }, - "Verm\u00f6genswirksame Leistungen": { - "account_number": "4170", - "account_type": "Expense Account" - }, - "Aushilfsl\u00f6hne": { - "account_number": "4190", - "account_type": "Expense Account" - } - }, - "Raumkosten": { - "is_group": 1, - "Miete und Nebenkosten": { - "account_number": "4210", - "account_type": "Expense Account" - }, - "Gas, Wasser, Strom (Verwaltung, Vertrieb)": { - "account_number": "4240", - "account_type": "Expense Account" - }, - "Reinigung": { - "account_number": "4250", - "account_type": "Expense Account" - } - }, - "Reparatur/Instandhaltung": { - "is_group": 1, - "Reparatur u. Instandh. von Anlagen/Maschinen u. Betriebs- u. Gesch\u00e4ftsausst.": { - "account_number": "4805", - "account_type": "Expense Account" - } - }, - "Versicherungsbeitr\u00e4ge": { - "is_group": 1, - "Versicherungen": { - "account_number": "4360", - "account_type": "Expense Account" - }, - "Beitr\u00e4ge": { - "account_number": "4380", - "account_type": "Expense Account" - }, - "sonstige Ausgaben": { - "account_number": "4390", - "account_type": "Expense Account" - }, - "steuerlich abzugsf\u00e4hige Versp\u00e4tungszuschl\u00e4ge und Zwangsgelder": { - "account_number": "4396", - "account_type": "Expense Account" - } - }, - "Werbe-/Reisekosten": { - "is_group": 1, - "Werbekosten": { - "account_number": "4610", - "account_type": "Expense Account" - }, - "Aufmerksamkeiten": { - "account_number": "4653", - "account_type": "Expense Account" - }, - "nicht abzugsf\u00e4hige Betriebsausg. aus Werbe-, Repr\u00e4s.- u. Reisekosten": { - "account_number": "4665", - "account_type": "Expense Account" - }, - "Reisekosten Unternehmer": { - "account_number": "4670", - "account_type": "Expense Account" - } - }, - "verschiedene Kosten": { - "is_group": 1, - "Porto": { - "account_number": "4910", - "account_type": "Expense Account" - }, - "Telekom": { - "account_number": "4920", - "account_type": "Expense Account" - }, - "Mobilfunk D2": { - "account_number": "4921", - "account_type": "Expense Account" - }, - "Internet": { - "account_number": "4922", - "account_type": "Expense Account" - }, - "B\u00fcrobedarf": { - "account_number": "4930", - "account_type": "Expense Account" - }, - "Zeitschriften, B\u00fccher": { - "account_number": "4940", - "account_type": "Expense Account" - }, - "Fortbildungskosten": { - "account_number": "4945", - "account_type": "Expense Account" - }, - "Buchf\u00fchrungskosten": { - "account_number": "4955", - "account_type": "Expense Account" - }, - "Abschlu\u00df- u. Pr\u00fcfungskosten": { - "account_number": "4957", - "account_type": "Expense Account" - }, - "Nebenkosten des Geldverkehrs": { - "account_number": "4970", - "account_type": "Expense Account" - }, - "Werkzeuge und Kleinger\u00e4te": { - "account_number": "4985", - "account_type": "Expense Account" - } - }, - "Zinsaufwendungen": { - "is_group": 1, - "Zinsaufwendungen f\u00fcr kurzfristige Verbindlichkeiten": { - "account_number": "2110", - "account_type": "Expense Account" - }, - "Zinsaufwendungen f\u00fcr KFZ Finanzierung": { - "account_number": "2121", - "account_type": "Expense Account" - } - } - }, - "Anfangsbestand 9": { - "is_group": 1, - "root_type": "Equity", - "Saldenvortragskonten": { - "is_group": 1, - "Saldenvortrag Sachkonten": { - "account_number": "9000" - }, - "Saldenvortr\u00e4ge Debitoren": { - "account_number": "9008" - }, - "Saldenvortr\u00e4ge Kreditoren": { - "account_number": "9009" - } - } - }, - "Privatkonten 1": { - "is_group": 1, - "root_type": "Equity", - "Privatentnahmen/-einlagen": { - "is_group": 1, - "Privatentnahme allgemein": { - "account_number": "1800" - }, - "Privatsteuern": { - "account_number": "1810" - }, - "Sonderausgaben beschr\u00e4nkt abzugsf\u00e4hig": { - "account_number": "1820" - }, - "Sonderausgaben unbeschr\u00e4nkt abzugsf\u00e4hig": { - "account_number": "1830" - }, - "Au\u00dfergew\u00f6hnliche Belastungen": { - "account_number": "1850" - }, - "Privateinlagen": { - "account_number": "1890" - } - } - } - } + }, + "Raumkosten": { + "is_group": 1, + "Miete und Nebenkosten": { + "account_number": "4210", + "account_type": "Expense Account" + }, + "Gas, Wasser, Strom (Verwaltung, Vertrieb)": { + "account_number": "4240", + "account_type": "Expense Account" + }, + "Reinigung": { + "account_number": "4250", + "account_type": "Expense Account" + } + }, + "Reparatur/Instandhaltung": { + "is_group": 1, + "Reparaturen und Instandhaltungen von anderen Anlagen und Betriebs- und Geschäftsausstattung": { + "account_number": "4805", + "account_type": "Expense Account" + } + }, + "Versicherungsbeiträge": { + "is_group": 1, + "Versicherungen": { + "account_number": "4360", + "account_type": "Expense Account" + }, + "Beiträge": { + "account_number": "4380", + "account_type": "Expense Account" + }, + "sonstige Ausgaben": { + "account_number": "4390", + "account_type": "Expense Account" + }, + "steuerlich abzugsfähige Verspätungszuschläge und Zwangsgelder": { + "account_number": "4396", + "account_type": "Expense Account" + } + }, + "Werbe-/Reisekosten": { + "is_group": 1, + "Werbekosten": { + "account_number": "4610", + "account_type": "Expense Account" + }, + "Aufmerksamkeiten": { + "account_number": "4653", + "account_type": "Expense Account" + }, + "nicht abzugsfähige Betriebsausg. aus Werbe-, Repräs.- u. Reisekosten": { + "account_number": "4665", + "account_type": "Expense Account" + }, + "Reisekosten Unternehmer": { + "account_number": "4670", + "account_type": "Expense Account" + } + }, + "verschiedene Kosten": { + "is_group": 1, + "Porto": { + "account_number": "4910", + "account_type": "Expense Account" + }, + "Telekom": { + "account_number": "4920", + "account_type": "Expense Account" + }, + "Mobilfunk D2": { + "account_number": "4921", + "account_type": "Expense Account" + }, + "Internet": { + "account_number": "4922", + "account_type": "Expense Account" + }, + "Bürobedarf": { + "account_number": "4930", + "account_type": "Expense Account" + }, + "Zeitschriften, Bücher": { + "account_number": "4940", + "account_type": "Expense Account" + }, + "Fortbildungskosten": { + "account_number": "4945", + "account_type": "Expense Account" + }, + "Buchführungskosten": { + "account_number": "4955", + "account_type": "Expense Account" + }, + "Abschluß- u. Prüfungskosten": { + "account_number": "4957", + "account_type": "Expense Account" + }, + "Nebenkosten des Geldverkehrs": { + "account_number": "4970", + "account_type": "Expense Account" + }, + "Werkzeuge und Kleingeräte": { + "account_number": "4985", + "account_type": "Expense Account" + } + }, + "Zinsaufwendungen": { + "is_group": 1, + "Zinsaufwendungen für kurzfristige Verbindlichkeiten": { + "account_number": "2110", + "account_type": "Expense Account" + }, + "Zinsaufwendungen für KFZ Finanzierung": { + "account_number": "2121", + "account_type": "Expense Account" + } + } + }, + "Anfangsbestand 9": { + "is_group": 1, + "root_type": "Equity", + "Saldenvortragskonten": { + "is_group": 1, + "Saldenvortrag Sachkonten": { + "account_number": "9000" + }, + "Saldenvorträge Debitoren": { + "account_number": "9008" + }, + "Saldenvorträge Kreditoren": { + "account_number": "9009" + } + } + }, + "Privatkonten 1": { + "is_group": 1, + "root_type": "Equity", + "Privatentnahmen/-einlagen": { + "is_group": 1, + "Privatentnahme allgemein": { + "account_number": "1800" + }, + "Privatsteuern": { + "account_number": "1810" + }, + "Sonderausgaben beschränkt abzugsfähig": { + "account_number": "1820" + }, + "Sonderausgaben unbeschränkt abzugsfähig": { + "account_number": "1830" + }, + "Außergewöhnliche Belastungen": { + "account_number": "1850" + }, + "Privateinlagen": { + "account_number": "1890" + } + } + } + } } From b0ed3c8aedc3ecf43d957b9a894491f180b77144 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 11 Feb 2023 12:27:06 +0530 Subject: [PATCH 40/53] fix: Ignore mandatory fields while creating tax templates for new companies (#34005) fix: Ignore mandatory fields while creating tax templates for new companies (#34005) (cherry picked from commit 0efdc6c13a4748c790596a276a5eb2bb67b7a87e) Co-authored-by: Deepesh Garg --- erpnext/setup/setup_wizard/operations/taxes_setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/setup/setup_wizard/operations/taxes_setup.py b/erpnext/setup/setup_wizard/operations/taxes_setup.py index 2f77dd6ae567..49ba78c63a42 100644 --- a/erpnext/setup/setup_wizard/operations/taxes_setup.py +++ b/erpnext/setup/setup_wizard/operations/taxes_setup.py @@ -158,6 +158,7 @@ def make_taxes_and_charges_template(company_name, doctype, template): # Ingone validations to make doctypes faster doc.flags.ignore_links = True doc.flags.ignore_validate = True + doc.flags.ignore_mandatory = True doc.insert(ignore_permissions=True) return doc From 5270fbe01a3e83a432610db94f4bc49359eb8821 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 11 Feb 2023 14:54:22 +0530 Subject: [PATCH 41/53] fix: set per_billed based on hours when amounts are zero (#33984) fix: set per_billed based on hours when amounts are zero (#33984) * fix: set per_billed based on hours when amounts are zero * test: calculate_percentage_billed (cherry picked from commit e4953df4a3b136b6a06b74b114a880d5d79eb103) Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> --- .../doctype/timesheet/test_timesheet.py | 31 +++++++++++++++++++ .../projects/doctype/timesheet/timesheet.py | 2 ++ 2 files changed, 33 insertions(+) diff --git a/erpnext/projects/doctype/timesheet/test_timesheet.py b/erpnext/projects/doctype/timesheet/test_timesheet.py index e098c3e3c45e..828a55e7bc13 100644 --- a/erpnext/projects/doctype/timesheet/test_timesheet.py +++ b/erpnext/projects/doctype/timesheet/test_timesheet.py @@ -161,6 +161,37 @@ def test_to_time(self): to_time = timesheet.time_logs[0].to_time self.assertEqual(to_time, add_to_date(from_time, hours=2, as_datetime=True)) + def test_per_billed_hours(self): + """If amounts are 0, per_billed should be calculated based on hours.""" + ts = frappe.new_doc("Timesheet") + ts.total_billable_amount = 0 + ts.total_billed_amount = 0 + ts.total_billable_hours = 2 + + ts.total_billed_hours = 0.5 + ts.calculate_percentage_billed() + self.assertEqual(ts.per_billed, 25) + + ts.total_billed_hours = 2 + ts.calculate_percentage_billed() + self.assertEqual(ts.per_billed, 100) + + def test_per_billed_amount(self): + """If amounts are > 0, per_billed should be calculated based on amounts, regardless of hours.""" + ts = frappe.new_doc("Timesheet") + ts.total_billable_hours = 2 + ts.total_billed_hours = 1 + ts.total_billable_amount = 200 + ts.total_billed_amount = 50 + ts.calculate_percentage_billed() + self.assertEqual(ts.per_billed, 25) + + ts.total_billed_hours = 3 + ts.total_billable_amount = 200 + ts.total_billed_amount = 200 + ts.calculate_percentage_billed() + self.assertEqual(ts.per_billed, 100) + def make_timesheet( employee, diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py index b9bb37a05cf0..4a27807e4ec9 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.py +++ b/erpnext/projects/doctype/timesheet/timesheet.py @@ -58,6 +58,8 @@ def calculate_percentage_billed(self): self.per_billed = 0 if self.total_billed_amount > 0 and self.total_billable_amount > 0: self.per_billed = (self.total_billed_amount * 100) / self.total_billable_amount + elif self.total_billed_hours > 0 and self.total_billable_hours > 0: + self.per_billed = (self.total_billed_hours * 100) / self.total_billable_hours def update_billing_hours(self, args): if args.is_billable: From dd31bd5254ad344064f4df30d967462a9c85a218 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 11 Feb 2023 16:22:26 +0530 Subject: [PATCH 42/53] refactor: install fixtures (#33964) refactor: install fixtures (#33964) * refactor: install fixtures * style: disable semgrep for install_defaults signature (cherry picked from commit 201573ab9af145d20f0d57cac00b8ec308fc039b) Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> --- .../setup_wizard/operations/install_fixtures.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index 4d9b871e5e7b..1f8c0d6a1ca1 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -335,16 +335,11 @@ def install(country=None): make_default_records() make_records(records) set_up_address_templates(default_country=country) - set_more_defaults() - update_global_search_doctypes() - - -def set_more_defaults(): - # Do more setup stuff that can be done here with no dependencies update_selling_defaults() update_buying_defaults() add_uom_data() update_item_variant_settings() + update_global_search_doctypes() def update_selling_defaults(): @@ -381,7 +376,7 @@ def add_uom_data(): ) for d in uoms: if not frappe.db.exists("UOM", _(d.get("uom_name"))): - uom_doc = frappe.get_doc( + frappe.get_doc( { "doctype": "UOM", "uom_name": _(d.get("uom_name")), @@ -404,7 +399,7 @@ def add_uom_data(): if not frappe.db.exists( "UOM Conversion Factor", {"from_uom": _(d.get("from_uom")), "to_uom": _(d.get("to_uom"))} ): - uom_conversion = frappe.get_doc( + frappe.get_doc( { "doctype": "UOM Conversion Factor", "category": _(d.get("category")), @@ -412,7 +407,7 @@ def add_uom_data(): "to_uom": _(d.get("to_uom")), "value": d.get("value"), } - ).insert(ignore_permissions=True) + ).db_insert() def add_market_segments(): @@ -468,7 +463,7 @@ def install_company(args): make_records(records) -def install_defaults(args=None): +def install_defaults(args=None): # nosemgrep records = [ # Price Lists { @@ -493,7 +488,7 @@ def install_defaults(args=None): # enable default currency frappe.db.set_value("Currency", args.get("currency"), "enabled", 1) - frappe.db.set_value("Stock Settings", None, "email_footer_address", args.get("company_name")) + frappe.db.set_single_value("Stock Settings", "email_footer_address", args.get("company_name")) set_global_defaults(args) update_stock_settings() From 49fd712966e270f094ff00089b46f194b061e4d6 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sun, 12 Feb 2023 09:02:40 +0530 Subject: [PATCH 43/53] fix: add payment hook to point of sale JS (#33988) fix: add payment hook to point of sale JS (#33988) (cherry picked from commit a0eb5e55359e47baa7391859f79a9ba3ef339cb9) Co-authored-by: Richard Case <110036763+casesolved-co-uk@users.noreply.github.com> --- erpnext/selling/page/point_of_sale/pos_payment.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/erpnext/selling/page/point_of_sale/pos_payment.js b/erpnext/selling/page/point_of_sale/pos_payment.js index 0a356b9a6fba..89ce61ab1680 100644 --- a/erpnext/selling/page/point_of_sale/pos_payment.js +++ b/erpnext/selling/page/point_of_sale/pos_payment.js @@ -322,6 +322,11 @@ erpnext.PointOfSale.Payment = class { this.focus_on_default_mop(); } + after_render() { + const frm = this.events.get_frm(); + frm.script_manager.trigger("after_payment_render", frm.doc.doctype, frm.doc.docname); + } + edit_cart() { this.events.toggle_other_sections(false); this.toggle_component(false); @@ -332,6 +337,7 @@ erpnext.PointOfSale.Payment = class { this.toggle_component(true); this.render_payment_section(); + this.after_render(); } toggle_remarks_control() { From 1d0e71bfe585c41bfcdc2ed29ade0887b466e10b Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sun, 12 Feb 2023 13:35:54 +0530 Subject: [PATCH 44/53] fix(ecommerce): throw invalid doctype error in shop by category (#33901) fix(ecommerce): throw invalid doctype error in shop by category (#33901) Co-authored-by: Deepesh Garg (cherry picked from commit 0df28c71743e2e91924e2c5062778e2e2e680666) Co-authored-by: Sabu Siyad --- erpnext/www/shop-by-category/index.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/erpnext/www/shop-by-category/index.py b/erpnext/www/shop-by-category/index.py index 8a92418d25ed..219747c9f8a5 100644 --- a/erpnext/www/shop-by-category/index.py +++ b/erpnext/www/shop-by-category/index.py @@ -51,21 +51,31 @@ def get_tabs(categories): return tab_values -def get_category_records(categories): +def get_category_records(categories: list): categorical_data = {} - for category in categories: - if category == "item_group": + + for c in categories: + if c == "item_group": categorical_data["item_group"] = frappe.db.get_all( "Item Group", filters={"parent_item_group": "All Item Groups", "show_in_website": 1}, fields=["name", "parent_item_group", "is_group", "image", "route"], ) - else: - doctype = frappe.unscrub(category) - fields = ["name"] - if frappe.get_meta(doctype, cached=True).get_field("image"): + + continue + + doctype = frappe.unscrub(c) + fields = ["name"] + + try: + meta = frappe.get_meta(doctype, cached=True) + if meta.get_field("image"): fields += ["image"] - categorical_data[category] = frappe.db.get_all(doctype, fields=fields) + data = frappe.db.get_all(doctype, fields=fields) + categorical_data[c] = data + except BaseException: + frappe.throw(_("DocType {} not found").format(doctype)) + continue return categorical_data From 699e93e17f61b9530c0670980de52b0f54473aec Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 13 Feb 2023 10:19:19 +0530 Subject: [PATCH 45/53] fix: Ignore Payment Ledger Entry on dunning cancel (backport #34025) (#34028) fix: Ignore Payment Ledger Entry on dunning cancel (#34025) * fix: Ignore Payment Ledger Entry on dunning cancel * chore: fix translation issue (cherry picked from commit 48bb2c942bfca2ad19d0b32d663f237245480696) Co-authored-by: Deepesh Garg --- erpnext/accounts/doctype/dunning/dunning.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/dunning/dunning.py b/erpnext/accounts/doctype/dunning/dunning.py index 9874d66fa553..7347865563a1 100644 --- a/erpnext/accounts/doctype/dunning/dunning.py +++ b/erpnext/accounts/doctype/dunning/dunning.py @@ -40,7 +40,7 @@ def on_submit(self): def on_cancel(self): if self.dunning_amount: - self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry") + self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry", "Payment Ledger Entry") make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name) def make_gl_entries(self): From 4d0e27ed2b219e15ad8738d41fea57c4e1a6430c Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 13 Feb 2023 11:08:55 +0530 Subject: [PATCH 46/53] feat: Setting to allow Sales Order creation against expired quotation (#33952) feat: Setting to allow Sales Order creation against expired quotation (#33952) * feat: Setting to allow Sales Order creation against expired quotation * chore: linting issues (cherry picked from commit 148703bfc2fa9248c22d69ef92d14697a91a9301) Co-authored-by: Deepesh Garg --- erpnext/selling/doctype/quotation/quotation.js | 14 +++++++++----- erpnext/selling/doctype/quotation/quotation.py | 11 +++++++++++ .../selling/doctype/quotation/test_quotation.py | 10 ++++++++++ .../doctype/selling_settings/selling_settings.json | 9 ++++++++- erpnext/startup/boot.py | 6 ++++++ 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index 6b42e4daead2..b348bd35754f 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -85,11 +85,15 @@ erpnext.selling.QuotationController = class QuotationController extends erpnext. } if (doc.docstatus == 1 && !["Lost", "Ordered"].includes(doc.status)) { - this.frm.add_custom_button( - __("Sales Order"), - this.frm.cscript["Make Sales Order"], - __("Create") - ); + if (frappe.boot.sysdefaults.allow_sales_order_creation_for_expired_quotation + || (!doc.valid_till) + || frappe.datetime.get_diff(doc.valid_till, frappe.datetime.get_today()) >= 0) { + this.frm.add_custom_button( + __("Sales Order"), + this.frm.cscript["Make Sales Order"], + __("Create") + ); + } if(doc.status!=="Ordered") { this.frm.add_custom_button(__('Set as Lost'), () => { diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index 6836d56647f6..063813b2dc70 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -195,6 +195,17 @@ def get_list_context(context=None): @frappe.whitelist() def make_sales_order(source_name: str, target_doc=None): + if not frappe.db.get_singles_value( + "Selling Settings", "allow_sales_order_creation_for_expired_quotation" + ): + quotation = frappe.db.get_value( + "Quotation", source_name, ["transaction_date", "valid_till"], as_dict=1 + ) + if quotation.valid_till and ( + quotation.valid_till < quotation.transaction_date or quotation.valid_till < getdate(nowdate()) + ): + frappe.throw(_("Validity period of this quotation has ended.")) + return _make_sales_order(source_name, target_doc) diff --git a/erpnext/selling/doctype/quotation/test_quotation.py b/erpnext/selling/doctype/quotation/test_quotation.py index 5aaba4fa4356..cdf5f5d00c58 100644 --- a/erpnext/selling/doctype/quotation/test_quotation.py +++ b/erpnext/selling/doctype/quotation/test_quotation.py @@ -144,11 +144,21 @@ def test_valid_till_before_transaction_date(self): def test_so_from_expired_quotation(self): from erpnext.selling.doctype.quotation.quotation import make_sales_order + frappe.db.set_single_value( + "Selling Settings", "allow_sales_order_creation_for_expired_quotation", 0 + ) + quotation = frappe.copy_doc(test_records[0]) quotation.valid_till = add_days(nowdate(), -1) quotation.insert() quotation.submit() + self.assertRaises(frappe.ValidationError, make_sales_order, quotation.name) + + frappe.db.set_single_value( + "Selling Settings", "allow_sales_order_creation_for_expired_quotation", 1 + ) + make_sales_order(quotation.name) def test_shopping_cart_without_website_item(self): diff --git a/erpnext/selling/doctype/selling_settings/selling_settings.json b/erpnext/selling/doctype/selling_settings/selling_settings.json index 2abb169b8a06..6ea66a02378c 100644 --- a/erpnext/selling/doctype/selling_settings/selling_settings.json +++ b/erpnext/selling/doctype/selling_settings/selling_settings.json @@ -27,6 +27,7 @@ "column_break_5", "allow_multiple_items", "allow_against_multiple_purchase_orders", + "allow_sales_order_creation_for_expired_quotation", "hide_tax_id", "enable_discount_accounting" ], @@ -172,6 +173,12 @@ "fieldname": "enable_discount_accounting", "fieldtype": "Check", "label": "Enable Discount Accounting for Selling" + }, + { + "default": "0", + "fieldname": "allow_sales_order_creation_for_expired_quotation", + "fieldtype": "Check", + "label": "Allow Sales Order Creation For Expired Quotation" } ], "icon": "fa fa-cog", @@ -179,7 +186,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2022-05-31 19:39:48.398738", + "modified": "2023-02-04 12:37:53.380857", "modified_by": "Administrator", "module": "Selling", "name": "Selling Settings", diff --git a/erpnext/startup/boot.py b/erpnext/startup/boot.py index bb120eaa6b31..62936fcfb896 100644 --- a/erpnext/startup/boot.py +++ b/erpnext/startup/boot.py @@ -25,6 +25,12 @@ def boot_session(bootinfo): frappe.db.get_single_value("CRM Settings", "default_valid_till") ) + bootinfo.sysdefaults.allow_sales_order_creation_for_expired_quotation = cint( + frappe.db.get_single_value( + "Selling Settings", "allow_sales_order_creation_for_expired_quotation" + ) + ) + # if no company, show a dialog box to create a new company bootinfo.customer_count = frappe.db.sql("""SELECT count(*) FROM `tabCustomer`""")[0][0] From cbafc51e753b03ae9a56f08046e1c598f41877ab Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 13 Feb 2023 13:29:18 +0530 Subject: [PATCH 47/53] fix: unwanted difference amount calculation on cr note and invoice with same currency (#34020) fix: unwanted difference amount calculation on cr note and invoice with same currency (#34020) * fix: incorrect difference amount while reconiling cr/dr notes * fix(test): catch incorrect difference amount calculation Fixed issues where difference amount was calculated for Cr Notes and Invoices of the same currency. --------- Co-authored-by: Deepesh Garg (cherry picked from commit e5a2b15fba27bb35496bdf6cc3eb4d67b7bcf369) Co-authored-by: ruthra kumar --- .../payment_reconciliation.py | 15 +++++++++++++-- .../test_payment_reconciliation.py | 10 ++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py index 154fdc039d40..675a3287fa41 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py @@ -234,7 +234,7 @@ def get_difference_amount(self, payment_entry, invoice, allocated_amount): def allocate_entries(self, args): self.validate_entries() - invoice_exchange_map = self.get_invoice_exchange_map(args.get("invoices")) + invoice_exchange_map = self.get_invoice_exchange_map(args.get("invoices"), args.get("payments")) default_exchange_gain_loss_account = frappe.get_cached_value( "Company", self.company, "exchange_gain_loss_account" ) @@ -253,6 +253,9 @@ def allocate_entries(self, args): pay["amount"] = 0 inv["exchange_rate"] = invoice_exchange_map.get(inv.get("invoice_number")) + if pay.get("reference_type") in ["Sales Invoice", "Purchase Invoice"]: + pay["exchange_rate"] = invoice_exchange_map.get(pay.get("reference_name")) + res.difference_amount = self.get_difference_amount(pay, inv, res["allocated_amount"]) res.difference_account = default_exchange_gain_loss_account res.exchange_rate = inv.get("exchange_rate") @@ -407,13 +410,21 @@ def validate_entries(self): if not self.get("payments"): frappe.throw(_("No records found in the Payments table")) - def get_invoice_exchange_map(self, invoices): + def get_invoice_exchange_map(self, invoices, payments): sales_invoices = [ d.get("invoice_number") for d in invoices if d.get("invoice_type") == "Sales Invoice" ] + + sales_invoices.extend( + [d.get("reference_name") for d in payments if d.get("reference_type") == "Sales Invoice"] + ) purchase_invoices = [ d.get("invoice_number") for d in invoices if d.get("invoice_type") == "Purchase Invoice" ] + purchase_invoices.extend( + [d.get("reference_name") for d in payments if d.get("reference_type") == "Purchase Invoice"] + ) + invoice_exchange_map = frappe._dict() if sales_invoices: diff --git a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py index 00e3934f10c0..f9dda0593b0d 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py @@ -473,6 +473,11 @@ def test_cr_note_against_invoice(self): invoices = [x.as_dict() for x in pr.get("invoices")] payments = [x.as_dict() for x in pr.get("payments")] pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments})) + + # Cr Note and Invoice are of the same currency. There shouldn't any difference amount. + for row in pr.allocation: + self.assertEqual(flt(row.get("difference_amount")), 0.0) + pr.reconcile() pr.get_unreconciled_entries() @@ -506,6 +511,11 @@ def test_cr_note_partial_against_invoice(self): payments = [x.as_dict() for x in pr.get("payments")] pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments})) pr.allocation[0].allocated_amount = allocated_amount + + # Cr Note and Invoice are of the same currency. There shouldn't any difference amount. + for row in pr.allocation: + self.assertEqual(flt(row.get("difference_amount")), 0.0) + pr.reconcile() # assert outstanding From 1540aea21df8029103ac31119054d4191f5b12f5 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 13 Feb 2023 13:29:41 +0530 Subject: [PATCH 48/53] refactor: filter only immediate upcoming payment term for each SO (#33923) refactor: filter only immediate upcoming payment term for each SO (#33923) * fix: ignore closed or 'on hold' orders * refactor: filter immediate upcoming term --------- Co-authored-by: Deepesh Garg (cherry picked from commit 192a3395a5ca5804ed48582b6c7137ae2138880a) Co-authored-by: ruthra kumar --- .../payment_terms_status_for_sales_order.js | 5 +++++ .../payment_terms_status_for_sales_order.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.js b/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.js index 991ac719cdc8..990d736baa4e 100644 --- a/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.js +++ b/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.js @@ -103,6 +103,11 @@ function get_filters() { return options } }, + { + "fieldname":"only_immediate_upcoming_term", + "label": __("Show only the Immediate Upcoming Term"), + "fieldtype": "Check", + }, ] return filters; } diff --git a/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.py b/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.py index 8bf56865a7d6..3682c5fd62e1 100644 --- a/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.py +++ b/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.py @@ -4,6 +4,7 @@ import frappe from frappe import _, qb, query_builder from frappe.query_builder import Criterion, functions +from frappe.utils.dateutils import getdate def get_columns(): @@ -208,6 +209,7 @@ def get_so_with_invoices(filters): ) .where( (so.docstatus == 1) + & (so.status.isin(["To Deliver and Bill", "To Bill"])) & (so.payment_terms_template != "NULL") & (so.company == conditions.company) & (so.transaction_date[conditions.start_date : conditions.end_date]) @@ -291,6 +293,18 @@ def filter_on_calculated_status(filters, sales_orders): return sales_orders +def filter_for_immediate_upcoming_term(filters, sales_orders): + if filters.only_immediate_upcoming_term and sales_orders: + immediate_term_found = set() + filtered_data = [] + for order in sales_orders: + if order.name not in immediate_term_found and order.due_date > getdate(): + filtered_data.append(order) + immediate_term_found.add(order.name) + return filtered_data + return sales_orders + + def execute(filters=None): columns = get_columns() sales_orders, so_invoices = get_so_with_invoices(filters) @@ -298,6 +312,8 @@ def execute(filters=None): sales_orders = filter_on_calculated_status(filters, sales_orders) + sales_orders = filter_for_immediate_upcoming_term(filters, sales_orders) + prepare_chart(sales_orders) data = sales_orders From c71d03555f41fe01c6eed9c3cf0184b3e9d58dd5 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Sun, 12 Feb 2023 14:06:40 +0530 Subject: [PATCH 49/53] fix: IntegrityError while cancelling journals against cr note (cherry picked from commit b9a7ff7c3df77f008afa9454e3386368767bf5cd) --- erpnext/accounts/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 31885ac07b3e..38aa8056e9cc 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -1512,9 +1512,12 @@ def update_voucher_outstanding(voucher_type, voucher_no, account, party_type, pa ref_doc = frappe.get_doc(voucher_type, voucher_no) # Didn't use db_set for optimisation purpose - ref_doc.outstanding_amount = outstanding["outstanding_in_account_currency"] + ref_doc.outstanding_amount = outstanding["outstanding_in_account_currency"] or 0.0 frappe.db.set_value( - voucher_type, voucher_no, "outstanding_amount", outstanding["outstanding_in_account_currency"] + voucher_type, + voucher_no, + "outstanding_amount", + outstanding["outstanding_in_account_currency"] or 0.0, ) ref_doc.set_status(update=True) From 087333abcbe0bca99d49bd2fe88766a8e751e7be Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 13 Feb 2023 16:30:03 +0530 Subject: [PATCH 50/53] fix: Concurrency issues in Sales and Purchase returns (#34019) fix: Concurrency issues in Sales and Purchase returns (#34019) (cherry picked from commit a67284e96dabe71b76a373b5f1f3142dccf3952b) Co-authored-by: Deepesh Garg --- erpnext/controllers/sales_and_purchase_return.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index 8bd09982bf42..935796c7a712 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -252,6 +252,7 @@ def get_already_returned_items(doc): child.parent = par.name and par.docstatus = 1 and par.is_return = 1 and par.return_against = %s group by item_code + for update """.format( column, doc.doctype, doc.doctype ), From c7c61239a3b95439f8de2342f9e080fed4fec592 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 14 Feb 2023 08:59:03 +0530 Subject: [PATCH 51/53] fix: Amount validation in Payment Request against Purchase Order (#34042) fix: Amount validation in Payment Request against Purchase Order (#34042) (cherry picked from commit ce748cec3a6e2b289878bf5d57ac6db3cb851618) Co-authored-by: Deepesh Garg --- .../payment_request/payment_request.py | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 68c2a32715c1..86c373cf93dc 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -45,21 +45,20 @@ def validate_reference_document(self): frappe.throw(_("To create a Payment Request reference document is required")) def validate_payment_request_amount(self): - existing_payment_request_amount = get_existing_payment_request_amount( - self.reference_doctype, self.reference_name + existing_payment_request_amount = flt( + get_existing_payment_request_amount(self.reference_doctype, self.reference_name) ) - if existing_payment_request_amount: - ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name) - if not hasattr(ref_doc, "order_type") or getattr(ref_doc, "order_type") != "Shopping Cart": - ref_amount = get_amount(ref_doc, self.payment_account) + ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name) + if not hasattr(ref_doc, "order_type") or getattr(ref_doc, "order_type") != "Shopping Cart": + ref_amount = get_amount(ref_doc, self.payment_account) - if existing_payment_request_amount + flt(self.grand_total) > ref_amount: - frappe.throw( - _("Total Payment Request amount cannot be greater than {0} amount").format( - self.reference_doctype - ) + if existing_payment_request_amount + flt(self.grand_total) > ref_amount: + frappe.throw( + _("Total Payment Request amount cannot be greater than {0} amount").format( + self.reference_doctype ) + ) def validate_currency(self): ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name) From 6fe7600844dc6ac9f4e83eaa9e8d414350591d02 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 14 Feb 2023 08:59:25 +0530 Subject: [PATCH 52/53] fix: should never get cutomer price on purchase document (#34002) fix: should never get cutomer price on purchase document (#34002) * fix: never get cutomer price on purchase document chores: syntax chore: typo in stock_entry get_uom_details (#33998) fix: typo in stock_entry get_uom_details chores: syntax * feat: add test for get_item_detail price list oriented * feat: add test for get_item_detail price price oriented * feat: add test for get_item_detail price price oriented * chore: clean test code (cherry picked from commit 231fe4156f9686eb7dd3b67e9fe0321920655689) Co-authored-by: HENRY Florian --- .../doctype/item_price/test_records.json | 14 +++++++ .../doctype/price_list/test_records.json | 16 ++++++++ erpnext/stock/get_item_details.py | 7 ++++ erpnext/stock/tests/test_get_item_details.py | 40 +++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 erpnext/stock/tests/test_get_item_details.py diff --git a/erpnext/stock/doctype/item_price/test_records.json b/erpnext/stock/doctype/item_price/test_records.json index 0a3d7e81985f..afe5ad65b756 100644 --- a/erpnext/stock/doctype/item_price/test_records.json +++ b/erpnext/stock/doctype/item_price/test_records.json @@ -38,5 +38,19 @@ "price_list_rate": 1000, "valid_from": "2017-04-10", "valid_upto": "2017-04-17" + }, + { + "doctype": "Item Price", + "item_code": "_Test Item", + "price_list": "_Test Buying Price List", + "price_list_rate": 100, + "supplier": "_Test Supplier" + }, + { + "doctype": "Item Price", + "item_code": "_Test Item", + "price_list": "_Test Selling Price List", + "price_list_rate": 200, + "customer": "_Test Customer" } ] diff --git a/erpnext/stock/doctype/price_list/test_records.json b/erpnext/stock/doctype/price_list/test_records.json index 7ca949c40263..e02a7adbd8ba 100644 --- a/erpnext/stock/doctype/price_list/test_records.json +++ b/erpnext/stock/doctype/price_list/test_records.json @@ -31,5 +31,21 @@ "enabled": 1, "price_list_name": "_Test Price List Rest of the World", "selling": 1 + }, + { + "buying": 0, + "currency": "USD", + "doctype": "Price List", + "enabled": 1, + "price_list_name": "_Test Selling Price List", + "selling": 1 + }, + { + "buying": 1, + "currency": "USD", + "doctype": "Price List", + "enabled": 1, + "price_list_name": "_Test Buying Price List", + "selling": 0 } ] diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 5af144110f0c..b53f429edf21 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -88,8 +88,15 @@ def get_item_details(args, doc=None, for_validate=False, overwrite_warehouse=Tru update_party_blanket_order(args, out) + # Never try to find a customer price if customer is set in these Doctype + current_customer = args.customer + if args.get("doctype") in ["Purchase Order", "Purchase Receipt", "Purchase Invoice"]: + args.customer = None + out.update(get_price_list_rate(args, item)) + args.customer = current_customer + if args.customer and cint(args.is_pos): out.update(get_pos_profile_item_details(args.company, args, update_data=True)) diff --git a/erpnext/stock/tests/test_get_item_details.py b/erpnext/stock/tests/test_get_item_details.py new file mode 100644 index 000000000000..b53e29e9e8e1 --- /dev/null +++ b/erpnext/stock/tests/test_get_item_details.py @@ -0,0 +1,40 @@ +import json + +import frappe +from frappe.test_runner import make_test_records +from frappe.tests.utils import FrappeTestCase + +from erpnext.stock.get_item_details import get_item_details + +test_ignore = ["BOM"] +test_dependencies = ["Customer", "Supplier", "Item", "Price List", "Item Price"] + + +class TestGetItemDetail(FrappeTestCase): + def setUp(self): + make_test_records("Price List") + super().setUp() + + def test_get_item_detail_purchase_order(self): + + args = frappe._dict( + { + "item_code": "_Test Item", + "company": "_Test Company", + "customer": "_Test Customer", + "conversion_rate": 1.0, + "price_list_currency": "USD", + "plc_conversion_rate": 1.0, + "doctype": "Purchase Order", + "name": None, + "supplier": "_Test Supplier", + "transaction_date": None, + "conversion_rate": 1.0, + "price_list": "_Test Buying Price List", + "is_subcontracted": 0, + "ignore_pricing_rule": 1, + "qty": 1, + } + ) + details = get_item_details(args) + self.assertEqual(details.get("price_list_rate"), 100) From 47d17f413639ef3601cc6c562cbbe3c2634ad837 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Mon, 13 Feb 2023 23:34:20 +0100 Subject: [PATCH 53/53] fix: BOM import failed as importer use same label field for Raw MaterialsItem table and Scrap Item table (cherry picked from commit 86be259341976a909b5d72a1537f1f63f477a7b8) --- erpnext/manufacturing/doctype/bom/bom.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom/bom.json b/erpnext/manufacturing/doctype/bom/bom.json index c2b331fcfd1f..db699b94d8fa 100644 --- a/erpnext/manufacturing/doctype/bom/bom.json +++ b/erpnext/manufacturing/doctype/bom/bom.json @@ -289,7 +289,7 @@ { "fieldname": "scrap_items", "fieldtype": "Table", - "label": "Items", + "label": "Scrap Items", "options": "BOM Scrap Item" }, { @@ -605,7 +605,7 @@ "image_field": "image", "is_submittable": 1, "links": [], - "modified": "2023-01-10 07:47:08.652616", + "modified": "2023-02-13 17:31:37.504565", "modified_by": "Administrator", "module": "Manufacturing", "name": "BOM",