From e0ff9142accec3660e01bad6ffb47411bd049349 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Mon, 27 Apr 2020 13:29:46 +0530 Subject: [PATCH 001/449] fix: show date in the message for already marked attendance --- erpnext/hr/doctype/attendance/attendance.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/hr/doctype/attendance/attendance.py b/erpnext/hr/doctype/attendance/attendance.py index b6c80655c2..9df097923e 100644 --- a/erpnext/hr/doctype/attendance/attendance.py +++ b/erpnext/hr/doctype/attendance/attendance.py @@ -35,13 +35,14 @@ class Attendance(Document): and docstatus != 2 """, (self.employee, getdate(self.attendance_date), self.name)) if res: - frappe.throw(_("Attendance for employee {0} is already marked").format(self.employee)) + frappe.throw(_("Attendance for employee {0} is already marked for the date {1}").format( + frappe.bold(self.employee), frappe.bold(self.attendance_date))) def check_leave_record(self): leave_record = frappe.db.sql(""" select leave_type, half_day, half_day_date from `tabLeave Application` - where employee = %s + where employee = %s and %s between from_date and to_date and status = 'Approved' and docstatus = 1 From bc346b5bea3d7c2781b793347992db95fab3e969 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 28 Apr 2020 11:17:45 +0530 Subject: [PATCH 002/449] fix: Default column width in Gross profit report --- .../report/gross_profit/gross_profit.py | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py index 6ef6d6eea0..4e22b05a81 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.py +++ b/erpnext/accounts/report/gross_profit/gross_profit.py @@ -55,27 +55,27 @@ def get_columns(group_wise_columns, filters): columns = [] column_map = frappe._dict({ "parent": _("Sales Invoice") + ":Link/Sales Invoice:120", - "posting_date": _("Posting Date") + ":Date", - "posting_time": _("Posting Time"), - "item_code": _("Item Code") + ":Link/Item", - "item_name": _("Item Name"), - "item_group": _("Item Group") + ":Link/Item Group", - "brand": _("Brand"), - "description": _("Description"), - "warehouse": _("Warehouse") + ":Link/Warehouse", - "qty": _("Qty") + ":Float", - "base_rate": _("Avg. Selling Rate") + ":Currency/currency", - "buying_rate": _("Valuation Rate") + ":Currency/currency", - "base_amount": _("Selling Amount") + ":Currency/currency", - "buying_amount": _("Buying Amount") + ":Currency/currency", - "gross_profit": _("Gross Profit") + ":Currency/currency", - "gross_profit_percent": _("Gross Profit %") + ":Percent", - "project": _("Project") + ":Link/Project", + "posting_date": _("Posting Date") + ":Date:100", + "posting_time": _("Posting Time") + ":Data:100", + "item_code": _("Item Code") + ":Link/Item:100", + "item_name": _("Item Name") + ":Data:100", + "item_group": _("Item Group") + ":Link/Item Group:100", + "brand": _("Brand") + ":Link/Brand:100", + "description": _("Description") +":Data:100", + "warehouse": _("Warehouse") + ":Link/Warehouse:100", + "qty": _("Qty") + ":Float:80", + "base_rate": _("Avg. Selling Rate") + ":Currency/currency:100", + "buying_rate": _("Valuation Rate") + ":Currency/currency:100", + "base_amount": _("Selling Amount") + ":Currency/currency:100", + "buying_amount": _("Buying Amount") + ":Currency/currency:100", + "gross_profit": _("Gross Profit") + ":Currency/currency:100", + "gross_profit_percent": _("Gross Profit %") + ":Percent:100", + "project": _("Project") + ":Link/Project:100", "sales_person": _("Sales person"), - "allocated_amount": _("Allocated Amount") + ":Currency/currency", - "customer": _("Customer") + ":Link/Customer", - "customer_group": _("Customer Group") + ":Link/Customer Group", - "territory": _("Territory") + ":Link/Territory" + "allocated_amount": _("Allocated Amount") + ":Currency/currency:100", + "customer": _("Customer") + ":Link/Customer:100", + "customer_group": _("Customer Group") + ":Link/Customer Group:100", + "territory": _("Territory") + ":Link/Territory:100" }) for col in group_wise_columns.get(scrub(filters.group_by)): @@ -85,7 +85,8 @@ def get_columns(group_wise_columns, filters): "fieldname": "currency", "label" : _("Currency"), "fieldtype": "Link", - "options": "Currency" + "options": "Currency", + "hidden": 1 }) return columns @@ -277,7 +278,7 @@ class GrossProfitGenerator(object): from `tabPurchase Invoice Item` a where a.item_code = %s and a.docstatus=1 and modified <= %s - order by a.modified desc limit 1""", (item_code,self.filters.to_date)) + order by a.modified desc limit 1""", (item_code, self.filters.to_date)) else: last_purchase_rate = frappe.db.sql(""" select (a.base_rate / a.conversion_factor) From ac98eb544850723ad0e5cfb730b1fd85ad1b53bb Mon Sep 17 00:00:00 2001 From: Marica Date: Tue, 28 Apr 2020 13:00:44 +0530 Subject: [PATCH 003/449] fix: Blanket Order in SO/PO child tables (#21443) --- .../doctype/purchase_order/purchase_order.js | 9 --------- erpnext/controllers/queries.py | 13 +++++++++++++ erpnext/public/js/controllers/transaction.js | 14 ++++++++++++++ erpnext/selling/doctype/sales_order/sales_order.js | 11 +---------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index ed054aedb5..4a8146a797 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -27,15 +27,6 @@ frappe.ui.form.on("Purchase Order", { frm.set_indicator_formatter('item_code', function(doc) { return (doc.qty<=doc.received_qty) ? "green" : "orange" }) - frm.set_query("blanket_order", "items", function() { - return { - filters: { - "company": frm.doc.company, - "docstatus": 1 - } - } - }); - frm.set_query("expense_account", "items", function() { return { query: "erpnext.controllers.queries.get_expense_account", diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index c14bb669a4..5febfd6bf2 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -371,6 +371,19 @@ def get_account_list(doctype, txt, searchfield, start, page_len, filters): fields = ["name", "parent_account"], limit_start=start, limit_page_length=page_len, as_list=True) +def get_blanket_orders(doctype, txt, searchfield, start, page_len, filters): + return frappe.db.sql("""select distinct bo.name, bo.blanket_order_type, bo.to_date + from `tabBlanket Order` bo, `tabBlanket Order Item` boi + where + boi.parent = bo.name + and boi.item_code = {item_code} + and bo.blanket_order_type = '{blanket_order_type}' + and bo.company = {company} + and bo.docstatus = 1""" + .format(item_code = frappe.db.escape(filters.get("item")), + blanket_order_type = filters.get("blanket_order_type"), + company = frappe.db.escape(filters.get("company")) + )) @frappe.whitelist() def get_income_account(doctype, txt, searchfield, start, page_len, filters): diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 5843034543..c9d7728521 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -175,6 +175,20 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ }; } + if (this.frm.fields_dict["items"].grid.get_field('blanket_order')) { + this.frm.set_query("blanket_order", "items", function(doc, cdt, cdn) { + var item = locals[cdt][cdn]; + return { + query: "erpnext.controllers.queries.get_blanket_orders", + filters: { + "company": doc.company, + "blanket_order_type": doc.doctype === "Sales Order" ? "Selling" : "Purchasing", + "item": item.item_code + } + } + }); + } + }, onload: function() { var me = this; diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js index 3c1ffe9596..45a43c5e7e 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.js +++ b/erpnext/selling/doctype/sales_order/sales_order.js @@ -65,15 +65,6 @@ frappe.ui.form.on("Sales Order", { } }); - frm.set_query("blanket_order", "items", function() { - return { - filters: { - "company": frm.doc.company, - "docstatus": 1 - } - } - }); - erpnext.queries.setup_warehouse_query(frm); }, @@ -148,7 +139,7 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend( } this.frm.add_custom_button(__('Pick List'), () => this.create_pick_list(), __('Create')); - + const order_is_a_sale = ["Sales", "Shopping Cart"].indexOf(doc.order_type) !== -1; const order_is_maintenance = ["Maintenance"].indexOf(doc.order_type) !== -1; // order type has been customised then show all the action buttons From c26db6a60669aaf0f13ddc04de49913fefc2c721 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 28 Apr 2020 13:12:22 +0530 Subject: [PATCH 004/449] fix: Report summary fix in consolidated financial statement for report type Profit and Loss --- .../consolidated_financial_statement.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py index b62238b59b..c2c7207e37 100644 --- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py +++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py @@ -84,6 +84,7 @@ def get_balance_sheet_data(fiscal_year, companies, columns, filters): def get_profit_loss_data(fiscal_year, companies, columns, filters): income, expense, net_profit_loss = get_income_expense_data(companies, fiscal_year, filters) + company_currency = get_company_currency(filters) data = [] data.extend(income or []) @@ -93,7 +94,7 @@ def get_profit_loss_data(fiscal_year, companies, columns, filters): chart = get_pl_chart_data(filters, columns, income, expense, net_profit_loss) - report_summary = get_pl_summary(companies, '', income, expense, net_profit_loss, True) + report_summary = get_pl_summary(companies, '', income, expense, net_profit_loss, company_currency, True) return data, None, chart, report_summary From 7889ca564c5baa95660245ae4696ed97e9b5aa76 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 28 Apr 2020 20:19:26 +0530 Subject: [PATCH 005/449] fix: Remove duplicate code from accounting dimension --- .../public/js/utils/dimension_tree_filter.js | 38 +++++++------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/erpnext/public/js/utils/dimension_tree_filter.js b/erpnext/public/js/utils/dimension_tree_filter.js index 75c5a820b4..b223fc557b 100644 --- a/erpnext/public/js/utils/dimension_tree_filter.js +++ b/erpnext/public/js/utils/dimension_tree_filter.js @@ -24,7 +24,7 @@ doctypes_with_dimensions.forEach((doctype) => { onload: function(frm) { erpnext.dimension_filters.forEach((dimension) => { frappe.model.with_doctype(dimension['document_type'], () => { - if (frappe.meta.has_field(dimension['document_type'], 'is_group')) { + if(frappe.meta.has_field(dimension['document_type'], 'is_group')) { frm.set_query(dimension['fieldname'], { "is_group": 0 }); @@ -42,19 +42,21 @@ doctypes_with_dimensions.forEach((doctype) => { update_dimension: function(frm) { erpnext.dimension_filters.forEach((dimension) => { - if (frm.is_new()) { - if (frm.doc.company && Object.keys(default_dimensions || {}).length > 0 + if(frm.is_new()) { + if(frm.doc.company && Object.keys(default_dimensions || {}).length > 0 && default_dimensions[frm.doc.company]) { - if (frappe.meta.has_field(doctype, dimension['fieldname'])) { - frm.set_value(dimension['fieldname'], - default_dimensions[frm.doc.company][dimension['document_type']]); - } + let default_dimension = default_dimensions[frm.doc.company][dimension['document_type']]; - $.each(frm.doc.items || frm.doc.accounts || [], function(i, row) { - frappe.model.set_value(row.doctype, row.name, dimension['fieldname'], - default_dimensions[frm.doc.company][dimension['document_type']]) - }); + if(default_dimension) { + if (frappe.meta.has_field(doctype, dimension['fieldname'])) { + frm.set_value(dimension['fieldname'], default_dimension); + } + + $.each(frm.doc.items || frm.doc.accounts || [], function(i, row) { + frappe.model.set_value(row.doctype, row.name, dimension['fieldname'], default_dimension); + }); + } } } }); @@ -71,20 +73,6 @@ child_docs.forEach((doctype) => { }); }, - accounts_add: function(frm, cdt, cdn) { - erpnext.dimension_filters.forEach((dimension) => { - var row = frappe.get_doc(cdt, cdn); - frm.script_manager.copy_from_first_row("accounts", row, [dimension['fieldname']]); - }); - }, - - items_add: function(frm, cdt, cdn) { - erpnext.dimension_filters.forEach((dimension) => { - var row = frappe.get_doc(cdt, cdn); - frm.script_manager.copy_from_first_row("items", row, [dimension['fieldname']]); - }); - }, - accounts_add: function(frm, cdt, cdn) { erpnext.dimension_filters.forEach((dimension) => { var row = frappe.get_doc(cdt, cdn); From 769145cabaea1e71aaf65660c15c48d2524485cd Mon Sep 17 00:00:00 2001 From: marination Date: Tue, 28 Apr 2020 21:28:53 +0530 Subject: [PATCH 006/449] fix: Removed Finished Product and Finished Qty columns from Stock Ledger Report --- erpnext/stock/report/stock_ledger/stock_ledger.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.py b/erpnext/stock/report/stock_ledger/stock_ledger.py index 28d72084de..0190f09f3d 100644 --- a/erpnext/stock/report/stock_ledger/stock_ledger.py +++ b/erpnext/stock/report/stock_ledger/stock_ledger.py @@ -46,19 +46,6 @@ def execute(filters=None): "out_qty": min(sle.actual_qty, 0) }) - # get the name of the item that was produced using this item - if sle.voucher_type == "Stock Entry": - purpose, work_order, fg_completed_qty = frappe.db.get_value(sle.voucher_type, sle.voucher_no, ["purpose", "work_order", "fg_completed_qty"]) - - if purpose == "Manufacture" and work_order: - finished_product = frappe.db.get_value("Work Order", work_order, "item_name") - finished_qty = fg_completed_qty - - sle.update({ - "finished_product": finished_product, - "finished_qty": finished_qty, - }) - data.append(sle) if include_uom: @@ -77,8 +64,6 @@ def get_columns(): {"label": _("In Qty"), "fieldname": "in_qty", "fieldtype": "Float", "width": 80, "convertible": "qty"}, {"label": _("Out Qty"), "fieldname": "out_qty", "fieldtype": "Float", "width": 80, "convertible": "qty"}, {"label": _("Balance Qty"), "fieldname": "qty_after_transaction", "fieldtype": "Float", "width": 100, "convertible": "qty"}, - {"label": _("Finished Product"), "fieldname": "finished_product", "width": 100}, - {"label": _("Finished Qty"), "fieldname": "finished_qty", "fieldtype": "Float", "width": 100, "convertible": "qty"}, {"label": _("Voucher #"), "fieldname": "voucher_no", "fieldtype": "Dynamic Link", "options": "voucher_type", "width": 150}, {"label": _("Warehouse"), "fieldname": "warehouse", "fieldtype": "Link", "options": "Warehouse", "width": 150}, {"label": _("Item Group"), "fieldname": "item_group", "fieldtype": "Link", "options": "Item Group", "width": 100}, From 60256e72999f068121ef723b263c2d877607f744 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 29 Apr 2020 12:05:56 +0530 Subject: [PATCH 007/449] fix: Group by filter fix in item wise sales and purchase register --- .../item_wise_purchase_register/item_wise_purchase_register.py | 2 +- .../report/item_wise_sales_register/item_wise_sales_register.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py index 127f3133f5..1f78c7a006 100644 --- a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py +++ b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py @@ -102,7 +102,7 @@ def _execute(filters=None, additional_table_columns=None, additional_query_colum data.append(row) - if filters.get('group_by'): + if filters.get('group_by') and item_list: total_row = total_row_map.get(prev_group_by_value or d.get('item_name')) total_row['percent_gt'] = flt(total_row['total']/grand_total * 100) data.append(total_row) diff --git a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py index 0c8957ae44..92a22e62f1 100644 --- a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py +++ b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py @@ -111,7 +111,7 @@ def _execute(filters=None, additional_table_columns=None, additional_query_colum data.append(row) - if filters.get('group_by'): + if filters.get('group_by') and item_list: total_row = total_row_map.get(prev_group_by_value or d.get('item_name')) total_row['percent_gt'] = flt(total_row['total']/grand_total * 100) data.append(total_row) From b30c9a5735d090ccc2da234f8a70676a41528d96 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 29 Apr 2020 11:16:34 +0530 Subject: [PATCH 008/449] fix: reload procedure doc on completion --- .../doctype/clinical_procedure/clinical_procedure.js | 8 +++++--- .../doctype/clinical_procedure/clinical_procedure.py | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.js b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.js index 5f36bdd95c..87c22ccf6f 100644 --- a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.js +++ b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.js @@ -80,6 +80,7 @@ frappe.ui.form.on('Clinical Procedure', { frappe.call({ method: 'complete_procedure', doc: frm.doc, + freeze: true, callback: function(r) { if (r.message) { frappe.show_alert({ @@ -87,8 +88,8 @@ frappe.ui.form.on('Clinical Procedure', { ['' + r.message + '']), indicator: 'green' }); - frm.reload_doc(); } + frm.reload_doc(); } }); } @@ -111,9 +112,10 @@ frappe.ui.form.on('Clinical Procedure', { frappe.call({ doc: frm.doc, method: 'make_material_receipt', + freeze: true, callback: function(r) { if (!r.exc) { - cur_frm.reload_doc(); + frm.reload_doc(); let doclist = frappe.model.sync(r.message); frappe.set_route('Form', doclist[0].doctype, doclist[0].name); } @@ -122,7 +124,7 @@ frappe.ui.form.on('Clinical Procedure', { } ); } else { - cur_frm.reload_doc(); + frm.reload_doc(); } } } diff --git a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py index db3afc8807..d6c0893914 100644 --- a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py +++ b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py @@ -87,7 +87,8 @@ class ClinicalProcedure(Document): else: frappe.throw(_('Please set Customer in Patient {0}').format(frappe.bold(self.patient)), title=_('Customer Not Found')) - frappe.db.set_value('Clinical Procedure', self.name, 'status', 'Completed') + self.db_set('status', 'Completed') + if self.consume_stock and self.items: return stock_entry From 033886ae3ebaab1340ab07b5107572c38ec88dc7 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 29 Apr 2020 13:06:52 +0530 Subject: [PATCH 009/449] fix: change Patient Medical Record subject fieldtype to Text Editor --- .../clinical_procedure/clinical_procedure.py | 2 +- .../healthcare/doctype/lab_test/lab_test.py | 18 +++++++------- .../patient_encounter/patient_encounter.py | 23 +++++++++++------- .../patient_medical_record.json | 4 ++-- .../doctype/vital_signs/vital_signs.py | 24 +++++++++---------- 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py index d6c0893914..297f1b9f4c 100644 --- a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py +++ b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py @@ -248,7 +248,7 @@ def make_procedure(source_name, target_doc=None): def insert_clinical_procedure_to_medical_record(doc): subject = cstr(doc.procedure_template) if doc.practitioner: - subject += ' ' + doc.practitioner + subject += frappe.bold(_('Healthcare Practitioner: ')) + doc.practitioner if subject and doc.notes: subject += '
' + doc.notes diff --git a/erpnext/healthcare/doctype/lab_test/lab_test.py b/erpnext/healthcare/doctype/lab_test/lab_test.py index 4e4015d2f0..ea8ce25c97 100644 --- a/erpnext/healthcare/doctype/lab_test/lab_test.py +++ b/erpnext/healthcare/doctype/lab_test/lab_test.py @@ -288,23 +288,23 @@ def insert_lab_test_to_medical_record(doc): table_row = False subject = cstr(doc.lab_test_name) if doc.practitioner: - subject += " "+ doc.practitioner + subject += frappe.bold(_("Healthcare Practitioner: "))+ doc.practitioner + "
" if doc.normal_test_items: item = doc.normal_test_items[0] comment = "" if item.lab_test_comment: comment = str(item.lab_test_comment) - table_row = item.lab_test_name + table_row = frappe.bold(_("Lab Test Conducted: ")) + item.lab_test_name if item.lab_test_event: - table_row += " " + item.lab_test_event + table_row += frappe.bold(_("Lab Test Event: ")) + item.lab_test_event if item.result_value: - table_row += " " + item.result_value + table_row += " " + frappe.bold(_("Lab Test Result: ")) + item.result_value if item.normal_range: - table_row += " normal_range("+item.normal_range+")" - table_row += " "+comment + table_row += " " + _("Normal Range:") + item.normal_range + table_row += " " + comment elif doc.special_test_items: item = doc.special_test_items[0] @@ -316,12 +316,12 @@ def insert_lab_test_to_medical_record(doc): item = doc.sensitivity_test_items[0] if item.antibiotic and item.antibiotic_sensitivity: - table_row = item.antibiotic +" "+ item.antibiotic_sensitivity + table_row = item.antibiotic + " " + item.antibiotic_sensitivity if table_row: - subject += "
"+table_row + subject += "
" + table_row if doc.lab_test_comment: - subject += "
"+ cstr(doc.lab_test_comment) + subject += "
" + cstr(doc.lab_test_comment) medical_record = frappe.new_doc("Patient Medical Record") medical_record.patient = doc.patient diff --git a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py index 767643bc73..1734c28e52 100644 --- a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py +++ b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py @@ -18,6 +18,9 @@ class PatientEncounter(Document): def after_insert(self): insert_encounter_to_medical_record(self) + def on_submit(self): + update_encounter_medical_record(self) + def on_cancel(self): if self.appointment: frappe.db.set_value('Patient Appointment', self.appointment, 'status', 'Open') @@ -66,22 +69,26 @@ def delete_medical_record(encounter): frappe.db.delete_doc_if_exists('Patient Medical Record', 'reference_name', encounter.name) def set_subject_field(encounter): - subject = encounter.practitioner + '\n' + subject = frappe.bold(_('Healthcare Practitioner: ')) + encounter.practitioner + '
' if encounter.symptoms: - subject += _('Symptoms: ') + cstr(encounter.symptoms) + '\n' + subject += frappe.bold(_('Symptoms: ')) + '
' + for entry in encounter.symptoms: + subject += cstr(entry.complaint) + '
' else: - subject += _('No Symptoms') + '\n' + subject += frappe.bold(_('No Symptoms')) + '
' if encounter.diagnosis: - subject += _('Diagnosis: ') + cstr(encounter.diagnosis) + '\n' + subject += frappe.bold(_('Diagnosis: ')) + '
' + for entry in encounter.diagnosis: + subject += cstr(entry.diagnosis) + '
' else: - subject += _('No Diagnosis') + '\n' + subject += frappe.bold(_('No Diagnosis')) + '
' if encounter.drug_prescription: - subject += '\n' + _('Drug(s) Prescribed.') + subject += '
' + _('Drug(s) Prescribed.') if encounter.lab_test_prescription: - subject += '\n' + _('Test(s) Prescribed.') + subject += '
' + _('Test(s) Prescribed.') if encounter.procedure_prescription: - subject += '\n' + _('Procedure(s) Prescribed.') + subject += '
' + _('Procedure(s) Prescribed.') return subject diff --git a/erpnext/healthcare/doctype/patient_medical_record/patient_medical_record.json b/erpnext/healthcare/doctype/patient_medical_record/patient_medical_record.json index 3655e24cb9..ed82355f33 100644 --- a/erpnext/healthcare/doctype/patient_medical_record/patient_medical_record.json +++ b/erpnext/healthcare/doctype/patient_medical_record/patient_medical_record.json @@ -57,7 +57,7 @@ }, { "fieldname": "subject", - "fieldtype": "Small Text", + "fieldtype": "Text Editor", "ignore_xss_filter": 1, "label": "Subject" }, @@ -125,7 +125,7 @@ ], "in_create": 1, "links": [], - "modified": "2020-03-23 19:26:59.308383", + "modified": "2020-04-29 12:26:57.679402", "modified_by": "Administrator", "module": "Healthcare", "name": "Patient Medical Record", diff --git a/erpnext/healthcare/doctype/vital_signs/vital_signs.py b/erpnext/healthcare/doctype/vital_signs/vital_signs.py index 959e8504c4..b0e78e8eb9 100644 --- a/erpnext/healthcare/doctype/vital_signs/vital_signs.py +++ b/erpnext/healthcare/doctype/vital_signs/vital_signs.py @@ -35,17 +35,17 @@ def delete_vital_signs_from_medical_record(doc): def set_subject_field(doc): subject = '' - if(doc.temperature): - subject += _('Temperature: ') + '\n'+ cstr(doc.temperature) + '. ' - if(doc.pulse): - subject += _('Pulse: ') + '\n' + cstr(doc.pulse) + '. ' - if(doc.respiratory_rate): - subject += _('Respiratory Rate: ') + '\n' + cstr(doc.respiratory_rate) + '. ' - if(doc.bp): - subject += _('BP: ') + '\n' + cstr(doc.bp) + '. ' - if(doc.bmi): - subject += _('BMI: ') + '\n' + cstr(doc.bmi) + '. ' - if(doc.nutrition_note): - subject += _('Note: ') + '\n' + cstr(doc.nutrition_note) + '. ' + if doc.temperature: + subject += frappe.bold(_('Temperature: ')) + cstr(doc.temperature) + '
' + if doc.pulse: + subject += frappe.bold(_('Pulse: ')) + cstr(doc.pulse) + '
' + if doc.respiratory_rate: + subject += frappe.bold(_('Respiratory Rate: ')) + cstr(doc.respiratory_rate) + '
' + if doc.bp: + subject += frappe.bold(_('BP: ')) + cstr(doc.bp) + '
' + if doc.bmi: + subject += frappe.bold(_('BMI: ')) + cstr(doc.bmi) + '
' + if doc.nutrition_note: + subject += frappe.bold(_('Note: ')) + cstr(doc.nutrition_note) + '
' return subject From 589440c5ad7dc7ff0cf6399b5244113caaf0c661 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 29 Apr 2020 13:47:14 +0530 Subject: [PATCH 010/449] feat: create medical record for therapy sessions --- .../clinical_procedure/clinical_procedure.py | 2 +- .../doctype/therapy_plan/therapy_plan.py | 10 ++++- .../therapy_session/therapy_session.js | 11 ++--- .../therapy_session/therapy_session.json | 26 +++++++++++- .../therapy_session/therapy_session.py | 40 ++++++++++++++++++- 5 files changed, 76 insertions(+), 13 deletions(-) diff --git a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py index 297f1b9f4c..b7d7a62a95 100644 --- a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py +++ b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py @@ -246,7 +246,7 @@ def make_procedure(source_name, target_doc=None): def insert_clinical_procedure_to_medical_record(doc): - subject = cstr(doc.procedure_template) + subject = frappe.bold(_("Clinical Procedure conducted: ")) + cstr(doc.procedure_template) + "
" if doc.practitioner: subject += frappe.bold(_('Healthcare Practitioner: ')) + doc.practitioner if subject and doc.notes: diff --git a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py index 201264f829..c19be17ba8 100644 --- a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py +++ b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py @@ -21,8 +21,14 @@ class TherapyPlan(Document): self.status = 'Completed' def set_totals(self): - total_sessions = sum([int(d.no_of_sessions) for d in self.get('therapy_plan_details')]) - total_sessions_completed = sum([int(d.sessions_completed) for d in self.get('therapy_plan_details')]) + total_sessions = 0 + total_sessions_completed = 0 + for entry in self.therapy_plan_details: + if entry.no_of_sessions: + total_sessions += entry.no_of_sessions + if entry.sessions_completed: + total_sessions_completed += entry.sessions_completed + self.db_set('total_sessions', total_sessions) self.db_set('total_sessions_completed', total_sessions_completed) diff --git a/erpnext/healthcare/doctype/therapy_session/therapy_session.js b/erpnext/healthcare/doctype/therapy_session/therapy_session.js index bb675752bb..80fca39661 100644 --- a/erpnext/healthcare/doctype/therapy_session/therapy_session.js +++ b/erpnext/healthcare/doctype/therapy_session/therapy_session.js @@ -13,14 +13,9 @@ frappe.ui.form.on('Therapy Session', { refresh: function(frm) { if (!frm.doc.__islocal) { - let target = 0; - let completed = 0; - $.each(frm.doc.exercises, function(_i, e) { - target += e.counts_target; - completed += e.counts_completed; - }); - frm.dashboard.add_indicator(__('Counts Targetted: {0}', [target]), 'blue'); - frm.dashboard.add_indicator(__('Counts Completed: {0}', [completed]), (completed < target) ? 'orange' : 'green'); + frm.dashboard.add_indicator(__('Counts Targeted: {0}', [frm.doc.total_counts_targeted]), 'blue'); + frm.dashboard.add_indicator(__('Counts Completed: {0}', [frm.doc.total_counts_completed]), + (frm.doc.total_counts_completed < frm.doc.total_counts_targeted) ? 'orange' : 'green'); } if (frm.doc.docstatus === 1) { diff --git a/erpnext/healthcare/doctype/therapy_session/therapy_session.json b/erpnext/healthcare/doctype/therapy_session/therapy_session.json index 5ff719672f..d8c4b99435 100644 --- a/erpnext/healthcare/doctype/therapy_session/therapy_session.json +++ b/erpnext/healthcare/doctype/therapy_session/therapy_session.json @@ -28,6 +28,10 @@ "invoiced", "exercises_section", "exercises", + "section_break_23", + "total_counts_targeted", + "column_break_25", + "total_counts_completed", "amended_from" ], "fields": [ @@ -173,11 +177,31 @@ "fieldtype": "Data", "label": "Patient Age", "read_only": 1 + }, + { + "fieldname": "total_counts_targeted", + "fieldtype": "Int", + "label": "Total Counts Targeted", + "read_only": 1 + }, + { + "fieldname": "total_counts_completed", + "fieldtype": "Int", + "label": "Total Counts Completed", + "read_only": 1 + }, + { + "fieldname": "section_break_23", + "fieldtype": "Section Break" + }, + { + "fieldname": "column_break_25", + "fieldtype": "Column Break" } ], "is_submittable": 1, "links": [], - "modified": "2020-04-21 13:16:46.378798", + "modified": "2020-04-29 13:22:13.190353", "modified_by": "Administrator", "module": "Healthcare", "name": "Therapy Session", diff --git a/erpnext/healthcare/doctype/therapy_session/therapy_session.py b/erpnext/healthcare/doctype/therapy_session/therapy_session.py index 45d2ee60e6..7e240955cf 100644 --- a/erpnext/healthcare/doctype/therapy_session/therapy_session.py +++ b/erpnext/healthcare/doctype/therapy_session/therapy_session.py @@ -6,10 +6,16 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document from frappe.model.mapper import get_mapped_doc +from frappe import _ +from frappe.utils import cstr class TherapySession(Document): + def validate(self): + self.set_total_counts() + def on_submit(self): self.update_sessions_count_in_therapy_plan() + insert_session_medical_record(self) def on_cancel(self): self.update_sessions_count_in_therapy_plan(on_cancel=True) @@ -24,6 +30,18 @@ class TherapySession(Document): entry.sessions_completed += 1 therapy_plan.save() + def set_total_counts(self): + target_total = 0 + counts_completed = 0 + for entry in self.exercises: + if entry.counts_target: + target_total += entry.counts_target + if entry.counts_completed: + counts_completed += entry.counts_completed + + self.db_set('total_counts_targeted', target_total) + self.db_set('total_counts_completed', counts_completed) + @frappe.whitelist() def create_therapy_session(source_name, target_doc=None): @@ -52,4 +70,24 @@ def create_therapy_session(source_name, target_doc=None): } }, target_doc, set_missing_values) - return doc \ No newline at end of file + return doc + + +def insert_session_medical_record(doc): + subject = frappe.bold(_('Therapy: ')) + cstr(doc.therapy_type) + '
' + if doc.therapy_plan: + subject += frappe.bold(_('Therapy Plan: ')) + cstr(doc.therapy_plan) + '
' + if doc.practitioner: + subject += frappe.bold(_('Healthcare Practitioner: ')) + doc.practitioner + subject += frappe.bold(_('Total Counts Targeted: ')) + cstr(doc.total_counts_targeted) + '
' + subject += frappe.bold(_('Total Counts Completed: ')) + cstr(doc.total_counts_completed) + '
' + + medical_record = frappe.new_doc('Patient Medical Record') + medical_record.patient = doc.patient + medical_record.subject = subject + medical_record.status = 'Open' + medical_record.communication_date = doc.start_date + medical_record.reference_doctype = 'Therapy Session' + medical_record.reference_name = doc.name + medical_record.reference_owner = doc.owner + medical_record.save(ignore_permissions=True) \ No newline at end of file From cf10fde5ec4e7112e7fdd58c30a6ad06be7e2f9d Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 29 Apr 2020 14:19:27 +0530 Subject: [PATCH 011/449] fix: mark form as dirty when editing or deleting exercise card --- .../doctype/exercise_type/exercise_type.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/erpnext/healthcare/doctype/exercise_type/exercise_type.js b/erpnext/healthcare/doctype/exercise_type/exercise_type.js index f450c9bccb..ff99dc2d72 100644 --- a/erpnext/healthcare/doctype/exercise_type/exercise_type.js +++ b/erpnext/healthcare/doctype/exercise_type/exercise_type.js @@ -24,6 +24,8 @@ erpnext.ExerciseEditor = Class.extend({ this.exercise_cards = $('
').appendTo(this.wrapper); + this.row = $('
').appendTo(this.exercise_cards); + let me = this; this.exercise_toolbar.find(".btn-add") @@ -32,7 +34,7 @@ erpnext.ExerciseEditor = Class.extend({ me.show_add_card_dialog(frm); }); - if (frm.doc.steps_table.length > 0) { + if (frm.doc.steps_table && frm.doc.steps_table.length > 0) { this.make_cards(frm); this.make_buttons(frm); } @@ -41,7 +43,6 @@ erpnext.ExerciseEditor = Class.extend({ make_cards: function(frm) { var me = this; $(me.exercise_cards).empty(); - this.row = $('
').appendTo(me.exercise_cards); $.each(frm.doc.steps_table, function(i, step) { $(repl(` @@ -78,6 +79,7 @@ erpnext.ExerciseEditor = Class.extend({ frm.doc.steps_table.pop(id); frm.refresh_field('steps_table'); $('#col-'+id).remove(); + frm.dirty(); }, 300); }); }, @@ -106,7 +108,10 @@ erpnext.ExerciseEditor = Class.extend({ ], primary_action: function() { let data = d.get_values(); - let i = frm.doc.steps_table.length; + let i = 0; + if (frm.doc.steps_table) { + i = frm.doc.steps_table.length; + } $(repl(`
@@ -165,9 +170,10 @@ erpnext.ExerciseEditor = Class.extend({ frm.doc.steps_table[id].image = data.image; frm.doc.steps_table[id].description = data.step_description; refresh_field('steps_table'); + frm.dirty(); new_dialog.hide(); }, - primary_action_label: __("Save"), + primary_action_label: __("Edit"), }); new_dialog.set_values({ From 5e8f748a63fef554387fb57cd899a4bee2901292 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 29 Apr 2020 17:34:36 +0530 Subject: [PATCH 012/449] feat: add create Sales Invoice option from Therapy Session --- .../therapy_session/therapy_session.js | 78 ++++++++++++++++++- .../therapy_session/therapy_session.json | 15 +++- .../therapy_session/therapy_session.py | 41 +++++++++- 3 files changed, 129 insertions(+), 5 deletions(-) diff --git a/erpnext/healthcare/doctype/therapy_session/therapy_session.js b/erpnext/healthcare/doctype/therapy_session/therapy_session.js index 80fca39661..abe4defaf9 100644 --- a/erpnext/healthcare/doctype/therapy_session/therapy_session.js +++ b/erpnext/healthcare/doctype/therapy_session/therapy_session.js @@ -19,12 +19,86 @@ frappe.ui.form.on('Therapy Session', { } if (frm.doc.docstatus === 1) { - frm.add_custom_button(__('Patient Assessment'),function() { + frm.add_custom_button(__('Patient Assessment'), function() { frappe.model.open_mapped_doc({ method: 'erpnext.healthcare.doctype.patient_assessment.patient_assessment.create_patient_assessment', frm: frm, }) }, 'Create'); + + frm.add_custom_button(__('Sales Invoice'), function() { + frappe.model.open_mapped_doc({ + method: 'erpnext.healthcare.doctype.therapy_session.therapy_session.invoice_therapy_session', + frm: frm, + }) + }, 'Create'); + } + }, + + patient: function(frm) { + if (frm.doc.patient) { + frappe.call({ + 'method': 'erpnext.healthcare.doctype.patient.patient.get_patient_detail', + args: { + patient: frm.doc.patient + }, + callback: function (data) { + let age = ''; + if (data.message.dob) { + age = calculate_age(data.message.dob); + } else if (data.message.age) { + age = data.message.age; + if (data.message.age_as_on) { + age = __('{0} as on {1}', [age, data.message.age_as_on]); + } + } + frm.set_value('patient_age', age); + frm.set_value('gender', data.message.sex); + frm.set_value('patient_name', data.message.patient_name); + } + }); + } else { + frm.set_value('patient_age', ''); + frm.set_value('gender', ''); + frm.set_value('patient_name', ''); + } + }, + + appointment: function(frm) { + if (frm.doc.appointment) { + frappe.call({ + 'method': 'frappe.client.get', + args: { + doctype: 'Patient Appointment', + name: frm.doc.appointment + }, + callback: function(data) { + let values = { + 'patient':data.message.patient, + 'therapy_type': data.message.therapy_type, + 'therapy_plan': data.message.therapy_plan, + 'practitioner': data.message.practitioner, + 'department': data.message.department, + 'start_date': data.message.appointment_date, + 'start_time': data.message.appointment_time, + 'service_unit': data.message.service_unit, + 'company': data.message.company + }; + frm.set_value(values); + } + }); + } else { + let values = { + 'patient': '', + 'therapy_type': '', + 'therapy_plan': '', + 'practitioner': '', + 'department': '', + 'start_date': '', + 'start_time': '', + 'service_unit': '', + }; + frm.set_value(values); } }, @@ -39,6 +113,8 @@ frappe.ui.form.on('Therapy Session', { callback: function(data) { frm.set_value('duration', data.message.default_duration); frm.set_value('rate', data.message.rate); + frm.set_value('service_unit', data.message.healthcare_service_unit); + frm.set_value('department', data.message.medical_department); frm.doc.exercises = []; $.each(data.message.exercises, function(_i, e) { let exercise = frm.add_child('exercises'); diff --git a/erpnext/healthcare/doctype/therapy_session/therapy_session.json b/erpnext/healthcare/doctype/therapy_session/therapy_session.json index d8c4b99435..00d74a0949 100644 --- a/erpnext/healthcare/doctype/therapy_session/therapy_session.json +++ b/erpnext/healthcare/doctype/therapy_session/therapy_session.json @@ -9,9 +9,11 @@ "naming_series", "appointment", "patient", + "patient_name", "patient_age", "gender", "column_break_5", + "company", "therapy_plan", "therapy_type", "practitioner", @@ -20,7 +22,6 @@ "duration", "rate", "location", - "company", "column_break_12", "service_unit", "start_date", @@ -163,7 +164,8 @@ "fieldname": "company", "fieldtype": "Link", "label": "Company", - "options": "Company" + "options": "Company", + "reqd": 1 }, { "default": "0", @@ -197,11 +199,18 @@ { "fieldname": "column_break_25", "fieldtype": "Column Break" + }, + { + "fetch_from": "patient.patient_name", + "fieldname": "patient_name", + "fieldtype": "Data", + "label": "Patient Name", + "read_only": 1 } ], "is_submittable": 1, "links": [], - "modified": "2020-04-29 13:22:13.190353", + "modified": "2020-04-29 16:49:16.286006", "modified_by": "Administrator", "module": "Healthcare", "name": "Therapy Session", diff --git a/erpnext/healthcare/doctype/therapy_session/therapy_session.py b/erpnext/healthcare/doctype/therapy_session/therapy_session.py index 7e240955cf..9650183712 100644 --- a/erpnext/healthcare/doctype/therapy_session/therapy_session.py +++ b/erpnext/healthcare/doctype/therapy_session/therapy_session.py @@ -7,7 +7,8 @@ import frappe from frappe.model.document import Document from frappe.model.mapper import get_mapped_doc from frappe import _ -from frappe.utils import cstr +from frappe.utils import cstr, getdate +from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import get_receivable_account, get_income_account class TherapySession(Document): def validate(self): @@ -73,6 +74,44 @@ def create_therapy_session(source_name, target_doc=None): return doc +@frappe.whitelist() +def invoice_therapy_session(source_name, target_doc=None): + def set_missing_values(source, target): + target.customer = frappe.db.get_value('Patient', source.patient, 'customer') + target.due_date = getdate() + target.debit_to = get_receivable_account(source.company) + item = target.append('items', {}) + item = get_therapy_item(source, item) + target.set_missing_values(for_validate=True) + + doc = get_mapped_doc('Therapy Session', source_name, { + 'Therapy Session': { + 'doctype': 'Sales Invoice', + 'field_map': [ + ['patient', 'patient'], + ['referring_practitioner', 'practitioner'], + ['company', 'company'], + ['due_date', 'start_date'] + ] + } + }, target_doc, set_missing_values) + + return doc + + +def get_therapy_item(therapy, item): + item.item_code = frappe.db.get_value('Therapy Type', therapy.therapy_type, 'item') + item.description = _('Therapy Session Charges: {0}').format(therapy.practitioner) + item.income_account = get_income_account(therapy.practitioner, therapy.company) + item.cost_center = frappe.get_cached_value('Company', therapy.company, 'cost_center') + item.rate = therapy.rate + item.amount = therapy.rate + item.qty = 1 + item.reference_dt = 'Therapy Session' + item.reference_dn = therapy.name + return item + + def insert_session_medical_record(doc): subject = frappe.bold(_('Therapy: ')) + cstr(doc.therapy_type) + '
' if doc.therapy_plan: From 57fc3a5c3cced1064210e2baedc2b3d09401e2b5 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 29 Apr 2020 19:23:16 +0530 Subject: [PATCH 013/449] fix: exercise type --- erpnext/healthcare/doctype/exercise_type/exercise_type.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/healthcare/doctype/exercise_type/exercise_type.js b/erpnext/healthcare/doctype/exercise_type/exercise_type.js index ff99dc2d72..68db0477c2 100644 --- a/erpnext/healthcare/doctype/exercise_type/exercise_type.js +++ b/erpnext/healthcare/doctype/exercise_type/exercise_type.js @@ -24,7 +24,7 @@ erpnext.ExerciseEditor = Class.extend({ this.exercise_cards = $('
').appendTo(this.wrapper); - this.row = $('
').appendTo(this.exercise_cards); + this.row = $('
').appendTo(this.wrapper); let me = this; From 9d5fabd7ac48f9ba8dd4f202ce145ae395253ebd Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 29 Apr 2020 22:14:45 +0530 Subject: [PATCH 014/449] fix: get_period_list API change fixes --- erpnext/hr/report/vehicle_expenses/vehicle_expenses.py | 3 ++- .../item_group_wise_sales_target_variance.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/erpnext/hr/report/vehicle_expenses/vehicle_expenses.py b/erpnext/hr/report/vehicle_expenses/vehicle_expenses.py index e5622b7ae1..eab58ffbbc 100644 --- a/erpnext/hr/report/vehicle_expenses/vehicle_expenses.py +++ b/erpnext/hr/report/vehicle_expenses/vehicle_expenses.py @@ -12,7 +12,8 @@ def execute(filters=None): columns, data, chart = [], [], [] if filters.get('fiscal_year'): company = erpnext.get_default_company() - period_list = get_period_list(filters.get('fiscal_year'), filters.get('fiscal_year'),"Monthly", company) + period_list = get_period_list(filters.get('fiscal_year'), filters.get('fiscal_year'), + '', '', 'Fiscal Year', 'Monthly', company=company) columns=get_columns() data=get_log_data(filters) chart=get_chart_data(data,period_list) diff --git a/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/item_group_wise_sales_target_variance.py b/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/item_group_wise_sales_target_variance.py index 0cb606b277..2d0d60ac06 100644 --- a/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/item_group_wise_sales_target_variance.py +++ b/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/item_group_wise_sales_target_variance.py @@ -11,9 +11,10 @@ from erpnext.accounts.doctype.monthly_distribution.monthly_distribution import g def get_data_column(filters, partner_doctype): data = [] - period_list = get_period_list(filters.fiscal_year, filters.fiscal_year, - filters.period, company=filters.company) + period_list = get_period_list(filters.fiscal_year, filters.fiscal_year, '', '', + 'Fiscal Year', filters.period, company=filters.company) + print(period_list) rows = get_data(filters, period_list, partner_doctype) columns = get_columns(filters, period_list, partner_doctype) From 7c2d50fa15193a367b7f77cc19a61b3df27b2669 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 29 Apr 2020 22:16:47 +0530 Subject: [PATCH 015/449] fix: Remove print --- .../item_group_wise_sales_target_variance.py | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/item_group_wise_sales_target_variance.py b/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/item_group_wise_sales_target_variance.py index 2d0d60ac06..857b9823e0 100644 --- a/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/item_group_wise_sales_target_variance.py +++ b/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/item_group_wise_sales_target_variance.py @@ -14,7 +14,6 @@ def get_data_column(filters, partner_doctype): period_list = get_period_list(filters.fiscal_year, filters.fiscal_year, '', '', 'Fiscal Year', filters.period, company=filters.company) - print(period_list) rows = get_data(filters, period_list, partner_doctype) columns = get_columns(filters, period_list, partner_doctype) From 7f374e7ba5e653e34e583cc61733ca2fe427d2bb Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Thu, 30 Apr 2020 17:55:03 +0530 Subject: [PATCH 016/449] fix: pre-process both the existing and new products --- erpnext/hub_node/api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index 2035174c98..b260417fbf 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -157,8 +157,9 @@ def publish_selected_items(items_to_publish): existing_items = map_fields(items_to_update) try: - item_sync_preprocess(len(items)) - convert_relative_image_urls_to_absolute(items) + item_sync_preprocess(len(new_items+existing_items)) + convert_relative_image_urls_to_absolute(new_items) + convert_relative_image_urls_to_absolute(existing_items) # TODO: Publish Progress connection = get_hub_connection() From 367b644d9eeb3c9d60fed7523a1ca29174f85c56 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Thu, 30 Apr 2020 20:31:12 +0530 Subject: [PATCH 017/449] fix: delete hub tracked item on unpublish --- erpnext/hub_node/api.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index b260417fbf..42f90006f4 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -144,27 +144,17 @@ def publish_selected_items(items_to_publish): 'hub_category': item.get('hub_category'), 'image_list': item.get('image_list') } - if frappe.db.exists('Hub Tracked Item', item_code): - items_to_update.append(item) - hub_tracked_item = frappe.get_doc('Hub Tracked Item', item_code) - hub_tracked_item.update(hub_dict) - hub_tracked_item.save() - else: - frappe.get_doc(hub_dict).insert(ignore_if_duplicate=True) + frappe.get_doc(hub_dict).insert(ignore_if_duplicate=True) - items_to_publish = list(filter(lambda x: x not in items_to_update, items_to_publish)) - new_items = map_fields(items_to_publish) - existing_items = map_fields(items_to_update) + items = map_fields(items_to_publish) try: - item_sync_preprocess(len(new_items+existing_items)) - convert_relative_image_urls_to_absolute(new_items) - convert_relative_image_urls_to_absolute(existing_items) + item_sync_preprocess(len(items)) + convert_relative_image_urls_to_absolute(items) # TODO: Publish Progress connection = get_hub_connection() - connection.insert_many(new_items) - connection.bulk_update(existing_items) + connection.insert_many(items) item_sync_postprocess() except Exception as e: @@ -180,6 +170,7 @@ def unpublish_item(item_code, hub_item_name): if response: frappe.db.set_value('Item', item_code, 'publish_in_hub', 0) + frappe.delete_doc('Hub Tracked Item', item_code) else: frappe.throw(_('Unable to update remote activity')) From 5ac2c49444e0240b5470b3768b868b6e61063641 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 1 May 2020 10:49:26 +0530 Subject: [PATCH 018/449] fix: Move Video Doctype from Education module to Core (#21234) (#21533) * fix: move Video Doctype from Education module to Core * fix: patch to retain Permissions Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> (cherry picked from commit f65fb1fcf80a3c0bbf0605c782efa192abc3236d) Co-authored-by: Rucha Mahabal --- erpnext/education/doctype/video/__init__.py | 0 erpnext/education/doctype/video/test_video.js | 23 ---- erpnext/education/doctype/video/test_video.py | 10 -- erpnext/education/doctype/video/video.js | 8 -- erpnext/education/doctype/video/video.json | 112 ------------------ erpnext/education/doctype/video/video.py | 13 -- erpnext/patches.txt | 3 +- ...tain_permission_rules_for_video_doctype.py | 21 ++++ .../operations/install_fixtures.py | 4 +- 9 files changed, 25 insertions(+), 169 deletions(-) delete mode 100644 erpnext/education/doctype/video/__init__.py delete mode 100644 erpnext/education/doctype/video/test_video.js delete mode 100644 erpnext/education/doctype/video/test_video.py delete mode 100644 erpnext/education/doctype/video/video.js delete mode 100644 erpnext/education/doctype/video/video.json delete mode 100644 erpnext/education/doctype/video/video.py create mode 100644 erpnext/patches/v12_0/retain_permission_rules_for_video_doctype.py diff --git a/erpnext/education/doctype/video/__init__.py b/erpnext/education/doctype/video/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/erpnext/education/doctype/video/test_video.js b/erpnext/education/doctype/video/test_video.js deleted file mode 100644 index a82a221319..0000000000 --- a/erpnext/education/doctype/video/test_video.js +++ /dev/null @@ -1,23 +0,0 @@ -/* eslint-disable */ -// rename this file from _test_[name] to test_[name] to activate -// and remove above this line - -QUnit.test("test: Video", function (assert) { - let done = assert.async(); - - // number of asserts - assert.expect(1); - - frappe.run_serially([ - // insert a new Video - () => frappe.tests.make('Video', [ - // values to be set - {key: 'value'} - ]), - () => { - assert.equal(cur_frm.doc.key, 'value'); - }, - () => done() - ]); - -}); diff --git a/erpnext/education/doctype/video/test_video.py b/erpnext/education/doctype/video/test_video.py deleted file mode 100644 index ecb09a2f9e..0000000000 --- a/erpnext/education/doctype/video/test_video.py +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors -# See license.txt -from __future__ import unicode_literals - -import frappe -import unittest - -class TestVideo(unittest.TestCase): - pass diff --git a/erpnext/education/doctype/video/video.js b/erpnext/education/doctype/video/video.js deleted file mode 100644 index c35c19b0c1..0000000000 --- a/erpnext/education/doctype/video/video.js +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors -// For license information, please see license.txt - -frappe.ui.form.on('Video', { - refresh: function(frm) { - - } -}); diff --git a/erpnext/education/doctype/video/video.json b/erpnext/education/doctype/video/video.json deleted file mode 100644 index e912eb32cb..0000000000 --- a/erpnext/education/doctype/video/video.json +++ /dev/null @@ -1,112 +0,0 @@ -{ - "allow_import": 1, - "allow_rename": 1, - "autoname": "field:title", - "creation": "2018-10-17 05:47:13.087395", - "doctype": "DocType", - "editable_grid": 1, - "engine": "InnoDB", - "field_order": [ - "title", - "provider", - "url", - "column_break_4", - "publish_date", - "duration", - "section_break_7", - "description" - ], - "fields": [ - { - "fieldname": "title", - "fieldtype": "Data", - "in_list_view": 1, - "label": "Title", - "reqd": 1, - "unique": 1 - }, - { - "fieldname": "description", - "fieldtype": "Text Editor", - "in_list_view": 1, - "label": "Description", - "reqd": 1 - }, - { - "fieldname": "duration", - "fieldtype": "Data", - "label": "Duration" - }, - { - "fieldname": "url", - "fieldtype": "Data", - "in_list_view": 1, - "label": "URL", - "reqd": 1 - }, - { - "fieldname": "publish_date", - "fieldtype": "Date", - "label": "Publish Date" - }, - { - "fieldname": "provider", - "fieldtype": "Select", - "in_list_view": 1, - "label": "Provider", - "options": "YouTube\nVimeo", - "reqd": 1 - }, - { - "fieldname": "column_break_4", - "fieldtype": "Column Break" - }, - { - "fieldname": "section_break_7", - "fieldtype": "Section Break" - } - ], - "modified": "2019-06-12 12:36:48.753092", - "modified_by": "Administrator", - "module": "Education", - "name": "Video", - "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "Academics User", - "share": 1, - "write": 1 - }, - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "Instructor", - "share": 1, - "write": 1 - }, - { - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "LMS User", - "share": 1 - } - ], - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1 -} \ No newline at end of file diff --git a/erpnext/education/doctype/video/video.py b/erpnext/education/doctype/video/video.py deleted file mode 100644 index b19f81258c..0000000000 --- a/erpnext/education/doctype/video/video.py +++ /dev/null @@ -1,13 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - -from __future__ import unicode_literals -import frappe -from frappe.model.document import Document - -class Video(Document): - - - def get_video(self): - pass diff --git a/erpnext/patches.txt b/erpnext/patches.txt index a216f53a8b..c85e593b47 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -674,4 +674,5 @@ erpnext.patches.v12_0.repost_stock_ledger_entries_for_target_warehouse erpnext.patches.v12_0.update_end_date_and_status_in_email_campaign erpnext.patches.v13_0.move_tax_slabs_from_payroll_period_to_income_tax_slab #123 erpnext.patches.v12_0.fix_quotation_expired_status -erpnext.patches.v12_0.update_appointment_reminder_scheduler_entry \ No newline at end of file +erpnext.patches.v12_0.update_appointment_reminder_scheduler_entry +erpnext.patches.v12_0.retain_permission_rules_for_video_doctype diff --git a/erpnext/patches/v12_0/retain_permission_rules_for_video_doctype.py b/erpnext/patches/v12_0/retain_permission_rules_for_video_doctype.py new file mode 100644 index 0000000000..ca8a13b13c --- /dev/null +++ b/erpnext/patches/v12_0/retain_permission_rules_for_video_doctype.py @@ -0,0 +1,21 @@ +from __future__ import unicode_literals +import frappe + +def execute(): + # to retain the roles and permissions from Education Module + # after moving doctype to core + permissions = frappe.db.sql(""" + SELECT + * + FROM + `tabDocPerm` + WHERE + parent='Video' + """, as_dict=True) + + frappe.reload_doc('core', 'doctype', 'video') + doc = frappe.get_doc('DocType', 'Video') + doc.permissions = [] + for perm in permissions: + doc.append('permissions', perm) + doc.save() diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index e4986e36b7..3be6f44832 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -32,7 +32,7 @@ def install(country=None): { 'doctype': 'Domain', 'domain': 'Agriculture'}, { 'doctype': 'Domain', 'domain': 'Non Profit'}, - # ensure at least an empty Address Template exists for this Country + # ensure at least an empty Address Template exists for this Country {'doctype':"Address Template", "country": country}, # item group @@ -271,7 +271,7 @@ def install(country=None): # Records for the Supplier Scorecard from erpnext.buying.doctype.supplier_scorecard.supplier_scorecard import make_default_records - + make_default_records() make_records(records) set_up_address_templates(default_country=country) From 795cf87aabae1b503d00f8bc2f1411b7bc816e07 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 1 May 2020 18:31:14 +0530 Subject: [PATCH 019/449] fix: test case for loan --- erpnext/loan_management/doctype/loan/test_loan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/loan_management/doctype/loan/test_loan.py b/erpnext/loan_management/doctype/loan/test_loan.py index 2d1ad33ed0..90b8534bc8 100644 --- a/erpnext/loan_management/doctype/loan/test_loan.py +++ b/erpnext/loan_management/doctype/loan/test_loan.py @@ -236,7 +236,7 @@ class TestLoan(unittest.TestCase): process_loan_interest_accrual_for_term_loans(posting_date=nowdate()) - repayment_entry = create_repayment_entry(loan.name, self.applicant2, add_days(get_last_day(nowdate()), 5), + repayment_entry = create_repayment_entry(loan.name, self.applicant2, add_days(nowdate(), 5), "Regular Payment", 89768.75) repayment_entry.submit() From cfd67a17a3e9d2f6cff235e08ffbb8360cabfcf4 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 1 May 2020 19:39:49 +0530 Subject: [PATCH 020/449] chore: change log for version 13 beta --- erpnext/change_log/v13/v13_0_0_beta_1.md | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 erpnext/change_log/v13/v13_0_0_beta_1.md diff --git a/erpnext/change_log/v13/v13_0_0_beta_1.md b/erpnext/change_log/v13/v13_0_0_beta_1.md new file mode 100644 index 0000000000..f84dc24560 --- /dev/null +++ b/erpnext/change_log/v13/v13_0_0_beta_1.md @@ -0,0 +1,44 @@ +# Version 13.0.0 Beta 1 Release Notes + +## Accounting +- [Loan Management and Accounting](https://docs.erpnext.com/docs/user/manual/en/loan-management) +- [Accounting Dimensions in Budget Variance Report](https://github.com/frappe/erpnext/pull/19973) +- [Tax Category in POS Profile](https://docs.erpnext.com/docs/user/manual/en/accounts/pos-profile) +- [Custom Fields in POS](https://github.com/frappe/erpnext/pull/19876) +- [HSN Code Wise Item Tax](https://github.com/frappe/erpnext/pull/19478) +- Auto State-wise Taxation for GST India + - The Accounts entered in CGST and SGST accounts in GST Settings will be automatically skipped for Interstate Transaction and the Accounts in IGST Account will be skipped in Intrastate transaction. + +## Stock +- [Fetch Items from BOM in Stock Entry](https://github.com/frappe/erpnext/pull/19498) +- [Inter Warehouse Stock Transfer in Purchase Receipt](https://docs.erpnext.com/docs/user/manual/en/stock/articles/material-transfer-from-delivery-note) + +## HR +- [Work From Home in Attendance](https://github.com/frappe/erpnext/pull/20464) +- [Bulk Mark Attendance](https://github.com/frappe/erpnext/pull/20062) + +## Healthcare +- [Refactored Healthcare Module](https://docs.erpnext.com/docs/user/manual/en/healthcare) +- [Rehabilitation Module](https://docs.erpnext.com/docs/user/manual/en/healthcare/exercise_type) + +## CRM +- [Social Media Post](https://docs.erpnext.com/docs/user/manual/en/CRM/social-media-post) +- [Make Quotation against Blanket Order](https://docs.erpnext.com/docs/user/manual/en/selling/blanket-order) +- [Calendar View for Opportunity](https://github.com/frappe/erpnext/pull/21280) + +## New Reports +- [Item-wise Sales Register](https://docs.erpnext.com/docs/user/manual/en/accounts/accounting-reports) +- [Territory-wise Sales](https://github.com/frappe/erpnext/pull/20428) + +## Other Changes +- [Report Summary in Financial Statement](https://github.com/frappe/erpnext/pull/20876) +- [Accounts Payable Report based on Payment Terms](https://docs.erpnext.com/docs/user/manual/en/accounts/accounting-reports) +- [Allow Purchase Invoice Creation Without Purchase Receipt Checkbox in Supplier](https://github.com/frappe/erpnext/pull/20864) +- [Allow Purchase Invoice Creation Without Purchase Order Checkbox in Supplier](https://github.com/frappe/erpnext/pull/20864) +- Add / Delete Items in submitted Sales / Purchase Order +- Provision to edit Item Details from Marketplace +- Nested Set filtering for Accounting Dimension +- UX changes and better validation message in all Modules +- Scan Barcode in Purchase Receipt +- Disable Rounded Totals Checkbox for Salary Slips in HR Settings + From 1101f9779e6fd73ed92b76617392df7d31200fff Mon Sep 17 00:00:00 2001 From: sahil28297 <37302950+sahil28297@users.noreply.github.com> Date: Fri, 1 May 2020 21:04:23 +0530 Subject: [PATCH 021/449] fix: update version --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 786b9cfd16..930acdee7e 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '12.0.0-dev' +__version__ = '13.0.0' def get_default_company(user=None): '''Get default company for user''' From dba2132c91e2df075e892d947b36e9faf44d7f9b Mon Sep 17 00:00:00 2001 From: Sahil Khan Date: Fri, 1 May 2020 21:25:26 +0550 Subject: [PATCH 022/449] bumped to version 13.0.0-beta.1 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 930acdee7e..43c3935220 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0' +__version__ = '13.0.0-beta.1' def get_default_company(user=None): '''Get default company for user''' From a367a07bf17ab617df2f8a2a079492a88256a85c Mon Sep 17 00:00:00 2001 From: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> Date: Sat, 2 May 2020 22:31:30 +0530 Subject: [PATCH 023/449] chore: Rename change log --- erpnext/change_log/v13/{v13_0_0_beta_1.md => v13_0_0_beta-1.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename erpnext/change_log/v13/{v13_0_0_beta_1.md => v13_0_0_beta-1.md} (100%) diff --git a/erpnext/change_log/v13/v13_0_0_beta_1.md b/erpnext/change_log/v13/v13_0_0_beta-1.md similarity index 100% rename from erpnext/change_log/v13/v13_0_0_beta_1.md rename to erpnext/change_log/v13/v13_0_0_beta-1.md From 33de842071a30cd58a206cf31a2af8d3f32c6e28 Mon Sep 17 00:00:00 2001 From: Raffael Meyer Date: Sat, 2 May 2020 19:25:49 +0200 Subject: [PATCH 024/449] Update v13_0_0_beta-1.md --- erpnext/change_log/v13/v13_0_0_beta-1.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/erpnext/change_log/v13/v13_0_0_beta-1.md b/erpnext/change_log/v13/v13_0_0_beta-1.md index f84dc24560..5bd13dd823 100644 --- a/erpnext/change_log/v13/v13_0_0_beta-1.md +++ b/erpnext/change_log/v13/v13_0_0_beta-1.md @@ -30,6 +30,14 @@ - [Item-wise Sales Register](https://docs.erpnext.com/docs/user/manual/en/accounts/accounting-reports) - [Territory-wise Sales](https://github.com/frappe/erpnext/pull/20428) +## Regional + +- Germany + + - [Update report DATEV Export to version 7.0](https://github.com/frappe/erpnext/pull/20582) and [allow to filter by voucher type](https://github.com/frappe/erpnext/pull/21060). + +- [Use any available Address Template](https://github.com/frappe/erpnext/pull/19862), not just your country's. + ## Other Changes - [Report Summary in Financial Statement](https://github.com/frappe/erpnext/pull/20876) - [Accounts Payable Report based on Payment Terms](https://docs.erpnext.com/docs/user/manual/en/accounts/accounting-reports) From fa1e0bdda22bdd39ca6ff05cec08324fd0b22ec2 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 21 May 2020 14:08:25 +0530 Subject: [PATCH 025/449] fix: dict object has no attribute append --- .../exponential_smoothing_forecasting.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py index b5127f133c..1b49df6af8 100644 --- a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py +++ b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py @@ -45,7 +45,7 @@ class ForecastingReport(ExponentialSmoothingForecast): def execute_report(self): self.prepare_periodical_data() self.forecast_future_data() - self.data = self.period_wise_data.values() + self.prepare_final_data() self.add_total() columns = self.get_columns() @@ -108,7 +108,17 @@ class ForecastingReport(ExponentialSmoothingForecast): """.format(doc=self.doctype, child_doc=self.child_doctype, date_field=date_field, cond=cond), tuple(input_data), as_dict=1) + def prepare_final_data(self): + self.data = [] + + if not self.period_wise_data: return + + for key in self.period_wise_data: + self.data.append(self.period_wise_data.get(key)) + def add_total(self): + if not self.data: return + total_row = { "item_code": _(frappe.bold("Total Quantity")) } From 54bcda42ced713f8ec13a338e921ff84bfe1a664 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 21 May 2020 18:57:42 +0530 Subject: [PATCH 026/449] fix(patch): Handle single value in patch (#21823) (#21834) (cherry picked from commit 5cef8db4db7b7ddf4d2f789cd10dcab13ce18987) Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> --- .../patches/v12_0/remove_duplicate_leave_ledger_entries.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/patches/v12_0/remove_duplicate_leave_ledger_entries.py b/erpnext/patches/v12_0/remove_duplicate_leave_ledger_entries.py index 98a2fcf27e..6353304d7a 100644 --- a/erpnext/patches/v12_0/remove_duplicate_leave_ledger_entries.py +++ b/erpnext/patches/v12_0/remove_duplicate_leave_ledger_entries.py @@ -40,5 +40,5 @@ def get_duplicate_records(): def delete_duplicate_ledger_entries(duplicate_records_list): """Delete duplicate leave ledger entries.""" - if duplicate_records_list: - frappe.db.sql(''' DELETE FROM `tabLeave Ledger Entry` WHERE name in {0}'''.format(tuple(duplicate_records_list))) #nosec \ No newline at end of file + if not duplicate_records_list: return + frappe.db.sql('''DELETE FROM `tabLeave Ledger Entry` WHERE name in %s''', ((tuple(duplicate_records_list)), )) \ No newline at end of file From 29742e4cbedb88736d2582fe425248fca6ac8c2c Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Fri, 22 May 2020 15:09:57 +0530 Subject: [PATCH 027/449] feat: rename loan management to loan on Desk Page (cherry picked from commit 5cf90baf165913e99de6a17ac5d7ab65066d8e96) --- .../desk_page/loan_management/loan_management.json | 6 +++--- erpnext/patches.txt | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/erpnext/loan_management/desk_page/loan_management/loan_management.json b/erpnext/loan_management/desk_page/loan_management/loan_management.json index f9ea978ed6..d2a17630c9 100644 --- a/erpnext/loan_management/desk_page/loan_management/loan_management.json +++ b/erpnext/loan_management/desk_page/loan_management/loan_management.json @@ -36,11 +36,11 @@ "extends_another_page": 0, "idx": 0, "is_standard": 1, - "label": "Loan Management", - "modified": "2020-04-02 11:28:51.380509", + "label": "Loan", + "modified": "2020-05-22 11:28:51.380509", "modified_by": "Administrator", "module": "Loan Management", - "name": "Loan Management", + "name": "Loan", "owner": "Administrator", "pin_to_bottom": 0, "pin_to_top": 0, diff --git a/erpnext/patches.txt b/erpnext/patches.txt index af7cb8eeda..4fd668c80b 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -691,3 +691,4 @@ erpnext.patches.v13_0.update_actual_start_and_end_date_in_wo erpnext.patches.v13_0.set_company_field_in_healthcare_doctypes erpnext.patches.v12_0.update_bom_in_so_mr execute:frappe.delete_doc("Report", "Department Analytics") +execute:frappe.rename_doc("Desk Page", "Loan Management", "Loan", force=True) From c71e7eb56f861d7562631729924e4d189b2b7adb Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Wed, 20 May 2020 14:56:29 +0530 Subject: [PATCH 028/449] fix: Move address and contact templates to frappe --- erpnext/public/build.json | 2 - erpnext/public/js/templates/address_list.html | 22 -------- erpnext/public/js/templates/contact_list.html | 54 ------------------- 3 files changed, 78 deletions(-) delete mode 100644 erpnext/public/js/templates/address_list.html delete mode 100644 erpnext/public/js/templates/contact_list.html diff --git a/erpnext/public/build.json b/erpnext/public/build.json index e94d1ffe5c..2695502269 100644 --- a/erpnext/public/build.json +++ b/erpnext/public/build.json @@ -23,8 +23,6 @@ "public/js/queries.js", "public/js/sms_manager.js", "public/js/utils/party.js", - "public/js/templates/address_list.html", - "public/js/templates/contact_list.html", "public/js/controllers/stock_controller.js", "public/js/payment/payments.js", "public/js/controllers/taxes_and_totals.js", diff --git a/erpnext/public/js/templates/address_list.html b/erpnext/public/js/templates/address_list.html deleted file mode 100644 index 0f967b67a0..0000000000 --- a/erpnext/public/js/templates/address_list.html +++ /dev/null @@ -1,22 +0,0 @@ -
-{% for(var i=0, l=addr_list.length; i -

- {%= i+1 %}. {%= addr_list[i].address_title %}{% if(addr_list[i].address_type!="Other") { %} - ({%= __(addr_list[i].address_type) %}){% } %} - {% if(addr_list[i].is_primary_address) { %} - ({%= __("Primary") %}){% } %} - {% if(addr_list[i].is_shipping_address) { %} - ({%= __("Shipping") %}){% } %} - - - {%= __("Edit") %} -

-

{%= addr_list[i].display %}

-
-{% } %} -{% if(!addr_list.length) { %} -

{%= __("No address added yet.") %}

-{% } %} -

\ No newline at end of file diff --git a/erpnext/public/js/templates/contact_list.html b/erpnext/public/js/templates/contact_list.html deleted file mode 100644 index 7e6969163b..0000000000 --- a/erpnext/public/js/templates/contact_list.html +++ /dev/null @@ -1,54 +0,0 @@ -
-{% for(var i=0, l=contact_list.length; i -

- {%= contact_list[i].first_name %} {%= contact_list[i].last_name %} - {% if(contact_list[i].is_primary_contact) { %} - ({%= __("Primary") %}) - {% } %} - {% if(contact_list[i].designation){ %} - – {%= contact_list[i].designation %} - {% } %} - - {%= __("Edit") %} -

- {% if (contact_list[i].phones || contact_list[i].email_ids) { %} -

- {% if(contact_list[i].phone) { %} - {%= __("Phone") %}: {%= contact_list[i].phone %} ({%= __("Primary") %})
- {% endif %} - {% if(contact_list[i].mobile_no) { %} - {%= __("Mobile No") %}: {%= contact_list[i].mobile_no %} ({%= __("Primary") %})
- {% endif %} - {% if(contact_list[i].phone_nos) { %} - {% for(var j=0, k=contact_list[i].phone_nos.length; j - {% } %} - {% endif %} -

-

- {% if(contact_list[i].email_id) { %} - {%= __("Email") %}: {%= contact_list[i].email_id %} ({%= __("Primary") %})
- {% endif %} - {% if(contact_list[i].email_ids) { %} - {% for(var j=0, k=contact_list[i].email_ids.length; j - {% } %} - {% endif %} -

- {% endif %} -

- {% if (contact_list[i].address) { %} - {%= __("Address") %}: {%= contact_list[i].address %}
- {% endif %} -

-
-{% } %} -{% if(!contact_list.length) { %} -

{%= __("No contacts added yet.") %}

-{% } %} -

-

\ No newline at end of file From 69178492735b81681d349dfab0117e17fcf2106c Mon Sep 17 00:00:00 2001 From: anoop Date: Wed, 20 May 2020 15:41:37 +0530 Subject: [PATCH 029/449] fix: service unit create - set fields based on service unit type, added validations --- .../healthcare_service_unit.json | 19 +++++++++++++------ .../healthcare_service_unit.py | 10 ++++++++-- .../healthcare_service_unit_type.json | 16 ++++++++-------- .../healthcare_service_unit_type.py | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.json b/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.json index ea4ae846f7..9ee865a62a 100644 --- a/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.json +++ b/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.json @@ -12,7 +12,6 @@ "engine": "InnoDB", "field_order": [ "healthcare_service_unit_name", - "parent_healthcare_service_unit", "is_group", "service_unit_type", "allow_appointments", @@ -20,8 +19,10 @@ "inpatient_occupancy", "occupancy_status", "column_break_9", - "warehouse", "company", + "warehouse", + "tree_details_section", + "parent_healthcare_service_unit", "lft", "rgt", "old_parent" @@ -51,7 +52,6 @@ "depends_on": "eval:doc.inpatient_occupancy != 1 && doc.allow_appointments != 1", "fieldname": "is_group", "fieldtype": "Check", - "in_list_view": 1, "label": "Is Group" }, { @@ -63,12 +63,12 @@ "options": "Healthcare Service Unit Type" }, { - "bold": 1, "default": "0", "depends_on": "eval:doc.is_group != 1 && doc.inpatient_occupancy != 1", "fetch_from": "service_unit_type.allow_appointments", "fieldname": "allow_appointments", "fieldtype": "Check", + "in_list_view": 1, "label": "Allow Appointments", "no_copy": 1, "read_only": 1 @@ -90,6 +90,7 @@ "fetch_from": "service_unit_type.inpatient_occupancy", "fieldname": "inpatient_occupancy", "fieldtype": "Check", + "in_list_view": 1, "label": "Inpatient Occupancy", "no_copy": 1, "read_only": 1, @@ -101,7 +102,7 @@ "fieldtype": "Select", "label": "Occupancy Status", "no_copy": 1, - "options": "\nVacant\nOccupied", + "options": "Vacant\nOccupied", "read_only": 1 }, { @@ -157,10 +158,16 @@ "options": "Healthcare Service Unit", "print_hide": 1, "report_hide": 1 + }, + { + "collapsible": 1, + "fieldname": "tree_details_section", + "fieldtype": "Section Break", + "label": "Tree Details" } ], "links": [], - "modified": "2020-03-26 16:13:08.675952", + "modified": "2020-05-20 18:26:56.065543", "modified_by": "Administrator", "module": "Healthcare", "name": "Healthcare Service Unit", diff --git a/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py b/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py index 13cc43d2be..9720078e32 100644 --- a/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py +++ b/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py @@ -27,5 +27,11 @@ class HealthcareServiceUnit(NestedSet): self.allow_appointments = 0 self.overlap_appointments = 0 self.inpatient_occupancy = 0 - elif not self.allow_appointments: - self.overlap_appointments = 0 + elif self.service_unit_type: + service_unit_type = frappe.get_doc('Healthcare Service Unit Type', self.service_unit_type) + self.allow_appointments = service_unit_type.allow_appointments + self.overlap_appointments = service_unit_type.overlap_appointments + self.inpatient_occupancy = service_unit_type.inpatient_occupancy + if self.inpatient_occupancy: + self.occupancy_status = 'Vacant' + self.overlap_appointments = 0 diff --git a/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.json b/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.json index 5fa47d91bc..4b8503d028 100644 --- a/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.json +++ b/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.json @@ -31,6 +31,7 @@ "fieldtype": "Data", "in_list_view": 1, "label": "Service Unit Type", + "no_copy": 1, "reqd": 1, "unique": 1 }, @@ -40,8 +41,7 @@ "depends_on": "eval:doc.inpatient_occupancy != 1", "fieldname": "allow_appointments", "fieldtype": "Check", - "label": "Allow Appointments", - "no_copy": 1 + "label": "Allow Appointments" }, { "bold": 1, @@ -49,8 +49,7 @@ "depends_on": "eval:doc.allow_appointments == 1 && doc.inpatient_occupany != 1", "fieldname": "overlap_appointments", "fieldtype": "Check", - "label": "Allow Overlap", - "no_copy": 1 + "label": "Allow Overlap" }, { "bold": 1, @@ -58,8 +57,7 @@ "depends_on": "eval:doc.allow_appointments != 1", "fieldname": "inpatient_occupancy", "fieldtype": "Check", - "label": "Inpatient Occupancy", - "no_copy": 1 + "label": "Inpatient Occupancy" }, { "bold": 1, @@ -79,6 +77,7 @@ "fieldname": "item", "fieldtype": "Link", "label": "Item", + "no_copy": 1, "options": "Item", "read_only": 1 }, @@ -86,7 +85,8 @@ "fieldname": "item_code", "fieldtype": "Data", "label": "Item Code", - "mandatory_depends_on": "eval: doc.is_billable == 1" + "mandatory_depends_on": "eval: doc.is_billable == 1", + "no_copy": 1 }, { "fieldname": "item_group", @@ -138,7 +138,7 @@ } ], "links": [], - "modified": "2020-01-30 16:06:00.624496", + "modified": "2020-05-20 15:31:09.627516", "modified_by": "Administrator", "module": "Healthcare", "name": "Healthcare Service Unit Type", diff --git a/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py b/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py index 286ecc0ff8..a99358cdc6 100644 --- a/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py +++ b/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py @@ -10,6 +10,20 @@ from frappe.model.rename_doc import rename_doc class HealthcareServiceUnitType(Document): def validate(self): + if self.allow_appointments and self.inpatient_occupancy: + frappe.msgprint( + _('Healthcare Service Unit Type cannot be both Allow Appointments and Inpatient Occupancy'), + raise_exception=1, title=_('Validation Error'), indicator='red' + ) + elif not self.allow_appointments and not self.inpatient_occupancy: + frappe.msgprint( + _('Healthcare Service Unit Type cannot be both Allow Appointments and Inpatient Occupancy'), + raise_exception=1, title=_('Validation Error'), indicator='red' + ) + + if not self.allow_appointments: + self.overlap_appointments = 0 + if self.is_billable: if self.disabled: frappe.db.set_value('Item', self.item, 'disabled', 1) From 18ace30a815a6f59741f87a98d6c1c1e25d1bebf Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 20 May 2020 22:15:12 +0530 Subject: [PATCH 030/449] fix: Project filter in Trial Baalance Report --- erpnext/accounts/report/trial_balance/trial_balance.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/report/trial_balance/trial_balance.py b/erpnext/accounts/report/trial_balance/trial_balance.py index 8bd4399e60..5a699b6580 100644 --- a/erpnext/accounts/report/trial_balance/trial_balance.py +++ b/erpnext/accounts/report/trial_balance/trial_balance.py @@ -71,7 +71,8 @@ def get_data(filters): opening_balances = get_opening_balances(filters) #add filter inside list so that the query in financial_statements.py doesn't break - filters.project = [filters.project] + if filters.project: + filters.project = [filters.project] set_gl_entries_by_account(filters.company, filters.from_date, filters.to_date, min_lft, max_rgt, filters, gl_entries_by_account, ignore_closing_entries=not flt(filters.with_period_closing_entry)) From 08f76d73e32e3b585aeab24240ac0ecd681f1a90 Mon Sep 17 00:00:00 2001 From: anoop Date: Thu, 21 May 2020 00:46:40 +0530 Subject: [PATCH 031/449] feat: admission and discharge schedule detials via dialog --- .../inpatient_record/inpatient_record.js | 66 ++++-- .../inpatient_record/inpatient_record.json | 219 ++++++++++++++++-- .../inpatient_record/inpatient_record.py | 101 +++++--- .../patient_encounter/patient_encounter.js | 125 ++++++++-- .../patient_encounter/patient_encounter.json | 4 +- 5 files changed, 417 insertions(+), 98 deletions(-) diff --git a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.js b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.js index 67c12f6c14..b640239b70 100644 --- a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.js +++ b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.js @@ -2,22 +2,37 @@ // For license information, please see license.txt frappe.ui.form.on('Inpatient Record', { + setup: function(frm) { + frm.get_field('drug_prescription').grid.editable_fields = [ + {fieldname: 'drug_code', columns: 2}, + {fieldname: 'drug_name', columns: 2}, + {fieldname: 'dosage', columns: 2}, + {fieldname: 'period', columns: 2} + ]; + }, refresh: function(frm) { - if(!frm.doc.__islocal && frm.doc.status == "Admission Scheduled"){ + if(!frm.doc.__islocal && (frm.doc.status == 'Admission Scheduled' || frm.doc.status == 'Admitted')) { + frm.enable_save(); + } else { + frm.disable_save(); + } + + if(!frm.doc.__islocal && frm.doc.status == 'Admission Scheduled') { frm.add_custom_button(__('Admit'), function() { admit_patient_dialog(frm); } ); - frm.set_df_property("btn_transfer", "hidden", 1); } - if(!frm.doc.__islocal && frm.doc.status == "Discharge Scheduled"){ + + if(!frm.doc.__islocal && frm.doc.status == 'Discharge Scheduled') { frm.add_custom_button(__('Discharge'), function() { discharge_patient(frm); } ); - frm.set_df_property("btn_transfer", "hidden", 0); } - if(!frm.doc.__islocal && (frm.doc.status == "Discharged" || frm.doc.status == "Discharge Scheduled")){ + if(!frm.doc.__islocal && frm.doc.status != 'Admitted') { frm.disable_save(); - frm.set_df_property("btn_transfer", "hidden", 1); + frm.set_df_property('btn_transfer', 'hidden', 1); + } else { + frm.set_df_property('btn_transfer', 'hidden', 0); } }, btn_transfer: function(frm) { @@ -28,14 +43,14 @@ frappe.ui.form.on('Inpatient Record', { var discharge_patient = function(frm) { frappe.call({ doc: frm.doc, - method: "discharge", + method: 'discharge', callback: function(data) { if(!data.exc){ frm.reload_doc(); } }, freeze: true, - freeze_message: "Process Discharge" + freeze_message: 'Processing Inpatient Discharge' }); }; @@ -44,12 +59,20 @@ var admit_patient_dialog = function(frm){ title: 'Admit Patient', width: 100, fields: [ - {fieldtype: "Link", label: "Service Unit Type", fieldname: "service_unit_type", options: "Healthcare Service Unit Type"}, - {fieldtype: "Link", label: "Service Unit", fieldname: "service_unit", options: "Healthcare Service Unit", reqd: 1}, - {fieldtype: "Datetime", label: "Admission Datetime", fieldname: "check_in", reqd: 1}, - {fieldtype: "Date", label: "Expected Discharge", fieldname: "expected_discharge"} + {fieldtype: 'Link', label: 'Service Unit Type', fieldname: 'service_unit_type', + options: 'Healthcare Service Unit Type', default: frm.doc.admission_service_unit_type + }, + {fieldtype: 'Link', label: 'Service Unit', fieldname: 'service_unit', + options: 'Healthcare Service Unit', reqd: 1 + }, + {fieldtype: 'Datetime', label: 'Admission Datetime', fieldname: 'check_in', + reqd: 1, default: frappe.datetime.now_datetime() + }, + {fieldtype: 'Date', label: 'Expected Discharge', fieldname: 'expected_discharge', + default: frm.doc.expected_length_of_stay ? frappe.datetime.add_days(frappe.datetime.now_datetime(), frm.doc.expected_length_of_stay) : '' + } ], - primary_action_label: __("Admit"), + primary_action_label: __('Admit'), primary_action : function(){ var service_unit = dialog.get_value('service_unit'); var check_in = dialog.get_value('check_in'); @@ -74,27 +97,28 @@ var admit_patient_dialog = function(frm){ } }, freeze: true, - freeze_message: "Process Admission" + freeze_message: 'Processing Patient Admission' }); frm.refresh_fields(); dialog.hide(); } }); - dialog.fields_dict["service_unit_type"].get_query = function(){ + dialog.fields_dict['service_unit_type'].get_query = function() { return { filters: { - "inpatient_occupancy": 1, - "allow_appointments": 0 + 'inpatient_occupancy': 1, + 'allow_appointments': 0 } }; }; - dialog.fields_dict["service_unit"].get_query = function(){ + dialog.fields_dict['service_unit'].get_query = function() { return { filters: { - "is_group": 0, - "service_unit_type": dialog.get_value("service_unit_type"), - "occupancy_status" : "Vacant" + 'is_group': 0, + 'company': frm.doc.company, + 'service_unit_type': dialog.get_value('service_unit_type'), + 'occupancy_status' : 'Vacant' } }; }; diff --git a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.json b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.json index c1b516d536..d3835409d9 100644 --- a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.json +++ b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.json @@ -22,17 +22,41 @@ "scheduled_date", "admitted_datetime", "expected_discharge", - "discharge_date", "references", - "cb_admission", - "admission_practitioner", "admission_encounter", - "cb_discharge", - "discharge_practitioner", - "discharge_encounter", + "admission_practitioner", + "medical_department", + "admission_ordered_for", + "expected_length_of_stay", + "admission_service_unit_type", + "cb_admission", + "primary_practitioner", + "secondary_practitioner", + "admission_instruction", + "encounter_details_section", + "chief_complaint", + "column_break_29", + "diagnosis", + "medication_section", + "drug_prescription", + "investigations_section", + "lab_test_prescription", + "procedures_section", + "procedure_prescription", + "rehabilitation_section", + "therapy_plan", + "therapies", "sb_inpatient_occupancy", "inpatient_occupancies", "btn_transfer", + "sb_discharge_details", + "discharge_ordered_date", + "discharge_practitioner", + "discharge_encounter", + "discharge_date", + "cb_discharge", + "discharge_instructions", + "followup_date", "sb_discharge_note", "discharge_note" ], @@ -54,7 +78,8 @@ "in_list_view": 1, "label": "Patient", "options": "Patient", - "reqd": 1 + "reqd": 1, + "set_only_once": 1 }, { "fetch_from": "patient.patient_name", @@ -108,11 +133,31 @@ "label": "Phone", "read_only": 1 }, + { + "fieldname": "medical_department", + "fieldtype": "Link", + "label": "Medical Department", + "options": "Medical Department", + "set_only_once": 1 + }, + { + "fieldname": "primary_practitioner", + "fieldtype": "Link", + "label": "Healthcare Practitioner (Primary)", + "options": "Healthcare Practitioner" + }, + { + "fieldname": "secondary_practitioner", + "fieldtype": "Link", + "label": "Healthcare Practitioner (Secondary)", + "options": "Healthcare Practitioner" + }, { "fieldname": "column_break_8", "fieldtype": "Column Break" }, { + "default": "Admission Scheduled", "fieldname": "status", "fieldtype": "Select", "in_list_view": 1, @@ -126,37 +171,45 @@ "fieldtype": "Date", "in_list_view": 1, "label": "Admission Schedule Date", + "read_only": 1, "reqd": 1 }, { - "default": "Today", + "fieldname": "admission_ordered_for", + "fieldtype": "Date", + "label": "Admission Ordered For", + "read_only": 1 + }, + { "fieldname": "admitted_datetime", "fieldtype": "Datetime", "in_list_view": 1, - "label": "Admitted Datetime" + "label": "Admitted Datetime", + "read_only": 1 + }, + { + "depends_on": "eval:(doc.expected_length_of_stay > 0)", + "fieldname": "expected_length_of_stay", + "fieldtype": "Int", + "label": "Expected Length of Stay", + "set_only_once": 1 }, { "fieldname": "expected_discharge", "fieldtype": "Date", "in_list_view": 1, - "label": "Expected Discharge" - }, - { - "fieldname": "discharge_date", - "fieldtype": "Date", - "in_list_view": 1, - "label": "Discharge Date" + "label": "Expected Discharge", + "read_only": 1 }, { "collapsible": 1, "fieldname": "references", "fieldtype": "Section Break", - "label": "References" + "label": "Admission Order Details" }, { "fieldname": "cb_admission", - "fieldtype": "Column Break", - "label": "Admission" + "fieldtype": "Column Break" }, { "fieldname": "admission_practitioner", @@ -172,10 +225,21 @@ "options": "Patient Encounter", "read_only": 1 }, + { + "fieldname": "chief_complaint", + "fieldtype": "Table MultiSelect", + "label": "Chief Complaint", + "options": "Patient Encounter Symptom" + }, + { + "fieldname": "admission_instruction", + "fieldtype": "Small Text", + "label": "Admission Instruction", + "set_only_once": 1 + }, { "fieldname": "cb_discharge", - "fieldtype": "Column Break", - "label": "Discharge" + "fieldtype": "Column Break" }, { "fieldname": "discharge_practitioner", @@ -192,10 +256,51 @@ "read_only": 1 }, { + "collapsible": 1, + "fieldname": "medication_section", + "fieldtype": "Section Break", + "label": "Medications" + }, + { + "fieldname": "drug_prescription", + "fieldtype": "Table", + "options": "Drug Prescription" + }, + { + "collapsible": 1, + "fieldname": "investigations_section", + "fieldtype": "Section Break", + "label": "Investigations" + }, + { + "fieldname": "lab_test_prescription", + "fieldtype": "Table", + "options": "Lab Prescription" + }, + { + "collapsible": 1, + "fieldname": "procedures_section", + "fieldtype": "Section Break", + "label": "Procedures" + }, + { + "fieldname": "procedure_prescription", + "fieldtype": "Table", + "options": "Procedure Prescription" + }, + { + "depends_on": "eval:(doc.status != \"Admission Scheduled\")", "fieldname": "sb_inpatient_occupancy", "fieldtype": "Section Break", "label": "Inpatient Occupancy" }, + { + "fieldname": "admission_service_unit_type", + "fieldtype": "Link", + "label": "Admission Service Unit Type", + "options": "Healthcare Service Unit Type", + "read_only": 1 + }, { "fieldname": "inpatient_occupancies", "fieldtype": "Table", @@ -208,10 +313,10 @@ "label": "Transfer" }, { - "depends_on": "eval:doc.status != \"Admission Scheduled\"", + "depends_on": "eval:(doc.status == \"Discharge Scheduled\" || doc.status == \"Discharged\")", "fieldname": "sb_discharge_note", "fieldtype": "Section Break", - "label": "Discharge Note" + "label": "Discharge Notes" }, { "fieldname": "discharge_note", @@ -224,10 +329,76 @@ "in_standard_filter": 1, "label": "Company", "options": "Company" + }, + { + "collapsible": 1, + "collapsible_depends_on": "eval:(doc.status == \"Admitted\")", + "fieldname": "encounter_details_section", + "fieldtype": "Section Break", + "label": "Encounter Impression" + }, + { + "fieldname": "column_break_29", + "fieldtype": "Column Break" + }, + { + "fieldname": "diagnosis", + "fieldtype": "Table MultiSelect", + "label": "Diagnosis", + "options": "Patient Encounter Diagnosis" + }, + { + "fieldname": "followup_date", + "fieldtype": "Date", + "label": "Follow Up Date" + }, + { + "collapsible": 1, + "depends_on": "eval:(doc.status == \"Discharge Scheduled\" || doc.status == \"Discharged\")", + "fieldname": "sb_discharge_details", + "fieldtype": "Section Break", + "label": "Discharge Detials" + }, + { + "fieldname": "discharge_instructions", + "fieldtype": "Small Text", + "label": "Discharge Instructions" + }, + { + "fieldname": "discharge_ordered_date", + "fieldtype": "Date", + "in_list_view": 1, + "label": "Discharge Ordered Date", + "read_only": 1 + }, + { + "collapsible": 1, + "fieldname": "rehabilitation_section", + "fieldtype": "Section Break", + "label": "Rehabilitation" + }, + { + "fieldname": "therapy_plan", + "fieldtype": "Link", + "hidden": 1, + "label": "Therapy Plan", + "options": "Therapy Plan", + "read_only": 1 + }, + { + "fieldname": "therapies", + "fieldtype": "Table", + "options": "Therapy Plan Detail" + }, + { + "fieldname": "discharge_date", + "fieldtype": "Date", + "label": "Discharge Date", + "read_only": 1 } ], "links": [], - "modified": "2020-04-07 13:13:39.351977", + "modified": "2020-05-21 00:37:12.939925", "modified_by": "Administrator", "module": "Healthcare", "name": "Inpatient Record", diff --git a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py index 835b38bedf..e668204dcf 100644 --- a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py +++ b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py @@ -3,7 +3,7 @@ # For license information, please see license.txt from __future__ import unicode_literals -import frappe +import frappe, json from frappe import _ from frappe.utils import today, now_datetime, getdate from frappe.model.document import Document @@ -11,8 +11,12 @@ from frappe.desk.reportview import get_match_cond class InpatientRecord(Document): def after_insert(self): - frappe.db.set_value("Patient", self.patient, "inpatient_status", "Admission Scheduled") - frappe.db.set_value("Patient", self.patient, "inpatient_record", self.name) + frappe.db.set_value('Patient', self.patient, 'inpatient_record', self.name) + frappe.db.set_value('Patient', self.patient, 'inpatient_status', self.status) + + if self.admission_encounter: # Update encounter + frappe.db.set_value('Patient Encounter', self.admission_encounter, 'inpatient_record', self.name) + frappe.db.set_value('Patient Encounter', self.admission_encounter, 'inpatient_status', self.status) def validate(self): self.validate_dates() @@ -26,7 +30,7 @@ class InpatientRecord(Document): (getdate(self.admitted_datetime) < getdate(today())): frappe.throw(_("Scheduled and Admitted dates can not be less than today")) if (getdate(self.expected_discharge) < getdate(self.scheduled_date)) or \ - (getdate(self.discharge_date) < getdate(self.scheduled_date)): + (getdate(self.discharge_ordered_date) < getdate(self.scheduled_date)): frappe.throw(_("Expected and Discharge dates cannot be less than Admission Schedule date")) def validate_already_scheduled_or_admitted(self): @@ -59,37 +63,76 @@ class InpatientRecord(Document): if service_unit: transfer_patient(self, service_unit, check_in) + @frappe.whitelist() -def schedule_inpatient(patient, encounter_id, practitioner): - patient_obj = frappe.get_doc('Patient', patient) +def schedule_inpatient(args): + admission_order = json.loads(args) # admission order via Encounter + if not admission_order or not admission_order['patient'] or not admission_order['admission_encounter']: + frappe.throw(_('Missing required details, did not create Inpatient Record')) + inpatient_record = frappe.new_doc('Inpatient Record') - inpatient_record.patient = patient - inpatient_record.patient_name = patient_obj.patient_name - inpatient_record.gender = patient_obj.sex - inpatient_record.blood_group = patient_obj.blood_group - inpatient_record.dob = patient_obj.dob - inpatient_record.mobile = patient_obj.mobile - inpatient_record.email = patient_obj.email - inpatient_record.phone = patient_obj.phone - inpatient_record.status = "Admission Scheduled" + + # Admission order details + set_details_from_ip_order(inpatient_record, admission_order) + + # Patient details + patient = frappe.get_doc('Patient', admission_order['patient']) + inpatient_record.patient = patient.name + inpatient_record.patient_name = patient.patient_name + inpatient_record.gender = patient.sex + inpatient_record.blood_group = patient.blood_group + inpatient_record.dob = patient.dob + inpatient_record.mobile = patient.mobile + inpatient_record.email = patient.email + inpatient_record.phone = patient.phone inpatient_record.scheduled_date = today() - inpatient_record.admission_practitioner = practitioner - inpatient_record.admission_encounter = encounter_id + + # Set encounter detials + encounter = frappe.get_doc('Patient Encounter', admission_order['admission_encounter']) + if encounter and encounter.symptoms: # Symptoms + set_ip_child_records(inpatient_record, 'chief_complaint', encounter.symptoms) + + if encounter and encounter.diagnosis: # Diagnosis + set_ip_child_records(inpatient_record, 'diagnosis', encounter.diagnosis) + + if encounter and encounter.drug_prescription: # Medication + set_ip_child_records(inpatient_record, 'drug_prescription', encounter.drug_prescription) + + if encounter and encounter.lab_test_prescription: # Lab Tests + set_ip_child_records(inpatient_record, 'lab_test_prescription', encounter.lab_test_prescription) + + if encounter and encounter.procedure_prescription: # Procedure Prescription + set_ip_child_records(inpatient_record, 'procedure_prescription', encounter.procedure_prescription) + + if encounter and encounter.therapies: # Therapies + inpatient_record.therapy_plan = encounter.therapy_plan + set_ip_child_records(inpatient_record, 'therapies', encounter.therapies) + + inpatient_record.status = 'Admission Scheduled' inpatient_record.save(ignore_permissions = True) @frappe.whitelist() -def schedule_discharge(patient, encounter_id=None, practitioner=None): - inpatient_record_id = frappe.db.get_value('Patient', patient, 'inpatient_record') +def schedule_discharge(args): + discharge_order = json.loads(args) + inpatient_record_id = frappe.db.get_value('Patient', discharge_order['patient'], 'inpatient_record') if inpatient_record_id: - inpatient_record = frappe.get_doc("Inpatient Record", inpatient_record_id) - inpatient_record.discharge_practitioner = practitioner - inpatient_record.discharge_encounter = encounter_id - inpatient_record.status = "Discharge Scheduled" - + inpatient_record = frappe.get_doc('Inpatient Record', inpatient_record_id) check_out_inpatient(inpatient_record) - + set_details_from_ip_order(inpatient_record, discharge_order) + inpatient_record.status = 'Discharge Scheduled' inpatient_record.save(ignore_permissions = True) - frappe.db.set_value("Patient", patient, "inpatient_status", "Discharge Scheduled") + frappe.db.set_value('Patient', discharge_order['patient'], 'inpatient_status', inpatient_record.status) + frappe.db.set_value('Patient Encounter', inpatient_record.discharge_encounter, 'inpatient_status', inpatient_record.status) + +def set_details_from_ip_order(inpatient_record, ip_order): + for key in ip_order: + inpatient_record.set(key, ip_order[key]) + +def set_ip_child_records(inpatient_record, inpatient_record_child, encounter_child): + for item in encounter_child: + table = inpatient_record.append(inpatient_record_child) + for df in table.meta.get('fields'): + table.set(df.fieldname, item.get(df.fieldname)) def check_out_inpatient(inpatient_record): if inpatient_record.inpatient_occupancies: @@ -149,14 +192,14 @@ def get_inpatient_docs_not_invoiced(doc, inpatient_record): def admit_patient(inpatient_record, service_unit, check_in, expected_discharge=None): inpatient_record.admitted_datetime = check_in - inpatient_record.status = "Admitted" + inpatient_record.status = 'Admitted' inpatient_record.expected_discharge = expected_discharge inpatient_record.set('inpatient_occupancies', []) transfer_patient(inpatient_record, service_unit, check_in) - frappe.db.set_value("Patient", inpatient_record.patient, "inpatient_status", "Admitted") - frappe.db.set_value("Patient", inpatient_record.patient, "inpatient_record", inpatient_record.name) + frappe.db.set_value('Patient', inpatient_record.patient, 'inpatient_status', 'Admitted') + frappe.db.set_value('Patient', inpatient_record.patient, 'inpatient_record', inpatient_record.name) def transfer_patient(inpatient_record, service_unit, check_in): item_line = inpatient_record.append('inpatient_occupancies', {}) diff --git a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js index 2410f8e10d..43e43acda4 100644 --- a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js +++ b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js @@ -180,35 +180,114 @@ frappe.ui.form.on('Patient Encounter', { } }); -let schedule_inpatient = function(frm) { - frappe.call({ - method: 'erpnext.healthcare.doctype.inpatient_record.inpatient_record.schedule_inpatient', - args: {patient: frm.doc.patient, encounter_id: frm.doc.name, practitioner: frm.doc.practitioner}, - callback: function(data) { - if (!data.exc) { - frm.reload_doc(); +var schedule_inpatient = function(frm) { + var dialog = new frappe.ui.Dialog({ + title: 'Patient Admission', + fields: [ + {fieldtype: 'Link', label: 'Medical Department', fieldname: 'medical_department', options: 'Medical Department', reqd: 1}, + {fieldtype: 'Link', label: 'Healthcare Practitioner (Primary)', fieldname: 'primary_practitioner', options: 'Healthcare Practitioner', reqd: 1}, + {fieldtype: 'Link', label: 'Healthcare Practitioner (Secondary)', fieldname: 'secondary_practitioner', options: 'Healthcare Practitioner'}, + {fieldtype: 'Column Break'}, + {fieldtype: 'Date', label: 'Admission Ordered For', fieldname: 'admission_ordered_for', default: 'Today'}, + {fieldtype: 'Link', label: 'Service Unit Type', fieldname: 'service_unit_type', options: 'Healthcare Service Unit Type'}, + {fieldtype: 'Int', label: 'Expected Length of Stay', fieldname: 'expected_length_of_stay'}, + {fieldtype: 'Section Break', label: 'Admission Instructions'}, + {fieldtype: 'Small Text', fieldname: 'admission_instruction'} + ], + primary_action_label: __('Order Admission'), + primary_action : function() { + var args = { + patient: frm.doc.patient, + admission_encounter: frm.doc.name, + referring_practitioner: frm.doc.practitioner, + company: frm.doc.company, + medical_department: dialog.get_value('medical_department'), + primary_practitioner: dialog.get_value('primary_practitioner'), + secondary_practitioner: dialog.get_value('secondary_practitioner'), + admission_ordered_for: dialog.get_value('admission_ordered_for'), + admission_service_unit_type: dialog.get_value('service_unit_type'), + expected_length_of_stay: dialog.get_value('expected_length_of_stay'), + admission_instruction: dialog.get_value('admission_instruction') } - }, - freeze: true, - freeze_message: __('Process Inpatient Scheduling') + frappe.call({ + method: 'erpnext.healthcare.doctype.inpatient_record.inpatient_record.schedule_inpatient', + args: { + args: args + }, + callback: function(data) { + if(!data.exc){ + frm.reload_doc(); + } + }, + freeze: true, + freeze_message: 'Scheduling Patient Admission' + }); + frm.refresh_fields(); + dialog.hide(); + } }); + + dialog.set_values({ + 'medical_department': frm.doc.medical_department, + 'primary_practitioner': frm.doc.practitioner, + }); + + dialog.fields_dict['service_unit_type'].get_query = function() { + return { + filters: { + 'inpatient_occupancy': 1, + 'allow_appointments': 0 + } + }; + }; + + dialog.show(); + dialog.$wrapper.find('.modal-dialog').css('width', '800px'); }; -let schedule_discharge = function(frm) { - frappe.call({ - method: 'erpnext.healthcare.doctype.inpatient_record.inpatient_record.schedule_discharge', - args: {patient: frm.doc.patient, encounter_id: frm.doc.name, practitioner: frm.doc.practitioner}, - callback: function(data) { - if (!data.exc) { - frm.reload_doc(); +var schedule_discharge = function(frm) { + var dialog = new frappe.ui.Dialog ({ + title: 'Inpatient Discharge', + fields: [ + {fieldtype: 'Date', label: 'Discharge Ordered Date', fieldname: 'discharge_ordered_date', default: 'Today', read_only: 1}, + {fieldtype: 'Date', label: 'Followup Date', fieldname: 'followup_date'}, + {fieldtype: 'Column Break'}, + {fieldtype: 'Small Text', label: 'Discharge Instructions', fieldname: 'discharge_instructions'}, + {fieldtype: 'Section Break', label:'Discharge Summary'}, + {fieldtype: 'Text Editor', label: 'Discharge Note', fieldname: 'discharge_note'} + ], + primary_action_label: __('Order Discharge'), + primary_action : function() { + var args = { + patient: frm.doc.patient, + discharge_encounter: frm.doc.name, + discharge_practitioner: frm.doc.practitioner, + discharge_ordered_date: dialog.get_value('discharge_ordered_date'), + followup_date: dialog.get_value('followup_date'), + discharge_instructions: dialog.get_value('discharge_instructions'), + discharge_note: dialog.get_value('discharge_note') } - }, - freeze: true, - freeze_message: 'Process Discharge' + frappe.call ({ + method: 'erpnext.healthcare.doctype.inpatient_record.inpatient_record.schedule_discharge', + args: {args}, + callback: function(data) { + if(!data.exc){ + frm.reload_doc(); + } + }, + freeze: true, + freeze_message: 'Scheduling Inpatient Discharge' + }); + frm.refresh_fields(); + dialog.hide(); + } }); + + dialog.show(); + dialog.$wrapper.find('.modal-dialog').css('width', '800px'); }; -let create_medical_record = function (frm) { +let create_medical_record = function(frm) { if (!frm.doc.patient) { frappe.throw(__('Please select patient')); } @@ -221,7 +300,7 @@ let create_medical_record = function (frm) { frappe.new_doc('Patient Medical Record'); }; -let create_vital_signs = function (frm) { +let create_vital_signs = function(frm) { if (!frm.doc.patient) { frappe.throw(__('Please select patient')); } @@ -233,7 +312,7 @@ let create_vital_signs = function (frm) { frappe.new_doc('Vital Signs'); }; -let create_procedure = function (frm) { +let create_procedure = function(frm) { if (!frm.doc.patient) { frappe.throw(__('Please select patient')); } diff --git a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.json b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.json index 05eec87398..15675f4673 100644 --- a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.json +++ b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.json @@ -52,6 +52,7 @@ ], "fields": [ { + "allow_on_submit": 1, "fieldname": "inpatient_record", "fieldtype": "Link", "label": "Inpatient Record", @@ -296,6 +297,7 @@ "read_only": 1 }, { + "allow_on_submit": 1, "fieldname": "inpatient_status", "fieldtype": "Data", "label": "Inpatient Status", @@ -326,7 +328,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-04-27 21:58:29.789797", + "modified": "2020-05-16 21:00:08.644531", "modified_by": "Administrator", "module": "Healthcare", "name": "Patient Encounter", From f71f9556abb6c5570dd130c8eed1579d936da2c5 Mon Sep 17 00:00:00 2001 From: anoop Date: Thu, 21 May 2020 01:31:48 +0530 Subject: [PATCH 032/449] fix: consider only submitted docs for invoicing --- .../healthcare/doctype/inpatient_record/inpatient_record.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py index e668204dcf..8056074668 100644 --- a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py +++ b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py @@ -187,8 +187,8 @@ def get_pending_doc(doc, doc_name_list, pending_invoices): return pending_invoices def get_inpatient_docs_not_invoiced(doc, inpatient_record): - return frappe.db.get_list(doc, filters = {"patient": inpatient_record.patient, - "inpatient_record": inpatient_record.name, "invoiced": 0}) + return frappe.db.get_list(doc, filters = {'patient': inpatient_record.patient, + 'inpatient_record': inpatient_record.name, 'docstatus': 1, 'invoiced': 0}) def admit_patient(inpatient_record, service_unit, check_in, expected_discharge=None): inpatient_record.admitted_datetime = check_in From 09ec030baa0f50e09a00ad9f8c9cfc900ad15b73 Mon Sep 17 00:00:00 2001 From: anoop Date: Thu, 21 May 2020 01:34:18 +0530 Subject: [PATCH 033/449] fix: ip-order dialogs use long text field --- .../doctype/patient_encounter/patient_encounter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js index 43e43acda4..ef1068e6cb 100644 --- a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js +++ b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js @@ -191,8 +191,8 @@ var schedule_inpatient = function(frm) { {fieldtype: 'Date', label: 'Admission Ordered For', fieldname: 'admission_ordered_for', default: 'Today'}, {fieldtype: 'Link', label: 'Service Unit Type', fieldname: 'service_unit_type', options: 'Healthcare Service Unit Type'}, {fieldtype: 'Int', label: 'Expected Length of Stay', fieldname: 'expected_length_of_stay'}, - {fieldtype: 'Section Break', label: 'Admission Instructions'}, - {fieldtype: 'Small Text', fieldname: 'admission_instruction'} + {fieldtype: 'Section Break'}, + {fieldtype: 'Long Text', label: 'Admission Instructions', fieldname: 'admission_instruction'} ], primary_action_label: __('Order Admission'), primary_action : function() { @@ -254,7 +254,7 @@ var schedule_discharge = function(frm) { {fieldtype: 'Column Break'}, {fieldtype: 'Small Text', label: 'Discharge Instructions', fieldname: 'discharge_instructions'}, {fieldtype: 'Section Break', label:'Discharge Summary'}, - {fieldtype: 'Text Editor', label: 'Discharge Note', fieldname: 'discharge_note'} + {fieldtype: 'Long Text', label: 'Discharge Note', fieldname: 'discharge_note'} ], primary_action_label: __('Order Discharge'), primary_action : function() { From 470fe65cc1b07f56d27d3dcc1106af1a40ee3132 Mon Sep 17 00:00:00 2001 From: anoop Date: Thu, 21 May 2020 02:26:55 +0530 Subject: [PATCH 034/449] fix: inpatient date validation removed, added role perms service unit defaults not set when created from tree, added validations on after_insert --- .../healthcare_service_unit.py | 2 +- .../inpatient_record/inpatient_record.json | 75 +++++++++++++++---- .../inpatient_record/inpatient_record.py | 5 +- 3 files changed, 64 insertions(+), 18 deletions(-) diff --git a/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py b/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py index 9720078e32..9e0417a2be 100644 --- a/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py +++ b/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py @@ -22,7 +22,7 @@ class HealthcareServiceUnit(NestedSet): super(HealthcareServiceUnit, self).on_update() self.validate_one_root() - def validate(self): + def after_insert(self): if self.is_group: self.allow_appointments = 0 self.overlap_appointments = 0 diff --git a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.json b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.json index d3835409d9..5ced845c1b 100644 --- a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.json +++ b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.json @@ -229,7 +229,8 @@ "fieldname": "chief_complaint", "fieldtype": "Table MultiSelect", "label": "Chief Complaint", - "options": "Patient Encounter Symptom" + "options": "Patient Encounter Symptom", + "permlevel": 1 }, { "fieldname": "admission_instruction", @@ -259,34 +260,40 @@ "collapsible": 1, "fieldname": "medication_section", "fieldtype": "Section Break", - "label": "Medications" + "label": "Medications", + "permlevel": 1 }, { "fieldname": "drug_prescription", "fieldtype": "Table", - "options": "Drug Prescription" + "options": "Drug Prescription", + "permlevel": 1 }, { "collapsible": 1, "fieldname": "investigations_section", "fieldtype": "Section Break", - "label": "Investigations" + "label": "Investigations", + "permlevel": 1 }, { "fieldname": "lab_test_prescription", "fieldtype": "Table", - "options": "Lab Prescription" + "options": "Lab Prescription", + "permlevel": 1 }, { "collapsible": 1, "fieldname": "procedures_section", "fieldtype": "Section Break", - "label": "Procedures" + "label": "Procedures", + "permlevel": 1 }, { "fieldname": "procedure_prescription", "fieldtype": "Table", - "options": "Procedure Prescription" + "options": "Procedure Prescription", + "permlevel": 1 }, { "depends_on": "eval:(doc.status != \"Admission Scheduled\")", @@ -320,7 +327,8 @@ }, { "fieldname": "discharge_note", - "fieldtype": "Text Editor" + "fieldtype": "Text Editor", + "permlevel": 1 }, { "fetch_from": "admission_encounter.company", @@ -335,7 +343,8 @@ "collapsible_depends_on": "eval:(doc.status == \"Admitted\")", "fieldname": "encounter_details_section", "fieldtype": "Section Break", - "label": "Encounter Impression" + "label": "Encounter Impression", + "permlevel": 1 }, { "fieldname": "column_break_29", @@ -345,7 +354,8 @@ "fieldname": "diagnosis", "fieldtype": "Table MultiSelect", "label": "Diagnosis", - "options": "Patient Encounter Diagnosis" + "options": "Patient Encounter Diagnosis", + "permlevel": 1 }, { "fieldname": "followup_date", @@ -375,7 +385,8 @@ "collapsible": 1, "fieldname": "rehabilitation_section", "fieldtype": "Section Break", - "label": "Rehabilitation" + "label": "Rehabilitation", + "permlevel": 1 }, { "fieldname": "therapy_plan", @@ -383,12 +394,14 @@ "hidden": 1, "label": "Therapy Plan", "options": "Therapy Plan", + "permlevel": 1, "read_only": 1 }, { "fieldname": "therapies", "fieldtype": "Table", - "options": "Therapy Plan Detail" + "options": "Therapy Plan Detail", + "permlevel": 1 }, { "fieldname": "discharge_date", @@ -398,7 +411,7 @@ } ], "links": [], - "modified": "2020-05-21 00:37:12.939925", + "modified": "2020-05-21 02:26:22.144575", "modified_by": "Administrator", "module": "Healthcare", "name": "Inpatient Record", @@ -415,6 +428,42 @@ "role": "Healthcare Administrator", "share": 1, "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Physician", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Nursing User", + "share": 1, + "write": 1 + }, + { + "permlevel": 1, + "read": 1, + "role": "Physician", + "write": 1 + }, + { + "permlevel": 1, + "read": 1, + "report": 1, + "role": "Nursing User" } ], "restrict_to_domain": "Healthcare", diff --git a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py index 8056074668..802ab414c0 100644 --- a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py +++ b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py @@ -26,12 +26,9 @@ class InpatientRecord(Document): frappe.db.set_value("Patient", self.patient, "inpatient_record", None) def validate_dates(self): - if (getdate(self.scheduled_date) < getdate(today())) or \ - (getdate(self.admitted_datetime) < getdate(today())): - frappe.throw(_("Scheduled and Admitted dates can not be less than today")) if (getdate(self.expected_discharge) < getdate(self.scheduled_date)) or \ (getdate(self.discharge_ordered_date) < getdate(self.scheduled_date)): - frappe.throw(_("Expected and Discharge dates cannot be less than Admission Schedule date")) + frappe.throw(_('Expected and Discharge dates cannot be less than Admission Schedule date')) def validate_already_scheduled_or_admitted(self): query = """ From f579680b97fc9bd348f34fab639686a7aadd936b Mon Sep 17 00:00:00 2001 From: anoop Date: Thu, 21 May 2020 03:08:47 +0530 Subject: [PATCH 035/449] fix: invoiced field position, medical department field corrected in query --- .../doctype/patient_appointment/patient_appointment.json | 4 ++-- .../doctype/patient_appointment/patient_appointment.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json index b8a400c6b7..ac35acc21a 100644 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json @@ -39,9 +39,9 @@ "section_break_16", "mode_of_payment", "billing_item", + "invoiced", "column_break_2", "paid_amount", - "invoiced", "ref_sales_invoice", "section_break_3", "referring_practitioner", @@ -348,7 +348,7 @@ } ], "links": [], - "modified": "2020-04-27 21:36:06.404062", + "modified": "2020-05-21 03:04:21.400893", "modified_by": "Administrator", "module": "Healthcare", "name": "Patient Appointment", diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py index 9eb6e77c85..512fb48360 100755 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py @@ -447,7 +447,7 @@ def get_prescribed_therapies(patient): """ SELECT t.therapy_type, t.name, t.parent, e.practitioner, - e.encounter_date, e.therapy_plan, e.visit_department + e.encounter_date, e.therapy_plan, e.medical_department FROM `tabPatient Encounter` e, `tabTherapy Plan Detail` t WHERE From ccbdfcbed1b1d15f4f4f113355b6685db851204c Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 21 May 2020 09:02:46 +0530 Subject: [PATCH 036/449] fix: service unit validation and translation --- .../healthcare_service_unit_type.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py b/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py index a99358cdc6..bb86eaacc4 100644 --- a/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py +++ b/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py @@ -12,12 +12,14 @@ class HealthcareServiceUnitType(Document): def validate(self): if self.allow_appointments and self.inpatient_occupancy: frappe.msgprint( - _('Healthcare Service Unit Type cannot be both Allow Appointments and Inpatient Occupancy'), + _('Healthcare Service Unit Type cannot have both {0} and {1}').format( + frappe.bold('Allow Appointments'), frappe.bold('Inpatient Occupancy')), raise_exception=1, title=_('Validation Error'), indicator='red' ) elif not self.allow_appointments and not self.inpatient_occupancy: frappe.msgprint( - _('Healthcare Service Unit Type cannot be both Allow Appointments and Inpatient Occupancy'), + _('Healthcare Service Unit Type must allow atleast one among {0} and {1}').format( + frappe.bold('Allow Appointments'), frappe.bold('Inpatient Occupancy')), raise_exception=1, title=_('Validation Error'), indicator='red' ) From 4da770d6c2f9065c87da11775f2b9c39e6d3230f Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 21 May 2020 09:27:42 +0530 Subject: [PATCH 037/449] fix(ip): code cleanup and translations --- .../inpatient_record/inpatient_record.js | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.js b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.js index b640239b70..971e166067 100644 --- a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.js +++ b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.js @@ -11,24 +11,24 @@ frappe.ui.form.on('Inpatient Record', { ]; }, refresh: function(frm) { - if(!frm.doc.__islocal && (frm.doc.status == 'Admission Scheduled' || frm.doc.status == 'Admitted')) { + if (!frm.doc.__islocal && (frm.doc.status == 'Admission Scheduled' || frm.doc.status == 'Admitted')) { frm.enable_save(); } else { frm.disable_save(); } - if(!frm.doc.__islocal && frm.doc.status == 'Admission Scheduled') { + if (!frm.doc.__islocal && frm.doc.status == 'Admission Scheduled') { frm.add_custom_button(__('Admit'), function() { admit_patient_dialog(frm); } ); } - if(!frm.doc.__islocal && frm.doc.status == 'Discharge Scheduled') { + if (!frm.doc.__islocal && frm.doc.status == 'Discharge Scheduled') { frm.add_custom_button(__('Discharge'), function() { discharge_patient(frm); } ); } - if(!frm.doc.__islocal && frm.doc.status != 'Admitted') { + if (!frm.doc.__islocal && frm.doc.status != 'Admitted') { frm.disable_save(); frm.set_df_property('btn_transfer', 'hidden', 1); } else { @@ -40,22 +40,22 @@ frappe.ui.form.on('Inpatient Record', { } }); -var discharge_patient = function(frm) { +let discharge_patient = function(frm) { frappe.call({ doc: frm.doc, method: 'discharge', callback: function(data) { - if(!data.exc){ + if (!data.exc) { frm.reload_doc(); } }, freeze: true, - freeze_message: 'Processing Inpatient Discharge' + freeze_message: __('Processing Inpatient Discharge') }); }; -var admit_patient_dialog = function(frm){ - var dialog = new frappe.ui.Dialog({ +let admit_patient_dialog = function(frm) { + let dialog = new frappe.ui.Dialog({ title: 'Admit Patient', width: 100, fields: [ @@ -74,13 +74,13 @@ var admit_patient_dialog = function(frm){ ], primary_action_label: __('Admit'), primary_action : function(){ - var service_unit = dialog.get_value('service_unit'); - var check_in = dialog.get_value('check_in'); - var expected_discharge = null; - if(dialog.get_value('expected_discharge')){ + let service_unit = dialog.get_value('service_unit'); + let check_in = dialog.get_value('check_in'); + let expected_discharge = null; + if (dialog.get_value('expected_discharge')) { expected_discharge = dialog.get_value('expected_discharge'); } - if(!service_unit && !check_in){ + if (!service_unit && !check_in) { return; } frappe.call({ @@ -92,12 +92,12 @@ var admit_patient_dialog = function(frm){ 'expected_discharge': expected_discharge }, callback: function(data) { - if(!data.exc){ + if (!data.exc) { frm.reload_doc(); } }, freeze: true, - freeze_message: 'Processing Patient Admission' + freeze_message: __('Processing Patient Admission') }); frm.refresh_fields(); dialog.hide(); @@ -126,21 +126,21 @@ var admit_patient_dialog = function(frm){ dialog.show(); }; -var transfer_patient_dialog = function(frm){ - var dialog = new frappe.ui.Dialog({ +let transfer_patient_dialog = function(frm) { + let dialog = new frappe.ui.Dialog({ title: 'Transfer Patient', width: 100, fields: [ - {fieldtype: "Link", label: "Leave From", fieldname: "leave_from", options: "Healthcare Service Unit", reqd: 1, read_only:1}, - {fieldtype: "Link", label: "Service Unit Type", fieldname: "service_unit_type", options: "Healthcare Service Unit Type"}, - {fieldtype: "Link", label: "Transfer To", fieldname: "service_unit", options: "Healthcare Service Unit", reqd: 1}, - {fieldtype: "Datetime", label: "Check In", fieldname: "check_in", reqd: 1} + {fieldtype: 'Link', label: 'Leave From', fieldname: 'leave_from', options: 'Healthcare Service Unit', reqd: 1, read_only:1}, + {fieldtype: 'Link', label: 'Service Unit Type', fieldname: 'service_unit_type', options: 'Healthcare Service Unit Type'}, + {fieldtype: 'Link', label: 'Transfer To', fieldname: 'service_unit', options: 'Healthcare Service Unit', reqd: 1}, + {fieldtype: 'Datetime', label: 'Check In', fieldname: 'check_in', reqd: 1} ], - primary_action_label: __("Transfer"), - primary_action : function(){ - var service_unit = null; - var check_in = dialog.get_value('check_in'); - var leave_from = null; + primary_action_label: __('Transfer'), + primary_action : function() { + let service_unit = null; + let check_in = dialog.get_value('check_in'); + let leave_from = null; if(dialog.get_value('leave_from')){ leave_from = dialog.get_value('leave_from'); } @@ -159,47 +159,47 @@ var transfer_patient_dialog = function(frm){ 'leave_from': leave_from }, callback: function(data) { - if(!data.exc){ + if (!data.exc) { frm.reload_doc(); } }, freeze: true, - freeze_message: "Process Transfer" + freeze_message: __('Process Transfer') }); frm.refresh_fields(); dialog.hide(); } }); - dialog.fields_dict["leave_from"].get_query = function(){ + dialog.fields_dict['leave_from'].get_query = function(){ return { - query : "erpnext.healthcare.doctype.inpatient_record.inpatient_record.get_leave_from", + query : 'erpnext.healthcare.doctype.inpatient_record.inpatient_record.get_leave_from', filters: {docname:frm.doc.name} }; }; - dialog.fields_dict["service_unit_type"].get_query = function(){ + dialog.fields_dict['service_unit_type'].get_query = function(){ return { filters: { - "inpatient_occupancy": 1, - "allow_appointments": 0 + 'inpatient_occupancy': 1, + 'allow_appointments': 0 } }; }; - dialog.fields_dict["service_unit"].get_query = function(){ + dialog.fields_dict['service_unit'].get_query = function(){ return { filters: { - "is_group": 0, - "service_unit_type": dialog.get_value("service_unit_type"), - "occupancy_status" : "Vacant" + 'is_group': 0, + 'service_unit_type': dialog.get_value('service_unit_type'), + 'occupancy_status' : 'Vacant' } }; }; dialog.show(); - var not_left_service_unit = null; - for(let inpatient_occupancy in frm.doc.inpatient_occupancies){ - if(frm.doc.inpatient_occupancies[inpatient_occupancy].left != 1){ + let not_left_service_unit = null; + for (let inpatient_occupancy in frm.doc.inpatient_occupancies) { + if (frm.doc.inpatient_occupancies[inpatient_occupancy].left != 1) { not_left_service_unit = frm.doc.inpatient_occupancies[inpatient_occupancy].service_unit; } } From 0d3231ebbaeb1edbdfd722ef2200e061a5f15fbd Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 21 May 2020 10:02:31 +0530 Subject: [PATCH 038/449] fix: add title to validation dialog --- .../healthcare/doctype/inpatient_record/inpatient_record.py | 4 ++-- .../healthcare/doctype/patient_encounter/patient_encounter.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py index 802ab414c0..cf63b65f4d 100644 --- a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py +++ b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py @@ -29,7 +29,7 @@ class InpatientRecord(Document): if (getdate(self.expected_discharge) < getdate(self.scheduled_date)) or \ (getdate(self.discharge_ordered_date) < getdate(self.scheduled_date)): frappe.throw(_('Expected and Discharge dates cannot be less than Admission Schedule date')) - + def validate_already_scheduled_or_admitted(self): query = """ select name, status @@ -168,7 +168,7 @@ def validate_invoiced_inpatient(inpatient_record): if pending_invoices: frappe.throw(_("Can not mark Inpatient Record Discharged, there are Unbilled Invoices {0}").format(", " - .join(pending_invoices))) + .join(pending_invoices)), title=_('Unbilled Invoices')) def get_pending_doc(doc, doc_name_list, pending_invoices): if doc_name_list: diff --git a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js index ef1068e6cb..edcee99d4b 100644 --- a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js +++ b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.js @@ -215,7 +215,7 @@ var schedule_inpatient = function(frm) { args: args }, callback: function(data) { - if(!data.exc){ + if (!data.exc) { frm.reload_doc(); } }, From 45de78bf94649e0a18f33b8284f6abb09e41792c Mon Sep 17 00:00:00 2001 From: Marica Date: Thu, 21 May 2020 11:35:00 +0530 Subject: [PATCH 039/449] fix: Employee Advance Return not working (#21812) --- erpnext/hr/doctype/employee_advance/employee_advance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/hr/doctype/employee_advance/employee_advance.py b/erpnext/hr/doctype/employee_advance/employee_advance.py index 23e4992066..db39eff0e4 100644 --- a/erpnext/hr/doctype/employee_advance/employee_advance.py +++ b/erpnext/hr/doctype/employee_advance/employee_advance.py @@ -146,7 +146,7 @@ def create_return_through_additional_salary(doc): return additional_salary @frappe.whitelist() -def make_return_entry(employee_name, company, employee_advance_name, return_amount, mode_of_payment, advance_account): +def make_return_entry(employee, company, employee_advance_name, return_amount, advance_account, mode_of_payment=None): return_account = get_default_bank_cash_account(company, account_type='Cash', mode_of_payment = mode_of_payment) mode_of_payment_type = '' From 8e9f3e464582553579a7a9a4bb660959100891bb Mon Sep 17 00:00:00 2001 From: Marica Date: Thu, 21 May 2020 12:07:43 +0530 Subject: [PATCH 040/449] fix: plc conversion rate set infinitely (#21820) --- erpnext/manufacturing/doctype/bom/bom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js index 44da9cae35..898955e51b 100644 --- a/erpnext/manufacturing/doctype/bom/bom.js +++ b/erpnext/manufacturing/doctype/bom/bom.js @@ -265,7 +265,7 @@ erpnext.bom.BomController = erpnext.TransactionController.extend({ plc_conversion_rate: function(doc) { if (!this.in_apply_price_list) { - this.apply_price_list(); + this.apply_price_list(null, true); } }, From 0f27be2facc07e5608999e31d5be7646faa29a11 Mon Sep 17 00:00:00 2001 From: marination Date: Thu, 21 May 2020 13:11:48 +0530 Subject: [PATCH 041/449] fix: Fetch customer into Delivery Note from Pick List --- erpnext/stock/doctype/pick_list/pick_list.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index 231af1a022..1f8d009f92 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -300,6 +300,7 @@ def create_delivery_note(source_name, target_doc=None): set_delivery_note_missing_values(delivery_note) delivery_note.pick_list = pick_list.name + delivery_note.customer = pick_list.customer if pick_list.customer else None return delivery_note From 64301c8adb1f17c3dbbdf7c0b669634550c5e5a1 Mon Sep 17 00:00:00 2001 From: marination Date: Thu, 21 May 2020 14:03:29 +0530 Subject: [PATCH 042/449] fix: Supplier Invoice No not fetched in Import Supplier Invoice --- .../import_supplier_invoice/import_supplier_invoice.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/regional/doctype/import_supplier_invoice/import_supplier_invoice.py b/erpnext/regional/doctype/import_supplier_invoice/import_supplier_invoice.py index 6784ea8a5b..6b9567c0e5 100644 --- a/erpnext/regional/doctype/import_supplier_invoice/import_supplier_invoice.py +++ b/erpnext/regional/doctype/import_supplier_invoice/import_supplier_invoice.py @@ -58,7 +58,7 @@ class ImportSupplierInvoice(Document): "naming_series": self.invoice_series, "document_type": line.TipoDocumento.text, "bill_date": get_datetime_str(line.Data.text), - "invoice_no": line.Numero.text, + "bill_no": line.Numero.text, "total_discount": 0, "items": [], "buying_price_list": self.default_buying_price_list @@ -249,7 +249,7 @@ def create_supplier(supplier_group, args): return existing_supplier_name else: - + new_supplier = frappe.new_doc("Supplier") new_supplier.supplier_name = re.sub('&', '&', args.supplier) new_supplier.supplier_group = supplier_group From ed26db899a9e6664f3a485880e7a610a96c3b788 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Thu, 21 May 2020 18:10:13 +0530 Subject: [PATCH 043/449] feat: BOM template (#21262) Co-authored-by: Marica --- erpnext/controllers/queries.py | 9 +- erpnext/manufacturing/doctype/bom/bom.js | 189 +++++- erpnext/manufacturing/doctype/bom/bom.json | 14 +- erpnext/manufacturing/doctype/bom/bom.py | 215 ++++-- erpnext/manufacturing/doctype/bom/bom_list.js | 6 +- .../doctype/bom_item/bom_item.json | 17 +- .../doctype/work_order/work_order.js | 26 + .../doctype/work_order/work_order.py | 50 +- .../work_order_item/work_order_item.json | 632 ++++-------------- erpnext/stock/doctype/item/item.py | 11 + 10 files changed, 546 insertions(+), 623 deletions(-) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index d9465917ec..9bba71d0dd 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -188,12 +188,6 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals # scan description only if items are less than 50000 description_cond = 'or tabItem.description LIKE %(txt)s' - extra_cond = " and tabItem.has_variants=0" - if (filters and isinstance(filters, dict) - and filters.get("doctype") == "BOM"): - extra_cond = "" - del filters["doctype"] - return frappe.db.sql("""select tabItem.name, if(length(tabItem.item_name) > 40, concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name, @@ -204,10 +198,10 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals from tabItem where tabItem.docstatus < 2 and tabItem.disabled=0 + and tabItem.has_variants=0 and (tabItem.end_of_life > %(today)s or ifnull(tabItem.end_of_life, '0000-00-00')='0000-00-00') and ({scond} or tabItem.item_code IN (select parent from `tabItem Barcode` where barcode LIKE %(txt)s) {description_cond}) - {extra_cond} {fcond} {mcond} order by if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999), @@ -218,7 +212,6 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals key=searchfield, columns=columns, scond=searchfields, - extra_cond=extra_cond, fcond=get_filters_cond(doctype, filters, conditions).replace('%', '%%'), mcond=get_match_cond(doctype).replace('%', '%%'), description_cond = description_cond), diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js index 898955e51b..47b4207241 100644 --- a/erpnext/manufacturing/doctype/bom/bom.js +++ b/erpnext/manufacturing/doctype/bom/bom.js @@ -29,10 +29,7 @@ frappe.ui.form.on("BOM", { frm.set_query("item", function() { return { - query: "erpnext.controllers.queries.item_query", - filters: { - "doctype": "BOM" - } + query: "erpnext.manufacturing.doctype.bom.bom.item_query" }; }); @@ -44,9 +41,12 @@ frappe.ui.form.on("BOM", { }; }); - frm.set_query("item_code", "items", function() { + frm.set_query("item_code", "items", function(doc) { return { - query: "erpnext.controllers.queries.item_query" + query: "erpnext.manufacturing.doctype.bom.bom.item_query", + filters: { + "item_code": doc.item + } }; }); @@ -96,6 +96,12 @@ frappe.ui.form.on("BOM", { frm.trigger("make_work_order"); }, __("Create")); + if (frm.doc.has_variants) { + frm.add_custom_button(__("Variant BOM"), function() { + frm.trigger("make_variant_bom"); + }, __("Create")); + } + if (frm.doc.inspection_required) { frm.add_custom_button(__("Quality Inspection"), function() { frm.trigger("make_quality_inspection"); @@ -124,7 +130,7 @@ frappe.ui.form.on("BOM", { } - if (frm.doc.__onload && frm.doc.__onload["has_variants"]) { + if (frm.doc.has_variants) { frm.set_intro(__('This is a Template BOM and will be used to make the work order for {0} of the item {1}', [ `variants`, @@ -138,9 +144,52 @@ frappe.ui.form.on("BOM", { }, make_work_order: function(frm) { + frm.events.setup_variant_prompt(frm, "Work Order", (frm, item, data, variant_items) => { + frappe.call({ + method: "erpnext.manufacturing.doctype.work_order.work_order.make_work_order", + args: { + bom_no: frm.doc.name, + item: item, + qty: data.qty || 0.0, + project: frm.doc.project, + variant_items: variant_items + }, + freeze: true, + callback: function(r) { + if(r.message) { + let doc = frappe.model.sync(r.message)[0]; + frappe.set_route("Form", doc.doctype, doc.name); + } + } + }); + }); + }, + + make_variant_bom: function(frm) { + frm.events.setup_variant_prompt(frm, "Variant BOM", (frm, item, data, variant_items) => { + frappe.call({ + method: "erpnext.manufacturing.doctype.bom.bom.make_variant_bom", + args: { + source_name: frm.doc.name, + bom_no: frm.doc.name, + item: item, + variant_items: variant_items + }, + freeze: true, + callback: function(r) { + if(r.message) { + let doc = frappe.model.sync(r.message)[0]; + frappe.set_route("Form", doc.doctype, doc.name); + } + } + }); + }, true); + }, + + setup_variant_prompt: function(frm, title, callback, skip_qty_field) { const fields = []; - if (frm.doc.__onload && frm.doc.__onload["has_variants"]) { + if (frm.doc.has_variants) { fields.push({ fieldtype: 'Link', label: __('Variant Item'), @@ -158,34 +207,106 @@ frappe.ui.form.on("BOM", { }); } - fields.push({ - fieldtype: 'Float', - label: __('Qty To Manufacture'), - fieldname: 'qty', - reqd: 1, - default: 1 + if (!skip_qty_field) { + fields.push({ + fieldtype: 'Float', + label: __('Qty To Manufacture'), + fieldname: 'qty', + reqd: 1, + default: 1 + }); + } + + var has_template_rm = frm.doc.items.filter(d => d.has_variants === 1) || []; + if (has_template_rm && has_template_rm.length > 0) { + fields.push({ + fieldname: "items", + fieldtype: "Table", + label: __("Raw Materials"), + fields: [ + { + fieldname: "item_code", + options: "Item", + label: __("Template Item"), + fieldtype: "Link", + in_list_view: 1, + reqd: 1, + }, + { + fieldname: "varint_item_code", + options: "Item", + label: __("Variant Item"), + fieldtype: "Link", + in_list_view: 1, + reqd: 1, + get_query: function(data) { + if (!data.item_code) { + frappe.throw(__("Select template item")); + } + + return { + query: "erpnext.controllers.queries.item_query", + filters: { + "variant_of": data.item_code + } + }; + } + }, + { + fieldname: "qty", + label: __("Quantity"), + fieldtype: "Float", + in_list_view: 1, + reqd: 1, + }, + { + fieldname: "source_warehouse", + label: __("Source Warehouse"), + fieldtype: "Link", + options: "Warehouse" + }, + { + fieldname: "operation", + label: __("Operation"), + fieldtype: "Data", + hidden: 1, + } + ], + in_place_edit: true, + data: [], + get_data: function () { + return []; + }, + }); + } + + let dialog = frappe.prompt(fields, data => { + let item = data.item || frm.doc.item; + let variant_items = data.items || []; + + variant_items.forEach(d => { + if (!d.varint_item_code) { + frappe.throw(__("Select variant item code for the template item {0}", [d.item_code])); + } + }) + + callback(frm, item, data, variant_items); + + }, __(title), __("Create")); + + has_template_rm.forEach(d => { + dialog.fields_dict.items.df.data.push({ + "item_code": d.item_code, + "varint_item_code": "", + "qty": d.qty, + "source_warehouse": d.source_warehouse, + "operation": d.operation + }); }); - frappe.prompt(fields, data => { - let item = data.item || frm.doc.item; - - frappe.call({ - method: "erpnext.manufacturing.doctype.work_order.work_order.make_work_order", - args: { - bom_no: frm.doc.name, - item: item, - qty: data.qty || 0.0, - project: frm.doc.project - }, - freeze: true, - callback: function(r) { - if(r.message) { - var doc = frappe.model.sync(r.message)[0]; - frappe.set_route("Form", doc.doctype, doc.name); - } - } - }); - }, __("Enter Value"), __("Create")); + if (has_template_rm) { + dialog.fields_dict.items.grid.refresh(); + } }, make_quality_inspection: function(frm) { diff --git a/erpnext/manufacturing/doctype/bom/bom.json b/erpnext/manufacturing/doctype/bom/bom.json index 4ce0ecf3f2..f551b91597 100644 --- a/erpnext/manufacturing/doctype/bom/bom.json +++ b/erpnext/manufacturing/doctype/bom/bom.json @@ -53,6 +53,7 @@ "section_break_25", "description", "column_break_27", + "has_variants", "section_break0", "exploded_items", "website_section", @@ -498,6 +499,17 @@ "options": "Currency", "print_hide": 1, "read_only": 1 + }, + { + "default": "0", + "fetch_from": "item.has_variants", + "fieldname": "has_variants", + "fieldtype": "Check", + "in_list_view": 1, + "label": "Has Variants", + "no_copy": 1, + "print_hide": 1, + "read_only": 1 } ], "icon": "fa fa-sitemap", @@ -505,7 +517,7 @@ "image_field": "image", "is_submittable": 1, "links": [], - "modified": "2020-05-05 14:29:32.634952", + "modified": "2020-05-21 12:29:32.634952", "modified_by": "Administrator", "module": "Manufacturing", "name": "BOM", diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 6ac653e37a..1bdac5731e 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -3,13 +3,16 @@ from __future__ import unicode_literals import frappe, erpnext -from frappe.utils import cint, cstr, flt +from frappe.utils import cint, cstr, flt, today from frappe import _ from erpnext.setup.utils import get_exchange_rate from frappe.website.website_generator import WebsiteGenerator from erpnext.stock.get_item_details import get_conversion_factor from erpnext.stock.get_item_details import get_price_list_rate from frappe.core.doctype.version.version import get_diff +from erpnext.controllers.queries import get_match_cond +from erpnext.stock.doctype.item.item import get_item_details +from frappe.model.mapper import get_mapped_doc import functools @@ -59,11 +62,6 @@ class BOM(WebsiteGenerator): self.name = name - def onload(self): - super(BOM, self).onload() - if self.get("item") and cint(frappe.db.get_value("Item", self.item, "has_variants")): - self.set_onload("has_variants", True) - def validate(self): self.route = frappe.scrub(self.name).replace('_', '-') self.clear_operations() @@ -103,9 +101,7 @@ class BOM(WebsiteGenerator): self.manage_default_bom() def get_item_det(self, item_code): - item = frappe.db.sql("""select name, item_name, docstatus, description, image, - is_sub_contracted_item, stock_uom, default_bom, last_purchase_rate, include_item_in_manufacturing - from `tabItem` where name=%s""", item_code, as_dict = 1) + item = get_item_details(item_code) if not item: frappe.throw(_("Item: {0} does not exist in the system").format(item_code)) @@ -150,10 +146,10 @@ class BOM(WebsiteGenerator): item = self.get_item_det(args['item_code']) - args['bom_no'] = args['bom_no'] or item and cstr(item[0]['default_bom']) or '' + args['bom_no'] = args['bom_no'] or item and cstr(item['default_bom']) or '' args['transfer_for_manufacture'] = (cstr(args.get('include_item_in_manufacturing', '')) or - item and item[0].include_item_in_manufacturing or 0) - args.update(item[0]) + item and item.include_item_in_manufacturing or 0) + args.update(item) rate = self.get_rm_rate(args) ret_item = { @@ -185,40 +181,14 @@ class BOM(WebsiteGenerator): self.rm_cost_as_per = "Valuation Rate" if arg.get('scrap_items'): - rate = self.get_valuation_rate(arg) + rate = get_valuation_rate(arg) elif arg: #Customer Provided parts will have zero rate if not frappe.db.get_value('Item', arg["item_code"], 'is_customer_provided_item'): if arg.get('bom_no') and self.set_rate_of_sub_assembly_item_based_on_bom: rate = flt(self.get_bom_unitcost(arg['bom_no'])) * (arg.get("conversion_factor") or 1) else: - if self.rm_cost_as_per == 'Valuation Rate': - rate = self.get_valuation_rate(arg) * (arg.get("conversion_factor") or 1) - elif self.rm_cost_as_per == 'Last Purchase Rate': - rate = flt(arg.get('last_purchase_rate') \ - or frappe.db.get_value("Item", arg['item_code'], "last_purchase_rate")) \ - * (arg.get("conversion_factor") or 1) - elif self.rm_cost_as_per == "Price List": - if not self.buying_price_list: - frappe.throw(_("Please select Price List")) - args = frappe._dict({ - "doctype": "BOM", - "price_list": self.buying_price_list, - "qty": arg.get("qty") or 1, - "uom": arg.get("uom") or arg.get("stock_uom"), - "stock_uom": arg.get("stock_uom"), - "transaction_type": "buying", - "company": self.company, - "currency": self.currency, - "conversion_rate": 1, # Passed conversion rate as 1 purposefully, as conversion rate is applied at the end of the function - "conversion_factor": arg.get("conversion_factor") or 1, - "plc_conversion_rate": 1, - "ignore_party": True - }) - item_doc = frappe.get_doc("Item", arg.get("item_code")) - out = frappe._dict() - get_price_list_rate(args, item_doc, out) - rate = out.price_list_rate + rate = get_bom_item_rate(arg, self) if not rate: if self.rm_cost_as_per == "Price List": @@ -286,31 +256,6 @@ class BOM(WebsiteGenerator): where is_active = 1 and name = %s""", bom_no, as_dict=1) return bom and bom[0]['unit_cost'] or 0 - def get_valuation_rate(self, args): - """ Get weighted average of valuation rate from all warehouses """ - - total_qty, total_value, valuation_rate = 0.0, 0.0, 0.0 - for d in frappe.db.sql("""select actual_qty, stock_value from `tabBin` - where item_code=%s""", args['item_code'], as_dict=1): - total_qty += flt(d.actual_qty) - total_value += flt(d.stock_value) - - if total_qty: - valuation_rate = total_value / total_qty - - if valuation_rate <= 0: - last_valuation_rate = frappe.db.sql("""select valuation_rate - from `tabStock Ledger Entry` - where item_code = %s and valuation_rate > 0 - order by posting_date desc, posting_time desc, creation desc limit 1""", args['item_code']) - - valuation_rate = flt(last_valuation_rate[0][0]) if last_valuation_rate else 0 - - if not valuation_rate: - valuation_rate = frappe.db.get_value("Item", args['item_code'], "valuation_rate") - - return flt(valuation_rate) - def manage_default_bom(self): """ Uncheck others if current one is selected as default or check the current one as default if it the only bom for the selected item, @@ -624,6 +569,62 @@ class BOM(WebsiteGenerator): if not d.batch_size or d.batch_size <= 0: d.batch_size = 1 +def get_bom_item_rate(args, bom_doc): + if bom_doc.rm_cost_as_per == 'Valuation Rate': + rate = get_valuation_rate(args) * (args.get("conversion_factor") or 1) + elif bom_doc.rm_cost_as_per == 'Last Purchase Rate': + rate = ( flt(args.get('last_purchase_rate')) \ + or frappe.db.get_value("Item", args['item_code'], "last_purchase_rate")) \ + * (args.get("conversion_factor") or 1) + elif bom_doc.rm_cost_as_per == "Price List": + if not bom_doc.buying_price_list: + frappe.throw(_("Please select Price List")) + bom_args = frappe._dict({ + "doctype": "BOM", + "price_list": bom_doc.buying_price_list, + "qty": args.get("qty") or 1, + "uom": args.get("uom") or args.get("stock_uom"), + "stock_uom": args.get("stock_uom"), + "transaction_type": "buying", + "company": bom_doc.company, + "currency": bom_doc.currency, + "conversion_rate": 1, # Passed conversion rate as 1 purposefully, as conversion rate is applied at the end of the function + "conversion_factor": args.get("conversion_factor") or 1, + "plc_conversion_rate": 1, + "ignore_party": True + }) + item_doc = frappe.get_cached_doc("Item", args.get("item_code")) + out = frappe._dict() + get_price_list_rate(bom_args, item_doc, out) + rate = out.price_list_rate + + return rate + +def get_valuation_rate(args): + """ Get weighted average of valuation rate from all warehouses """ + + total_qty, total_value, valuation_rate = 0.0, 0.0, 0.0 + for d in frappe.db.sql("""select actual_qty, stock_value from `tabBin` + where item_code=%s""", args['item_code'], as_dict=1): + total_qty += flt(d.actual_qty) + total_value += flt(d.stock_value) + + if total_qty: + valuation_rate = total_value / total_qty + + if valuation_rate <= 0: + last_valuation_rate = frappe.db.sql("""select valuation_rate + from `tabStock Ledger Entry` + where item_code = %s and valuation_rate > 0 + order by posting_date desc, posting_time desc, creation desc limit 1""", args['item_code']) + + valuation_rate = flt(last_valuation_rate[0][0]) if last_valuation_rate else 0 + + if not valuation_rate: + valuation_rate = frappe.db.get_value("Item", args['item_code'], "valuation_rate") + + return flt(valuation_rate) + def get_list_context(context): context.title = _("Bill of Materials") # context.introduction = _('Boms') @@ -639,6 +640,8 @@ def get_bom_items_as_dict(bom, company, qty=1, fetch_exploded=1, fetch_scrap_ite sum(bom_item.{qty_field}/ifnull(bom.quantity, 1)) * %(qty)s as qty, item.image, bom.project, + bom_item.rate, + bom_item.amount, item.stock_uom, item.item_group, item.allow_alternative_item, @@ -655,6 +658,7 @@ def get_bom_items_as_dict(bom, company, qty=1, fetch_exploded=1, fetch_scrap_ite where bom_item.docstatus < 2 and bom.name = %(bom)s + and ifnull(item.has_variants, 0) = 0 and item.is_stock_item in (1, {is_stock_item}) {where_conditions} group by item_code, stock_uom @@ -897,3 +901,84 @@ def get_bom_diff(bom1, bom2): out.removed.append([df.fieldname, d.as_dict()]) return out + +def item_query(doctype, txt, searchfield, start, page_len, filters): + meta = frappe.get_meta("Item", cached=True) + searchfields = meta.get_search_fields() + + order_by = "idx desc, name, item_name" + + fields = ["name", "item_group", "item_name", "description"] + fields.extend([field for field in searchfields + if not field in ["name", "item_group", "description"]]) + + searchfields = searchfields + [field for field in [searchfield or "name", "item_code", "item_group", "item_name"] + if not field in searchfields] + + query_filters = { + "disabled": 0, + "ifnull(end_of_life, '5050-50-50')": (">", today()) + } + + or_cond_filters = {} + if txt: + for s_field in searchfields: + or_cond_filters[s_field] = ("like", "%{0}%".format(txt)) + + barcodes = frappe.get_all("Item Barcode", + fields=["distinct parent as item_code"], + filters = {"barcode": ("like", "%{0}%".format(txt))}) + + barcodes = [d.item_code for d in barcodes] + if barcodes: + or_cond_filters["name"] = ("in", barcodes) + + for cond in get_match_cond(doctype, as_condition=False): + for key, value in cond.items(): + if key == doctype: + key = "name" + + query_filters[key] = ("in", value) + + if filters and filters.get("item_code"): + has_variants = frappe.get_cached_value("Item", filters.get("item_code"), "has_variants") + if not has_variants: + query_filters["has_variants"] = 0 + + return frappe.get_all("Item", + fields = fields, filters=query_filters, + or_filters = or_cond_filters, order_by=order_by, + limit_start=start, limit_page_length=page_len, as_list=1) + +@frappe.whitelist() +def make_variant_bom(source_name, bom_no, item, variant_items, target_doc=None): + from erpnext.manufacturing.doctype.work_order.work_order import add_variant_item + + def postprocess(source, doc): + doc.item = item + doc.quantity = 1 + + item_data = get_item_details(item) + doc.update({ + "item_name": item_data.item_name, + "description": item_data.description, + "uom": item_data.stock_uom, + "allow_alternative_item": item_data.allow_alternative_item + }) + + add_variant_item(variant_items, doc, source_name) + + doc = get_mapped_doc('BOM', source_name, { + 'BOM': { + 'doctype': 'BOM', + 'validation': { + 'docstatus': ['=', 1] + } + }, + 'BOM Item': { + 'doctype': 'BOM Item', + 'condition': lambda doc: doc.has_variants == 0 + }, + }, target_doc, postprocess) + + return doc \ No newline at end of file diff --git a/erpnext/manufacturing/doctype/bom/bom_list.js b/erpnext/manufacturing/doctype/bom/bom_list.js index 2b06ed72ed..94cb466bd8 100644 --- a/erpnext/manufacturing/doctype/bom/bom_list.js +++ b/erpnext/manufacturing/doctype/bom/bom_list.js @@ -1,7 +1,9 @@ frappe.listview_settings['BOM'] = { - add_fields: ["is_active", "is_default", "total_cost"], + add_fields: ["is_active", "is_default", "total_cost", "has_variants"], get_indicator: function(doc) { - if(doc.is_default) { + if(doc.is_active && doc.has_variants) { + return [__("Template"), "orange", "has_variants,=,Yes"]; + } else if(doc.is_default) { return [__("Default"), "green", "is_default,=,Yes"]; } else if(doc.is_active) { return [__("Active"), "blue", "is_active,=,Yes"]; diff --git a/erpnext/manufacturing/doctype/bom_item/bom_item.json b/erpnext/manufacturing/doctype/bom_item/bom_item.json index f094be4c64..e34be61bc7 100644 --- a/erpnext/manufacturing/doctype/bom_item/bom_item.json +++ b/erpnext/manufacturing/doctype/bom_item/bom_item.json @@ -1,8 +1,10 @@ { + "actions": [], "creation": "2013-02-22 01:27:49", "doctype": "DocType", "document_type": "Setup", "editable_grid": 1, + "engine": "InnoDB", "field_order": [ "item_code", "item_name", @@ -33,6 +35,7 @@ "scrap", "qty_consumed_per_unit", "section_break_27", + "has_variants", "include_item_in_manufacturing", "original_item" ], @@ -57,6 +60,7 @@ "label": "Item Name" }, { + "depends_on": "eval:parent.with_operations == 1", "fieldname": "operation", "fieldtype": "Link", "label": "Item operation", @@ -258,11 +262,22 @@ "label": "Original Item", "options": "Item", "read_only": 1 + }, + { + "default": "0", + "fetch_from": "item_code.has_variants", + "fieldname": "has_variants", + "fieldtype": "Check", + "label": "Has Variants", + "no_copy": 1, + "print_hide": 1, + "read_only": 1 } ], "idx": 1, "istable": 1, - "modified": "2019-11-22 11:38:52.087303", + "links": [], + "modified": "2020-04-09 14:30:26.535546", "modified_by": "Administrator", "module": "Manufacturing", "name": "BOM Item", diff --git a/erpnext/manufacturing/doctype/work_order/work_order.js b/erpnext/manufacturing/doctype/work_order/work_order.js index c125571960..a244f582c4 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.js +++ b/erpnext/manufacturing/doctype/work_order/work_order.js @@ -449,6 +449,32 @@ frappe.ui.form.on("Work Order Item", { } }); } + }, + + item_code: function(frm, cdt, cdn) { + let row = locals[cdt][cdn]; + + if (row.item_code) { + frappe.call({ + method: "erpnext.stock.doctype.item.item.get_item_details", + args: { + item_code: row.item_code, + company: frm.doc.company + }, + callback: function(r) { + if (r.message) { + frappe.model.set_value(cdt, cdn, { + "required_qty": 1, + "item_name": r.message.item_name, + "description": r.message.description, + "source_warehouse": r.message.default_warehouse, + "allow_alternative_item": r.message.allow_alternative_item, + "include_item_in_manufacturing": r.message.include_item_in_manufacturing + }); + } + } + }); + } } }); diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index c2789559b0..e2233a3e2f 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -8,9 +8,9 @@ import math from frappe import _ from frappe.utils import flt, get_datetime, getdate, date_diff, cint, nowdate, get_link_to_form, time_diff_in_hours from frappe.model.document import Document -from erpnext.manufacturing.doctype.bom.bom import validate_bom_no, get_bom_items_as_dict +from erpnext.manufacturing.doctype.bom.bom import validate_bom_no, get_bom_items_as_dict, get_bom_item_rate from dateutil.relativedelta import relativedelta -from erpnext.stock.doctype.item.item import validate_end_of_life +from erpnext.stock.doctype.item.item import validate_end_of_life, get_item_defaults from erpnext.manufacturing.doctype.workstation.workstation import WorkstationHolidayError from erpnext.projects.doctype.timesheet.timesheet import OverlapError from erpnext.manufacturing.doctype.manufacturing_settings.manufacturing_settings import get_mins_between_operations @@ -541,6 +541,8 @@ class WorkOrder(Document): # For instance in BOM Explosion Item child table, the items coming from sub assembly items for item in sorted(item_dict.values(), key=lambda d: d['idx'] or 9999): self.append('required_items', { + 'rate': item.rate, + 'amount': item.amount, 'operation': item.operation, 'item_code': item.item_code, 'item_name': item.item_name, @@ -637,9 +639,10 @@ def get_bom_operations(doctype, txt, searchfield, start, page_len, filters): filters = filters, fields = ['operation'], as_list=1) @frappe.whitelist() -def get_item_details(item, project = None): +def get_item_details(item, project = None, skip_bom_info=False): res = frappe.db.sql(""" - select stock_uom, description + select stock_uom, description, item_name, allow_alternative_item, + include_item_in_manufacturing from `tabItem` where disabled=0 and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %s) @@ -650,6 +653,7 @@ def get_item_details(item, project = None): return {} res = res[0] + if skip_bom_info: return res filters = {"item": item, "is_default": 1} @@ -681,7 +685,7 @@ def get_item_details(item, project = None): return res @frappe.whitelist() -def make_work_order(bom_no, item, qty=0, project=None): +def make_work_order(bom_no, item, qty=0, project=None, variant_items=None): if not frappe.has_permission("Work Order", "write"): frappe.throw(_("Not permitted"), frappe.PermissionError) @@ -696,8 +700,44 @@ def make_work_order(bom_no, item, qty=0, project=None): wo_doc.qty = flt(qty) wo_doc.get_items_and_operations_from_bom() + if variant_items: + add_variant_item(variant_items, wo_doc, bom_no, "required_items") + return wo_doc +def add_variant_item(variant_items, wo_doc, bom_no, table_name="items"): + if isinstance(variant_items, string_types): + variant_items = json.loads(variant_items) + + for item in variant_items: + args = frappe._dict({ + "item_code": item.get("varint_item_code"), + "required_qty": item.get("qty"), + "qty": item.get("qty"), # for bom + "source_warehouse": item.get("source_warehouse"), + "operation": item.get("operation") + }) + + bom_doc = frappe.get_cached_doc("BOM", bom_no) + item_data = get_item_details(args.item_code, skip_bom_info=True) + args.update(item_data) + + args["rate"] = get_bom_item_rate({ + "item_code": args.get("item_code"), + "qty": args.get("required_qty"), + "uom": args.get("stock_uom"), + "stock_uom": args.get("stock_uom"), + "conversion_factor": 1 + }, bom_doc) + + if not args.source_warehouse: + args["source_warehouse"] = get_item_defaults(item.get("varint_item_code"), + wo_doc.company).default_warehouse + + args["amount"] = flt(args.get("required_qty")) * flt(args.get("rate")) + args["uom"] = item_data.stock_uom + wo_doc.append(table_name, args) + @frappe.whitelist() def check_if_scrap_warehouse_mandatory(bom_no): res = {"set_scrap_wh_mandatory": False } diff --git a/erpnext/manufacturing/doctype/work_order_item/work_order_item.json b/erpnext/manufacturing/doctype/work_order_item/work_order_item.json index 4442162636..3acf5727d1 100644 --- a/erpnext/manufacturing/doctype/work_order_item/work_order_item.json +++ b/erpnext/manufacturing/doctype/work_order_item/work_order_item.json @@ -1,526 +1,144 @@ { - "allow_copy": 0, - "allow_events_in_timeline": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "beta": 0, - "creation": "2016-04-18 07:38:26.314642", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "", - "editable_grid": 1, - "engine": "InnoDB", + "actions": [], + "creation": "2016-04-18 07:38:26.314642", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "operation", + "item_code", + "source_warehouse", + "column_break_3", + "item_name", + "description", + "allow_alternative_item", + "include_item_in_manufacturing", + "qty_section", + "required_qty", + "rate", + "amount", + "column_break_11", + "transferred_qty", + "consumed_qty", + "available_qty_at_source_warehouse", + "available_qty_at_wip_warehouse" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "operation", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Operation", - "length": 0, - "no_copy": 0, - "options": "Operation", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "operation", + "fieldtype": "Link", + "label": "Operation", + "options": "Operation" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "item_code", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Item Code", - "length": 0, - "no_copy": 0, - "options": "Item", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "item_code", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Item Code", + "options": "Item" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "source_warehouse", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 1, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Source Warehouse", - "length": 0, - "no_copy": 0, - "options": "Warehouse", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "source_warehouse", + "fieldtype": "Link", + "ignore_user_permissions": 1, + "in_list_view": 1, + "label": "Source Warehouse", + "options": "Warehouse" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "column_break_3", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "item_name", - "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Item Name", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "item_name", + "fieldtype": "Data", + "label": "Item Name", + "read_only": 1 + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "description", - "fieldtype": "Text", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Description", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "description", + "fieldtype": "Text", + "label": "Description", + "read_only": 1 + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "qty_section", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Qty", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "qty_section", + "fieldtype": "Section Break", + "label": "Qty" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "required_qty", - "fieldtype": "Float", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Required Qty", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "required_qty", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Required Qty" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "depends_on": "eval:!parent.skip_transfer", - "fieldname": "transferred_qty", - "fieldtype": "Float", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Transferred Qty", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "depends_on": "eval:!parent.skip_transfer", + "fieldname": "transferred_qty", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Transferred Qty", + "read_only": 1 + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "allow_alternative_item", - "fieldtype": "Check", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Allow Alternative Item", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "default": "0", + "fieldname": "allow_alternative_item", + "fieldtype": "Check", + "label": "Allow Alternative Item" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "include_item_in_manufacturing", - "fieldtype": "Check", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Include Item In Manufacturing", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "default": "0", + "fieldname": "include_item_in_manufacturing", + "fieldtype": "Check", + "label": "Include Item In Manufacturing" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "column_break_11", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "column_break_11", + "fieldtype": "Column Break" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "depends_on": "eval:!parent.skip_transfer", - "fieldname": "consumed_qty", - "fieldtype": "Float", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Consumed Qty", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "depends_on": "eval:!parent.skip_transfer", + "fieldname": "consumed_qty", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Consumed Qty", + "read_only": 1 + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "available_qty_at_source_warehouse", - "fieldtype": "Float", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Available Qty at Source Warehouse", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "available_qty_at_source_warehouse", + "fieldtype": "Float", + "label": "Available Qty at Source Warehouse", + "read_only": 1 + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "available_qty_at_wip_warehouse", - "fieldtype": "Float", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Available Qty at WIP Warehouse", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldname": "available_qty_at_wip_warehouse", + "fieldtype": "Float", + "label": "Available Qty at WIP Warehouse", + "read_only": 1 + }, + { + "fieldname": "rate", + "fieldtype": "Currency", + "label": "Rate", + "read_only": 1 + }, + { + "fieldname": "amount", + "fieldtype": "Currency", + "label": "Amount", + "read_only": 1 } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 1, - "max_attachments": 0, - "modified": "2018-11-20 19:04:38.508839", - "modified_by": "Administrator", - "module": "Manufacturing", - "name": "Work Order Item", - "name_case": "", - "owner": "Administrator", - "permissions": [], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0, - "track_views": 0 + ], + "istable": 1, + "links": [], + "modified": "2020-04-13 18:46:32.966416", + "modified_by": "Administrator", + "module": "Manufacturing", + "name": "Work Order Item", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index 7a1c1279ea..3436a5d013 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -1143,6 +1143,17 @@ def set_item_default(item_code, company, fieldname, value): d.db_insert() item.clear_cache() +@frappe.whitelist() +def get_item_details(item_code, company=None): + out = frappe._dict() + if company: + out = get_item_defaults(item_code, company) or frappe._dict() + + doc = frappe.get_cached_doc("Item", item_code) + out.update(doc.as_dict()) + + return out + @frappe.whitelist() def get_uom_conv_factor(uom, stock_uom): uoms = [uom, stock_uom] From 9b8b712083d890bc98a8719cd04575a36dddb9d8 Mon Sep 17 00:00:00 2001 From: Prssanna Desai Date: Thu, 21 May 2020 18:35:03 +0530 Subject: [PATCH 044/449] fix: hide delete company transacations button if not system manager (#21839) --- erpnext/setup/doctype/company/company.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/setup/doctype/company/company.js b/erpnext/setup/doctype/company/company.js index 0fbe49eab7..875904fe6f 100644 --- a/erpnext/setup/doctype/company/company.js +++ b/erpnext/setup/doctype/company/company.js @@ -107,6 +107,9 @@ frappe.ui.form.on("Company", { erpnext.company.set_chart_of_accounts_options(frm.doc); + if (!frappe.user.has_role('System Manager')) { + frm.get_field("delete_company_transactions").hide(); + } }, make_default_tax_template: function(frm) { @@ -134,7 +137,7 @@ frappe.ui.form.on("Company", { var d = frappe.prompt({ fieldtype:"Data", fieldname: "company_name", - label: __("Please re-type company name to confirm"), + label: __("Please enter the company name to confirm"), reqd: 1, description: __("Please make sure you really want to delete all the transactions for this company. Your master data will remain as it is. This action cannot be undone.") }, From 8f756d3a74bcd357fda9d81f6edfb24fd0ebe52f Mon Sep 17 00:00:00 2001 From: sahil28297 <37302950+sahil28297@users.noreply.github.com> Date: Thu, 21 May 2020 18:42:10 +0530 Subject: [PATCH 045/449] fix(set_serial_no_status): auto commit on many writes (#21845) --- erpnext/patches/v12_0/set_serial_no_status.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/erpnext/patches/v12_0/set_serial_no_status.py b/erpnext/patches/v12_0/set_serial_no_status.py index 4ec84ef0f9..abba37d48e 100644 --- a/erpnext/patches/v12_0/set_serial_no_status.py +++ b/erpnext/patches/v12_0/set_serial_no_status.py @@ -5,8 +5,12 @@ from frappe.utils import getdate, nowdate def execute(): frappe.reload_doc('stock', 'doctype', 'serial_no') - for serial_no in frappe.db.sql("""select name, delivery_document_type, warranty_expiry_date from `tabSerial No` - where (status is NULL OR status='')""", as_dict = 1): + serial_no_list = frappe.db.sql("""select name, delivery_document_type, warranty_expiry_date from `tabSerial No` + where (status is NULL OR status='')""", as_dict = 1) + if len(serial_no_list) > 20000: + frappe.db.auto_commit_on_many_writes = True + + for serial_no in serial_no_list: if serial_no.get("delivery_document_type"): status = "Delivered" elif serial_no.get("warranty_expiry_date") and getdate(serial_no.get("warranty_expiry_date")) <= getdate(nowdate()): @@ -14,4 +18,7 @@ def execute(): else: status = "Active" - frappe.db.set_value("Serial No", serial_no.get("name"), "status", status) \ No newline at end of file + frappe.db.set_value("Serial No", serial_no.get("name"), "status", status) + + if frappe.db.auto_commit_on_many_writes: + frappe.db.auto_commit_on_many_writes = False From 1b94fe444fc6c23a29c7b1eabb61e5b1e30b5f85 Mon Sep 17 00:00:00 2001 From: Anurag Mishra <32095923+Anurag810@users.noreply.github.com> Date: Thu, 21 May 2020 18:47:39 +0530 Subject: [PATCH 046/449] fix: convert goals point to flt (#21844) --- .../hr/doctype/appraisal_template/appraisal_template.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/hr/doctype/appraisal_template/appraisal_template.py b/erpnext/hr/doctype/appraisal_template/appraisal_template.py index e5d3c42e1b..d0dfad4be3 100644 --- a/erpnext/hr/doctype/appraisal_template/appraisal_template.py +++ b/erpnext/hr/doctype/appraisal_template/appraisal_template.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import frappe -from frappe.utils import cint +from frappe.utils import cint, flt from frappe import _ from frappe.model.document import Document @@ -11,11 +11,11 @@ from frappe.model.document import Document class AppraisalTemplate(Document): def validate(self): self.check_total_points() - - def check_total_points(self): + + def check_total_points(self): total_points = 0 for d in self.get("goals"): - total_points += int(d.per_weightage or 0) + total_points += flt(d.per_weightage) if cint(total_points) != 100: frappe.throw(_("Sum of points for all goals should be 100. It is {0}").format(total_points)) From 015c1192a7070ff6b0cfbdce5144b748f52fad4f Mon Sep 17 00:00:00 2001 From: Anupam K Date: Fri, 22 May 2020 01:10:55 +0530 Subject: [PATCH 047/449] adding report card in education desk --- erpnext/education/desk_page/education/education.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/erpnext/education/desk_page/education/education.json b/erpnext/education/desk_page/education/education.json index fc2697f0d7..b341ec4b99 100644 --- a/erpnext/education/desk_page/education/education.json +++ b/erpnext/education/desk_page/education/education.json @@ -64,6 +64,11 @@ "hidden": 0, "label": "Assessment Reports", "links": "[\n {\n \"dependencies\": [\n \"Assessment Result\"\n ],\n \"doctype\": \"Assessment Result\",\n \"is_query_report\": true,\n \"label\": \"Course wise Assessment Report\",\n \"name\": \"Course wise Assessment Report\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Assessment Result\"\n ],\n \"doctype\": \"Assessment Result\",\n \"is_query_report\": true,\n \"label\": \"Final Assessment Grades\",\n \"name\": \"Final Assessment Grades\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Assessment Plan\"\n ],\n \"doctype\": \"Assessment Plan\",\n \"is_query_report\": true,\n \"label\": \"Assessment Plan Status\",\n \"name\": \"Assessment Plan Status\",\n \"type\": \"report\"\n },\n {\n \"label\": \"Student Report Generation Tool\",\n \"name\": \"Student Report Generation Tool\",\n \"type\": \"doctype\"\n }\n]" + }, + { + "hidden": 0, + "label": "Reports", + "links": "[\n {\n \"dependencies\": [\n \"Fees\"\n ],\n \"doctype\": \"Fees\",\n \"is_query_report\": true,\n \"label\": \"Student Fee Collection\",\n \"name\": \"Student Fee Collection\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Student Attendance\"\n ],\n \"doctype\": \"Student Attendance\",\n \"is_query_report\": true,\n \"label\": \"Student Monthly Attendance Sheet\",\n \"name\": \"Student Monthly Attendance Sheet\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Student Attendance\"\n ],\n \"doctype\": \"Student Attendance\",\n \"is_query_report\": true,\n \"label\": \"Absent Student Report\",\n \"name\": \"Absent Student Report\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Program Enrollment\"\n ],\n \"doctype\": \"Program Enrollment\",\n \"is_query_report\": true,\n \"label\": \"Student and Guardian Contact Details\",\n \"name\": \"Student and Guardian Contact Details\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Student Attendance\"\n ],\n \"doctype\": \"Student Attendance\",\n \"is_query_report\": true,\n \"label\": \"Student Batch-Wise Attendance\",\n \"name\": \"Student Batch-Wise Attendance\",\n \"type\": \"report\"\n }\n]" } ], "category": "Domains", @@ -77,7 +82,7 @@ "idx": 0, "is_standard": 1, "label": "Education", - "modified": "2020-04-01 11:28:51.011309", + "modified": "2020-05-22 01:09:13.058482", "modified_by": "Administrator", "module": "Education", "name": "Education", From 1fe8956347c8757b982238a86862f3c5e7b58651 Mon Sep 17 00:00:00 2001 From: Marica Date: Fri, 22 May 2020 10:48:35 +0530 Subject: [PATCH 048/449] fix: Added Inactive serial no status (#21848) --- erpnext/patches.txt | 2 +- erpnext/patches/v12_0/set_serial_no_status.py | 4 +++- erpnext/stock/doctype/serial_no/serial_no.json | 4 ++-- erpnext/stock/doctype/serial_no/serial_no.py | 2 ++ erpnext/stock/doctype/serial_no/serial_no_list.js | 2 ++ 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 4fd668c80b..eacede6a92 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -684,7 +684,7 @@ execute:frappe.delete_doc_if_exists("Page", "appointment-analytic") execute:frappe.rename_doc("Desk Page", "Getting Started", "Home", force=True) erpnext.patches.v12_0.unset_customer_supplier_based_on_type_of_item_price erpnext.patches.v12_0.set_valid_till_date_in_supplier_quotation -erpnext.patches.v12_0.set_serial_no_status +erpnext.patches.v12_0.set_serial_no_status #2020-05-21 erpnext.patches.v12_0.update_price_list_currency_in_bom execute:frappe.delete_doc_if_exists('Dashboard', 'Accounts') erpnext.patches.v13_0.update_actual_start_and_end_date_in_wo diff --git a/erpnext/patches/v12_0/set_serial_no_status.py b/erpnext/patches/v12_0/set_serial_no_status.py index abba37d48e..3b5f5ef340 100644 --- a/erpnext/patches/v12_0/set_serial_no_status.py +++ b/erpnext/patches/v12_0/set_serial_no_status.py @@ -5,7 +5,7 @@ from frappe.utils import getdate, nowdate def execute(): frappe.reload_doc('stock', 'doctype', 'serial_no') - serial_no_list = frappe.db.sql("""select name, delivery_document_type, warranty_expiry_date from `tabSerial No` + serial_no_list = frappe.db.sql("""select name, delivery_document_type, warranty_expiry_date, warehouse from `tabSerial No` where (status is NULL OR status='')""", as_dict = 1) if len(serial_no_list) > 20000: frappe.db.auto_commit_on_many_writes = True @@ -15,6 +15,8 @@ def execute(): status = "Delivered" elif serial_no.get("warranty_expiry_date") and getdate(serial_no.get("warranty_expiry_date")) <= getdate(nowdate()): status = "Expired" + elif not serial_no.get("warehouse"): + status = "Inactive" else: status = "Active" diff --git a/erpnext/stock/doctype/serial_no/serial_no.json b/erpnext/stock/doctype/serial_no/serial_no.json index 731a730279..d9f8b62754 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.json +++ b/erpnext/stock/doctype/serial_no/serial_no.json @@ -420,14 +420,14 @@ "fieldtype": "Select", "in_standard_filter": 1, "label": "Status", - "options": "\nActive\nDelivered\nExpired", + "options": "\nActive\nInactive\nDelivered\nExpired", "read_only": 1 } ], "icon": "fa fa-barcode", "idx": 1, "links": [], - "modified": "2020-04-08 13:29:58.517772", + "modified": "2020-05-21 19:29:58.517772", "modified_by": "Administrator", "module": "Stock", "name": "Serial No", diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py index 914eea379a..f3514c7385 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.py +++ b/erpnext/stock/doctype/serial_no/serial_no.py @@ -42,6 +42,8 @@ class SerialNo(StockController): self.status = "Delivered" elif self.warranty_expiry_date and getdate(self.warranty_expiry_date) <= getdate(nowdate()): self.status = "Expired" + elif not self.warehouse: + self.status = "Inactive" else: self.status = "Active" diff --git a/erpnext/stock/doctype/serial_no/serial_no_list.js b/erpnext/stock/doctype/serial_no/serial_no_list.js index 651f790583..7526d1d8a5 100644 --- a/erpnext/stock/doctype/serial_no/serial_no_list.js +++ b/erpnext/stock/doctype/serial_no/serial_no_list.js @@ -5,6 +5,8 @@ frappe.listview_settings['Serial No'] = { return [__("Delivered"), "green", "delivery_document_type,is,set"]; } else if (doc.warranty_expiry_date && frappe.datetime.get_diff(doc.warranty_expiry_date, frappe.datetime.nowdate()) <= 0) { return [__("Expired"), "red", "warranty_expiry_date,not in,|warranty_expiry_date,<=,Today|delivery_document_type,is,not set"]; + } else if (!doc.warehouse) { + return [__("Inactive"), "grey", "warehouse,is,not set"]; } else { return [__("Active"), "green", "delivery_document_type,is,not set"]; } From 131ca435e7c74fbe55dee55a8b5375688a52f5a1 Mon Sep 17 00:00:00 2001 From: Chinmay Pai Date: Fri, 22 May 2020 10:50:13 +0530 Subject: [PATCH 049/449] fix: set customer and supplier details using sql (#21846) * fix: set customer and supplier details using sql instead of slowing down the query with get_doc and save() we can just use sql to update the required values for customer and supplier Signed-off-by: Chinmay D. Pai * chore: remove extra quote Co-authored-by: Himanshu * fix: update sql query to include tabPrice List Signed-off-by: Chinmay D. Pai Co-authored-by: Himanshu --- ...er_supplier_based_on_type_of_item_price.py | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/erpnext/patches/v12_0/unset_customer_supplier_based_on_type_of_item_price.py b/erpnext/patches/v12_0/unset_customer_supplier_based_on_type_of_item_price.py index 60aec05466..b8efb210a0 100644 --- a/erpnext/patches/v12_0/unset_customer_supplier_based_on_type_of_item_price.py +++ b/erpnext/patches/v12_0/unset_customer_supplier_based_on_type_of_item_price.py @@ -1,15 +1,29 @@ from __future__ import unicode_literals import frappe + def execute(): - invalid_selling_item_price = frappe.db.sql( - """SELECT name FROM `tabItem Price` WHERE selling = 1 and buying = 0 and (supplier IS NOT NULL or supplier = '')""" - ) - invalid_buying_item_price = frappe.db.sql( - """SELECT name FROM `tabItem Price` WHERE selling = 0 and buying = 1 and (customer IS NOT NULL or customer = '')""" - ) - docs_to_modify = invalid_buying_item_price + invalid_selling_item_price - for d in docs_to_modify: - # saving the doc will auto reset invalid customer/supplier field - doc = frappe.get_doc("Item Price", d[0]) - doc.save() \ No newline at end of file + """ + set proper customer and supplier details for item price + based on selling and buying values + """ + + # update for selling + frappe.db.sql( + """UPDATE `tabItem Price` ip, `tabPrice List` pl + SET ip.`reference` = ip.`customer`, ip.`supplier` = NULL + WHERE ip.`selling` = 1 + AND ip.`buying` = 0 + AND (ip.`supplier` IS NOT NULL OR ip.`supplier` = '') + AND ip.`price_list` = pl.`name` + AND pl.`enabled` = 1""") + + # update for buying + frappe.db.sql( + """UPDATE `tabItem Price` ip, `tabPrice List` pl + SET ip.`reference` = ip.`supplier`, ip.`customer` = NULL + WHERE ip.`selling` = 0 + AND ip.`buying` = 1 + AND (ip.`customer` IS NOT NULL OR ip.`customer` = '') + AND ip.`price_list` = pl.`name` + AND pl.`enabled` = 1""") From f42408c00369468c0774b20c15ac444b789c50ce Mon Sep 17 00:00:00 2001 From: Michelle Alva <50285544+michellealva@users.noreply.github.com> Date: Fri, 22 May 2020 10:51:19 +0530 Subject: [PATCH 050/449] fix: expense account error message in DN (#21851) Changed error message if expense account not set for item in Delivery Note. Earlier: Expense or Difference account is mandatory for Item IT - 6 as it impacts overall stock value After fix: Expense Account not set for Item IT - 6. Please set an Expense Account for the item in the Items table --- erpnext/controllers/stock_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 86de80815d..90d293088b 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -226,7 +226,7 @@ class StockController(AccountsController): def check_expense_account(self, item): if not item.get("expense_account"): - frappe.throw(_("Expense or Difference account is mandatory for Item {0} as it impacts overall stock value").format(item.item_code)) + frappe.throw(_("Expense Account not set for Item {0}. Please set an Expense Account for the item in the Items table").format(item.item_code)) else: is_expense_account = frappe.db.get_value("Account", From bd24a074597970e7bee9e02ffac6b84f022444ab Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Fri, 22 May 2020 12:28:45 +0530 Subject: [PATCH 051/449] fix: Item tax template not getting mapped from source to traget doc (#21862) --- erpnext/public/js/controllers/transaction.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 28c2102aef..637d3b3267 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1652,8 +1652,10 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ if(!r.exc) { $.each(me.frm.doc.items || [], function(i, item) { if(item.item_code && r.message.hasOwnProperty(item.item_code)) { - item.item_tax_template = r.message[item.item_code].item_tax_template; - item.item_tax_rate = r.message[item.item_code].item_tax_rate; + if (!item.item_tax_template) { + item.item_tax_template = r.message[item.item_code].item_tax_template; + item.item_tax_rate = r.message[item.item_code].item_tax_rate; + } me.add_taxes_from_item_tax_template(item.item_tax_rate); } else { item.item_tax_template = ""; From 32635ef193472880222c782dc613a5d684e37421 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 22 May 2020 13:13:17 +0530 Subject: [PATCH 052/449] fix: Remove duplicate leave ledger entry (#21871) * fix: Remove duplicate leave ledger entry * fix: Remove duplicate leave ledger entry --- .../remove_duplicate_leave_ledger_entries.py | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/erpnext/patches/v12_0/remove_duplicate_leave_ledger_entries.py b/erpnext/patches/v12_0/remove_duplicate_leave_ledger_entries.py index 6353304d7a..24286dcebf 100644 --- a/erpnext/patches/v12_0/remove_duplicate_leave_ledger_entries.py +++ b/erpnext/patches/v12_0/remove_duplicate_leave_ledger_entries.py @@ -6,6 +6,7 @@ import frappe def execute(): """Delete duplicate leave ledger entries of type allocation created.""" + frappe.reload_doc('hr', 'doctype', 'leave_ledger_entry') if not frappe.db.a_row_exists("Leave Ledger Entry"): return @@ -14,31 +15,32 @@ def execute(): def get_duplicate_records(): """Fetch all but one duplicate records from the list of expired leave allocation.""" - return frappe.db.sql_list(""" - WITH duplicate_records AS - (SELECT - name, transaction_name, is_carry_forward, - ROW_NUMBER() over(partition by transaction_name order by creation)as row - FROM `tabLeave Ledger Entry` l - WHERE (EXISTS - (SELECT name - FROM `tabLeave Ledger Entry` - WHERE - transaction_name = l.transaction_name - AND transaction_type = 'Leave Allocation' - AND name <> l.name - AND employee = l.employee - AND docstatus = 1 - AND leave_type = l.leave_type - AND is_carry_forward=l.is_carry_forward - AND to_date = l.to_date - AND from_date = l.from_date - AND is_expired = 1 - ))) - SELECT name FROM duplicate_records WHERE row > 1 + return frappe.db.sql(""" + SELECT name, employee, transaction_name, leave_type, is_carry_forward, from_date, to_date + FROM `tabLeave Ledger Entry` + WHERE + transaction_type = 'Leave Allocation' + AND docstatus = 1 + AND is_expired = 1 + GROUP BY + employee, transaction_name, leave_type, is_carry_forward, from_date, to_date + HAVING + count(name) > 1 + ORDER BY + creation """) def delete_duplicate_ledger_entries(duplicate_records_list): """Delete duplicate leave ledger entries.""" if not duplicate_records_list: return - frappe.db.sql('''DELETE FROM `tabLeave Ledger Entry` WHERE name in %s''', ((tuple(duplicate_records_list)), )) \ No newline at end of file + for d in duplicate_records_list: + frappe.db.sql(''' + DELETE FROM `tabLeave Ledger Entry` + WHERE name != %s + AND employee = %s + AND transaction_name = %s + AND leave_type = %s + AND is_carry_forward = %s + AND from_date = %s + AND to_date = %s + ''', tuple(d)) \ No newline at end of file From febf6b260e3cdc7a7fb30a06b1e4d669b8dc78e4 Mon Sep 17 00:00:00 2001 From: sahil28297 <37302950+sahil28297@users.noreply.github.com> Date: Fri, 22 May 2020 15:52:15 +0530 Subject: [PATCH 053/449] fix(patch): rerun remove_duplicate_leave_ledger_entries (#21878) --- erpnext/patches.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index eacede6a92..cb82901697 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -678,7 +678,7 @@ erpnext.patches.v13_0.move_tax_slabs_from_payroll_period_to_income_tax_slab #123 erpnext.patches.v12_0.fix_quotation_expired_status erpnext.patches.v12_0.update_appointment_reminder_scheduler_entry erpnext.patches.v12_0.retain_permission_rules_for_video_doctype -erpnext.patches.v12_0.remove_duplicate_leave_ledger_entries +erpnext.patches.v12_0.remove_duplicate_leave_ledger_entries #2020-05-22 erpnext.patches.v13_0.patch_to_fix_reverse_linking_in_additional_salary_encashment_and_incentive execute:frappe.delete_doc_if_exists("Page", "appointment-analytic") execute:frappe.rename_doc("Desk Page", "Getting Started", "Home", force=True) From 804c8709e35d14691afb0ac876af91b4a972e899 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 22 May 2020 20:39:50 +0530 Subject: [PATCH 054/449] chore: added change log (#21869) * chore: added change log * fix: change log --- erpnext/change_log/v13/v13_0_0_beta_2.md | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 erpnext/change_log/v13/v13_0_0_beta_2.md diff --git a/erpnext/change_log/v13/v13_0_0_beta_2.md b/erpnext/change_log/v13/v13_0_0_beta_2.md new file mode 100644 index 0000000000..05c52c9c28 --- /dev/null +++ b/erpnext/change_log/v13/v13_0_0_beta_2.md @@ -0,0 +1,68 @@ +### Version 13.0.0 Beta 2 Release Notes + +#### Accounting +- Onboarding and Dashboard ([#21677](https://github.com/frappe/erpnext/pull/21677)) +- Immutable Ledger ([#18740](https://github.com/frappe/erpnext/pull/18740)) +- Process Deferred Accounting document ([#19658](https://github.com/frappe/erpnext/pull/19658)) +- Journal Entry Template ([#21404](https://github.com/frappe/erpnext/pull/21404)) + + +#### Buying +- Onboarding and Dashboard ([#21611](https://github.com/frappe/erpnext/pull/21611)) +- New Reports + - Requested Items To Order ([#21611](https://github.com/frappe/erpnext/pull/21611)) + - Purchase Order Analysis ([#21611](https://github.com/frappe/erpnext/pull/21611)) + - Refactored Quoted Item Comparison report ([#21273](https://github.com/frappe/erpnext/pull/21273)) + +#### Stock +- Onboarding and Dashboard ([#21727](https://github.com/frappe/erpnext/pull/21727)) +- Invoice from Purchase Receipt with duplicate items which has been partially returned ([#20724](https://github.com/frappe/erpnext/pull/20724)) +- Report Enhancements ([#21727](https://github.com/frappe/erpnext/pull/21727)) + - Item Shortage Report + - Stock Ageing + - Purchase Receipt Trends + - Delivery Note Trends + +#### Manufacturing +- Onboarding and Dashboard ([#21430](https://github.com/frappe/erpnext/pull/21430)) +- Production forecasting using exponential smoothing method ([#21724](https://github.com/frappe/erpnext/pull/21724)) +- BOM Template ([#21262](https://github.com/frappe/erpnext/pull/21262)) +- Run MRP at parent level in the production plan and make material transfer based upon materials availability ([#21545](https://github.com/frappe/erpnext/pull/21545)) +- Downtime Entry ([#21430](https://github.com/frappe/erpnext/pull/21430)) +- New Reports + - Production Planning Report ([#21763](https://github.com/frappe/erpnext/pull/21763)) + - BOM Operations Time ([#21763](https://github.com/frappe/erpnext/pull/21763)) + - Work Order Summary ([#21430](https://github.com/frappe/erpnext/pull/21430)) + - Job card Summary ([#21430](https://github.com/frappe/erpnext/pull/21430)) + - Downtime Analysis ([#21430](https://github.com/frappe/erpnext/pull/21430)) + - Quality Inspection ([#21430](https://github.com/frappe/erpnext/pull/21430)) + + +#### HR +- Onboarding and Dashboard ([#21705](https://github.com/frappe/erpnext/pull/21705)) +- Recurring Additional Salary and reference fields ([#20936](https://github.com/frappe/erpnext/pull/20936)) +- Payroll based on employee cost center ([#21609](https://github.com/frappe/erpnext/pull/21609)) +- Payroll based on attendance ([#21258](https://github.com/frappe/erpnext/pull/21258)) +- Monthly attendance sheet report enhancements, group by Department, Designation, Employee Grade and Branch ([#21331](https://github.com/frappe/erpnext/pull/21331)) +- Upload Attendance template now have pre-filled holiday status ([#20947](https://github.com/frappe/erpnext/pull/20947)) +- New and enhanced reports + - Employee Analytics report ([#21705](https://github.com/frappe/erpnext/pull/21705)) + - Employee Leave Balance ([#20754](https://github.com/frappe/erpnext/pull/20754)) + - Employee Leave Balance Summary ([#20754](https://github.com/frappe/erpnext/pull/20754)) + +#### Healthcare +- Onboarding and Dashboard ([#21774](https://github.com/frappe/erpnext/pull/21774)) +- Multi company support in Healthcare ([#21290](https://github.com/frappe/erpnext/pull/21290)) + +#### CRM +- Onboarding and Dashboard ([#21733](https://github.com/frappe/erpnext/pull/21733)) + +#### Selling +- Territory tree in Customer Acquisition and Loyalty report ([#21668](https://github.com/frappe/erpnext/pull/21668)) + +#### Project +- Onboarding and Dashboard ([#21587](https://github.com/frappe/erpnext/pull/21587)) +- Project Summary Report ([#21587](https://github.com/frappe/erpnext/pull/21587)) + +#### Integrations +- Woocommerce Integration ([#13217](https://github.com/frappe/erpnext/pull/13217)) \ No newline at end of file From a7f39a98799f76c02a9bbf7fac19486545ffa08c Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Sun, 24 May 2020 00:54:04 +0530 Subject: [PATCH 055/449] fix: set default posting_date value to None using mutable python defaults, and especially function calls, inside function definitions causes bugs that can be really hard to debug sometimes. please refrain from using such defaults. instead, using None is almost always a sane default. the values can then be manipulated inside the function instead. Signed-off-by: Chinmay D. Pai (cherry picked from commit 0d147b011e5a9685de81564170f0668070d75af4) --- erpnext/accounts/deferred_revenue.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/deferred_revenue.py b/erpnext/accounts/deferred_revenue.py index b57e6783ce..448011016e 100644 --- a/erpnext/accounts/deferred_revenue.py +++ b/erpnext/accounts/deferred_revenue.py @@ -199,10 +199,13 @@ def book_deferred_income_or_expense(doc, deferred_process, posting_date=None): if item.get(enable_check): _book_deferred_revenue_or_expense(item) -def process_deferred_accounting(posting_date=today()): +def process_deferred_accounting(posting_date=None): ''' Converts deferred income/expense into income/expense Executed via background jobs on every month end ''' + if not posting_date: + posting_date = today() + if not cint(frappe.db.get_singles_value('Accounts Settings', 'automatically_process_deferred_accounting_entry')): return From 5f57f5948206a55280ec140674ce6108fbcd30d6 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 24 May 2020 21:55:47 +0530 Subject: [PATCH 056/449] fix: Company query for number cards (cherry picked from commit 9f963a2ac730e38dc480a8ecdc523f1af168d956) --- erpnext/healthcare/dashboard_fixtures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/healthcare/dashboard_fixtures.py b/erpnext/healthcare/dashboard_fixtures.py index 59da71a0ec..967117d22c 100644 --- a/erpnext/healthcare/dashboard_fixtures.py +++ b/erpnext/healthcare/dashboard_fixtures.py @@ -19,7 +19,7 @@ def get_company(): else: company = frappe.get_list("Company", limit=1) if company: - return company.name + return company[0].name return None def get_dashboards(): From fa62b72174910391517090fe720afe84a44c6e80 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 25 May 2020 11:00:18 +0000 Subject: [PATCH 057/449] refactor: open link in new tab (#21909) --- erpnext/buying/doctype/buying_settings/buying_settings.js | 2 +- erpnext/stock/doctype/stock_settings/stock_settings.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/buying/doctype/buying_settings/buying_settings.js b/erpnext/buying/doctype/buying_settings/buying_settings.js index a27950a941..01b40cd26f 100644 --- a/erpnext/buying/doctype/buying_settings/buying_settings.js +++ b/erpnext/buying/doctype/buying_settings/buying_settings.js @@ -11,7 +11,7 @@ frappe.tour['Buying Settings'] = [ { fieldname: "supp_master_name", title: "Supplier Naming By", - description: __("By default, the Item Name is set as per the Item Code entered. If you want Items to be named by a set ") + "Naming Series" + __(" choose the 'Naming Series' option."), + description: __("By default, the Item Name is set as per the Item Code entered. If you want Items to be named by a set ") + "Naming Series" + __(" choose the 'Naming Series' option."), }, { fieldname: "buying_price_list", diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.js b/erpnext/stock/doctype/stock_settings/stock_settings.js index 6f9757274d..877d0c3bbf 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.js +++ b/erpnext/stock/doctype/stock_settings/stock_settings.js @@ -36,7 +36,7 @@ frappe.tour['Stock Settings'] = [ { fieldname: "valuation_method", title: __("Valuation Method"), - description: __("Choose between FIFO and Moving Average Valuation Methods. Click ") + "here" + __(" to know more about them.") + description: __("Choose between FIFO and Moving Average Valuation Methods. Click ") + "here" + __(" to know more about them.") }, { fieldname: "show_barcode_field", From 4771362d39978a8f754714dd00df0867a521bbd7 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 25 May 2020 19:18:01 +0530 Subject: [PATCH 058/449] fix(healthcare): patient vitals undefined (#21906) (#21918) (cherry picked from commit 4dd6b9986fbf5320a80288b871d32ded4c4e39f1) Co-authored-by: Rucha Mahabal --- erpnext/healthcare/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/healthcare/utils.py b/erpnext/healthcare/utils.py index f092578003..9abaa0784a 100644 --- a/erpnext/healthcare/utils.py +++ b/erpnext/healthcare/utils.py @@ -512,10 +512,10 @@ def get_children(doctype, parent, company, is_root=False): def get_patient_vitals(patient, from_date=None, to_date=None): if not patient: return - vitals = frappe.db.get_all('Vital Signs', { + vitals = frappe.db.get_all('Vital Signs', filters={ 'docstatus': 1, 'patient': patient - }, order_by='signs_date, signs_time') + }, order_by='signs_date, signs_time', fields=['*']) if len(vitals): return vitals From dba67dc4a5b972e4376658597149cac62418b40f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 25 May 2020 19:18:11 +0530 Subject: [PATCH 059/449] fix(Healthcare): unhide company field in Sample Collection, add field in Rehab DocTypes (#21907) (#21917) * fix: unhide company field in Sample Collection * fix: add and set company field in rehab doctypes (cherry picked from commit 316d136acabba37e58c5987f22570bc1ebf9b64b) Co-authored-by: Rucha Mahabal --- .../doctype/patient_assessment/patient_assessment.json | 10 +++++++++- .../doctype/sample_collection/sample_collection.json | 8 +++----- .../healthcare/doctype/therapy_plan/therapy_plan.json | 10 +++++++++- erpnext/patches.txt | 2 +- .../v13_0/set_company_field_in_healthcare_doctypes.py | 4 ++-- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/erpnext/healthcare/doctype/patient_assessment/patient_assessment.json b/erpnext/healthcare/doctype/patient_assessment/patient_assessment.json index 3952a8153f..15c94344e9 100644 --- a/erpnext/healthcare/doctype/patient_assessment/patient_assessment.json +++ b/erpnext/healthcare/doctype/patient_assessment/patient_assessment.json @@ -11,6 +11,7 @@ "patient", "assessment_template", "column_break_4", + "company", "healthcare_practitioner", "assessment_datetime", "assessment_description", @@ -127,11 +128,18 @@ "fieldname": "assessment_description", "fieldtype": "Small Text", "label": "Assessment Description" + }, + { + "fieldname": "company", + "fieldtype": "Link", + "in_standard_filter": 1, + "label": "Company", + "options": "Company" } ], "is_submittable": 1, "links": [], - "modified": "2020-04-21 13:23:09.815007", + "modified": "2020-05-25 14:38:38.302399", "modified_by": "Administrator", "module": "Healthcare", "name": "Patient Assessment", diff --git a/erpnext/healthcare/doctype/sample_collection/sample_collection.json b/erpnext/healthcare/doctype/sample_collection/sample_collection.json index c352287faf..016cfbc3ae 100644 --- a/erpnext/healthcare/doctype/sample_collection/sample_collection.json +++ b/erpnext/healthcare/doctype/sample_collection/sample_collection.json @@ -85,11 +85,9 @@ { "fieldname": "company", "fieldtype": "Link", - "hidden": 1, + "in_standard_filter": 1, "label": "Company", - "options": "Company", - "print_hide": 1, - "report_hide": 1 + "options": "Company" }, { "fieldname": "section_break_6", @@ -167,7 +165,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-04-04 19:17:02.707203", + "modified": "2020-05-25 14:36:46.990469", "modified_by": "Administrator", "module": "Healthcare", "name": "Sample Collection", diff --git a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.json b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.json index ca78b6618e..9edfeb2faa 100644 --- a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.json +++ b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.json @@ -10,6 +10,7 @@ "patient", "patient_name", "column_break_4", + "company", "status", "start_date", "section_break_3", @@ -98,10 +99,17 @@ "label": "Status", "options": "Not Started\nIn Progress\nCompleted\nCancelled", "read_only": 1 + }, + { + "fieldname": "company", + "fieldtype": "Link", + "in_standard_filter": 1, + "label": "Company", + "options": "Company" } ], "links": [], - "modified": "2020-04-21 13:13:43.956014", + "modified": "2020-05-25 14:38:53.649315", "modified_by": "Administrator", "module": "Healthcare", "name": "Therapy Plan", diff --git a/erpnext/patches.txt b/erpnext/patches.txt index cb82901697..481cd35d49 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -688,7 +688,7 @@ erpnext.patches.v12_0.set_serial_no_status #2020-05-21 erpnext.patches.v12_0.update_price_list_currency_in_bom execute:frappe.delete_doc_if_exists('Dashboard', 'Accounts') erpnext.patches.v13_0.update_actual_start_and_end_date_in_wo -erpnext.patches.v13_0.set_company_field_in_healthcare_doctypes +erpnext.patches.v13_0.set_company_field_in_healthcare_doctypes #2020-05-25 erpnext.patches.v12_0.update_bom_in_so_mr execute:frappe.delete_doc("Report", "Department Analytics") execute:frappe.rename_doc("Desk Page", "Loan Management", "Loan", force=True) diff --git a/erpnext/patches/v13_0/set_company_field_in_healthcare_doctypes.py b/erpnext/patches/v13_0/set_company_field_in_healthcare_doctypes.py index 9d0dae4553..a7d4c665a1 100644 --- a/erpnext/patches/v13_0/set_company_field_in_healthcare_doctypes.py +++ b/erpnext/patches/v13_0/set_company_field_in_healthcare_doctypes.py @@ -3,8 +3,8 @@ import frappe def execute(): company = frappe.db.get_single_value('Global Defaults', 'default_company') - doctypes = ['Clinical Procedure', 'Inpatient Record', 'Lab Test', 'Patient Appointment', 'Patient Encounter', 'Vital Signs'] + doctypes = ['Clinical Procedure', 'Inpatient Record', 'Lab Test', 'Sample Collection' 'Patient Appointment', 'Patient Encounter', 'Vital Signs', 'Therapy Session', 'Therapy Plan', 'Patient Assessment'] for entry in doctypes: if frappe.db.exists('DocType', entry): - frappe.reload_doc("Healthcare", "doctype", entry) + frappe.reload_doc('Healthcare', 'doctype', entry) frappe.db.sql("update `tab{dt}` set company = '{company}' where ifnull(company, '') = ''".format(dt=entry, company=company)) From 3f09b1fade2279c353cb274f874927f54e5468c8 Mon Sep 17 00:00:00 2001 From: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> Date: Sat, 2 May 2020 22:31:30 +0530 Subject: [PATCH 060/449] chore: Rename change log --- erpnext/change_log/v13/{v13_0_0_beta_1.md => v13_0_0_beta-1.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename erpnext/change_log/v13/{v13_0_0_beta_1.md => v13_0_0_beta-1.md} (100%) diff --git a/erpnext/change_log/v13/v13_0_0_beta_1.md b/erpnext/change_log/v13/v13_0_0_beta-1.md similarity index 100% rename from erpnext/change_log/v13/v13_0_0_beta_1.md rename to erpnext/change_log/v13/v13_0_0_beta-1.md From 08ed9fc0643a1f7f7fe5a38c234fe91f73cec591 Mon Sep 17 00:00:00 2001 From: Raffael Meyer Date: Sat, 2 May 2020 19:25:49 +0200 Subject: [PATCH 061/449] Update v13_0_0_beta-1.md --- erpnext/change_log/v13/v13_0_0_beta-1.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/erpnext/change_log/v13/v13_0_0_beta-1.md b/erpnext/change_log/v13/v13_0_0_beta-1.md index f84dc24560..5bd13dd823 100644 --- a/erpnext/change_log/v13/v13_0_0_beta-1.md +++ b/erpnext/change_log/v13/v13_0_0_beta-1.md @@ -30,6 +30,14 @@ - [Item-wise Sales Register](https://docs.erpnext.com/docs/user/manual/en/accounts/accounting-reports) - [Territory-wise Sales](https://github.com/frappe/erpnext/pull/20428) +## Regional + +- Germany + + - [Update report DATEV Export to version 7.0](https://github.com/frappe/erpnext/pull/20582) and [allow to filter by voucher type](https://github.com/frappe/erpnext/pull/21060). + +- [Use any available Address Template](https://github.com/frappe/erpnext/pull/19862), not just your country's. + ## Other Changes - [Report Summary in Financial Statement](https://github.com/frappe/erpnext/pull/20876) - [Accounts Payable Report based on Payment Terms](https://docs.erpnext.com/docs/user/manual/en/accounts/accounting-reports) From 65fa85ed89109ef58e3909b6cbde026139be6a79 Mon Sep 17 00:00:00 2001 From: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> Date: Tue, 26 May 2020 10:34:20 +0530 Subject: [PATCH 062/449] Rename v13_0_0_beta_2.md to v13_0_0_beta-2.md --- erpnext/change_log/v13/{v13_0_0_beta_2.md => v13_0_0_beta-2.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename erpnext/change_log/v13/{v13_0_0_beta_2.md => v13_0_0_beta-2.md} (99%) diff --git a/erpnext/change_log/v13/v13_0_0_beta_2.md b/erpnext/change_log/v13/v13_0_0_beta-2.md similarity index 99% rename from erpnext/change_log/v13/v13_0_0_beta_2.md rename to erpnext/change_log/v13/v13_0_0_beta-2.md index 05c52c9c28..fb54483d5a 100644 --- a/erpnext/change_log/v13/v13_0_0_beta_2.md +++ b/erpnext/change_log/v13/v13_0_0_beta-2.md @@ -65,4 +65,4 @@ - Project Summary Report ([#21587](https://github.com/frappe/erpnext/pull/21587)) #### Integrations -- Woocommerce Integration ([#13217](https://github.com/frappe/erpnext/pull/13217)) \ No newline at end of file +- Woocommerce Integration ([#13217](https://github.com/frappe/erpnext/pull/13217)) From ccb9ae49aaf98c95f6c0dbfeb85be8da2602ea52 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Tue, 26 May 2020 10:58:19 +0530 Subject: [PATCH 063/449] fix: Rename change log to fix Invalid version string --- erpnext/change_log/v13/{v13_0_0_beta-1.md => v13_0_0-beta_1.md} | 0 erpnext/change_log/v13/{v13_0_0_beta-2.md => v13_0_0-beta_2.md} | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename erpnext/change_log/v13/{v13_0_0_beta-1.md => v13_0_0-beta_1.md} (100%) rename erpnext/change_log/v13/{v13_0_0_beta-2.md => v13_0_0-beta_2.md} (99%) diff --git a/erpnext/change_log/v13/v13_0_0_beta-1.md b/erpnext/change_log/v13/v13_0_0-beta_1.md similarity index 100% rename from erpnext/change_log/v13/v13_0_0_beta-1.md rename to erpnext/change_log/v13/v13_0_0-beta_1.md diff --git a/erpnext/change_log/v13/v13_0_0_beta-2.md b/erpnext/change_log/v13/v13_0_0-beta_2.md similarity index 99% rename from erpnext/change_log/v13/v13_0_0_beta-2.md rename to erpnext/change_log/v13/v13_0_0-beta_2.md index fb54483d5a..05c52c9c28 100644 --- a/erpnext/change_log/v13/v13_0_0_beta-2.md +++ b/erpnext/change_log/v13/v13_0_0-beta_2.md @@ -65,4 +65,4 @@ - Project Summary Report ([#21587](https://github.com/frappe/erpnext/pull/21587)) #### Integrations -- Woocommerce Integration ([#13217](https://github.com/frappe/erpnext/pull/13217)) +- Woocommerce Integration ([#13217](https://github.com/frappe/erpnext/pull/13217)) \ No newline at end of file From 0662a2194c3ef33a83280349026de56b3f1f071f Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Tue, 26 May 2020 12:19:13 +0000 Subject: [PATCH 064/449] fix: title for onboarding step (#21930) --- .../introduction_to_stock_entry.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/onboarding_step/introduction_to_stock_entry/introduction_to_stock_entry.json b/erpnext/stock/onboarding_step/introduction_to_stock_entry/introduction_to_stock_entry.json index 447611fe47..009a44f6e4 100644 --- a/erpnext/stock/onboarding_step/introduction_to_stock_entry/introduction_to_stock_entry.json +++ b/erpnext/stock/onboarding_step/introduction_to_stock_entry/introduction_to_stock_entry.json @@ -8,12 +8,12 @@ "is_mandatory": 0, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-19 18:55:41.457289", + "modified": "2020-05-26 15:55:41.457289", "modified_by": "Administrator", "name": "Introduction to Stock Entry", "owner": "Administrator", "show_full_form": 0, - "title": "Introduction to the multi-purpose stock transaction", + "title": "Introduction to Stock Entry", "validate_action": 1, "video_url": "https://www.youtube.com/watch?v=Njt107hlY3I" } \ No newline at end of file From 1edca82280aff9fb3ecad10a2206b4e709e49838 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 26 May 2020 18:01:20 +0530 Subject: [PATCH 065/449] fix(Healthcare): set company in healthcare service unit setup (#21929) (#21934) (cherry picked from commit c52bbd79bf02be46248c5daa100d80168c59f151) Co-authored-by: Rucha Mahabal --- erpnext/healthcare/setup.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/erpnext/healthcare/setup.py b/erpnext/healthcare/setup.py index 2087f49f32..06840801d3 100644 --- a/erpnext/healthcare/setup.py +++ b/erpnext/healthcare/setup.py @@ -195,10 +195,21 @@ def create_sensitivity(): def add_healthcare_service_unit_tree_root(): record = [ - { - "doctype": "Healthcare Service Unit", - "healthcare_service_unit_name": "All Healthcare Service Units", - "is_group": 1 - } + { + "doctype": "Healthcare Service Unit", + "healthcare_service_unit_name": "All Healthcare Service Units", + "is_group": 1, + "company": get_company() + } ] insert_record(record) + +def get_company(): + company = frappe.defaults.get_defaults().company + if company: + return company + else: + company = frappe.get_list("Company", limit=1) + if company: + return company[0].name + return None From 8513d516e39a73d48e1bb6b9f5624d941252bec1 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Tue, 26 May 2020 12:52:09 +0000 Subject: [PATCH 066/449] fix: status label in project summary report (#21935) --- erpnext/projects/report/project_summary/project_summary.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/projects/report/project_summary/project_summary.js b/erpnext/projects/report/project_summary/project_summary.js index 15367acd7d..c12a83ee9e 100644 --- a/erpnext/projects/report/project_summary/project_summary.js +++ b/erpnext/projects/report/project_summary/project_summary.js @@ -16,7 +16,7 @@ frappe.query_reports["Project Summary"] = { "fieldname": "status", "label": __("Status"), "fieldtype": "Select", - "options": "Open\nComplete\nCancelled", + "options": "Open\nCompleted\nCancelled", "default": "Open" } ] From 41ef0b849ef92a63ab68ee2367497d1283a5b081 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Tue, 26 May 2020 20:29:08 +0530 Subject: [PATCH 067/449] feat: added tour to manufacturing settings --- .../manufacturing_settings.js | 28 +++++++++++++++++++ .../explore_manufacturing_settings.json | 4 +-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.js b/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.js index ac144e24b1..668e981d18 100644 --- a/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.js +++ b/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.js @@ -3,3 +3,31 @@ frappe.ui.form.on('Manufacturing Settings', { }); + +frappe.tour["Manufacturing Settings"] = [ + { + fieldname: "material_consumption", + title: __("Allow Multiple Material Consumption"), + description: __("If ticked, multiple materials can be used for a single Work Order. This is useful if one or more time consuming products are being manufactured.") + }, + { + fieldname: "backflush_raw_materials_based_on", + title: __("Backflush Raw Materials"), + description: __("The Stock Entry of type 'Manufacture' is known as backflush. Raw materials being consumed to manufacture finished goods is known as backflushing.

When creating Manufacture Entry, raw-material items are backflushed based on BOM of production item. If you want raw-material items to be backflushed based on Material Transfer entry made against that Work Order instead, then you can set it under this field.") + }, + { + fieldname: "default_wip_warehouse", + title: __("Work In Progress Warehouse"), + description: __("This Warehouse will be auto-updated in the Work In Progress Warehouse field of Work Orders.") + }, + { + fieldname: "default_fg_warehouse", + title: __("Finished Goods Warehouse"), + description: __("This Warehouse will be auto-updated in the Target Warehouse field of Work Order.") + }, + { + fieldname: "update_bom_costs_automatically", + title: __("Update BOM Cost Automatically"), + description: __("If ticked, the BOM cost will be automatically updated based on Valuation Rate / Price List Rate / last purchase rate of raw materials.") + } +]; \ No newline at end of file diff --git a/erpnext/manufacturing/onboarding_step/explore_manufacturing_settings/explore_manufacturing_settings.json b/erpnext/manufacturing/onboarding_step/explore_manufacturing_settings/explore_manufacturing_settings.json index 582aba40d6..7ef202ee4e 100644 --- a/erpnext/manufacturing/onboarding_step/explore_manufacturing_settings/explore_manufacturing_settings.json +++ b/erpnext/manufacturing/onboarding_step/explore_manufacturing_settings/explore_manufacturing_settings.json @@ -1,5 +1,5 @@ { - "action": "Update Settings", + "action": "Show Form Tour", "creation": "2020-05-19 11:55:11.378374", "docstatus": 0, "doctype": "Onboarding Step", @@ -8,7 +8,7 @@ "is_mandatory": 0, "is_single": 1, "is_skipped": 0, - "modified": "2020-05-19 12:12:28.145366", + "modified": "2020-05-26 20:28:03.558199", "modified_by": "Administrator", "name": "Explore Manufacturing Settings", "owner": "Administrator", From 4e9ae53a13ad796ea8b2e7aa143cbca9c631469a Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 26 May 2020 23:07:11 +0530 Subject: [PATCH 068/449] fix: manufacturing dashboard and work order summary chart --- erpnext/manufacturing/dashboard_fixtures.py | 42 ++++++++++--------- .../downtime_entry/downtime_entry.json | 11 ++++- .../downtime_analysis/downtime_analysis.py | 11 +++-- .../work_order_summary/work_order_summary.py | 11 ++--- 4 files changed, 44 insertions(+), 31 deletions(-) diff --git a/erpnext/manufacturing/dashboard_fixtures.py b/erpnext/manufacturing/dashboard_fixtures.py index ef61f230ac..4a17fd07fb 100644 --- a/erpnext/manufacturing/dashboard_fixtures.py +++ b/erpnext/manufacturing/dashboard_fixtures.py @@ -3,7 +3,7 @@ import frappe, erpnext, json from frappe import _ -from frappe.utils import nowdate, get_date_str +from frappe.utils import nowdate, get_first_day, get_last_day, add_months from erpnext.accounts.utils import get_fiscal_year def get_data(): @@ -28,10 +28,10 @@ def get_dashboards(): { "chart": "Job Card Analysis", "width": "Full" } ], "cards": [ - { "card": "Total Work Order" }, - { "card": "Completed Work Order" }, + { "card": "Monthly Total Work Order" }, + { "card": "Monthly Completed Work Order" }, { "card": "Ongoing Job Card" }, - { "card": "Total Quality Inspection"} + { "card": "Monthly Quality Inspection"} ] }] @@ -180,38 +180,37 @@ def get_charts(): }] def get_number_cards(): - fiscal_year = get_fiscal_year(date=nowdate()) - year_start_date = get_date_str(fiscal_year[1]) - year_end_date = get_date_str(fiscal_year[2]) + start_date = add_months(nowdate(), -1) + end_date = nowdate() return [{ "doctype": "Number Card", "document_type": "Work Order", - "name": "Total Work Order", + "name": "Monthly Total Work Order", "filters_json": json.dumps([ ['Work Order', 'docstatus', '=', 1], - ['Work Order', 'creation', 'between', [year_start_date, year_end_date]] + ['Work Order', 'creation', 'between', [start_date, end_date]] ]), "function": "Count", "is_public": 1, - "label": _("Total Work Order"), + "label": _("Monthly Total Work Order"), "show_percentage_stats": 1, - "stats_time_interval": "Monthly" + "stats_time_interval": "Weekly" }, { "doctype": "Number Card", "document_type": "Work Order", - "name": "Completed Work Order", + "name": "Monthly Completed Work Order", "filters_json": json.dumps([ ['Work Order', 'status', '=', 'Completed'], ['Work Order', 'docstatus', '=', 1], - ['Work Order', 'creation', 'between', [year_start_date, year_end_date]] + ['Work Order', 'creation', 'between', [start_date, end_date]] ]), "function": "Count", "is_public": 1, - "label": _("Completed Work Order"), + "label": _("Monthly Completed Work Order"), "show_percentage_stats": 1, - "stats_time_interval": "Monthly" + "stats_time_interval": "Weekly" }, { "doctype": "Number Card", @@ -225,16 +224,19 @@ def get_number_cards(): "is_public": 1, "label": _("Ongoing Job Card"), "show_percentage_stats": 1, - "stats_time_interval": "Monthly" + "stats_time_interval": "Weekly" }, { "doctype": "Number Card", "document_type": "Quality Inspection", - "name": "Total Quality Inspection", - "filters_json": json.dumps([['Quality Inspection', 'docstatus', '=', 1]]), + "name": "Monthly Quality Inspection", + "filters_json": json.dumps([ + ['Quality Inspection', 'docstatus', '=', 1], + ['Quality Inspection', 'creation', 'between', [start_date, end_date]] + ]), "function": "Count", "is_public": 1, - "label": _("Total Quality Inspection"), + "label": _("Monthly Quality Inspection"), "show_percentage_stats": 1, - "stats_time_interval": "Monthly" + "stats_time_interval": "Weekly" }] \ No newline at end of file diff --git a/erpnext/manufacturing/doctype/downtime_entry/downtime_entry.json b/erpnext/manufacturing/doctype/downtime_entry/downtime_entry.json index 9acb4f0513..b301a9ec05 100644 --- a/erpnext/manufacturing/doctype/downtime_entry/downtime_entry.json +++ b/erpnext/manufacturing/doctype/downtime_entry/downtime_entry.json @@ -1,11 +1,13 @@ { "actions": [], "allow_import": 1, + "autoname": "naming_series:", "creation": "2020-04-18 04:50:46.187638", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", "field_order": [ + "naming_series", "workstation", "operator", "column_break_4", @@ -78,10 +80,17 @@ "fieldname": "remarks", "fieldtype": "Text", "label": "Remarks" + }, + { + "fieldname": "naming_series", + "fieldtype": "Select", + "label": "Naming Series", + "options": "DT-", + "reqd": 1 } ], "links": [], - "modified": "2020-05-19 12:59:37.358483", + "modified": "2020-05-26 22:14:54.479831", "modified_by": "Administrator", "module": "Manufacturing", "name": "Downtime Entry", diff --git a/erpnext/manufacturing/report/downtime_analysis/downtime_analysis.py b/erpnext/manufacturing/report/downtime_analysis/downtime_analysis.py index 2b2be4faa3..093309a005 100644 --- a/erpnext/manufacturing/report/downtime_analysis/downtime_analysis.py +++ b/erpnext/manufacturing/report/downtime_analysis/downtime_analysis.py @@ -24,7 +24,12 @@ def get_data(filters): if filters.get("workstation"): query_filters["workstation"] = filters.get("workstation") - return frappe.get_all("Downtime Entry", fields= fields, filters=query_filters) + data = frappe.get_all("Downtime Entry", fields= fields, filters=query_filters) or [] + for d in data: + if d.downtime: + d.downtime = d.downtime / 60 + + return data def get_chart_data(data, columns): labels = sorted(list(set([d.workstation for d in data]))) @@ -44,7 +49,7 @@ def get_chart_data(data, columns): "data": { "labels": labels, "datasets": [ - {"name": "Dataset 1", "values": datasets} + {"name": "Machine Downtime", "values": datasets} ] }, "type": "bar" @@ -88,7 +93,7 @@ def get_columns(filters): "width": 160 }, { - "label": _("Downtime (In Mins)"), + "label": _("Downtime (In Hours)"), "fieldname": "downtime", "fieldtype": "Float", "width": 150 diff --git a/erpnext/manufacturing/report/work_order_summary/work_order_summary.py b/erpnext/manufacturing/report/work_order_summary/work_order_summary.py index bc09ed4335..fb047b230c 100644 --- a/erpnext/manufacturing/report/work_order_summary/work_order_summary.py +++ b/erpnext/manufacturing/report/work_order_summary/work_order_summary.py @@ -56,7 +56,7 @@ def get_chart_data(data, filters): return get_chart_based_on_qty(data, filters) def get_chart_based_on_status(data): - labels = ["Not Started", "In Process", "Stopped", "Completed"] + labels = ["Completed", "In Process", "Stopped", "Not Started"] status_wise_data = { "Not Started": 0, @@ -66,13 +66,10 @@ def get_chart_based_on_status(data): } for d in data: - if d.status == "In Process" and d.produced_qty: - status_wise_data["Completed"] += d.produced_qty + status_wise_data[d.status] += 1 - status_wise_data[d.status] += d.qty - - values = [status_wise_data["Not Started"], status_wise_data["In Process"], - status_wise_data["Stopped"], status_wise_data["Completed"]] + values = [status_wise_data["Completed"], status_wise_data["In Process"], + status_wise_data["Stopped"], status_wise_data["Not Started"]] chart = { "data": { From 56893ed37334c8e634ec0214519c23fe7f935b49 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 27 May 2020 06:23:06 +0000 Subject: [PATCH 069/449] refactor: project summary report (#21953) * feat: added more filters * feat: show only first 30 projects in chart * fix: status completed * refactor: allow empty option in status filter --- .../report/project_summary/project_summary.js | 21 ++++++++++++++++++- .../report/project_summary/project_summary.py | 17 ++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/erpnext/projects/report/project_summary/project_summary.js b/erpnext/projects/report/project_summary/project_summary.js index c12a83ee9e..414b7b206a 100644 --- a/erpnext/projects/report/project_summary/project_summary.js +++ b/erpnext/projects/report/project_summary/project_summary.js @@ -12,12 +12,31 @@ frappe.query_reports["Project Summary"] = { "default": frappe.defaults.get_user_default("Company"), "reqd": 1 }, + { + "fieldname": "is_active", + "label": __("Is Active"), + "fieldtype": "Select", + "options": "\nYes\nNo", + "default": "Yes", + }, { "fieldname": "status", "label": __("Status"), "fieldtype": "Select", - "options": "Open\nCompleted\nCancelled", + "options": "\nOpen\nCompleted\nCancelled", "default": "Open" + }, + { + "fieldname": "project_type", + "label": __("Project Type"), + "fieldtype": "Link", + "options": "Project Type" + }, + { + "fieldname": "priority", + "label": __("Priority"), + "fieldtype": "Select", + "options": "\nLow\nMedium\nHigh" } ] }; diff --git a/erpnext/projects/report/project_summary/project_summary.py b/erpnext/projects/report/project_summary/project_summary.py index a20d7f25a3..ea7f1ab2e7 100644 --- a/erpnext/projects/report/project_summary/project_summary.py +++ b/erpnext/projects/report/project_summary/project_summary.py @@ -9,7 +9,7 @@ def execute(filters=None): columns = get_columns() data = [] - data = frappe.db.get_all("Project", filters=filters, fields=["name", 'status', "percent_complete", "expected_start_date", "expected_end_date"], order_by="expected_end_date") + data = frappe.db.get_all("Project", filters=filters, fields=["name", 'status', "percent_complete", "expected_start_date", "expected_end_date", "project_type"], order_by="expected_end_date") for project in data: project["total_tasks"] = frappe.db.count("Task", filters={"project": project.name}) @@ -30,6 +30,13 @@ def get_columns(): "options": "Project", "width": 200 }, + { + "fieldname": "project_type", + "label": _("Type"), + "fieldtype": "Link", + "options": "Project Type", + "width": 120 + }, { "fieldname": "status", "label": _("Status"), @@ -88,19 +95,19 @@ def get_chart_data(data): return { "data": { - 'labels': labels, + 'labels': labels[:30], 'datasets': [ { "name": "Overdue", - "values": overdue + "values": overdue[:30] }, { "name": "Completed", - "values": completed + "values": completed[:30] }, { "name": "Total Tasks", - "values": total + "values": total[:30] }, ] }, From 2cdd572f6b760f94c7e3ea5543188067f03ddb3c Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 27 May 2020 12:44:02 +0530 Subject: [PATCH 070/449] fix: addtional salary date validation (#21952) (#21955) (cherry picked from commit ef0026c06f224a486978164325461abb81e32aac) Co-authored-by: Anurag Mishra <32095923+Anurag810@users.noreply.github.com> --- erpnext/hr/doctype/additional_salary/additional_salary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/hr/doctype/additional_salary/additional_salary.py b/erpnext/hr/doctype/additional_salary/additional_salary.py index bab6fb545f..e369ba7cef 100644 --- a/erpnext/hr/doctype/additional_salary/additional_salary.py +++ b/erpnext/hr/doctype/additional_salary/additional_salary.py @@ -37,7 +37,7 @@ class AdditionalSalary(Document): frappe.throw(_("Payroll date can not be less than employee's joining date.")) elif getdate(self.from_date) < getdate(date_of_joining): frappe.throw(_("From date can not be less than employee's joining date.")) - elif getdate(self.to_date) > getdate(relieving_date): + elif relieving_date and getdate(self.to_date) > getdate(relieving_date): frappe.throw(_("To date can not be greater than employee's relieving date.")) def get_amount(self, sal_start_date, sal_end_date): From 5c9469b1ee49a65320f60b1fb809ffe7aa0554f2 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 27 May 2020 12:52:52 +0530 Subject: [PATCH 071/449] fix: titles and order of Healthcare Onboarding steps (#21948) (#21956) * fix(Healthcare): title and order of onboarding steps * refactor: healthcare settings tour (cherry picked from commit a18c896a5641fb74b7cb82bf6808a0b7dcdcfb6d) Co-authored-by: Rucha Mahabal --- .../doctype/healthcare_settings/healthcare_settings.js | 10 +++++----- .../module_onboarding/healthcare/healthcare.json | 10 +++++----- .../create_healthcare_practitioner.json} | 8 ++++---- .../explore_clinical_procedure_templates.json | 2 +- .../explore_healthcare_settings.json | 2 +- .../introduction_to_healthcare_practitioner.json} | 6 +++--- 6 files changed, 19 insertions(+), 19 deletions(-) rename erpnext/healthcare/onboarding_step/{create_practitioner/create_practitioner.json => create_healthcare_practitioner/create_healthcare_practitioner.json} (64%) rename erpnext/healthcare/onboarding_step/{setup_schedule_and_employee_for_healthcare_practitioner/setup_schedule_and_employee_for_healthcare_practitioner.json => introduction_to_healthcare_practitioner/introduction_to_healthcare_practitioner.json} (68%) diff --git a/erpnext/healthcare/doctype/healthcare_settings/healthcare_settings.js b/erpnext/healthcare/doctype/healthcare_settings/healthcare_settings.js index c266ba8647..cf2276fc07 100644 --- a/erpnext/healthcare/doctype/healthcare_settings/healthcare_settings.js +++ b/erpnext/healthcare/doctype/healthcare_settings/healthcare_settings.js @@ -57,19 +57,19 @@ frappe.tour['Healthcare Settings'] = [ description: __('Checking this will automatically create a Sales Invoice whenever an appointment is booked for a Patient.') }, { - fieldname: 'healthcare_service_items', + fieldname: 'inpatient_visit_charge_item', title: __('Healthcare Service Items'), - description: __('Set up the Healthcare Service Items for billing. Click ') + "here" + __(' to know more') + description: __('You can create a service item for Inpatient Visit Charge and set it here. Similarly, you can set up other Healthcare Service Items for billing in this section. Click ') + "here" + __(' to know more') }, { - fieldname: 'sb_in_ac', + fieldname: 'income_account', title: __('Set up default Accounts for the Healthcare Facility'), description: __('If you wish to override default accounts settings and configure the Income and Receivable accounts for Healthcare, you can do so here.') }, { - fieldname: 'out_patient_sms_alerts', + fieldname: 'send_registration_msg', title: __('Out Patient SMS alerts'), - description: __('You can set up Out Patient SMS alerts here. Click ') + "here" + __(' to know more') + description: __('If you want to send SMS alert on Patient Registration, you can enable this option. Similary, you can set up Out Patient SMS alerts for other functionalities in this section. Click ') + "here" + __(' to know more') } ]; diff --git a/erpnext/healthcare/module_onboarding/healthcare/healthcare.json b/erpnext/healthcare/module_onboarding/healthcare/healthcare.json index db35149f87..3e50726060 100644 --- a/erpnext/healthcare/module_onboarding/healthcare/healthcare.json +++ b/erpnext/healthcare/module_onboarding/healthcare/healthcare.json @@ -10,7 +10,7 @@ "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/healthcare", "idx": 0, "is_complete": 0, - "modified": "2020-05-19 12:52:09.757729", + "modified": "2020-05-26 23:16:37.603361", "modified_by": "Administrator", "module": "Healthcare", "name": "Healthcare", @@ -19,14 +19,14 @@ { "step": "Create Patient" }, - { - "step": "Create Practitioner" - }, { "step": "Create Practitioner Schedule" }, { - "step": "Setup Schedule and Employee for Healthcare Practitioner" + "step": "Introduction to Healthcare Practitioner" + }, + { + "step": "Create Healthcare Practitioner" }, { "step": "Explore Healthcare Settings" diff --git a/erpnext/healthcare/onboarding_step/create_practitioner/create_practitioner.json b/erpnext/healthcare/onboarding_step/create_healthcare_practitioner/create_healthcare_practitioner.json similarity index 64% rename from erpnext/healthcare/onboarding_step/create_practitioner/create_practitioner.json rename to erpnext/healthcare/onboarding_step/create_healthcare_practitioner/create_healthcare_practitioner.json index 614b201a58..c45a347080 100644 --- a/erpnext/healthcare/onboarding_step/create_practitioner/create_practitioner.json +++ b/erpnext/healthcare/onboarding_step/create_healthcare_practitioner/create_healthcare_practitioner.json @@ -1,6 +1,6 @@ { "action": "Create Entry", - "creation": "2020-05-19 10:39:55.728057", + "creation": "2020-05-19 10:39:55.728058", "docstatus": 0, "doctype": "Onboarding Step", "idx": 0, @@ -8,12 +8,12 @@ "is_mandatory": 1, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-19 12:27:39.851375", + "modified": "2020-05-26 23:16:31.965521", "modified_by": "Administrator", - "name": "Create Practitioner", + "name": "Create Healthcare Practitioner", "owner": "Administrator", "reference_document": "Healthcare Practitioner", "show_full_form": 1, - "title": "Create Practitioner", + "title": "Create Healthcare Practitioner", "validate_action": 1 } \ No newline at end of file diff --git a/erpnext/healthcare/onboarding_step/explore_clinical_procedure_templates/explore_clinical_procedure_templates.json b/erpnext/healthcare/onboarding_step/explore_clinical_procedure_templates/explore_clinical_procedure_templates.json index f0c0f612e1..697b761e52 100644 --- a/erpnext/healthcare/onboarding_step/explore_clinical_procedure_templates/explore_clinical_procedure_templates.json +++ b/erpnext/healthcare/onboarding_step/explore_clinical_procedure_templates/explore_clinical_procedure_templates.json @@ -8,7 +8,7 @@ "is_mandatory": 0, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-19 11:46:35.085270", + "modified": "2020-05-26 23:10:24.504030", "modified_by": "Administrator", "name": "Explore Clinical Procedure Templates", "owner": "Administrator", diff --git a/erpnext/healthcare/onboarding_step/explore_healthcare_settings/explore_healthcare_settings.json b/erpnext/healthcare/onboarding_step/explore_healthcare_settings/explore_healthcare_settings.json index 2bdab69faa..b2d5aef431 100644 --- a/erpnext/healthcare/onboarding_step/explore_healthcare_settings/explore_healthcare_settings.json +++ b/erpnext/healthcare/onboarding_step/explore_healthcare_settings/explore_healthcare_settings.json @@ -8,7 +8,7 @@ "is_mandatory": 1, "is_single": 1, "is_skipped": 0, - "modified": "2020-05-19 12:26:48.682673", + "modified": "2020-05-26 23:10:24.507648", "modified_by": "Administrator", "name": "Explore Healthcare Settings", "owner": "Administrator", diff --git a/erpnext/healthcare/onboarding_step/setup_schedule_and_employee_for_healthcare_practitioner/setup_schedule_and_employee_for_healthcare_practitioner.json b/erpnext/healthcare/onboarding_step/introduction_to_healthcare_practitioner/introduction_to_healthcare_practitioner.json similarity index 68% rename from erpnext/healthcare/onboarding_step/setup_schedule_and_employee_for_healthcare_practitioner/setup_schedule_and_employee_for_healthcare_practitioner.json rename to erpnext/healthcare/onboarding_step/introduction_to_healthcare_practitioner/introduction_to_healthcare_practitioner.json index c5af177e34..fa4c9036d7 100644 --- a/erpnext/healthcare/onboarding_step/setup_schedule_and_employee_for_healthcare_practitioner/setup_schedule_and_employee_for_healthcare_practitioner.json +++ b/erpnext/healthcare/onboarding_step/introduction_to_healthcare_practitioner/introduction_to_healthcare_practitioner.json @@ -9,12 +9,12 @@ "is_mandatory": 1, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-19 12:26:42.492734", + "modified": "2020-05-26 22:07:07.482530", "modified_by": "Administrator", - "name": "Setup Schedule and Employee for Healthcare Practitioner", + "name": "Introduction to Healthcare Practitioner", "owner": "Administrator", "reference_document": "Healthcare Practitioner", "show_full_form": 0, - "title": "Setup Schedule and Employee for Healthcare Practitioner", + "title": "Introduction to Healthcare Practitioner", "validate_action": 0 } \ No newline at end of file From 6bb1eb26ffe314661f715af1d1be1bd84118aa63 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 27 May 2020 14:47:46 +0530 Subject: [PATCH 072/449] fix: filters for the manufacturing reports --- .../job_card_summary/job_card_summary.js | 29 ++++++++++++++++--- .../job_card_summary/job_card_summary.py | 29 +++++++++++++++---- .../work_order_summary/work_order_summary.js | 29 ++++++++++++++++--- 3 files changed, 73 insertions(+), 14 deletions(-) diff --git a/erpnext/manufacturing/report/job_card_summary/job_card_summary.js b/erpnext/manufacturing/report/job_card_summary/job_card_summary.js index b7e307183f..33953b1265 100644 --- a/erpnext/manufacturing/report/job_card_summary/job_card_summary.js +++ b/erpnext/manufacturing/report/job_card_summary/job_card_summary.js @@ -13,17 +13,38 @@ frappe.query_reports["Job Card Summary"] = { reqd: 1 }, { - label: __("From Date"), + fieldname: "fiscal_year", + label: __("Fiscal Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: frappe.defaults.get_user_default("fiscal_year"), + reqd: 1, + on_change: function(query_report) { + var fiscal_year = query_report.get_values().fiscal_year; + if (!fiscal_year) { + return; + } + frappe.model.with_doc("Fiscal Year", fiscal_year, function(r) { + var fy = frappe.model.get_doc("Fiscal Year", fiscal_year); + frappe.query_report.set_filter_value({ + from_date: fy.year_start_date, + to_date: fy.year_end_date + }); + }); + } + }, + { + label: __("From Posting Date"), fieldname:"from_date", fieldtype: "Date", - default: frappe.datetime.add_months(frappe.datetime.get_today(), -12), + default: frappe.defaults.get_user_default("year_start_date"), reqd: 1 }, { - label: __("To Date"), + label: __("To Posting Datetime"), fieldname:"to_date", fieldtype: "Date", - default: frappe.datetime.get_today(), + default: frappe.defaults.get_user_default("year_end_date"), reqd: 1, }, { diff --git a/erpnext/manufacturing/report/job_card_summary/job_card_summary.py b/erpnext/manufacturing/report/job_card_summary/job_card_summary.py index ae1e4f3046..953d8201a7 100644 --- a/erpnext/manufacturing/report/job_card_summary/job_card_summary.py +++ b/erpnext/manufacturing/report/job_card_summary/job_card_summary.py @@ -15,9 +15,12 @@ def execute(filters=None): return columns, data, None, chart_data def get_data(filters): - query_filters = {"docstatus": ("<", 2)} + query_filters = { + "docstatus": ("=", 1), + "posting_date": ("between", [filters.from_date, filters.to_date]) + } - fields = ["name", "status", "work_order", "production_item", "item_name", + fields = ["name", "status", "work_order", "production_item", "item_name", "posting_date", "total_completed_qty", "workstation", "operation", "employee_name", "total_time_in_mins"] for field in ["work_order", "workstation", "operation", "company"]: @@ -30,12 +33,19 @@ def get_data(filters): if not data: return [] job_cards = [d.name for d in data] + + job_card_time_filter = { + "docstatus": 1, + "parent": ("in", job_cards), + } + job_card_time_details = {} for job_card_data in frappe.get_all("Job Card Time Log", fields=["min(from_time) as from_time", "max(to_time) as to_time", "parent"], - filters={"docstatus": ("<", 2), "parent": ("in", job_cards)}, group_by="parent"): + filters=job_card_time_filter, group_by="parent", debug=1): job_card_time_details[job_card_data.parent] = job_card_data + res = [] for d in data: if d.status == "Material Transferred": d.status = "Open" @@ -43,8 +53,9 @@ def get_data(filters): if job_card_time_details.get(d.name): d.from_time = job_card_time_details.get(d.name).from_time d.to_time = job_card_time_details.get(d.name).to_time + res.append(d) - return data + return res def get_chart_data(job_card_details, filters): labels, periodic_data = prepare_chart_data(job_card_details, filters) @@ -86,10 +97,10 @@ def prepare_chart_data(job_card_details, filters): labels.append(period) for d in job_card_details: - if getdate(d.from_time) >= from_date and getdate(d.to_time) <= end_date: + if getdate(d.posting_date) > from_date and getdate(d.posting_date) <= end_date: status = "Completed" if d.status == "Completed" else "Pending" - if periodic_data.get(status) and periodic_data.get(status).get(period): + if periodic_data.get(status).get(period): periodic_data[status][period] += 1 else: periodic_data[status][period] = 1 @@ -105,6 +116,12 @@ def get_columns(filters): "options": "Job Card", "width": 100 }, + { + "label": _("Posting Date"), + "fieldname": "posting_date", + "fieldtype": "Date", + "width": 100 + }, ] if not filters.get("status"): diff --git a/erpnext/manufacturing/report/work_order_summary/work_order_summary.js b/erpnext/manufacturing/report/work_order_summary/work_order_summary.js index ec9fe35d63..22928657b9 100644 --- a/erpnext/manufacturing/report/work_order_summary/work_order_summary.js +++ b/erpnext/manufacturing/report/work_order_summary/work_order_summary.js @@ -13,17 +13,38 @@ frappe.query_reports["Work Order Summary"] = { reqd: 1 }, { - label: __("From Date"), + fieldname: "fiscal_year", + label: __("Fiscal Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: frappe.defaults.get_user_default("fiscal_year"), + reqd: 1, + on_change: function(query_report) { + var fiscal_year = query_report.get_values().fiscal_year; + if (!fiscal_year) { + return; + } + frappe.model.with_doc("Fiscal Year", fiscal_year, function(r) { + var fy = frappe.model.get_doc("Fiscal Year", fiscal_year); + frappe.query_report.set_filter_value({ + from_date: fy.year_start_date, + to_date: fy.year_end_date + }); + }); + } + }, + { + label: __("From Posting Date"), fieldname:"from_date", fieldtype: "Date", - default: frappe.datetime.add_months(frappe.datetime.get_today(), -12), + default: frappe.defaults.get_user_default("year_start_date"), reqd: 1 }, { - label: __("To Date"), + label: __("To Posting Datetime"), fieldname:"to_date", fieldtype: "Date", - default: frappe.datetime.get_today(), + default: frappe.defaults.get_user_default("year_end_date"), reqd: 1, }, { From 310309e81603385823a2378219cc675976a450ed Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 27 May 2020 12:57:16 +0530 Subject: [PATCH 073/449] fix: label changed in production plan (cherry picked from commit 07388495f36c389830277d7a21124593f91d8cb9) --- .../manufacturing/doctype/production_plan/production_plan.js | 4 ++-- .../report/bom_operations_time/bom_operations_time.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js index 64c952b67b..1a64bc5e24 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.js +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js @@ -201,9 +201,9 @@ frappe.ui.form.on('Production Plan', { title: title, fields: [ { - "fieldtype": "Table MultiSelect", "label": __("Source Warehouses"), + "fieldtype": "Table MultiSelect", "label": __("Source Warehouses (Optional)"), "fieldname": "warehouses", "options": "Production Plan Material Request Warehouse", - "description": "System will pickup the materials from the selected warehouses", + "description": __("System will pickup the materials from the selected warehouses. If not specified, system will create material request for purchase."), get_query: function () { return { filters: { diff --git a/erpnext/manufacturing/report/bom_operations_time/bom_operations_time.py b/erpnext/manufacturing/report/bom_operations_time/bom_operations_time.py index 1279011b22..e7d92658f7 100644 --- a/erpnext/manufacturing/report/bom_operations_time/bom_operations_time.py +++ b/erpnext/manufacturing/report/bom_operations_time/bom_operations_time.py @@ -103,7 +103,7 @@ def get_columns(filters): "fieldtype": "Int", "width": 140 }, { - "label": _("Subassembly BOM Count"), + "label": _("Sub-assembly BOM Count"), "fieldname": "used_as_subassembly_items", "fieldtype": "Int", "width": 180 From 7634250e780fc803e04182e463b2ae85601ff0e5 Mon Sep 17 00:00:00 2001 From: Marica Date: Wed, 27 May 2020 20:28:47 +0530 Subject: [PATCH 074/449] fix: Grammar fixes (#21971) --- erpnext/buying/dashboard_fixtures.py | 6 +++--- erpnext/buying/desk_page/buying/buying.json | 8 ++++---- erpnext/stock/desk_page/stock/stock.json | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/erpnext/buying/dashboard_fixtures.py b/erpnext/buying/dashboard_fixtures.py index 0e2f78f347..186bfb23af 100644 --- a/erpnext/buying/dashboard_fixtures.py +++ b/erpnext/buying/dashboard_fixtures.py @@ -41,7 +41,7 @@ def get_dashboards(): { "chart": "Top Suppliers", "width": "Full"} ], "cards": [ - { "card": "This Year Purchases"}, + { "card": "Annual Purchase"}, { "card": "Purchase Orders to Receive"}, { "card": "Purchase Orders to Bill"}, { "card": "Active Suppliers"} @@ -142,7 +142,7 @@ def get_charts(): def get_number_cards(): return [ { - "name": "This Year Purchases", + "name": "Annual Purchase", "aggregate_function_based_on": "base_net_total", "doctype": "Number Card", "document_type": "Purchase Order", @@ -155,7 +155,7 @@ def get_number_cards(): ]), "function": "Sum", "is_public": 1, - "label": _("This Year Purchases"), + "label": _("Annual Purchase"), "owner": "Administrator", "show_percentage_stats": 1, "stats_time_interval": "Monthly" diff --git a/erpnext/buying/desk_page/buying/buying.json b/erpnext/buying/desk_page/buying/buying.json index ee18545fd4..88f0a2b421 100644 --- a/erpnext/buying/desk_page/buying/buying.json +++ b/erpnext/buying/desk_page/buying/buying.json @@ -55,7 +55,7 @@ "idx": 0, "is_standard": 1, "label": "Buying", - "modified": "2020-05-19 19:44:36.260982", + "modified": "2020-05-27 19:15:05.067756", "modified_by": "Administrator", "module": "Buying", "name": "Buying", @@ -66,7 +66,7 @@ "shortcuts": [ { "color": "#cef6d1", - "format": "{} available", + "format": "{} Available", "label": "Item", "link_to": "Item", "stats_filter": "{\n \"disabled\": 0\n}", @@ -82,7 +82,7 @@ }, { "color": "#ffe8cd", - "format": "{} to Receive", + "format": "{} To Receive", "label": "Purchase Order", "link_to": "Purchase Order", "stats_filter": "{\n \"company\": [\"like\", '%' + frappe.defaults.get_global_default(\"company\") + '%'],\n \"status\":[\"in\", [\"To Receive\", \"To Receive and Bill\"]]\n}", @@ -99,7 +99,7 @@ "type": "Report" }, { - "label": "Buying Dashboard", + "label": "Dashboard", "link_to": "Buying", "type": "Dashboard" } diff --git a/erpnext/stock/desk_page/stock/stock.json b/erpnext/stock/desk_page/stock/stock.json index 4506664c1e..23401fd761 100644 --- a/erpnext/stock/desk_page/stock/stock.json +++ b/erpnext/stock/desk_page/stock/stock.json @@ -58,7 +58,7 @@ "idx": 0, "is_standard": 1, "label": "Stock", - "modified": "2020-05-19 17:36:08.185652", + "modified": "2020-05-27 19:14:51.210671", "modified_by": "Administrator", "module": "Stock", "name": "Stock", @@ -69,7 +69,7 @@ "shortcuts": [ { "color": "#cef6d1", - "format": "{} available", + "format": "{} Available", "label": "Item", "link_to": "Item", "stats_filter": "{\n \"disabled\" : 0\n}", @@ -90,7 +90,7 @@ }, { "color": "#ffe8cd", - "format": "{} to Bill", + "format": "{} To Bill", "label": "Purchase Receipt", "link_to": "Purchase Receipt", "stats_filter": "{\n \"company\": [\"like\", '%' + frappe.defaults.get_global_default(\"company\") + '%'],\n \"status\": \"To Bill\"\n}", @@ -98,7 +98,7 @@ }, { "color": "#ffe8cd", - "format": "{} to Bill", + "format": "{} To Bill", "label": "Delivery Note", "link_to": "Delivery Note", "stats_filter": "{\n \"company\": [\"like\", '%' + frappe.defaults.get_global_default(\"company\") + '%'],\n \"status\": \"To Bill\"\n}", @@ -115,7 +115,7 @@ "type": "Report" }, { - "label": "Stock Dashboard", + "label": "Dashboard", "link_to": "Stock", "type": "Dashboard" } From 97ca1e7e71d460aade7e55dc1a749a41b8dd9182 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 27 May 2020 20:31:43 +0530 Subject: [PATCH 075/449] onbarding steps fix (#21959) (#21975) (cherry picked from commit a77032f926fde8244854715f6506e1f081fb3b95) Co-authored-by: Anupam Kumar --- erpnext/crm/module_onboarding/crm/crm.json | 2 +- .../create_and_send_quotation.json | 6 +++--- erpnext/crm/onboarding_step/create_lead/create_lead.json | 6 +++--- .../create_opportunity/create_opportunity.json | 2 +- .../introduction_to_crm/introduction_to_crm.json | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/erpnext/crm/module_onboarding/crm/crm.json b/erpnext/crm/module_onboarding/crm/crm.json index 694763f7c7..9b3d91ecee 100644 --- a/erpnext/crm/module_onboarding/crm/crm.json +++ b/erpnext/crm/module_onboarding/crm/crm.json @@ -16,7 +16,7 @@ "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/CRM", "idx": 0, "is_complete": 0, - "modified": "2020-05-20 12:53:47.029412", + "modified": "2020-05-27 11:33:09.941263", "modified_by": "Administrator", "module": "CRM", "name": "CRM", diff --git a/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json b/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json index a6edfd7e53..9201d77cf8 100644 --- a/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json +++ b/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json @@ -8,12 +8,12 @@ "is_mandatory": 0, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-14 17:30:07.887411", + "modified": "2020-05-27 11:30:28.237263", "modified_by": "Administrator", "name": "Create and Send Quotation", "owner": "Administrator", "reference_document": "Quotation", - "show_full_form": 0, + "show_full_form": 1, "title": "Create and Send Quotation", - "validate_action": 0 + "validate_action": 1 } \ No newline at end of file diff --git a/erpnext/crm/onboarding_step/create_lead/create_lead.json b/erpnext/crm/onboarding_step/create_lead/create_lead.json index 47a45d70a8..6ff0bd61f1 100644 --- a/erpnext/crm/onboarding_step/create_lead/create_lead.json +++ b/erpnext/crm/onboarding_step/create_lead/create_lead.json @@ -8,12 +8,12 @@ "is_mandatory": 0, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-14 17:28:36.441387", + "modified": "2020-05-27 11:30:59.493720", "modified_by": "Administrator", "name": "Create Lead", "owner": "Administrator", "reference_document": "Lead", - "show_full_form": 0, + "show_full_form": 1, "title": "Create Lead", - "validate_action": 0 + "validate_action": 1 } \ No newline at end of file diff --git a/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json b/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json index 231cf17bb5..9f996d9e2b 100644 --- a/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json +++ b/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json @@ -15,5 +15,5 @@ "reference_document": "Opportunity", "show_full_form": 0, "title": "Create Opportunity", - "validate_action": 0 + "validate_action": 1 } \ No newline at end of file diff --git a/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json b/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json index 552ade0fdd..545a756a59 100644 --- a/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json +++ b/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json @@ -8,12 +8,12 @@ "is_mandatory": 0, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-14 17:28:16.448676", + "modified": "2020-05-27 11:28:07.452857", "modified_by": "Administrator", "name": "Introduction to CRM", "owner": "Administrator", "show_full_form": 0, "title": "Introduction to CRM", - "validate_action": 0, + "validate_action": 1, "video_url": "https://www.youtube.com/watch?v=o9XCSZHJfpA" } \ No newline at end of file From 4ea24687fc443d96047a063fa1934e43065d6a1c Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 27 May 2020 20:32:11 +0530 Subject: [PATCH 076/449] fix: Module Onboarding for HR (#21963) (#21976) (cherry picked from commit d6d84a3c1561195810c6e1da9cdd16ad7ff62b18) Co-authored-by: Anurag Mishra <32095923+Anurag810@users.noreply.github.com> --- .../create_holiday_list/create_holiday_list.json | 4 ++-- .../onboarding_step/create_leave_type/create_leave_type.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/hr/onboarding_step/create_holiday_list/create_holiday_list.json b/erpnext/hr/onboarding_step/create_holiday_list/create_holiday_list.json index 25cb9febd0..208e394560 100644 --- a/erpnext/hr/onboarding_step/create_holiday_list/create_holiday_list.json +++ b/erpnext/hr/onboarding_step/create_holiday_list/create_holiday_list.json @@ -1,6 +1,6 @@ { "action": "Create Entry", - "creation": "2020-05-14 11:47:34.700174", + "creation": "2020-05-27 11:47:34.700174", "docstatus": 0, "doctype": "Onboarding Step", "idx": 0, @@ -13,7 +13,7 @@ "name": "Create Holiday list", "owner": "Administrator", "reference_document": "Holiday List", - "show_full_form": 0, + "show_full_form": 1, "title": "Create Holiday list", "validate_action": 0 } \ No newline at end of file diff --git a/erpnext/hr/onboarding_step/create_leave_type/create_leave_type.json b/erpnext/hr/onboarding_step/create_leave_type/create_leave_type.json index e8b97c2e5b..8cbfc5c81f 100644 --- a/erpnext/hr/onboarding_step/create_leave_type/create_leave_type.json +++ b/erpnext/hr/onboarding_step/create_leave_type/create_leave_type.json @@ -1,6 +1,6 @@ { "action": "Create Entry", - "creation": "2020-05-20 11:17:31.119312", + "creation": "2020-05-27 11:17:31.119312", "docstatus": 0, "doctype": "Onboarding Step", "idx": 0, @@ -13,7 +13,7 @@ "name": "Create Leave Type", "owner": "Administrator", "reference_document": "Leave Type", - "show_full_form": 0, + "show_full_form": 1, "title": "Create Leave Type", "validate_action": 0 } \ No newline at end of file From 402ed1000446f92a5a6169f492bcdd7316004a13 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 27 May 2020 15:01:30 +0000 Subject: [PATCH 077/449] fix: compare start and end time to prevent negative diff (#21974) * fix: compare start and end time to prevent negative diff * feat: parse date when comparing --- erpnext/manufacturing/doctype/job_card/job_card.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py index e43b98aee1..d97714a23e 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.py +++ b/erpnext/manufacturing/doctype/job_card/job_card.py @@ -102,8 +102,11 @@ class JobCard(Document): workstation_doc = frappe.get_cached_doc("Workstation", self.workstation) if (not workstation_doc.working_hours or cint(frappe.db.get_single_value("Manufacturing Settings", "allow_overtime"))): - row.remaining_time_in_mins -= time_diff_in_minutes(row.planned_end_time, - row.planned_start_time) + if getdate(row.planned_end_time) < getdate(row.planned_start_time): + row.planned_end_time = add_to_date(row.planned_start_time, minutes=row.time_in_mins) + row.remaining_time_in_mins = 0.0 + else: + row.remaining_time_in_mins -= time_diff_in_minutes(row.planned_end_time, row.planned_start_time) self.update_time_logs(row) return From 48b7a1a20f683d6cd69749e67a8eb79f0d7535e9 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 27 May 2020 20:36:28 +0530 Subject: [PATCH 078/449] fix: use get_datetime instead of getdate --- erpnext/manufacturing/doctype/job_card/job_card.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py index d97714a23e..c29d4ba3d5 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.py +++ b/erpnext/manufacturing/doctype/job_card/job_card.py @@ -102,7 +102,7 @@ class JobCard(Document): workstation_doc = frappe.get_cached_doc("Workstation", self.workstation) if (not workstation_doc.working_hours or cint(frappe.db.get_single_value("Manufacturing Settings", "allow_overtime"))): - if getdate(row.planned_end_time) < getdate(row.planned_start_time): + if get_datetime(row.planned_end_time) < get_datetime(row.planned_start_time): row.planned_end_time = add_to_date(row.planned_start_time, minutes=row.time_in_mins) row.remaining_time_in_mins = 0.0 else: From 01dda8a000f5785b19bfdcfdd2902b58980d1fc6 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 27 May 2020 20:50:20 +0530 Subject: [PATCH 079/449] fix: Filtering issues in opneing invoice creation tool (#21969) (#21979) (cherry picked from commit 0030b95595e2a74b0167a5e791d62371af4bb24a) Co-authored-by: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> --- .../opening_invoice_creation_tool.js | 71 ++++++++++++------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.js b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.js index 4d8da37efe..699eb08e17 100644 --- a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.js +++ b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.js @@ -11,21 +11,9 @@ frappe.ui.form.on('Opening Invoice Creation Tool', { }; }); - frm.set_query('cost_center', 'invoices', function(doc, cdt, cdn) { - return { - filters: { - 'company': doc.company - } - }; - }); - - frm.set_query('cost_center', function(doc) { - return { - filters: { - 'company': doc.company - } - }; - }); + if (frm.doc.company) { + frm.trigger('setup_company_filters'); + } }, refresh: function(frm) { @@ -51,19 +39,50 @@ frappe.ui.form.on('Opening Invoice Creation Tool', { }); }, - company: function(frm) { - frappe.call({ - method: 'erpnext.accounts.doctype.opening_invoice_creation_tool.opening_invoice_creation_tool.get_temporary_opening_account', - args: { - company: frm.doc.company - }, - callback: (r) => { - if (r.message) { - frm.doc.__onload.temporary_opening_account = r.message; - frm.trigger('update_invoice_table'); + setup_company_filters: function(frm) { + frm.set_query('cost_center', 'invoices', function(doc, cdt, cdn) { + return { + filters: { + 'company': doc.company + } + }; + }); + + frm.set_query('cost_center', function(doc) { + return { + filters: { + 'company': doc.company + } + }; + }); + + frm.set_query('temporary_opening_account', 'invoices', function(doc, cdt, cdn) { + return { + filters: { + 'company': doc.company } } - }) + }); + }, + + company: function(frm) { + if (frm.doc.company) { + + frm.trigger('setup_company_filters'); + + frappe.call({ + method: 'erpnext.accounts.doctype.opening_invoice_creation_tool.opening_invoice_creation_tool.get_temporary_opening_account', + args: { + company: frm.doc.company + }, + callback: (r) => { + if (r.message) { + frm.doc.__onload.temporary_opening_account = r.message; + frm.trigger('update_invoice_table'); + } + } + }) + } }, invoice_type: function(frm) { From 8644a7f1fc047dcfa800bbef22f0c84c6ea8e8fb Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 27 May 2020 20:50:28 +0530 Subject: [PATCH 080/449] fix: Do not allow backdated stock transactions in previous fiscal year (#21967) (#21980) (cherry picked from commit 873542bc7f57f6627d6a906f133ea179785a3795) Co-authored-by: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> --- erpnext/utilities/transaction_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py index ea96503dff..024aa6f31d 100644 --- a/erpnext/utilities/transaction_base.py +++ b/erpnext/utilities/transaction_base.py @@ -166,7 +166,7 @@ class TransactionBase(StatusUpdater): last_transaction_time = frappe.db.sql(""" select MAX(timestamp(posting_date, posting_time)) as posting_time from `tabStock Ledger Entry` - where docstatus = 1 and fiscal_year = %s""", (fiscal_year))[0][0] + where docstatus = 1""")[0][0] cur_doc_posting_datetime = "%s %s" % (self.posting_date, self.get("posting_time") or "00:00:00") From 8f1aed73fdd3d93938eef161a42c63b28aeb5152 Mon Sep 17 00:00:00 2001 From: Marica Date: Wed, 27 May 2020 20:57:02 +0530 Subject: [PATCH 081/449] fix: Buying Module fixes (#21966) * fix: Buying Module fixes * fix: Delete Report files as well * fix: Add Purchase Order Analysis to Stock & Accounting --- .../desk_page/accounting/accounting.json | 5 +- .../__init__.py | 0 .../purchase_order_items_to_be_billed.js | 8 --- .../purchase_order_items_to_be_billed.json | 33 ------------ .../purchase_order_items_to_be_billed.py | 26 --------- .../module_onboarding/buying/buying.json | 4 +- .../requested_items_to_be_ordered/__init__.py | 0 .../requested_items_to_be_ordered.json | 31 ----------- .../requested_items_to_order.js | 14 ++++- .../requested_items_to_order.py | 54 +++++++++++++------ erpnext/patches.txt | 1 + .../v13_0/delete_old_purchase_reports.py | 15 ++++++ erpnext/stock/desk_page/stock/stock.json | 4 +- .../__init__.py | 0 .../purchase_order_items_to_be_received.json | 34 ------------ .../__init__.py | 0 ..._order_items_to_be_received_or_billed.json | 34 ------------ 17 files changed, 74 insertions(+), 189 deletions(-) delete mode 100644 erpnext/accounts/report/purchase_order_items_to_be_billed/__init__.py delete mode 100644 erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.js delete mode 100644 erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.json delete mode 100644 erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.py delete mode 100644 erpnext/buying/report/requested_items_to_be_ordered/__init__.py delete mode 100644 erpnext/buying/report/requested_items_to_be_ordered/requested_items_to_be_ordered.json create mode 100644 erpnext/patches/v13_0/delete_old_purchase_reports.py delete mode 100644 erpnext/stock/report/purchase_order_items_to_be_received/__init__.py delete mode 100644 erpnext/stock/report/purchase_order_items_to_be_received/purchase_order_items_to_be_received.json delete mode 100644 erpnext/stock/report/purchase_order_items_to_be_received_or_billed/__init__.py delete mode 100644 erpnext/stock/report/purchase_order_items_to_be_received_or_billed/purchase_order_items_to_be_received_or_billed.json diff --git a/erpnext/accounts/desk_page/accounting/accounting.json b/erpnext/accounts/desk_page/accounting/accounting.json index 576d10c024..42fb9f4f37 100644 --- a/erpnext/accounts/desk_page/accounting/accounting.json +++ b/erpnext/accounts/desk_page/accounting/accounting.json @@ -18,7 +18,7 @@ { "hidden": 0, "label": "Accounts Payable", - "links": "[\n {\n \"description\": \"Bills raised by Suppliers.\",\n \"label\": \"Purchase Invoice\",\n \"name\": \"Purchase Invoice\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Supplier database.\",\n \"label\": \"Supplier\",\n \"name\": \"Supplier\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Bank/Cash transactions against party or for internal transfer\",\n \"label\": \"Payment Entry\",\n \"name\": \"Payment Entry\",\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Purchase Invoice\"\n ],\n \"doctype\": \"Purchase Invoice\",\n \"is_query_report\": true,\n \"label\": \"Accounts Payable\",\n \"name\": \"Accounts Payable\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Purchase Invoice\"\n ],\n \"doctype\": \"Purchase Invoice\",\n \"is_query_report\": true,\n \"label\": \"Accounts Payable Summary\",\n \"name\": \"Accounts Payable Summary\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Purchase Invoice\"\n ],\n \"doctype\": \"Purchase Invoice\",\n \"is_query_report\": true,\n \"label\": \"Purchase Register\",\n \"name\": \"Purchase Register\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Purchase Invoice\"\n ],\n \"doctype\": \"Purchase Invoice\",\n \"is_query_report\": true,\n \"label\": \"Item-wise Purchase Register\",\n \"name\": \"Item-wise Purchase Register\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Purchase Invoice\"\n ],\n \"doctype\": \"Purchase Invoice\",\n \"is_query_report\": true,\n \"label\": \"Purchase Order Items To Be Billed\",\n \"name\": \"Purchase Order Items To Be Billed\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Purchase Invoice\"\n ],\n \"doctype\": \"Purchase Invoice\",\n \"is_query_report\": true,\n \"label\": \"Received Items To Be Billed\",\n \"name\": \"Received Items To Be Billed\",\n \"type\": \"report\"\n }\n]" + "links": "[\n {\n \"description\": \"Bills raised by Suppliers.\",\n \"label\": \"Purchase Invoice\",\n \"name\": \"Purchase Invoice\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Supplier database.\",\n \"label\": \"Supplier\",\n \"name\": \"Supplier\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Bank/Cash transactions against party or for internal transfer\",\n \"label\": \"Payment Entry\",\n \"name\": \"Payment Entry\",\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Purchase Invoice\"\n ],\n \"doctype\": \"Purchase Invoice\",\n \"is_query_report\": true,\n \"label\": \"Accounts Payable\",\n \"name\": \"Accounts Payable\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Purchase Invoice\"\n ],\n \"doctype\": \"Purchase Invoice\",\n \"is_query_report\": true,\n \"label\": \"Accounts Payable Summary\",\n \"name\": \"Accounts Payable Summary\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Purchase Invoice\"\n ],\n \"doctype\": \"Purchase Invoice\",\n \"is_query_report\": true,\n \"label\": \"Purchase Register\",\n \"name\": \"Purchase Register\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Purchase Invoice\"\n ],\n \"doctype\": \"Purchase Invoice\",\n \"is_query_report\": true,\n \"label\": \"Item-wise Purchase Register\",\n \"name\": \"Item-wise Purchase Register\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Purchase Order\"\n ],\n \"doctype\": \"Purchase Order\",\n \"is_query_report\": true,\n \"label\": \"Purchase Order Analysis\",\n \"name\": \"Purchase Order Analysis\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Purchase Invoice\"\n ],\n \"doctype\": \"Purchase Invoice\",\n \"is_query_report\": true,\n \"label\": \"Received Items To Be Billed\",\n \"name\": \"Received Items To Be Billed\",\n \"type\": \"report\"\n }\n]" }, { "hidden": 0, @@ -94,10 +94,11 @@ "docstatus": 0, "doctype": "Desk Page", "extends_another_page": 0, + "hide_custom": 0, "idx": 0, "is_standard": 1, "label": "Accounting", - "modified": "2020-05-18 17:27:26.882340", + "modified": "2020-05-27 20:34:50.949772", "modified_by": "Administrator", "module": "Accounts", "name": "Accounting", diff --git a/erpnext/accounts/report/purchase_order_items_to_be_billed/__init__.py b/erpnext/accounts/report/purchase_order_items_to_be_billed/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.js b/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.js deleted file mode 100644 index 24c9592c24..0000000000 --- a/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.js +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors -// For license information, please see license.txt - -frappe.query_reports["Purchase Order Items To Be Billed"] = { - "filters": [ - - ] -} diff --git a/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.json b/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.json deleted file mode 100644 index 3645ec02e1..0000000000 --- a/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "add_total_row": 1, - "apply_user_permissions": 1, - "creation": "2013-05-28 15:54:16", - "disabled": 0, - "docstatus": 0, - "doctype": "Report", - "idx": 3, - "is_standard": "Yes", - "modified": "2017-02-24 20:00:24.302988", - "modified_by": "Administrator", - "module": "Accounts", - "name": "Purchase Order Items To Be Billed", - "owner": "Administrator", - "query": "select \n `tabPurchase Order`.`name` as \"Purchase Order:Link/Purchase Order:120\",\n `tabPurchase Order`.`transaction_date` as \"Date:Date:100\",\n\t`tabPurchase Order`.`supplier` as \"Supplier:Link/Supplier:120\",\n\t`tabPurchase Order`.`supplier_name` as \"Supplier Name::150\",\n\t`tabPurchase Order Item`.`project` as \"Project\",\n\t`tabPurchase Order Item`.item_code as \"Item Code:Link/Item:120\",\n\t`tabPurchase Order Item`.base_amount as \"Amount:Currency:100\",\n\t(`tabPurchase Order Item`.billed_amt * ifnull(`tabPurchase Order`.conversion_rate, 1)) as \"Billed Amount:Currency:100\", \n\t(`tabPurchase Order Item`.base_amount - (`tabPurchase Order Item`.billed_amt * ifnull(`tabPurchase Order`.conversion_rate, 1))) as \"Amount to Bill:Currency:100\",\n\t`tabPurchase Order Item`.item_name as \"Item Name::150\",\n\t`tabPurchase Order Item`.description as \"Description::200\",\n\t`tabPurchase Order`.company as \"Company:Link/Company:\"\nfrom\n\t`tabPurchase Order`, `tabPurchase Order Item`\nwhere\n\t`tabPurchase Order Item`.`parent` = `tabPurchase Order`.`name`\n\tand `tabPurchase Order`.docstatus = 1\n\tand `tabPurchase Order`.status != \"Closed\"\n and `tabPurchase Order Item`.amount > 0\n\tand (`tabPurchase Order Item`.billed_amt * ifnull(`tabPurchase Order`.conversion_rate, 1)) < `tabPurchase Order Item`.base_amount\norder by `tabPurchase Order`.transaction_date asc", - "ref_doctype": "Purchase Invoice", - "report_name": "Purchase Order Items To Be Billed", - "report_type": "Script Report", - "roles": [ - { - "role": "Accounts User" - }, - { - "role": "Purchase User" - }, - { - "role": "Auditor" - }, - { - "role": "Accounts Manager" - } - ] -} \ No newline at end of file diff --git a/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.py b/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.py deleted file mode 100644 index 99d0a36813..0000000000 --- a/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - -from __future__ import unicode_literals -import frappe -from frappe import _ -from erpnext.accounts.report.non_billed_report import get_ordered_to_be_billed_data - -def execute(filters=None): - columns = get_column() - args = get_args() - data = get_ordered_to_be_billed_data(args) - return columns, data - -def get_column(): - return [ - _("Purchase Order") + ":Link/Purchase Order:120", _("Status") + "::120", _("Date") + ":Date:100", - _("Suplier") + ":Link/Supplier:120", _("Suplier Name") + "::120", - _("Project") + ":Link/Project:120", _("Item Code") + ":Link/Item:120", - _("Amount") + ":Currency:100", _("Billed Amount") + ":Currency:100", _("Amount to Bill") + ":Currency:100", - _("Item Name") + "::120", _("Description") + "::120", _("Company") + ":Link/Company:120", - ] - -def get_args(): - return {'doctype': 'Purchase Order', 'party': 'supplier', - 'date': 'transaction_date', 'order': 'transaction_date', 'order_by': 'asc'} diff --git a/erpnext/buying/module_onboarding/buying/buying.json b/erpnext/buying/module_onboarding/buying/buying.json index 8c798b3473..8fe2f388b0 100644 --- a/erpnext/buying/module_onboarding/buying/buying.json +++ b/erpnext/buying/module_onboarding/buying/buying.json @@ -19,7 +19,7 @@ "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/buying", "idx": 0, "is_complete": 0, - "modified": "2020-05-19 20:03:55.776080", + "modified": "2020-05-27 17:17:52.075947", "modified_by": "Administrator", "module": "Buying", "name": "Buying", @@ -49,6 +49,6 @@ ], "subtitle": "Products, Purchases, Analysis and more.", "success_message": "The Buying Module is all set up!", - "title": "Let's Setup the Buying Module.", + "title": "Let's Set Up the Buying Module.", "user_can_dismiss": 1 } \ No newline at end of file diff --git a/erpnext/buying/report/requested_items_to_be_ordered/__init__.py b/erpnext/buying/report/requested_items_to_be_ordered/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/erpnext/buying/report/requested_items_to_be_ordered/requested_items_to_be_ordered.json b/erpnext/buying/report/requested_items_to_be_ordered/requested_items_to_be_ordered.json deleted file mode 100644 index bb112698d3..0000000000 --- a/erpnext/buying/report/requested_items_to_be_ordered/requested_items_to_be_ordered.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "add_total_row": 1, - "creation": "2013-05-13 16:10:02", - "disable_prepared_report": 0, - "disabled": 0, - "docstatus": 0, - "doctype": "Report", - "idx": 3, - "is_standard": "Yes", - "modified": "2019-04-18 19:02:03.099422", - "modified_by": "Administrator", - "module": "Buying", - "name": "Requested Items To Be Ordered", - "owner": "Administrator", - "prepared_report": 0, - "query": "select \n mr.name as \"Material Request:Link/Material Request:120\",\n\tmr.transaction_date as \"Date:Date:100\",\n\tmr_item.item_code as \"Item Code:Link/Item:120\",\n\tsum(ifnull(mr_item.stock_qty, 0)) as \"Qty:Float:100\",\n\tifnull(mr_item.stock_uom, '') as \"UOM:Link/UOM:100\",\n\tsum(ifnull(mr_item.ordered_qty, 0)) as \"Ordered Qty:Float:100\", \n\t(sum(mr_item.stock_qty) - sum(ifnull(mr_item.ordered_qty, 0))) as \"Qty to Order:Float:100\",\n\tmr_item.item_name as \"Item Name::150\",\n\tmr_item.description as \"Description::200\",\n\tmr.company as \"Company:Link/Company:\"\nfrom\n\t`tabMaterial Request` mr, `tabMaterial Request Item` mr_item\nwhere\n\tmr_item.parent = mr.name\n\tand mr.material_request_type = \"Purchase\"\n\tand mr.docstatus = 1\n\tand mr.status != \"Stopped\"\ngroup by mr.name, mr_item.item_code\nhaving\n\tsum(ifnull(mr_item.ordered_qty, 0)) < sum(ifnull(mr_item.stock_qty, 0))\norder by mr.transaction_date asc", - "ref_doctype": "Purchase Order", - "report_name": "Requested Items To Be Ordered", - "report_type": "Query Report", - "roles": [ - { - "role": "Stock User" - }, - { - "role": "Purchase Manager" - }, - { - "role": "Purchase User" - } - ] - } \ No newline at end of file diff --git a/erpnext/buying/report/requested_items_to_order/requested_items_to_order.js b/erpnext/buying/report/requested_items_to_order/requested_items_to_order.js index 21adb13547..9555e8252a 100644 --- a/erpnext/buying/report/requested_items_to_order/requested_items_to_order.js +++ b/erpnext/buying/report/requested_items_to_order/requested_items_to_order.js @@ -35,7 +35,7 @@ frappe.query_reports["Requested Items to Order"] = { "fieldtype": "Link", "width": "80", "options": "Material Request", - "get_query": () =>{ + "get_query": () => { return { filters: { "docstatus": 1, @@ -45,6 +45,18 @@ frappe.query_reports["Requested Items to Order"] = { } } }, + { + "fieldname": "item_code", + "label": __("Item"), + "fieldtype": "Link", + "width": "80", + "options": "Item", + "get_query": () => { + return { + query: "erpnext.controllers.queries.item_query" + } + } + }, { "fieldname": "group_by_mr", "label": __("Group by Material Request"), diff --git a/erpnext/buying/report/requested_items_to_order/requested_items_to_order.py b/erpnext/buying/report/requested_items_to_order/requested_items_to_order.py index a021d3c1ca..cca01b104a 100644 --- a/erpnext/buying/report/requested_items_to_order/requested_items_to_order.py +++ b/erpnext/buying/report/requested_items_to_order/requested_items_to_order.py @@ -44,6 +44,9 @@ def get_conditions(filters): if filters.get("material_request"): conditions += " and mr.name = '{0}'".format(filters.get("material_request")) + if filters.get("item_code"): + conditions += " and mr_item.item_code = '{0}'".format(filters.get("item_code")) + return conditions def get_data(filters, conditions): @@ -74,25 +77,41 @@ def get_data(filters, conditions): return data +def update_qty_columns(row_to_update, data_row): + fields = ["qty", "ordered_qty", "qty_to_order"] + for field in fields: + row_to_update[field] += flt(data_row[field]) + def prepare_data(data, filters): """Prepare consolidated Report data and Chart data""" - material_request_map = {} + material_request_map, item_qty_map = {}, {} for row in data: - if not row["material_request"] in material_request_map: - # create an entry with mr as key - row_copy = copy.deepcopy(row) - material_request_map[row["material_request"]] = row_copy + # item wise map for charts + if not row["item_code"] in item_qty_map: + item_qty_map[row["item_code"]] = { + "qty" : row["qty"], + "ordered_qty" : row["ordered_qty"], + "qty_to_order" : row["qty_to_order"] + } else: - mr_row = material_request_map[row["material_request"]] - mr_row["required_date"] = min(getdate(mr_row["required_date"]), getdate(row["required_date"])) + item_entry = item_qty_map[row["item_code"]] + update_qty_columns(item_entry, row) - #sum numeric rows - fields = ["qty", "ordered_qty", "qty_to_order"] - for field in fields: - mr_row[field] = flt(mr_row[field]) + flt(row[field]) + if filters.get("group_by_mr"): + # consolidated material request map for group by filter + if not row["material_request"] in material_request_map: + # create an entry with mr as key + row_copy = copy.deepcopy(row) + material_request_map[row["material_request"]] = row_copy + else: + mr_row = material_request_map[row["material_request"]] + mr_row["required_date"] = min(getdate(mr_row["required_date"]), getdate(row["required_date"])) - chart_data = prepare_chart_data(material_request_map) + #sum numeric columns + update_qty_columns(mr_row, row) + + chart_data = prepare_chart_data(item_qty_map) if filters.get("group_by_mr"): data =[] @@ -102,12 +121,15 @@ def prepare_data(data, filters): return data, chart_data -def prepare_chart_data(data): +def prepare_chart_data(item_data): labels, qty_to_order, ordered_qty = [], [], [] - for row in data: - mr_row = data[row] - labels.append(mr_row["material_request"]) + if len(item_data) > 30: + item_data = dict(list(item_data.items())[:30]) + + for row in item_data: + mr_row = item_data[row] + labels.append(row) qty_to_order.append(mr_row["qty_to_order"]) ordered_qty.append(mr_row["ordered_qty"]) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 481cd35d49..1d2bb12d8c 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -692,3 +692,4 @@ erpnext.patches.v13_0.set_company_field_in_healthcare_doctypes #2020-05-25 erpnext.patches.v12_0.update_bom_in_so_mr execute:frappe.delete_doc("Report", "Department Analytics") execute:frappe.rename_doc("Desk Page", "Loan Management", "Loan", force=True) +erpnext.patches.v13_0.delete_old_purchase_reports \ No newline at end of file diff --git a/erpnext/patches/v13_0/delete_old_purchase_reports.py b/erpnext/patches/v13_0/delete_old_purchase_reports.py new file mode 100644 index 0000000000..8271d2e6dc --- /dev/null +++ b/erpnext/patches/v13_0/delete_old_purchase_reports.py @@ -0,0 +1,15 @@ +# Copyright (c) 2019, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals + +import frappe + +def execute(): + reports_to_delete = ["Requested Items To Be Ordered", + "Purchase Order Items To Be Received or Billed","Purchase Order Items To Be Received", + "Purchase Order Items To Be Billed"] + + for report in reports_to_delete: + if frappe.db.exists("Report", report): + frappe.delete_doc("Report", report) \ No newline at end of file diff --git a/erpnext/stock/desk_page/stock/stock.json b/erpnext/stock/desk_page/stock/stock.json index 23401fd761..9404292c04 100644 --- a/erpnext/stock/desk_page/stock/stock.json +++ b/erpnext/stock/desk_page/stock/stock.json @@ -33,7 +33,7 @@ { "hidden": 0, "label": "Key Reports", - "links": "[\n {\n \"dependencies\": [\n \"Item Price\"\n ],\n \"doctype\": \"Item Price\",\n \"is_query_report\": false,\n \"label\": \"Item-wise Price List Rate\",\n \"name\": \"Item-wise Price List Rate\",\n \"onboard\": 1,\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Stock Entry\"\n ],\n \"doctype\": \"Stock Entry\",\n \"is_query_report\": true,\n \"label\": \"Stock Analytics\",\n \"name\": \"Stock Analytics\",\n \"onboard\": 1,\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Delivery Note\"\n ],\n \"doctype\": \"Delivery Note\",\n \"is_query_report\": true,\n \"label\": \"Delivery Note Trends\",\n \"name\": \"Delivery Note Trends\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Purchase Receipt\"\n ],\n \"doctype\": \"Purchase Receipt\",\n \"is_query_report\": true,\n \"label\": \"Purchase Receipt Trends\",\n \"name\": \"Purchase Receipt Trends\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Delivery Note\"\n ],\n \"doctype\": \"Delivery Note\",\n \"is_query_report\": true,\n \"label\": \"Ordered Items To Be Delivered\",\n \"name\": \"Ordered Items To Be Delivered\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Purchase Receipt\"\n ],\n \"doctype\": \"Purchase Receipt\",\n \"is_query_report\": true,\n \"label\": \"Purchase Order Items To Be Received\",\n \"name\": \"Purchase Order Items To Be Received\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Bin\"\n ],\n \"doctype\": \"Bin\",\n \"is_query_report\": true,\n \"label\": \"Item Shortage Report\",\n \"name\": \"Item Shortage Report\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Batch\"\n ],\n \"doctype\": \"Batch\",\n \"is_query_report\": true,\n \"label\": \"Batch-Wise Balance History\",\n \"name\": \"Batch-Wise Balance History\",\n \"type\": \"report\"\n }\n]" + "links": "[\n {\n \"dependencies\": [\n \"Item Price\"\n ],\n \"doctype\": \"Item Price\",\n \"is_query_report\": false,\n \"label\": \"Item-wise Price List Rate\",\n \"name\": \"Item-wise Price List Rate\",\n \"onboard\": 1,\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Stock Entry\"\n ],\n \"doctype\": \"Stock Entry\",\n \"is_query_report\": true,\n \"label\": \"Stock Analytics\",\n \"name\": \"Stock Analytics\",\n \"onboard\": 1,\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Delivery Note\"\n ],\n \"doctype\": \"Delivery Note\",\n \"is_query_report\": true,\n \"label\": \"Delivery Note Trends\",\n \"name\": \"Delivery Note Trends\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Purchase Receipt\"\n ],\n \"doctype\": \"Purchase Receipt\",\n \"is_query_report\": true,\n \"label\": \"Purchase Receipt Trends\",\n \"name\": \"Purchase Receipt Trends\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Delivery Note\"\n ],\n \"doctype\": \"Delivery Note\",\n \"is_query_report\": true,\n \"label\": \"Ordered Items To Be Delivered\",\n \"name\": \"Ordered Items To Be Delivered\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Purchase Order\"\n ],\n \"doctype\": \"Purchase Order\",\n \"is_query_report\": true,\n \"label\": \"Purchase Order Analysis\",\n \"name\": \"Purchase Order Analysis\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Bin\"\n ],\n \"doctype\": \"Bin\",\n \"is_query_report\": true,\n \"label\": \"Item Shortage Report\",\n \"name\": \"Item Shortage Report\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Batch\"\n ],\n \"doctype\": \"Batch\",\n \"is_query_report\": true,\n \"label\": \"Batch-Wise Balance History\",\n \"name\": \"Batch-Wise Balance History\",\n \"type\": \"report\"\n }\n]" }, { "hidden": 0, @@ -58,7 +58,7 @@ "idx": 0, "is_standard": 1, "label": "Stock", - "modified": "2020-05-27 19:14:51.210671", + "modified": "2020-05-27 20:38:25.255323", "modified_by": "Administrator", "module": "Stock", "name": "Stock", diff --git a/erpnext/stock/report/purchase_order_items_to_be_received/__init__.py b/erpnext/stock/report/purchase_order_items_to_be_received/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/erpnext/stock/report/purchase_order_items_to_be_received/purchase_order_items_to_be_received.json b/erpnext/stock/report/purchase_order_items_to_be_received/purchase_order_items_to_be_received.json deleted file mode 100644 index dfaa9ed6cc..0000000000 --- a/erpnext/stock/report/purchase_order_items_to_be_received/purchase_order_items_to_be_received.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "add_total_row": 1, - "creation": "2013-02-22 18:01:55", - "disable_prepared_report": 0, - "disabled": 0, - "docstatus": 0, - "doctype": "Report", - "idx": 3, - "is_standard": "Yes", - "modified": "2019-04-01 22:12:05.573343", - "modified_by": "Administrator", - "module": "Stock", - "name": "Purchase Order Items To Be Received", - "owner": "Administrator", - "prepared_report": 0, - "query": "select \n `tabPurchase Order`.`name` as \"Purchase Order:Link/Purchase Order:120\",\n `tabPurchase Order`.`status` as \"Status:Data:120\",\n\t`tabPurchase Order`.`transaction_date` as \"Date:Date:100\",\n\t`tabPurchase Order Item`.`schedule_date` as \"Reqd by Date:Date:110\",\n\t`tabPurchase Order`.`supplier` as \"Supplier:Link/Supplier:120\",\n\t`tabPurchase Order`.`supplier_name` as \"Supplier Name::150\",\n\t`tabPurchase Order Item`.`project` as \"Project\",\n\t`tabPurchase Order Item`.item_code as \"Item Code:Link/Item:120\",\n\t`tabPurchase Order Item`.qty as \"Qty:Float:100\",\n\t`tabPurchase Order Item`.received_qty as \"Received Qty:Float:100\", \n\t(`tabPurchase Order Item`.qty - ifnull(`tabPurchase Order Item`.received_qty, 0)) as \"Qty to Receive:Float:100\",\n `tabPurchase Order Item`.warehouse as \"Warehouse:Link/Warehouse:150\",\n\t`tabPurchase Order Item`.item_name as \"Item Name::150\",\n\t`tabPurchase Order Item`.description as \"Description::200\",\n `tabPurchase Order Item`.brand as \"Brand::100\",\n\t`tabPurchase Order`.`company` as \"Company:Link/Company:\"\nfrom\n\t`tabPurchase Order`, `tabPurchase Order Item`\nwhere\n\t`tabPurchase Order Item`.`parent` = `tabPurchase Order`.`name`\n\tand `tabPurchase Order`.docstatus = 1\n\tand `tabPurchase Order`.status not in (\"Stopped\", \"Closed\")\n\tand ifnull(`tabPurchase Order Item`.received_qty, 0) < ifnull(`tabPurchase Order Item`.qty, 0)\norder by `tabPurchase Order`.transaction_date asc", - "ref_doctype": "Purchase Receipt", - "report_name": "Purchase Order Items To Be Received", - "report_type": "Query Report", - "roles": [ - { - "role": "Stock Manager" - }, - { - "role": "Stock User" - }, - { - "role": "Purchase User" - }, - { - "role": "Accounts User" - } - ] -} \ No newline at end of file diff --git a/erpnext/stock/report/purchase_order_items_to_be_received_or_billed/__init__.py b/erpnext/stock/report/purchase_order_items_to_be_received_or_billed/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/erpnext/stock/report/purchase_order_items_to_be_received_or_billed/purchase_order_items_to_be_received_or_billed.json b/erpnext/stock/report/purchase_order_items_to_be_received_or_billed/purchase_order_items_to_be_received_or_billed.json deleted file mode 100644 index 48c0f423fd..0000000000 --- a/erpnext/stock/report/purchase_order_items_to_be_received_or_billed/purchase_order_items_to_be_received_or_billed.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "add_total_row": 0, - "creation": "2019-09-16 14:10:33.102865", - "disable_prepared_report": 0, - "disabled": 0, - "docstatus": 0, - "doctype": "Report", - "idx": 0, - "is_standard": "Yes", - "modified": "2019-09-21 15:19:55.710578", - "modified_by": "Administrator", - "module": "Stock", - "name": "Purchase Order Items To Be Received or Billed", - "owner": "Administrator", - "prepared_report": 0, - "query": "SELECT\n\t`poi_pri`.`purchase_order` as \"Purchase Order:Link/Purchase Order:120\",\n\t`poi_pri`.`status` as \"Status:Data:120\",\n\t`poi_pri`.`transaction_date` as \"Date:Date:100\",\n\t`poi_pri`.`schedule_date` as \"Reqd by Date:Date:110\",\n\t`poi_pri`.`supplier` as \"Supplier:Link/Supplier:120\",\n\t`poi_pri`.`supplier_name` as \"Supplier Name::150\",\n\t`poi_pri`.`item_code` as \"Item Code:Link/Item:120\",\n\t`poi_pri`.`qty` as \"Qty:Float:100\",\n\t`poi_pri`.`base_amount` as \"Base Amount:Currency:100\",\n\t`poi_pri`.`received_qty` as \"Received Qty:Float:100\",\n\t`poi_pri`.`received_amount` as \"Received Qty Amount:Currency:100\",\n\t`poi_pri`.`qty_to_receive` as \"Qty to Receive:Float:100\",\n\t`poi_pri`.`amount_to_be_received` as \"Amount to Receive:Currency:100\",\n\t`poi_pri`.`billed_amount` as \"Billed Amount:Currency:100\",\n\t`poi_pri`.`amount_to_be_billed` as \"Amount To Be Billed:Currency:100\",\n\tSUM(`pii`.`qty`) AS \"Billed Qty:Float:100\",\n\t`poi_pri`.qty - SUM(`pii`.`qty`) AS \"Qty To Be Billed:Float:100\",\n\t`poi_pri`.`warehouse` as \"Warehouse:Link/Warehouse:150\",\n\t`poi_pri`.`item_name` as \"Item Name::150\",\n\t`poi_pri`.`description` as \"Description::200\",\n\t`poi_pri`.`brand` as \"Brand::100\",\n\t`poi_pri`.`project` as \"Project\",\n\t`poi_pri`.`company` as \"Company:Link/Company:\"\nFROM\n\t(SELECT\n\t\t`po`.`name` AS 'purchase_order',\n\t\t`po`.`status`,\n\t\t`po`.`company`,\n\t\t`poi`.`warehouse`,\n\t\t`poi`.`brand`,\n\t\t`poi`.`description`,\n\t\t`po`.`transaction_date`,\n\t\t`poi`.`schedule_date`,\n\t\t`po`.`supplier`,\n\t\t`po`.`supplier_name`,\n\t\t`poi`.`project`,\n\t\t`poi`.`item_code`,\n\t\t`poi`.`item_name`,\n\t\t`poi`.`qty`,\n\t\t`poi`.`base_amount`,\n\t\t`poi`.`received_qty`,\n\t\t(`poi`.billed_amt * ifnull(`po`.conversion_rate, 1)) as billed_amount,\n\t\t(`poi`.base_amount - (`poi`.billed_amt * ifnull(`po`.conversion_rate, 1))) as amount_to_be_billed,\n\t\t`poi`.`qty` - IFNULL(`poi`.`received_qty`, 0) AS 'qty_to_receive',\n\t\t(`poi`.`qty` - IFNULL(`poi`.`received_qty`, 0)) * `poi`.`rate` AS 'amount_to_be_received',\n\t\tSUM(`pri`.`amount`) AS 'received_amount',\n\t\t`poi`.`name` AS 'poi_name',\n\t\t`pri`.`name` AS 'pri_name'\n\tFROM\n\t\t`tabPurchase Order` po\n\t\tLEFT JOIN `tabPurchase Order Item` poi\n\t\tON `poi`.`parent` = `po`.`name`\n\t\tLEFT JOIN `tabPurchase Receipt Item` pri\n\t\tON `pri`.`purchase_order_item` = `poi`.`name`\n\t\t\tAND `pri`.`docstatus`=1\n\tWHERE\n\t\t`po`.`status` not in ('Stopped', 'Closed')\n\t\tAND `po`.`docstatus` = 1\n\t\tAND IFNULL(`poi`.`received_qty`, 0) < IFNULL(`poi`.`qty`, 0)\n\tGROUP BY `poi`.`name`\n\tORDER BY `po`.`transaction_date` ASC\n\t) poi_pri\n\tLEFT JOIN `tabPurchase Invoice Item` pii\n\tON `pii`.`po_detail` = `poi_pri`.`poi_name`\n\t\tAND `pii`.`docstatus`=1\nGROUP BY `poi_pri`.`poi_name`", - "ref_doctype": "Purchase Order", - "report_name": "Purchase Order Items To Be Received or Billed", - "report_type": "Query Report", - "roles": [ - { - "role": "Purchase Manager" - }, - { - "role": "Purchase User" - }, - { - "role": "Stock User" - }, - { - "role": "Stock Manager" - } - ] -} \ No newline at end of file From c63b68949785a076a6d4d3bd6dcea0f5cc9eecda Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Wed, 27 May 2020 20:29:10 +0530 Subject: [PATCH 082/449] fix: Total for ageing column 121-Above (#21972) (cherry picked from commit 152377f84d7de8b8a0d20d970660ee107d5eca26) --- .../accounts/report/accounts_receivable/accounts_receivable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py index a0a1b9783a..c6f852a66d 100755 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py @@ -534,7 +534,7 @@ class ReceivablePayableReport(object): def get_ageing_data(self, entry_date, row): # [0-30, 30-60, 60-90, 90-120, 120-above] - row.range1 = row.range2 = row.range3 = row.range4 = range5 = 0.0 + row.range1 = row.range2 = row.range3 = row.range4 = row.range5 = 0.0 if not (self.age_as_on and entry_date): return From 962e9bcd71da73f1f0c77a400402c71ef49f9f11 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Wed, 27 May 2020 21:53:29 +0530 Subject: [PATCH 083/449] fix: raw material warehouse in Production Planning Report (#21983) --- .../production_planning_report/production_planning_report.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/erpnext/manufacturing/report/production_planning_report/production_planning_report.py b/erpnext/manufacturing/report/production_planning_report/production_planning_report.py index b5e6c6fc85..5ac3923187 100644 --- a/erpnext/manufacturing/report/production_planning_report/production_planning_report.py +++ b/erpnext/manufacturing/report/production_planning_report/production_planning_report.py @@ -220,6 +220,9 @@ class ProductionPlanReport(object): if item_details: warehouses = [item_details["default_warehouse"]] + if self.filters.raw_material_warehouse: + warehouses = get_child_warehouses(self.filters.raw_material_warehouse) + d.remaining_qty = d.required_qty self.pick_materials_from_warehouses(d, data, warehouses) From 5255b714efbc78b26d8b02225a91d8ccc8b7a483 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 28 May 2020 09:55:24 +0530 Subject: [PATCH 084/449] refactor: showing the order's data for past period --- .../exponential_smoothing_forecasting.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py index 1b49df6af8..cac8067729 100644 --- a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py +++ b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py @@ -21,8 +21,6 @@ class ExponentialSmoothingForecast(object): if value.get(period.key) and not forecast_data: value[forecast_key] = flt(value.get("avg", 0)) or flt(value.get(period.key)) - # will be use to forecaset next period - forecast_data.append([value.get(period.key), value.get(forecast_key)]) elif forecast_data: previous_period_data = forecast_data[-1] value[forecast_key] = (previous_period_data[1] + @@ -31,6 +29,10 @@ class ExponentialSmoothingForecast(object): ) ) + if value.get(forecast_key): + # will be use to forecaset next period + forecast_data.append([value.get(period.key), value.get(forecast_key)]) + class ForecastingReport(ExponentialSmoothingForecast): def __init__(self, filters=None): self.filters = frappe._dict(filters or {}) @@ -78,7 +80,9 @@ class ForecastingReport(ExponentialSmoothingForecast): list_of_period_value = [value.get(p.key, 0) for p in self.period_list] if list_of_period_value: - value["avg"] = sum(list_of_period_value) / len(list_of_period_value) + total_qty = [1 for d in list_of_period_value if d] + if total_qty: + value["avg"] = flt(sum(list_of_period_value)) / flt(sum(total_qty)) def get_data_for_forecast(self): cond = "" @@ -152,15 +156,19 @@ class ForecastingReport(ExponentialSmoothingForecast): "width": 130 }] - width = 150 if self.filters.periodicity in ['Yearly', "Half-Yearly", "Quarterly"] else 100 + width = 180 if self.filters.periodicity in ['Yearly', "Half-Yearly", "Quarterly"] else 100 for period in self.period_list: if (self.filters.periodicity in ['Yearly', "Half-Yearly", "Quarterly"] or period.from_date >= getdate(self.filters.from_date)): - forecast_key = 'forecast_' + period.key + forecast_key = period.key + label = _(period.label) + if period.from_date >= getdate(self.filters.from_date): + forecast_key = 'forecast_' + period.key + label = _(period.label) + " " + _("(Forecast)") columns.append({ - "label": _(period.label), + "label": label, "fieldname": forecast_key, "fieldtype": self.fieldtype, "width": width, From b8ffaa7f07b9986d2970d0880fc5d743e43078c7 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 28 May 2020 10:10:22 +0530 Subject: [PATCH 085/449] refactor: display draft job card as Open job card --- .../job_card_summary/job_card_summary.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/erpnext/manufacturing/report/job_card_summary/job_card_summary.py b/erpnext/manufacturing/report/job_card_summary/job_card_summary.py index 953d8201a7..b1bff3500c 100644 --- a/erpnext/manufacturing/report/job_card_summary/job_card_summary.py +++ b/erpnext/manufacturing/report/job_card_summary/job_card_summary.py @@ -16,7 +16,7 @@ def execute(filters=None): def get_data(filters): query_filters = { - "docstatus": ("=", 1), + "docstatus": ("<", 2), "posting_date": ("between", [filters.from_date, filters.to_date]) } @@ -35,7 +35,7 @@ def get_data(filters): job_cards = [d.name for d in data] job_card_time_filter = { - "docstatus": 1, + "docstatus": ("<", 2), "parent": ("in", job_cards), } @@ -47,27 +47,28 @@ def get_data(filters): res = [] for d in data: - if d.status == "Material Transferred": + if d.status != "Completed": d.status = "Open" if job_card_time_details.get(d.name): d.from_time = job_card_time_details.get(d.name).from_time d.to_time = job_card_time_details.get(d.name).to_time - res.append(d) + + res.append(d) return res def get_chart_data(job_card_details, filters): labels, periodic_data = prepare_chart_data(job_card_details, filters) - pending, completed = [], [] + open_job_cards, completed = [], [] datasets = [] for d in labels: - pending.append(periodic_data.get("Pending").get(d)) + open_job_cards.append(periodic_data.get("Open").get(d)) completed.append(periodic_data.get("Completed").get(d)) - datasets.append({"name": "Pending", "values": pending}) + datasets.append({"name": "Open", "values": open_job_cards}) datasets.append({"name": "Completed", "values": completed}) chart = { @@ -84,7 +85,7 @@ def prepare_chart_data(job_card_details, filters): labels = [] periodic_data = { - "Pending": {}, + "Open": {}, "Completed": {} } @@ -98,7 +99,7 @@ def prepare_chart_data(job_card_details, filters): for d in job_card_details: if getdate(d.posting_date) > from_date and getdate(d.posting_date) <= end_date: - status = "Completed" if d.status == "Completed" else "Pending" + status = "Completed" if d.status == "Completed" else "Open" if periodic_data.get(status).get(period): periodic_data[status][period] += 1 From 2f45fad47d5742234e60d4b90f846860d716fb6f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 28 May 2020 14:43:38 +0530 Subject: [PATCH 086/449] CRM dashboard fixes (#21989) (#22003) (cherry picked from commit f10771029a88f987795eb46e5081cb109b1a8d6f) Co-authored-by: Anupam Kumar --- erpnext/crm/dashboard_fixtures.py | 24 ++++++++++++++++++------ erpnext/crm/desk_page/crm/crm.json | 4 ++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/erpnext/crm/dashboard_fixtures.py b/erpnext/crm/dashboard_fixtures.py index 16904b3429..0535cbbcc9 100644 --- a/erpnext/crm/dashboard_fixtures.py +++ b/erpnext/crm/dashboard_fixtures.py @@ -21,8 +21,8 @@ def get_dashboards(): { "chart": "Opportunity Trends", "width": "Full"}, { "chart": "Won Opportunities", "width": "Full" }, { "chart": "Territory Wise Opportunity Count", "width": "Half"}, - { "chart": "Territory Wise Sales", "width": "Half"}, { "chart": "Opportunities via Campaigns", "width": "Half" }, + { "chart": "Territory Wise Sales", "width": "Full"}, { "chart": "Lead Source", "width": "Half"} ], "cards": [ @@ -59,7 +59,7 @@ def get_charts(): 'is_public': 1, 'timeseries': 1, "owner": "Administrator", - "filters_json": json.dumps([["Opportunity", "company", "=", company, False]]), + "filters_json": json.dumps([]), "type": "Bar" }, { @@ -90,7 +90,11 @@ def get_charts(): 'timeseries': 1, "owner": "Administrator", "filters_json": json.dumps([["Opportunity", "company", "=", company, False]]), - "type": "Pie" + "type": "Pie", + "custom_options": json.dumps({ + "truncateLegends": 1, + "maxSlices": 8 + }) }, { "name": "Won Opportunities", @@ -123,7 +127,11 @@ def get_charts(): ["Opportunity", "company", "=", company, False] ]), "owner": "Administrator", - "type": "Donut" + "type": "Donut", + "custom_options": json.dumps({ + "truncateLegends": 1, + "maxSlices": 8 + }) }, { "name": "Territory Wise Sales", @@ -140,7 +148,7 @@ def get_charts(): ["Opportunity", "company", "=", company, False], ["Opportunity", "status", "=", "Converted", False] ]), - "type": "Donut" + "type": "Bar" }, { "name": "Lead Source", @@ -152,7 +160,11 @@ def get_charts(): "document_type": "Lead", 'is_public': 1, "owner": "Administrator", - "type": "Pie" + "type": "Pie", + "custom_options": json.dumps({ + "truncateLegends": 1, + "maxSlices": 8 + }) }] def get_number_cards(): diff --git a/erpnext/crm/desk_page/crm/crm.json b/erpnext/crm/desk_page/crm/crm.json index 2fc4582917..013fabef89 100644 --- a/erpnext/crm/desk_page/crm/crm.json +++ b/erpnext/crm/desk_page/crm/crm.json @@ -42,7 +42,7 @@ "idx": 0, "is_standard": 1, "label": "CRM", - "modified": "2020-05-20 12:11:36.250491", + "modified": "2020-05-28 13:29:28.253749", "modified_by": "Administrator", "module": "CRM", "name": "CRM", @@ -76,7 +76,7 @@ "type": "Report" }, { - "label": "CRM Dashboard", + "label": "Dashboard", "link_to": "CRM", "type": "Dashboard" } From 4afda7601574a93e9232d06341556dbcf0f142ab Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 28 May 2020 15:06:38 +0530 Subject: [PATCH 087/449] fix: set fiscal year for Profit and Loss chart --- erpnext/accounts/dashboard_fixtures.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/dashboard_fixtures.py b/erpnext/accounts/dashboard_fixtures.py index 1eed5a0f9c..421c86dba0 100644 --- a/erpnext/accounts/dashboard_fixtures.py +++ b/erpnext/accounts/dashboard_fixtures.py @@ -60,9 +60,9 @@ def get_charts(): "report_name": "Profit and Loss Statement", "filters_json": json.dumps({ "company": company.name, - "filter_based_on": "Date Range", - "period_start_date": get_date_str(fiscal_year[1]), - "period_end_date": get_date_str(fiscal_year[2]), + "filter_based_on": "Fiscal Year", + "from_fiscal_year": fiscal_year[0], + "to_fiscal_year": fiscal_year[0], "periodicity": "Monthly", "include_default_book_entries": 1 }), From fa0b73ce2594d6ceb3cf9cddefb3e328da147733 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 28 May 2020 09:50:22 +0000 Subject: [PATCH 088/449] refactor: clean up desk pages (#22004) (#22007) * refactor: clean up desk pages * refactor: update label for CRM --- erpnext/buying/desk_page/buying/buying.json | 8 +- erpnext/crm/desk_page/crm/crm.json | 4 +- erpnext/crm/module_onboarding/crm/crm.json | 4 +- erpnext/hr/desk_page/hr/hr.json | 19 ++-- .../loan_management.json => loan/loan.json} | 6 +- .../manufacturing/manufacturing.json | 6 +- .../projects/desk_page/projects/projects.json | 6 +- .../selling/desk_page/selling/selling.json | 94 +++++++++++++++++++ .../support/desk_page/support/support.json | 25 ++--- 9 files changed, 141 insertions(+), 31 deletions(-) rename erpnext/loan_management/desk_page/{loan_management/loan_management.json => loan/loan.json} (96%) create mode 100644 erpnext/selling/desk_page/selling/selling.json diff --git a/erpnext/buying/desk_page/buying/buying.json b/erpnext/buying/desk_page/buying/buying.json index 88f0a2b421..c4cdce1615 100644 --- a/erpnext/buying/desk_page/buying/buying.json +++ b/erpnext/buying/desk_page/buying/buying.json @@ -36,7 +36,7 @@ "links": "[\n {\n \"is_query_report\": true,\n \"label\": \"Items To Be Requested\",\n \"name\": \"Items To Be Requested\",\n \"onboard\": 1,\n \"reference_doctype\": \"Item\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Item-wise Purchase History\",\n \"name\": \"Item-wise Purchase History\",\n \"onboard\": 1,\n \"reference_doctype\": \"Item\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Subcontracted Raw Materials To Be Transferred\",\n \"name\": \"Subcontracted Raw Materials To Be Transferred\",\n \"reference_doctype\": \"Purchase Order\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Subcontracted Item To Be Received\",\n \"name\": \"Subcontracted Item To Be Received\",\n \"reference_doctype\": \"Purchase Order\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Quoted Item Comparison\",\n \"name\": \"Quoted Item Comparison\",\n \"onboard\": 1,\n \"reference_doctype\": \"Supplier Quotation\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Material Requests for which Supplier Quotations are not created\",\n \"name\": \"Material Requests for which Supplier Quotations are not created\",\n \"reference_doctype\": \"Material Request\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Supplier Addresses And Contacts\",\n \"name\": \"Address And Contacts\",\n \"reference_doctype\": \"Address\",\n \"route_options\": {\n \"party_type\": \"Supplier\"\n },\n \"type\": \"report\"\n }\n]" } ], - "cards_label": "Masters & Reports ", + "cards_label": "", "category": "Modules", "charts": [ { @@ -44,7 +44,7 @@ "label": "Purchase Order Trends" } ], - "charts_label": "Buying Dashboard", + "charts_label": "", "creation": "2020-01-28 11:50:26.195467", "developer_mode_only": 0, "disable_user_customization": 0, @@ -55,7 +55,7 @@ "idx": 0, "is_standard": 1, "label": "Buying", - "modified": "2020-05-27 19:15:05.067756", + "modified": "2020-05-28 13:32:49.960574", "modified_by": "Administrator", "module": "Buying", "name": "Buying", @@ -104,5 +104,5 @@ "type": "Dashboard" } ], - "shortcuts_label": "Quick Access" + "shortcuts_label": "" } \ No newline at end of file diff --git a/erpnext/crm/desk_page/crm/crm.json b/erpnext/crm/desk_page/crm/crm.json index 013fabef89..eb69dc06b6 100644 --- a/erpnext/crm/desk_page/crm/crm.json +++ b/erpnext/crm/desk_page/crm/crm.json @@ -42,7 +42,7 @@ "idx": 0, "is_standard": 1, "label": "CRM", - "modified": "2020-05-28 13:29:28.253749", + "modified": "2020-05-28 13:33:52.906750", "modified_by": "Administrator", "module": "CRM", "name": "CRM", @@ -52,6 +52,7 @@ "pin_to_top": 0, "shortcuts": [ { + "color": "#ffe8cd", "format": "{} Open", "label": "Lead", "link_to": "Lead", @@ -59,6 +60,7 @@ "type": "DocType" }, { + "color": "#cef6d1", "format": "{} Assigned", "label": "Opportunity", "link_to": "Opportunity", diff --git a/erpnext/crm/module_onboarding/crm/crm.json b/erpnext/crm/module_onboarding/crm/crm.json index 9b3d91ecee..c43fcaef8c 100644 --- a/erpnext/crm/module_onboarding/crm/crm.json +++ b/erpnext/crm/module_onboarding/crm/crm.json @@ -16,7 +16,7 @@ "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/CRM", "idx": 0, "is_complete": 0, - "modified": "2020-05-27 11:33:09.941263", + "modified": "2020-05-28 13:59:33.693420", "modified_by": "Administrator", "module": "CRM", "name": "CRM", @@ -37,6 +37,6 @@ ], "subtitle": "Lead, Opportunity, Customer and more", "success_message": "CRM Module is all setup!", - "title": "Let's Setup Your CRM", + "title": "Let's Set Up Your CRM", "user_can_dismiss": 1 } \ No newline at end of file diff --git a/erpnext/hr/desk_page/hr/hr.json b/erpnext/hr/desk_page/hr/hr.json index 2d0e8857ca..89abca00aa 100644 --- a/erpnext/hr/desk_page/hr/hr.json +++ b/erpnext/hr/desk_page/hr/hr.json @@ -93,7 +93,7 @@ "idx": 0, "is_standard": 1, "label": "HR", - "modified": "2020-05-20 11:20:54.255557", + "modified": "2020-05-28 13:36:07.710600", "modified_by": "Administrator", "module": "HR", "name": "HR", @@ -103,6 +103,7 @@ "pin_to_top": 0, "shortcuts": [ { + "color": "#cef6d1", "format": "{} Active", "label": "Employee", "link_to": "Employee", @@ -110,17 +111,19 @@ "type": "DocType" }, { - "label": "Attendance", - "link_to": "Attendance", - "stats_filter": "", - "type": "DocType" - }, - { + "color": "#ffe8cd", + "format": "{} Open", "label": "Leave Application", "link_to": "Leave Application", "stats_filter": "{\"status\":\"Open\"}", "type": "DocType" }, + { + "label": "Attendance", + "link_to": "Attendance", + "stats_filter": "", + "type": "DocType" + }, { "label": "Salary Structure", "link_to": "Payroll Entry", @@ -133,7 +136,7 @@ }, { "format": "{} Open", - "label": "HR Dashboard", + "label": "Dashboard", "link_to": "Human Resource", "stats_filter": "{\n \"status\": \"Open\"\n}", "type": "Dashboard" diff --git a/erpnext/loan_management/desk_page/loan_management/loan_management.json b/erpnext/loan_management/desk_page/loan/loan.json similarity index 96% rename from erpnext/loan_management/desk_page/loan_management/loan_management.json rename to erpnext/loan_management/desk_page/loan/loan.json index d2a17630c9..d79860a352 100644 --- a/erpnext/loan_management/desk_page/loan_management/loan_management.json +++ b/erpnext/loan_management/desk_page/loan/loan.json @@ -34,10 +34,11 @@ "docstatus": 0, "doctype": "Desk Page", "extends_another_page": 0, + "hide_custom": 0, "idx": 0, "is_standard": 1, "label": "Loan", - "modified": "2020-05-22 11:28:51.380509", + "modified": "2020-05-28 13:37:42.017709", "modified_by": "Administrator", "module": "Loan Management", "name": "Loan", @@ -46,8 +47,11 @@ "pin_to_top": 0, "shortcuts": [ { + "color": "#ffe8cd", + "format": "{} Open", "label": "Loan Application", "link_to": "Loan Application", + "stats_filter": "{ \"status\": \"Open\" }", "type": "DocType" }, { diff --git a/erpnext/manufacturing/desk_page/manufacturing/manufacturing.json b/erpnext/manufacturing/desk_page/manufacturing/manufacturing.json index f2e07bfe20..763f533a94 100644 --- a/erpnext/manufacturing/desk_page/manufacturing/manufacturing.json +++ b/erpnext/manufacturing/desk_page/manufacturing/manufacturing.json @@ -47,7 +47,7 @@ "idx": 0, "is_standard": 1, "label": "Manufacturing", - "modified": "2020-05-20 11:50:20.029056", + "modified": "2020-05-28 13:54:02.048419", "modified_by": "Administrator", "module": "Manufacturing", "name": "Manufacturing", @@ -58,6 +58,7 @@ "restrict_to_domain": "Manufacturing", "shortcuts": [ { + "color": "#cef6d1", "format": "{} Active", "label": "Item", "link_to": "Item", @@ -66,6 +67,7 @@ "type": "DocType" }, { + "color": "#cef6d1", "format": "{} Active", "label": "BOM", "link_to": "BOM", @@ -74,6 +76,7 @@ "type": "DocType" }, { + "color": "#ffe8cd", "format": "{} Open", "label": "Work Order", "link_to": "Work Order", @@ -82,6 +85,7 @@ "type": "DocType" }, { + "color": "#ffe8cd", "format": "{} Open", "label": "Production Plan", "link_to": "Production Plan", diff --git a/erpnext/projects/desk_page/projects/projects.json b/erpnext/projects/desk_page/projects/projects.json index fdbe13b2fb..d91fe5304a 100644 --- a/erpnext/projects/desk_page/projects/projects.json +++ b/erpnext/projects/desk_page/projects/projects.json @@ -33,7 +33,7 @@ "idx": 0, "is_standard": 1, "label": "Projects", - "modified": "2020-05-19 21:09:52.031828", + "modified": "2020-05-28 13:38:19.934937", "modified_by": "Administrator", "module": "Projects", "name": "Projects", @@ -42,7 +42,7 @@ "pin_to_top": 0, "shortcuts": [ { - "color": "#4d4da8", + "color": "#cef6d1", "format": "{} Assigned", "label": "Task", "link_to": "Task", @@ -50,7 +50,7 @@ "type": "DocType" }, { - "color": "#4d4da8", + "color": "#ffe8cd", "format": "{} Open", "label": "Project", "link_to": "Project", diff --git a/erpnext/selling/desk_page/selling/selling.json b/erpnext/selling/desk_page/selling/selling.json new file mode 100644 index 0000000000..c32a7c8481 --- /dev/null +++ b/erpnext/selling/desk_page/selling/selling.json @@ -0,0 +1,94 @@ +{ + "cards": [ + { + "hidden": 0, + "label": "Items and Pricing", + "links": "[\n {\n \"description\": \"All Products or Services.\",\n \"label\": \"Item\",\n \"name\": \"Item\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\",\n \"Price List\"\n ],\n \"description\": \"Multiple Item prices.\",\n \"label\": \"Item Price\",\n \"name\": \"Item Price\",\n \"onboard\": 1,\n \"route\": \"#Report/Item Price\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Price List master.\",\n \"label\": \"Price List\",\n \"name\": \"Price List\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Tree of Item Groups.\",\n \"icon\": \"fa fa-sitemap\",\n \"label\": \"Item Group\",\n \"link\": \"Tree/Item Group\",\n \"name\": \"Item Group\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\"\n ],\n \"description\": \"Bundle items at time of sale.\",\n \"label\": \"Product Bundle\",\n \"name\": \"Product Bundle\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Rules for applying different promotional schemes.\",\n \"label\": \"Promotional Scheme\",\n \"name\": \"Promotional Scheme\",\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\"\n ],\n \"description\": \"Rules for applying pricing and discount.\",\n \"label\": \"Pricing Rule\",\n \"name\": \"Pricing Rule\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Rules for adding shipping costs.\",\n \"label\": \"Shipping Rule\",\n \"name\": \"Shipping Rule\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Define coupon codes.\",\n \"label\": \"Coupon Code\",\n \"name\": \"Coupon Code\",\n \"type\": \"doctype\"\n }\n]" + }, + { + "hidden": 0, + "label": "Settings", + "links": "[\n {\n \"description\": \"Default settings for selling transactions.\",\n \"label\": \"Selling Settings\",\n \"name\": \"Selling Settings\",\n \"settings\": 1,\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Template of terms or contract.\",\n \"label\": \"Terms and Conditions Template\",\n \"name\": \"Terms and Conditions\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Tax template for selling transactions.\",\n \"label\": \"Sales Taxes and Charges Template\",\n \"name\": \"Sales Taxes and Charges Template\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Track Leads by Lead Source.\",\n \"label\": \"Lead Source\",\n \"name\": \"Lead Source\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Manage Customer Group Tree.\",\n \"icon\": \"fa fa-sitemap\",\n \"label\": \"Customer Group\",\n \"link\": \"Tree/Customer Group\",\n \"name\": \"Customer Group\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"All Contacts.\",\n \"label\": \"Contact\",\n \"name\": \"Contact\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"All Addresses.\",\n \"label\": \"Address\",\n \"name\": \"Address\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Manage Territory Tree.\",\n \"icon\": \"fa fa-sitemap\",\n \"label\": \"Territory\",\n \"link\": \"Tree/Territory\",\n \"name\": \"Territory\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Sales campaigns.\",\n \"label\": \"Campaign\",\n \"name\": \"Campaign\",\n \"type\": \"doctype\"\n }\n]" + }, + { + "hidden": 0, + "label": "Other Reports", + "links": "[\n {\n \"dependencies\": [\n \"Lead\"\n ],\n \"doctype\": \"Lead\",\n \"is_query_report\": true,\n \"label\": \"Lead Details\",\n \"name\": \"Lead Details\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Address\"\n ],\n \"doctype\": \"Address\",\n \"is_query_report\": true,\n \"label\": \"Customer Addresses And Contacts\",\n \"name\": \"Address And Contacts\",\n \"route_options\": {\n \"party_type\": \"Customer\"\n },\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"BOM\"\n ],\n \"doctype\": \"BOM\",\n \"is_query_report\": true,\n \"label\": \"BOM Search\",\n \"name\": \"BOM Search\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Item\"\n ],\n \"doctype\": \"Item\",\n \"is_query_report\": true,\n \"label\": \"Available Stock for Packing Items\",\n \"name\": \"Available Stock for Packing Items\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Order\"\n ],\n \"doctype\": \"Sales Order\",\n \"is_query_report\": true,\n \"label\": \"Pending SO Items For Purchase Request\",\n \"name\": \"Pending SO Items For Purchase Request\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Customer\"\n ],\n \"doctype\": \"Customer\",\n \"is_query_report\": true,\n \"label\": \"Customer Credit Balance\",\n \"name\": \"Customer Credit Balance\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Customer\"\n ],\n \"doctype\": \"Customer\",\n \"is_query_report\": true,\n \"label\": \"Customers Without Any Sales Transactions\",\n \"name\": \"Customers Without Any Sales Transactions\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Customer\"\n ],\n \"doctype\": \"Customer\",\n \"is_query_report\": true,\n \"label\": \"Sales Partners Commission\",\n \"name\": \"Sales Partners Commission\",\n \"type\": \"report\"\n }\n]" + }, + { + "hidden": 0, + "label": "Sales", + "links": "[\n {\n \"description\": \"Customer Database.\",\n \"label\": \"Customer\",\n \"name\": \"Customer\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\",\n \"Customer\"\n ],\n \"description\": \"Quotes to Leads or Customers.\",\n \"label\": \"Quotation\",\n \"name\": \"Quotation\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\",\n \"Customer\"\n ],\n \"description\": \"Confirmed orders from Customers.\",\n \"label\": \"Sales Order\",\n \"name\": \"Sales Order\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\",\n \"Customer\"\n ],\n \"description\": \"Invoices for Costumers.\",\n \"label\": \"Sales Invoice\",\n \"name\": \"Sales Invoice\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\",\n \"Customer\"\n ],\n \"description\": \"Blanket Orders from Costumers.\",\n \"label\": \"Blanket Order\",\n \"name\": \"Blanket Order\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\"\n ],\n \"description\": \"Manage Sales Partners.\",\n \"label\": \"Sales Partner\",\n \"name\": \"Sales Partner\",\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\",\n \"Customer\"\n ],\n \"description\": \"Manage Sales Person Tree.\",\n \"icon\": \"fa fa-sitemap\",\n \"label\": \"Sales Person\",\n \"link\": \"Tree/Sales Person\",\n \"name\": \"Sales Person\",\n \"type\": \"doctype\"\n }\n]" + }, + { + "hidden": 0, + "label": "Key Reports", + "links": "[\n {\n \"dependencies\": [\n \"Sales Order\"\n ],\n \"doctype\": \"Sales Order\",\n \"is_query_report\": true,\n \"label\": \"Sales Analytics\",\n \"name\": \"Sales Analytics\",\n \"onboard\": 1,\n \"type\": \"report\"\n },\n {\n \"icon\": \"fa fa-bar-chart\",\n \"label\": \"Sales Funnel\",\n \"name\": \"sales-funnel\",\n \"onboard\": 1,\n \"type\": \"page\"\n },\n {\n \"dependencies\": [\n \"Customer\"\n ],\n \"doctype\": \"Customer\",\n \"icon\": \"fa fa-bar-chart\",\n \"is_query_report\": true,\n \"label\": \"Customer Acquisition and Loyalty\",\n \"name\": \"Customer Acquisition and Loyalty\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Order\"\n ],\n \"doctype\": \"Sales Order\",\n \"is_query_report\": true,\n \"label\": \"Inactive Customers\",\n \"name\": \"Inactive Customers\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Order\"\n ],\n \"doctype\": \"Sales Order\",\n \"is_query_report\": true,\n \"label\": \"Ordered Items To Be Delivered\",\n \"name\": \"Ordered Items To Be Delivered\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Order\"\n ],\n \"doctype\": \"Sales Order\",\n \"is_query_report\": true,\n \"label\": \"Sales Person-wise Transaction Summary\",\n \"name\": \"Sales Person-wise Transaction Summary\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Item\"\n ],\n \"doctype\": \"Item\",\n \"is_query_report\": true,\n \"label\": \"Item-wise Sales History\",\n \"name\": \"Item-wise Sales History\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Quotation\"\n ],\n \"doctype\": \"Quotation\",\n \"is_query_report\": true,\n \"label\": \"Quotation Trends\",\n \"name\": \"Quotation Trends\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Order\"\n ],\n \"doctype\": \"Sales Order\",\n \"is_query_report\": true,\n \"label\": \"Sales Order Trends\",\n \"name\": \"Sales Order Trends\",\n \"type\": \"report\"\n }\n]" + } + ], + "category": "Modules", + "charts": [ + { + "chart_name": "Income", + "label": "Income" + } + ], + "creation": "2020-01-28 11:49:12.092882", + "developer_mode_only": 0, + "disable_user_customization": 0, + "docstatus": 0, + "doctype": "Desk Page", + "extends_another_page": 0, + "hide_custom": 1, + "idx": 0, + "is_standard": 1, + "label": "Selling", + "modified": "2020-05-28 13:46:08.314240", + "modified_by": "Administrator", + "module": "Selling", + "name": "Selling", + "owner": "Administrator", + "pin_to_bottom": 0, + "pin_to_top": 0, + "shortcuts": [ + { + "color": "#ffe8cd", + "format": "{} Draft", + "label": "Sales Invoice", + "link_to": "Sales Invoice", + "stats_filter": "{ \"status\": \"Draft\" }", + "type": "DocType" + }, + { + "color": "#ffe8cd", + "format": "{} To Deliver", + "label": "Sales Order", + "link_to": "Sales Order", + "stats_filter": "{\"Status\": \"To Deliver and Bill\"}", + "type": "DocType" + }, + { + "color": "#cef6d1", + "format": "{} Open", + "label": "Quotation", + "link_to": "Quotation", + "stats_filter": "{ \"Status\": \"Open\" }", + "type": "DocType" + }, + { + "label": "Delivery Note", + "link_to": "Delivery Note", + "type": "DocType" + }, + { + "label": "Accounts Receivable", + "link_to": "Accounts Receivable", + "type": "Report" + }, + { + "label": "Sales Register", + "link_to": "Sales Register", + "type": "Report" + } + ] +} \ No newline at end of file diff --git a/erpnext/support/desk_page/support/support.json b/erpnext/support/desk_page/support/support.json index 596987f46a..a3fe72d051 100644 --- a/erpnext/support/desk_page/support/support.json +++ b/erpnext/support/desk_page/support/support.json @@ -2,8 +2,8 @@ "cards": [ { "hidden": 0, - "label": "Service Level Agreement", - "links": "[\n {\n \"description\": \"Service Level.\",\n \"label\": \"Service Level\",\n \"name\": \"Service Level\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Service Level Agreement.\",\n \"label\": \"Service Level Agreement\",\n \"name\": \"Service Level Agreement\",\n \"type\": \"doctype\"\n }\n]" + "label": "Issues", + "links": "[\n {\n \"description\": \"Support queries from customers.\",\n \"label\": \"Issue\",\n \"name\": \"Issue\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Issue Type.\",\n \"label\": \"Issue Type\",\n \"name\": \"Issue Type\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Issue Priority.\",\n \"label\": \"Issue Priority\",\n \"name\": \"Issue Priority\",\n \"type\": \"doctype\"\n }\n]" }, { "hidden": 0, @@ -12,8 +12,8 @@ }, { "hidden": 0, - "label": "Issues", - "links": "[\n {\n \"description\": \"Support queries from customers.\",\n \"label\": \"Issue\",\n \"name\": \"Issue\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Issue Type.\",\n \"label\": \"Issue Type\",\n \"name\": \"Issue Type\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Issue Priority.\",\n \"label\": \"Issue Priority\",\n \"name\": \"Issue Priority\",\n \"type\": \"doctype\"\n }\n]" + "label": "Service Level Agreement", + "links": "[\n {\n \"description\": \"Service Level.\",\n \"label\": \"Service Level\",\n \"name\": \"Service Level\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Service Level Agreement.\",\n \"label\": \"Service Level Agreement\",\n \"name\": \"Service Level Agreement\",\n \"type\": \"doctype\"\n }\n]" }, { "hidden": 0, @@ -39,11 +39,11 @@ "docstatus": 0, "doctype": "Desk Page", "extends_another_page": 0, - "icon": "", + "hide_custom": 0, "idx": 0, "is_standard": 1, "label": "Support", - "modified": "2020-04-01 11:28:51.120583", + "modified": "2020-05-28 13:51:23.869954", "modified_by": "Administrator", "module": "Support", "name": "Support", @@ -52,19 +52,22 @@ "pin_to_top": 0, "shortcuts": [ { + "color": "#ffc4c4", + "format": "{} Assigned", "label": "Issue", "link_to": "Issue", - "type": "DocType" - }, - { - "label": "Service Level", - "link_to": "Service Level", + "stats_filter": "{\n \"_assign\": [\"like\", '%' + frappe.session.user + '%'],\n \"status\": \"Open\"\n}", "type": "DocType" }, { "label": "Maintenance Visit", "link_to": "Maintenance Visit", "type": "DocType" + }, + { + "label": "Service Level", + "link_to": "Service Level", + "type": "DocType" } ] } \ No newline at end of file From 354baf0c5e45c970eba51ffa5d71a5d149f84912 Mon Sep 17 00:00:00 2001 From: Marica Date: Thu, 28 May 2020 18:31:50 +0530 Subject: [PATCH 089/449] fix: Delete Auto Email Reports (#22010) --- erpnext/patches/v13_0/delete_old_purchase_reports.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/erpnext/patches/v13_0/delete_old_purchase_reports.py b/erpnext/patches/v13_0/delete_old_purchase_reports.py index 8271d2e6dc..8bdc07ee5b 100644 --- a/erpnext/patches/v13_0/delete_old_purchase_reports.py +++ b/erpnext/patches/v13_0/delete_old_purchase_reports.py @@ -12,4 +12,12 @@ def execute(): for report in reports_to_delete: if frappe.db.exists("Report", report): - frappe.delete_doc("Report", report) \ No newline at end of file + delete_auto_email_reports(report) + + frappe.delete_doc("Report", report) + +def delete_auto_email_reports(report): + """ Check for one or multiple Auto Email Reports and delete """ + auto_email_reports = frappe.db.get_values("Auto Email Report", {"report": report}, ["name"]) + for auto_email_report in auto_email_reports: + frappe.delete_doc("Auto Email Report", auto_email_report[0]) \ No newline at end of file From a0f061abd903a05638faa3c14dab90f787a66506 Mon Sep 17 00:00:00 2001 From: sahil28297 <37302950+sahil28297@users.noreply.github.com> Date: Thu, 28 May 2020 18:32:34 +0530 Subject: [PATCH 090/449] fix(rename_bank_reconcilliation): do not delete doc after renaming (#22014) --- erpnext/patches/v12_0/rename_bank_reconciliation.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/erpnext/patches/v12_0/rename_bank_reconciliation.py b/erpnext/patches/v12_0/rename_bank_reconciliation.py index eda47a95e0..2efa854fba 100644 --- a/erpnext/patches/v12_0/rename_bank_reconciliation.py +++ b/erpnext/patches/v12_0/rename_bank_reconciliation.py @@ -8,9 +8,6 @@ def execute(): if frappe.db.table_exists("Bank Reconciliation"): frappe.rename_doc('DocType', 'Bank Reconciliation', 'Bank Clearance', force=True) frappe.reload_doc('Accounts', 'doctype', 'Bank Clearance') - + frappe.rename_doc('DocType', 'Bank Reconciliation Detail', 'Bank Clearance Detail', force=True) frappe.reload_doc('Accounts', 'doctype', 'Bank Clearance Detail') - - frappe.delete_doc("DocType", "Bank Reconciliation") - frappe.delete_doc("DocType", "Bank Reconciliation Detail") From 11bd731d164bba2746506a4195fdeefca84e42e2 Mon Sep 17 00:00:00 2001 From: sahil28297 <37302950+sahil28297@users.noreply.github.com> Date: Thu, 28 May 2020 18:50:13 +0530 Subject: [PATCH 091/449] fix(set_purchase_receipt_delivery_note_detail): commit after every 100 sql updates (#22018) --- .../set_purchase_receipt_delivery_note_detail.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/erpnext/patches/v12_0/set_purchase_receipt_delivery_note_detail.py b/erpnext/patches/v12_0/set_purchase_receipt_delivery_note_detail.py index 6f843cdabd..52c9a2d7b3 100644 --- a/erpnext/patches/v12_0/set_purchase_receipt_delivery_note_detail.py +++ b/erpnext/patches/v12_0/set_purchase_receipt_delivery_note_detail.py @@ -64,11 +64,13 @@ def execute(): return_document_map = make_return_document_map(doctype, return_document_map) + count = 0 + #iterate through original documents and its return documents for docname in return_document_map: - doc_items = frappe.get_doc(doctype, docname).get("items") + doc_items = frappe.get_cached_doc(doctype, docname).get("items") for return_doc in return_document_map[docname]: - return_doc_items = frappe.get_doc(doctype, return_doc).get("items") + return_doc_items = frappe.get_cached_doc(doctype, return_doc).get("items") #iterate through return document items and original document items for mapping for return_item in return_doc_items: @@ -80,9 +82,11 @@ def execute(): else: continue + # commit after every 100 sql updates + count += 1 + if count%100 == 0: + frappe.db.commit() + set_document_detail_in_return_document("Purchase Receipt") set_document_detail_in_return_document("Delivery Note") frappe.db.commit() - - - From 1a1447c2a12fa460ee1968f73e0c7c2913860820 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 28 May 2020 19:03:37 +0530 Subject: [PATCH 092/449] fix: empty filters in Healthcare Charts (cherry picked from commit a3dd75e77f6139f47dc142212550768d78197fee) --- erpnext/healthcare/dashboard_fixtures.py | 8 ++++---- erpnext/healthcare/desk_page/healthcare/healthcare.json | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/erpnext/healthcare/dashboard_fixtures.py b/erpnext/healthcare/dashboard_fixtures.py index 967117d22c..94668a16d9 100644 --- a/erpnext/healthcare/dashboard_fixtures.py +++ b/erpnext/healthcare/dashboard_fixtures.py @@ -71,7 +71,7 @@ def get_charts(): "chart_name": _("Department wise Patient Appointments"), "chart_type": "Custom", "source": "Department wise Patient Appointments", - "filters_json": json.dumps({}), + "filters_json": json.dumps([]), 'is_public': 1, "owner": "Administrator", "type": "Bar", @@ -159,7 +159,7 @@ def get_charts(): "document_type": "Patient Encounter Symptom", "group_by_type": "Count", "group_by_based_on": "complaint", - "filters_json": json.dumps({}), + "filters_json": json.dumps([]), 'is_public': 1, "owner": "Administrator", "type": "Percentage", @@ -173,7 +173,7 @@ def get_charts(): "document_type": "Patient Encounter Diagnosis", "group_by_type": "Count", "group_by_based_on": "diagnosis", - "filters_json": json.dumps({}), + "filters_json": json.dumps([]), 'is_public': 1, "owner": "Administrator", "type": "Percentage", @@ -229,7 +229,7 @@ def get_number_cards(): }, { "name": "Appointments to Bill", - "label": _("Appointments to Bill"), + "label": _("Appointments To Bill"), "function": "Count", "doctype": "Number Card", "document_type": "Patient Appointment", diff --git a/erpnext/healthcare/desk_page/healthcare/healthcare.json b/erpnext/healthcare/desk_page/healthcare/healthcare.json index 60b53137cd..334b65563b 100644 --- a/erpnext/healthcare/desk_page/healthcare/healthcare.json +++ b/erpnext/healthcare/desk_page/healthcare/healthcare.json @@ -64,7 +64,7 @@ "idx": 0, "is_standard": 1, "label": "Healthcare", - "modified": "2020-05-19 20:57:22.797267", + "modified": "2020-05-28 19:02:28.824995", "modified_by": "Administrator", "module": "Healthcare", "name": "Healthcare", @@ -109,7 +109,7 @@ "type": "Page" }, { - "label": "Healthcare Dashboard", + "label": "Dashboard", "link_to": "Healthcare", "type": "Dashboard" } From f42a37ea43c6ccbf9070ffad8d9eb30ffb6570c0 Mon Sep 17 00:00:00 2001 From: Sahil Khan Date: Thu, 28 May 2020 20:41:41 +0550 Subject: [PATCH 093/449] bumped to version 13.0.0-beta.2 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 43c3935220..530a6e4880 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0-beta.1' +__version__ = '13.0.0-beta.2' def get_default_company(user=None): '''Get default company for user''' From 25add7c9bfe115847f0849cf4b94119a1b2b4948 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 29 May 2020 09:34:14 +0530 Subject: [PATCH 094/449] crm onboarding typos (#22008) (#22025) (cherry picked from commit 8385fed04293e16cf2017af8435ff48899707f13) Co-authored-by: Anupam Kumar --- erpnext/crm/module_onboarding/crm/crm.json | 8 ++++---- .../create_and_send_quotation.json | 2 +- erpnext/crm/onboarding_step/create_lead/create_lead.json | 2 +- .../introduction_to_crm/introduction_to_crm.json | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/erpnext/crm/module_onboarding/crm/crm.json b/erpnext/crm/module_onboarding/crm/crm.json index c43fcaef8c..44d672a7b5 100644 --- a/erpnext/crm/module_onboarding/crm/crm.json +++ b/erpnext/crm/module_onboarding/crm/crm.json @@ -16,7 +16,7 @@ "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/CRM", "idx": 0, "is_complete": 0, - "modified": "2020-05-28 13:59:33.693420", + "modified": "2020-05-28 21:07:41.278784", "modified_by": "Administrator", "module": "CRM", "name": "CRM", @@ -35,8 +35,8 @@ "step": "Create and Send Quotation" } ], - "subtitle": "Lead, Opportunity, Customer and more", - "success_message": "CRM Module is all setup!", - "title": "Let's Set Up Your CRM", + "subtitle": "Lead, Opportunity, Customer and more.", + "success_message": "CRM Module is all Set Up!", + "title": "Let's Set Up Your CRM.", "user_can_dismiss": 1 } \ No newline at end of file diff --git a/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json b/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json index 9201d77cf8..78f7e4de9c 100644 --- a/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json +++ b/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json @@ -8,7 +8,7 @@ "is_mandatory": 0, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-27 11:30:28.237263", + "modified": "2020-05-28 21:07:11.461172", "modified_by": "Administrator", "name": "Create and Send Quotation", "owner": "Administrator", diff --git a/erpnext/crm/onboarding_step/create_lead/create_lead.json b/erpnext/crm/onboarding_step/create_lead/create_lead.json index 6ff0bd61f1..c45e8b036c 100644 --- a/erpnext/crm/onboarding_step/create_lead/create_lead.json +++ b/erpnext/crm/onboarding_step/create_lead/create_lead.json @@ -8,7 +8,7 @@ "is_mandatory": 0, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-27 11:30:59.493720", + "modified": "2020-05-28 21:07:01.373403", "modified_by": "Administrator", "name": "Create Lead", "owner": "Administrator", diff --git a/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json b/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json index 545a756a59..fa26921ae2 100644 --- a/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json +++ b/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json @@ -8,7 +8,7 @@ "is_mandatory": 0, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-27 11:28:07.452857", + "modified": "2020-05-14 17:28:16.448676", "modified_by": "Administrator", "name": "Introduction to CRM", "owner": "Administrator", From 9b36a9be2680041f3812a168db9b46e6ecf4725a Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Fri, 29 May 2020 12:44:09 +0530 Subject: [PATCH 095/449] fix: check if swift_number exists in bank account Signed-off-by: Chinmay D. Pai (cherry picked from commit d6587fa1d5dc115cf2ea09946800aba9878f9200) --- .../patches/v12_0/move_bank_account_swift_number_to_bank.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/patches/v12_0/move_bank_account_swift_number_to_bank.py b/erpnext/patches/v12_0/move_bank_account_swift_number_to_bank.py index 3c9758eb84..1ddbae6cd2 100644 --- a/erpnext/patches/v12_0/move_bank_account_swift_number_to_bank.py +++ b/erpnext/patches/v12_0/move_bank_account_swift_number_to_bank.py @@ -4,7 +4,7 @@ import frappe def execute(): frappe.reload_doc('accounts', 'doctype', 'bank', force=1) - if frappe.db.table_exists('Bank') and frappe.db.table_exists('Bank Account'): + if frappe.db.table_exists('Bank') and frappe.db.table_exists('Bank Account') and frappe.db.has_column('Bank Account', 'swift_number'): frappe.db.sql(""" UPDATE `tabBank` b, `tabBank Account` ba SET b.swift_number = ba.swift_number, b.branch_code = ba.branch_code @@ -12,4 +12,4 @@ def execute(): """) frappe.reload_doc('accounts', 'doctype', 'bank_account') - frappe.reload_doc('accounts', 'doctype', 'payment_request') \ No newline at end of file + frappe.reload_doc('accounts', 'doctype', 'payment_request') From bfa93ea76fe8222d65ae2299d634b6b3a2ab46f3 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 29 May 2020 21:31:28 +0530 Subject: [PATCH 096/449] fix: Migrate standard_tax_exemption_amount if field exists (#22036) (#22047) (cherry picked from commit 2186c223b9513d72b8d935410aca305d732761d9) Co-authored-by: Nabin Hait --- ..._slabs_from_payroll_period_to_income_tax_slab.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/erpnext/patches/v13_0/move_tax_slabs_from_payroll_period_to_income_tax_slab.py b/erpnext/patches/v13_0/move_tax_slabs_from_payroll_period_to_income_tax_slab.py index ec94cd01d1..5ade8ca0f4 100644 --- a/erpnext/patches/v13_0/move_tax_slabs_from_payroll_period_to_income_tax_slab.py +++ b/erpnext/patches/v13_0/move_tax_slabs_from_payroll_period_to_income_tax_slab.py @@ -14,15 +14,21 @@ def execute(): frappe.reload_doc("hr", "doctype", doctype) + standard_tax_exemption_amount_exists = frappe.db.has_column("Payroll Period", "standard_tax_exemption_amount") + + select_fields = "name, start_date, end_date" + if standard_tax_exemption_amount_exists: + select_fields = "name, start_date, end_date, standard_tax_exemption_amount" + for company in frappe.get_all("Company"): payroll_periods = frappe.db.sql(""" SELECT - name, start_date, end_date, standard_tax_exemption_amount + {0} FROM `tabPayroll Period` WHERE company=%s ORDER BY start_date DESC - """, company.name, as_dict = 1) + """.format(select_fields), company.name, as_dict = 1) for i, period in enumerate(payroll_periods): income_tax_slab = frappe.new_doc("Income Tax Slab") @@ -36,7 +42,8 @@ def execute(): income_tax_slab.effective_from = period.start_date income_tax_slab.company = company.name income_tax_slab.allow_tax_exemption = 1 - income_tax_slab.standard_tax_exemption_amount = period.standard_tax_exemption_amount + if standard_tax_exemption_amount_exists: + income_tax_slab.standard_tax_exemption_amount = period.standard_tax_exemption_amount income_tax_slab.flags.ignore_mandatory = True income_tax_slab.submit() From d9f7b4df8f951e063916cc33321e9b9bf4640c1c Mon Sep 17 00:00:00 2001 From: karthikeyan5 Date: Sat, 30 May 2020 15:00:56 +0530 Subject: [PATCH 097/449] fix(ewb): remove checksum validation for TRANSIN (cherry picked from commit ca46bedfcb874ac5e03d44a00b996d31db336d85) --- erpnext/regional/india/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index 732780a0a3..3085a310c4 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -615,8 +615,9 @@ def get_transport_details(data, doc): data.transDocDate = frappe.utils.formatdate(doc.lr_date, 'dd/mm/yyyy') if doc.gst_transporter_id: - validate_gstin_check_digit(doc.gst_transporter_id, label='GST Transporter ID') - data.transporterId = doc.gst_transporter_id + if doc.gst_transporter_id[0:2] != "88": + validate_gstin_check_digit(doc.gst_transporter_id, label='GST Transporter ID') + data.transporterId = doc.gst_transporter_id return data From 8f17438723cf78bdf20b8311561f8713ada45e0a Mon Sep 17 00:00:00 2001 From: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> Date: Sat, 30 May 2020 23:21:47 +0530 Subject: [PATCH 098/449] chore: Delete redundant change-log file Not sure how this still exists even after renaming the file - https://github.com/frappe/erpnext/pull/21923 - https://github.com/frappe/erpnext/commit/ccb9ae49aaf98c95f6c0dbfeb85be8da2602ea52#diff-05325be11cd93bcdb3c8cebcb60b2c35 --- erpnext/change_log/v13/v13_0_0_beta-1.md | 52 ------------------------ 1 file changed, 52 deletions(-) delete mode 100644 erpnext/change_log/v13/v13_0_0_beta-1.md diff --git a/erpnext/change_log/v13/v13_0_0_beta-1.md b/erpnext/change_log/v13/v13_0_0_beta-1.md deleted file mode 100644 index 5bd13dd823..0000000000 --- a/erpnext/change_log/v13/v13_0_0_beta-1.md +++ /dev/null @@ -1,52 +0,0 @@ -# Version 13.0.0 Beta 1 Release Notes - -## Accounting -- [Loan Management and Accounting](https://docs.erpnext.com/docs/user/manual/en/loan-management) -- [Accounting Dimensions in Budget Variance Report](https://github.com/frappe/erpnext/pull/19973) -- [Tax Category in POS Profile](https://docs.erpnext.com/docs/user/manual/en/accounts/pos-profile) -- [Custom Fields in POS](https://github.com/frappe/erpnext/pull/19876) -- [HSN Code Wise Item Tax](https://github.com/frappe/erpnext/pull/19478) -- Auto State-wise Taxation for GST India - - The Accounts entered in CGST and SGST accounts in GST Settings will be automatically skipped for Interstate Transaction and the Accounts in IGST Account will be skipped in Intrastate transaction. - -## Stock -- [Fetch Items from BOM in Stock Entry](https://github.com/frappe/erpnext/pull/19498) -- [Inter Warehouse Stock Transfer in Purchase Receipt](https://docs.erpnext.com/docs/user/manual/en/stock/articles/material-transfer-from-delivery-note) - -## HR -- [Work From Home in Attendance](https://github.com/frappe/erpnext/pull/20464) -- [Bulk Mark Attendance](https://github.com/frappe/erpnext/pull/20062) - -## Healthcare -- [Refactored Healthcare Module](https://docs.erpnext.com/docs/user/manual/en/healthcare) -- [Rehabilitation Module](https://docs.erpnext.com/docs/user/manual/en/healthcare/exercise_type) - -## CRM -- [Social Media Post](https://docs.erpnext.com/docs/user/manual/en/CRM/social-media-post) -- [Make Quotation against Blanket Order](https://docs.erpnext.com/docs/user/manual/en/selling/blanket-order) -- [Calendar View for Opportunity](https://github.com/frappe/erpnext/pull/21280) - -## New Reports -- [Item-wise Sales Register](https://docs.erpnext.com/docs/user/manual/en/accounts/accounting-reports) -- [Territory-wise Sales](https://github.com/frappe/erpnext/pull/20428) - -## Regional - -- Germany - - - [Update report DATEV Export to version 7.0](https://github.com/frappe/erpnext/pull/20582) and [allow to filter by voucher type](https://github.com/frappe/erpnext/pull/21060). - -- [Use any available Address Template](https://github.com/frappe/erpnext/pull/19862), not just your country's. - -## Other Changes -- [Report Summary in Financial Statement](https://github.com/frappe/erpnext/pull/20876) -- [Accounts Payable Report based on Payment Terms](https://docs.erpnext.com/docs/user/manual/en/accounts/accounting-reports) -- [Allow Purchase Invoice Creation Without Purchase Receipt Checkbox in Supplier](https://github.com/frappe/erpnext/pull/20864) -- [Allow Purchase Invoice Creation Without Purchase Order Checkbox in Supplier](https://github.com/frappe/erpnext/pull/20864) -- Add / Delete Items in submitted Sales / Purchase Order -- Provision to edit Item Details from Marketplace -- Nested Set filtering for Accounting Dimension -- UX changes and better validation message in all Modules -- Scan Barcode in Purchase Receipt -- Disable Rounded Totals Checkbox for Salary Slips in HR Settings - From 1dd5efcfc439e66ed715e2ae290ea14aa9f7fd4e Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 1 Jun 2020 11:30:34 +0530 Subject: [PATCH 099/449] fix: Method in hooks for proccesing deferred revenue --- erpnext/hooks.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/erpnext/hooks.py b/erpnext/hooks.py index e6f6c8e47a..394655195a 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -318,8 +318,7 @@ scheduler_events = { "erpnext.loan_management.doctype.loan_interest_accrual.loan_interest_accrual.process_loan_interest_accrual_for_term_loans" ], "monthly_long": [ - "erpnext.accounts.deferred_revenue.convert_deferred_revenue_to_income", - "erpnext.accounts.deferred_revenue.convert_deferred_expense_to_expense", + "erpnext.accounts.deferred_revenue.process_deferred_accounting", "erpnext.hr.utils.allocate_earned_leaves", "erpnext.loan_management.doctype.loan_interest_accrual.loan_interest_accrual.process_loan_interest_accrual_for_demand_loans" ] From 2e55609a84974855daec7a067c71fe0b4bf9d289 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Mon, 1 Jun 2020 12:03:31 +0530 Subject: [PATCH 100/449] Revert "fix: Method in hooks for processing deferred revenue" --- erpnext/hooks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 9d7cdc2a3b..ab161aa9f5 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -320,7 +320,8 @@ scheduler_events = { "erpnext.loan_management.doctype.loan_interest_accrual.loan_interest_accrual.process_loan_interest_accrual_for_term_loans" ], "monthly_long": [ - "erpnext.accounts.deferred_revenue.process_deferred_accounting", + "erpnext.accounts.deferred_revenue.convert_deferred_revenue_to_income", + "erpnext.accounts.deferred_revenue.convert_deferred_expense_to_expense", "erpnext.hr.utils.allocate_earned_leaves", "erpnext.loan_management.doctype.loan_interest_accrual.loan_interest_accrual.process_loan_interest_accrual_for_demand_loans" ] From 3064e361e11983d73cc0c7626294029f16cb882f Mon Sep 17 00:00:00 2001 From: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> Date: Sat, 30 May 2020 23:21:47 +0530 Subject: [PATCH 101/449] chore: Delete redundant change-log file Not sure how this still exists even after renaming the file - https://github.com/frappe/erpnext/pull/21923 - https://github.com/frappe/erpnext/commit/ccb9ae49aaf98c95f6c0dbfeb85be8da2602ea52#diff-05325be11cd93bcdb3c8cebcb60b2c35 --- erpnext/change_log/v13/v13_0_0_beta-1.md | 52 ------------------------ 1 file changed, 52 deletions(-) delete mode 100644 erpnext/change_log/v13/v13_0_0_beta-1.md diff --git a/erpnext/change_log/v13/v13_0_0_beta-1.md b/erpnext/change_log/v13/v13_0_0_beta-1.md deleted file mode 100644 index 5bd13dd823..0000000000 --- a/erpnext/change_log/v13/v13_0_0_beta-1.md +++ /dev/null @@ -1,52 +0,0 @@ -# Version 13.0.0 Beta 1 Release Notes - -## Accounting -- [Loan Management and Accounting](https://docs.erpnext.com/docs/user/manual/en/loan-management) -- [Accounting Dimensions in Budget Variance Report](https://github.com/frappe/erpnext/pull/19973) -- [Tax Category in POS Profile](https://docs.erpnext.com/docs/user/manual/en/accounts/pos-profile) -- [Custom Fields in POS](https://github.com/frappe/erpnext/pull/19876) -- [HSN Code Wise Item Tax](https://github.com/frappe/erpnext/pull/19478) -- Auto State-wise Taxation for GST India - - The Accounts entered in CGST and SGST accounts in GST Settings will be automatically skipped for Interstate Transaction and the Accounts in IGST Account will be skipped in Intrastate transaction. - -## Stock -- [Fetch Items from BOM in Stock Entry](https://github.com/frappe/erpnext/pull/19498) -- [Inter Warehouse Stock Transfer in Purchase Receipt](https://docs.erpnext.com/docs/user/manual/en/stock/articles/material-transfer-from-delivery-note) - -## HR -- [Work From Home in Attendance](https://github.com/frappe/erpnext/pull/20464) -- [Bulk Mark Attendance](https://github.com/frappe/erpnext/pull/20062) - -## Healthcare -- [Refactored Healthcare Module](https://docs.erpnext.com/docs/user/manual/en/healthcare) -- [Rehabilitation Module](https://docs.erpnext.com/docs/user/manual/en/healthcare/exercise_type) - -## CRM -- [Social Media Post](https://docs.erpnext.com/docs/user/manual/en/CRM/social-media-post) -- [Make Quotation against Blanket Order](https://docs.erpnext.com/docs/user/manual/en/selling/blanket-order) -- [Calendar View for Opportunity](https://github.com/frappe/erpnext/pull/21280) - -## New Reports -- [Item-wise Sales Register](https://docs.erpnext.com/docs/user/manual/en/accounts/accounting-reports) -- [Territory-wise Sales](https://github.com/frappe/erpnext/pull/20428) - -## Regional - -- Germany - - - [Update report DATEV Export to version 7.0](https://github.com/frappe/erpnext/pull/20582) and [allow to filter by voucher type](https://github.com/frappe/erpnext/pull/21060). - -- [Use any available Address Template](https://github.com/frappe/erpnext/pull/19862), not just your country's. - -## Other Changes -- [Report Summary in Financial Statement](https://github.com/frappe/erpnext/pull/20876) -- [Accounts Payable Report based on Payment Terms](https://docs.erpnext.com/docs/user/manual/en/accounts/accounting-reports) -- [Allow Purchase Invoice Creation Without Purchase Receipt Checkbox in Supplier](https://github.com/frappe/erpnext/pull/20864) -- [Allow Purchase Invoice Creation Without Purchase Order Checkbox in Supplier](https://github.com/frappe/erpnext/pull/20864) -- Add / Delete Items in submitted Sales / Purchase Order -- Provision to edit Item Details from Marketplace -- Nested Set filtering for Accounting Dimension -- UX changes and better validation message in all Modules -- Scan Barcode in Purchase Receipt -- Disable Rounded Totals Checkbox for Salary Slips in HR Settings - From cdd92d756d52b2c8c3250e1dad6dc9436138b2be Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 7 Jun 2020 00:01:20 +0530 Subject: [PATCH 102/449] fix: Cancelled entries in tds payable monthly report --- .../accounts/report/tds_payable_monthly/tds_payable_monthly.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py b/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py index 4ac0f65611..a9fb237a04 100644 --- a/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py +++ b/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py @@ -111,7 +111,7 @@ def get_gle_map(filters): # {"purchase_invoice": list of dict of all gle created for this invoice} gle_map = {} gle = frappe.db.get_all('GL Entry',\ - {"voucher_no": ["in", [d.get("name") for d in filters["invoices"]]]}, + {"voucher_no": ["in", [d.get("name") for d in filters["invoices"]]], 'is_cancelled': 0}, ["fiscal_year", "credit", "debit", "account", "voucher_no", "posting_date"]) for d in gle: From 3fed098f16097e6071d1403e45811852ec694243 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 7 Jun 2020 21:18:47 +0530 Subject: [PATCH 103/449] fix: Precision in loan amount calculation --- .../loan_management/loan_management.json | 6 +-- .../loan_interest_accrual.py | 30 +++++++------ .../doctype/loan_repayment/loan_repayment.py | 45 ++++++++++++------- .../doctype/loan_type/loan_type.json | 3 +- .../loan_security_status.py | 13 +++--- 5 files changed, 54 insertions(+), 43 deletions(-) diff --git a/erpnext/loan_management/desk_page/loan_management/loan_management.json b/erpnext/loan_management/desk_page/loan_management/loan_management.json index 691d2c1e0c..fe113d4700 100644 --- a/erpnext/loan_management/desk_page/loan_management/loan_management.json +++ b/erpnext/loan_management/desk_page/loan_management/loan_management.json @@ -23,7 +23,7 @@ { "hidden": 0, "label": "Reports", - "links": "[\n {\n \"dependencies\": [\n \"Loan Repayment\"\n ],\n \"doctype\": \"Loan Repayment\",\n \"incomplete_dependencies\": [\n \"Loan Repayment\"\n ],\n \"is_query_report\": true,\n \"label\": \"Loan Repayment and Closure\",\n \"name\": \"Loan Repayment and Closure\",\n \"route\": \"#query-report/Loan Repayment and Closure\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Loan Security Pledge\"\n ],\n \"doctype\": \"Loan Security Pledge\",\n \"incomplete_dependencies\": [\n \"Loan Security Pledge\"\n ],\n \"is_query_report\": true,\n \"label\": \"Loan Security Status\",\n \"name\": \"Loan Security Status\",\n \"route\": \"#query-report/Loan Security Status\",\n \"type\": \"report\"\n }\n]" + "links": "[\n {\n \"doctype\": \"Loan Repayment\",\n \"is_query_report\": true,\n \"label\": \"Loan Repayment and Closure\",\n \"name\": \"Loan Repayment and Closure\",\n \"route\": \"#query-report/Loan Repayment and Closure\",\n \"type\": \"report\"\n },\n {\n \"doctype\": \"Loan Security Pledge\",\n \"is_query_report\": true,\n \"label\": \"Loan Security Status\",\n \"name\": \"Loan Security Status\",\n \"route\": \"#query-report/Loan Security Status\",\n \"type\": \"report\"\n }\n]" } ], "category": "Modules", @@ -36,8 +36,8 @@ "extends_another_page": 0, "idx": 0, "is_standard": 1, - "label": "Loan Management", - "modified": "2020-04-01 11:28:51.380509", + "label": "Loan", + "modified": "2020-06-07 19:42:14.947902", "modified_by": "Administrator", "module": "Loan Management", "name": "Loan Management", diff --git a/erpnext/loan_management/doctype/loan_interest_accrual/loan_interest_accrual.py b/erpnext/loan_management/doctype/loan_interest_accrual/loan_interest_accrual.py index 094b9c698c..659173557b 100644 --- a/erpnext/loan_management/doctype/loan_interest_accrual/loan_interest_accrual.py +++ b/erpnext/loan_management/doctype/loan_interest_accrual/loan_interest_accrual.py @@ -176,21 +176,23 @@ def get_term_loans(date, term_loan=None, loan_type=None): return term_loans def make_loan_interest_accrual_entry(args): - loan_interest_accrual = frappe.new_doc("Loan Interest Accrual") - loan_interest_accrual.loan = args.loan - loan_interest_accrual.applicant_type = args.applicant_type - loan_interest_accrual.applicant = args.applicant - loan_interest_accrual.interest_income_account = args.interest_income_account - loan_interest_accrual.loan_account = args.loan_account - loan_interest_accrual.pending_principal_amount = flt(args.pending_principal_amount, 2) - loan_interest_accrual.interest_amount = flt(args.interest_amount, 2) - loan_interest_accrual.posting_date = args.posting_date or nowdate() - loan_interest_accrual.process_loan_interest_accrual = args.process_loan_interest - loan_interest_accrual.repayment_schedule_name = args.repayment_schedule_name - loan_interest_accrual.payable_principal_amount = args.payable_principal + precision = cint(frappe.db.get_default("currency_precision")) or 2 - loan_interest_accrual.save() - loan_interest_accrual.submit() + loan_interest_accrual = frappe.new_doc("Loan Interest Accrual") + loan_interest_accrual.loan = args.loan + loan_interest_accrual.applicant_type = args.applicant_type + loan_interest_accrual.applicant = args.applicant + loan_interest_accrual.interest_income_account = args.interest_income_account + loan_interest_accrual.loan_account = args.loan_account + loan_interest_accrual.pending_principal_amount = flt(args.pending_principal_amount, precision) + loan_interest_accrual.interest_amount = flt(args.interest_amount, precision) + loan_interest_accrual.posting_date = args.posting_date or nowdate() + loan_interest_accrual.process_loan_interest_accrual = args.process_loan_interest + loan_interest_accrual.repayment_schedule_name = args.repayment_schedule_name + loan_interest_accrual.payable_principal_amount = args.payable_principal + + loan_interest_accrual.save() + loan_interest_accrual.submit() def get_no_of_days_for_interest_accural(loan, posting_date): diff --git a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py index 87e8a15ab4..66456f9e94 100644 --- a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py +++ b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import frappe, erpnext import json from frappe import _ -from frappe.utils import flt, getdate +from frappe.utils import flt, getdate, cint from six import iteritems from frappe.model.document import Document from frappe.utils import date_diff, add_days, getdate, add_months, get_first_day, get_datetime @@ -29,8 +29,11 @@ class LoanRepayment(AccountsController): def on_cancel(self): self.mark_as_unpaid() self.make_gl_entries(cancel=1) + self.ignore_linked_doctypes = ['GL Entry'] def set_missing_values(self, amounts): + precision = cint(frappe.db.get_default("currency_precision")) or 2 + if not self.posting_date: self.posting_date = get_datetime() @@ -38,24 +41,26 @@ class LoanRepayment(AccountsController): self.cost_center = erpnext.get_default_cost_center(self.company) if not self.interest_payable: - self.interest_payable = flt(amounts['interest_amount'], 2) + self.interest_payable = flt(amounts['interest_amount'], precision) if not self.penalty_amount: - self.penalty_amount = flt(amounts['penalty_amount'], 2) + self.penalty_amount = flt(amounts['penalty_amount'], precision) if not self.pending_principal_amount: - self.pending_principal_amount = flt(amounts['pending_principal_amount'], 2) + self.pending_principal_amount = flt(amounts['pending_principal_amount'], precision) if not self.payable_principal_amount and self.is_term_loan: - self.payable_principal_amount = flt(amounts['payable_principal_amount'], 2) + self.payable_principal_amount = flt(amounts['payable_principal_amount'], precision) if not self.payable_amount: - self.payable_amount = flt(amounts['payable_amount'], 2) + self.payable_amount = flt(amounts['payable_amount'], precision) if amounts.get('due_date'): self.due_date = amounts.get('due_date') def validate_amount(self): + precision = cint(frappe.db.get_default("currency_precision")) or 2 + if not self.amount_paid: frappe.throw(_("Amount paid cannot be zero")) @@ -63,11 +68,13 @@ class LoanRepayment(AccountsController): msg = _("Paid amount cannot be less than {0}").format(self.penalty_amount) frappe.throw(msg) - if self.payment_type == "Loan Closure" and flt(self.amount_paid, 2) < flt(self.payable_amount, 2): + if self.payment_type == "Loan Closure" and flt(self.amount_paid, precision) < flt(self.payable_amount, precision): msg = _("Amount of {0} is required for Loan closure").format(self.payable_amount) frappe.throw(msg) def update_paid_amount(self): + precision = cint(frappe.db.get_default("currency_precision")) or 2 + loan = frappe.get_doc("Loan", self.against_loan) for payment in self.repayment_details: @@ -75,10 +82,13 @@ class LoanRepayment(AccountsController): SET paid_principal_amount = `paid_principal_amount` + %s, paid_interest_amount = `paid_interest_amount` + %s WHERE name = %s""", - (flt(payment.paid_principal_amount), flt(payment.paid_interest_amount), payment.loan_interest_accrual)) + (flt(payment.paid_principal_amount, precision), flt(payment.paid_interest_amount, precision), payment.loan_interest_accrual)) - if flt(loan.total_principal_paid + self.principal_amount_paid, 2) >= flt(loan.total_payment, 2): - frappe.db.set_value("Loan", self.against_loan, "status", "Loan Closure Requested") + if flt(loan.total_principal_paid + self.principal_amount_paid, precision) >= flt(loan.total_payment, precision): + if loan.is_secured_loan: + frappe.db.set_value("Loan", self.against_loan, "status", "Loan Closure Requested") + else: + frappe.db.set_value("Loan", self.against_loan, "status", "Closed") frappe.db.sql(""" UPDATE `tabLoan` SET total_amount_paid = %s, total_principal_paid = %s WHERE name = %s """, (loan.total_amount_paid + self.amount_paid, @@ -249,6 +259,7 @@ def get_accrued_interest_entries(against_loan): # So it pulls all the unpaid Loan Interest Accrual Entries and calculates the penalty if applicable def get_amounts(amounts, against_loan, posting_date, payment_type): + precision = cint(frappe.db.get_default("currency_precision")) or 2 against_loan_doc = frappe.get_doc("Loan", against_loan) loan_type_details = frappe.get_doc("Loan Type", against_loan_doc.loan_type) @@ -277,8 +288,8 @@ def get_amounts(amounts, against_loan, posting_date, payment_type): payable_principal_amount += entry.payable_principal_amount pending_accrual_entries.setdefault(entry.name, { - 'interest_amount': flt(entry.interest_amount), - 'payable_principal_amount': flt(entry.payable_principal_amount) + 'interest_amount': flt(entry.interest_amount, precision), + 'payable_principal_amount': flt(entry.payable_principal_amount, precision) }) final_due_date = due_date @@ -291,11 +302,11 @@ def get_amounts(amounts, against_loan, posting_date, payment_type): per_day_interest = (payable_principal_amount * (loan_type_details.rate_of_interest / 100))/365 total_pending_interest += (pending_days * per_day_interest) - amounts["pending_principal_amount"] = pending_principal_amount - amounts["payable_principal_amount"] = payable_principal_amount - amounts["interest_amount"] = total_pending_interest - amounts["penalty_amount"] = penalty_amount - amounts["payable_amount"] = payable_principal_amount + total_pending_interest + penalty_amount + amounts["pending_principal_amount"] = flt(pending_principal_amount, precision) + amounts["payable_principal_amount"] = flt(payable_principal_amount, precision) + amounts["interest_amount"] = flt(total_pending_interest, precision) + amounts["penalty_amount"] = flt(penalty_amount, precision) + amounts["payable_amount"] = flt(payable_principal_amount + total_pending_interest + penalty_amount, precision) amounts["pending_accrual_entries"] = pending_accrual_entries if final_due_date: diff --git a/erpnext/loan_management/doctype/loan_type/loan_type.json b/erpnext/loan_management/doctype/loan_type/loan_type.json index 51c5cb98a6..1dd3710cd2 100644 --- a/erpnext/loan_management/doctype/loan_type/loan_type.json +++ b/erpnext/loan_management/doctype/loan_type/loan_type.json @@ -41,6 +41,7 @@ "options": "Company:company:default_currency" }, { + "default": "0", "fieldname": "rate_of_interest", "fieldtype": "Percent", "label": "Rate of Interest (%) Yearly", @@ -143,7 +144,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-04-15 00:24:43.259963", + "modified": "2020-06-07 18:55:59.346292", "modified_by": "Administrator", "module": "Loan Management", "name": "Loan Type", diff --git a/erpnext/loan_management/report/loan_security_status/loan_security_status.py b/erpnext/loan_management/report/loan_security_status/loan_security_status.py index ea6a2ee645..1951855475 100644 --- a/erpnext/loan_management/report/loan_security_status/loan_security_status.py +++ b/erpnext/loan_management/report/loan_security_status/loan_security_status.py @@ -76,7 +76,8 @@ def get_columns(filters): "fieldtype": "Link", "fieldname": "currency", "options": "Currency", - "width": 50 + "width": 50, + "hidden": 1 } ] @@ -84,17 +85,13 @@ def get_columns(filters): def get_data(filters): - loan_security_price_map = frappe._dict(frappe.get_all("Loan Security", - fields=["name", "loan_security_price"], as_list=1 - )) - data = [] conditions = get_conditions(filters) loan_security_pledges = frappe.db.sql(""" SELECT p.name, p.applicant, p.loan, p.status, p.pledge_time, - c.loan_security, c.qty + c.loan_security, c.qty, c.loan_security_price, c.amount FROM `tabLoan Security Pledge` p, `tabPledge` c WHERE @@ -115,8 +112,8 @@ def get_data(filters): row["pledge_time"] = pledge.pledge_time row["loan_security"] = pledge.loan_security row["qty"] = pledge.qty - row["loan_security_price"] = loan_security_price_map.get(pledge.loan_security) - row["loan_security_value"] = row["loan_security_price"] * pledge.qty + row["loan_security_price"] = pledge.loan_security_price + row["loan_security_value"] = pledge.amount row["currency"] = default_currency data.append(row) From df93589032f7da80d0142329d691aa79133fe6ea Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 7 Jun 2020 21:23:55 +0530 Subject: [PATCH 104/449] fix: Ignore GL Entry on cancel --- .../doctype/loan_disbursement/loan_disbursement.py | 1 + .../doctype/loan_interest_accrual/loan_interest_accrual.py | 1 + 2 files changed, 2 insertions(+) diff --git a/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.py b/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.py index c9e36a84dd..d44088bee7 100644 --- a/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.py +++ b/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.py @@ -27,6 +27,7 @@ class LoanDisbursement(AccountsController): def on_cancel(self): self.make_gl_entries(cancel=1) + self.ignore_linked_doctypes = ['GL Entry'] def set_missing_values(self): if not self.disbursement_date: diff --git a/erpnext/loan_management/doctype/loan_interest_accrual/loan_interest_accrual.py b/erpnext/loan_management/doctype/loan_interest_accrual/loan_interest_accrual.py index 659173557b..e6ceb55185 100644 --- a/erpnext/loan_management/doctype/loan_interest_accrual/loan_interest_accrual.py +++ b/erpnext/loan_management/doctype/loan_interest_accrual/loan_interest_accrual.py @@ -31,6 +31,7 @@ class LoanInterestAccrual(AccountsController): self.update_is_accrued() self.make_gl_entries(cancel=1) + self.ignore_linked_doctypes = ['GL Entry'] def update_is_accrued(self): frappe.db.set_value('Repayment Schedule', self.repayment_schedule_name, 'is_accrued', 0) From c1bc819f18a0ebd210edc9973a255a8d99a16226 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Tue, 9 Jun 2020 17:41:27 +0530 Subject: [PATCH 105/449] Revert "fix: docfield of sales_order is not fetching route options for new doc (#21123)" This reverts commit 5c54adec28c7fda2e290a1bd2bfd1ab7f3c751d0. (cherry picked from commit e5fe00cf58bf1aa0edbb07bfbc70dc66c60023f2) --- erpnext/projects/doctype/project/project.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/projects/doctype/project/project.js b/erpnext/projects/doctype/project/project.js index 5862963496..3570a0f2be 100644 --- a/erpnext/projects/doctype/project/project.js +++ b/erpnext/projects/doctype/project/project.js @@ -18,7 +18,7 @@ frappe.ui.form.on("Project", { }; }, onload: function (frm) { - var so = frm.get_docfield("Project", "sales_order"); + var so = frappe.meta.get_docfield("Project", "sales_order"); so.get_route_options_for_new_doc = function (field) { if (frm.is_new()) return; return { @@ -135,4 +135,4 @@ function open_form(frm, doctype, child_doctype, parentfield) { frappe.ui.form.make_quick_entry(doctype, null, null, new_doc); }); -} +} \ No newline at end of file From 9e3d6755d7e3b4c1b9a290ce13193d5d927ebbcb Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 10 Jun 2020 19:57:49 +0530 Subject: [PATCH 106/449] fix: Party validation for inter-warehouse transaction (cherry picked from commit 7963e2b708db5c0240b228846f17d999373f59b3) --- erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 05b85dabd4..a81fdacf47 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1450,11 +1450,17 @@ def get_inter_company_details(doc, doctype): parties = frappe.db.get_all("Supplier", fields=["name"], filters={"disabled": 0, "is_internal_supplier": 1, "represents_company": doc.company}) company = frappe.get_cached_value("Customer", doc.customer, "represents_company") + if not parties: + frappe.throw(_('No Supplier found for Inter Company Transactions which represents company {0}').format(frappe.bold(doc.company))) + party = get_internal_party(parties, "Supplier", doc) else: parties = frappe.db.get_all("Customer", fields=["name"], filters={"disabled": 0, "is_internal_customer": 1, "represents_company": doc.company}) company = frappe.get_cached_value("Supplier", doc.supplier, "represents_company") + if not parties: + frappe.throw(_('No Customer found for Inter Company Transactions which represents company {0}').format(frappe.bold(doc.company))) + party = get_internal_party(parties, "Customer", doc) return { From 5a176a78b724ad99d1d27974b4ef0567352fe9be Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 12 Jun 2020 13:01:22 +0530 Subject: [PATCH 107/449] feat(Attendance): Add In and Out time to attendance (#21547) (#22212) * feat(Attendance): Add In and Out time to attendance Co-authored-by: Karthikeyan S * fix:add depends in attendance IN time and OUT time Co-authored-by: Karthikeyan S (cherry picked from commit 90957b7f747b89e85037aeb713043a4e4437e96d) Co-authored-by: Vignesh S --- erpnext/hr/doctype/attendance/attendance.json | 35 ++++++++++++++++--- .../employee_checkin/employee_checkin.py | 6 ++-- erpnext/hr/doctype/shift_type/shift_type.py | 13 +++---- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/erpnext/hr/doctype/attendance/attendance.json b/erpnext/hr/doctype/attendance/attendance.json index 906f6f77f2..a656a7ea5f 100644 --- a/erpnext/hr/doctype/attendance/attendance.json +++ b/erpnext/hr/doctype/attendance/attendance.json @@ -19,11 +19,15 @@ "attendance_date", "company", "department", - "shift", "attendance_request", - "amended_from", + "details_section", + "shift", + "in_time", + "out_time", + "column_break_18", "late_entry", - "early_exit" + "early_exit", + "amended_from" ], "fields": [ { @@ -172,13 +176,36 @@ "fieldname": "early_exit", "fieldtype": "Check", "label": "Early Exit" + }, + { + "fieldname": "details_section", + "fieldtype": "Section Break", + "label": "Details" + }, + { + "depends_on": "shift", + "fieldname": "in_time", + "fieldtype": "Datetime", + "label": "In Time", + "read_only": 1 + }, + { + "depends_on": "shift", + "fieldname": "out_time", + "fieldtype": "Datetime", + "label": "Out Time", + "read_only": 1 + }, + { + "fieldname": "column_break_18", + "fieldtype": "Column Break" } ], "icon": "fa fa-ok", "idx": 1, "is_submittable": 1, "links": [], - "modified": "2020-04-11 11:40:14.319496", + "modified": "2020-05-29 13:51:37.177231", "modified_by": "Administrator", "module": "HR", "name": "Attendance", diff --git a/erpnext/hr/doctype/employee_checkin/employee_checkin.py b/erpnext/hr/doctype/employee_checkin/employee_checkin.py index 86705121ac..15fbd4e015 100644 --- a/erpnext/hr/doctype/employee_checkin/employee_checkin.py +++ b/erpnext/hr/doctype/employee_checkin/employee_checkin.py @@ -72,7 +72,7 @@ def add_log_based_on_employee_field(employee_field_value, timestamp, device_id=N return doc -def mark_attendance_and_link_log(logs, attendance_status, attendance_date, working_hours=None, late_entry=False, early_exit=False, shift=None): +def mark_attendance_and_link_log(logs, attendance_status, attendance_date, working_hours=None, late_entry=False, early_exit=False, in_time=None, out_time=None, shift=None): """Creates an attendance and links the attendance to the Employee Checkin. Note: If attendance is already present for the given date, the logs are marked as skipped and no exception is thrown. @@ -100,7 +100,9 @@ def mark_attendance_and_link_log(logs, attendance_status, attendance_date, worki 'company': employee_doc.company, 'shift': shift, 'late_entry': late_entry, - 'early_exit': early_exit + 'early_exit': early_exit, + 'in_time': in_time, + 'out_time': out_time } attendance = frappe.get_doc(doc_dict).insert() attendance.submit() diff --git a/erpnext/hr/doctype/shift_type/shift_type.py b/erpnext/hr/doctype/shift_type/shift_type.py index d56080eecd..19735648aa 100644 --- a/erpnext/hr/doctype/shift_type/shift_type.py +++ b/erpnext/hr/doctype/shift_type/shift_type.py @@ -28,13 +28,14 @@ class ShiftType(Document): logs = frappe.db.get_list('Employee Checkin', fields="*", filters=filters, order_by="employee,time") for key, group in itertools.groupby(logs, key=lambda x: (x['employee'], x['shift_actual_start'])): single_shift_logs = list(group) - attendance_status, working_hours, late_entry, early_exit = self.get_attendance(single_shift_logs) - mark_attendance_and_link_log(single_shift_logs, attendance_status, key[1].date(), working_hours, late_entry, early_exit, self.name) + attendance_status, working_hours, late_entry, early_exit, in_time, out_time = self.get_attendance(single_shift_logs) + mark_attendance_and_link_log(single_shift_logs, attendance_status, key[1].date(), working_hours, late_entry, early_exit, in_time, out_time, self.name) for employee in self.get_assigned_employee(self.process_attendance_after, True): self.mark_absent_for_dates_with_no_attendance(employee) def get_attendance(self, logs): - """Return attendance_status, working_hours for a set of logs belonging to a single shift. + """Return attendance_status, working_hours, late_entry, early_exit, in_time, out_time + for a set of logs belonging to a single shift. Assumtion: 1. These logs belongs to an single shift, single employee and is not in a holiday date. 2. Logs are in chronological order @@ -48,10 +49,10 @@ class ShiftType(Document): early_exit = True if self.working_hours_threshold_for_absent and total_working_hours < self.working_hours_threshold_for_absent: - return 'Absent', total_working_hours, late_entry, early_exit + return 'Absent', total_working_hours, late_entry, early_exit, in_time, out_time if self.working_hours_threshold_for_half_day and total_working_hours < self.working_hours_threshold_for_half_day: - return 'Half Day', total_working_hours, late_entry, early_exit - return 'Present', total_working_hours, late_entry, early_exit + return 'Half Day', total_working_hours, late_entry, early_exit, in_time, out_time + return 'Present', total_working_hours, late_entry, early_exit, in_time, out_time def mark_absent_for_dates_with_no_attendance(self, employee): """Marks Absents for the given employee on working days in this shift which have no attendance marked. From 103645835bdb91a0d9fa4a5ba4babab7bbad9b03 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 14 Jun 2020 13:27:19 +0530 Subject: [PATCH 108/449] fix: Handle cancelled entries in financial statements --- erpnext/accounts/report/financial_statements.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 4a35a66865..5ec78ac72a 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -391,6 +391,7 @@ def set_gl_entries_by_account( where company=%(company)s {additional_conditions} and posting_date <= %(to_date)s + and is_cancelled = 0 order by account, posting_date""".format(additional_conditions=additional_conditions), gl_filters, as_dict=True) #nosec if filters and filters.get('presentation_currency'): From 6e2ca779c5f66f82486e8e52ec908b7e20283f87 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Fri, 12 Jun 2020 18:33:42 +0530 Subject: [PATCH 109/449] feat: Accounting entries for service item in Purchase receipt (cherry picked from commit c258ac82c58f5937a0f5fcd564ef624f5ec6227a) --- erpnext/accounts/doctype/account/account.json | 82 +++- .../purchase_invoice/purchase_invoice.py | 12 + erpnext/setup/doctype/company/company.js | 5 +- erpnext/setup/doctype/company/company.json | 373 +++++++++++++----- .../purchase_receipt/purchase_receipt.py | 27 ++ .../stock_settings/stock_settings.json | 131 ++++-- 6 files changed, 489 insertions(+), 141 deletions(-) diff --git a/erpnext/accounts/doctype/account/account.json b/erpnext/accounts/doctype/account/account.json index af252e6191..d2659d429b 100644 --- a/erpnext/accounts/doctype/account/account.json +++ b/erpnext/accounts/doctype/account/account.json @@ -34,11 +34,15 @@ { "fieldname": "properties", "fieldtype": "Section Break", - "oldfieldtype": "Section Break" + "oldfieldtype": "Section Break", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "column_break0", "fieldtype": "Column Break", + "show_days": 1, + "show_seconds": 1, "width": "50%" }, { @@ -49,7 +53,9 @@ "no_copy": 1, "oldfieldname": "account_name", "oldfieldtype": "Data", - "reqd": 1 + "reqd": 1, + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "account_number", @@ -57,13 +63,17 @@ "in_list_view": 1, "in_standard_filter": 1, "label": "Account Number", - "read_only": 1 + "read_only": 1, + "show_days": 1, + "show_seconds": 1 }, { "default": "0", "fieldname": "is_group", "fieldtype": "Check", - "label": "Is Group" + "label": "Is Group", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "company", @@ -75,7 +85,9 @@ "options": "Company", "read_only": 1, "remember_last_selected_value": 1, - "reqd": 1 + "reqd": 1, + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "root_type", @@ -83,7 +95,9 @@ "in_standard_filter": 1, "label": "Root Type", "options": "\nAsset\nLiability\nIncome\nExpense\nEquity", - "read_only": 1 + "read_only": 1, + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "report_type", @@ -91,24 +105,32 @@ "in_standard_filter": 1, "label": "Report Type", "options": "\nBalance Sheet\nProfit and Loss", - "read_only": 1 + "read_only": 1, + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:doc.is_group==0", "fieldname": "account_currency", "fieldtype": "Link", "label": "Currency", - "options": "Currency" + "options": "Currency", + "show_days": 1, + "show_seconds": 1 }, { "default": "0", "fieldname": "inter_company_account", "fieldtype": "Check", - "label": "Inter Company Account" + "label": "Inter Company Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "column_break1", "fieldtype": "Column Break", + "show_days": 1, + "show_seconds": 1, "width": "50%" }, { @@ -120,7 +142,9 @@ "oldfieldtype": "Link", "options": "Account", "reqd": 1, - "search_index": 1 + "search_index": 1, + "show_days": 1, + "show_seconds": 1 }, { "description": "Setting Account Type helps in selecting this Account in transactions.", @@ -130,7 +154,9 @@ "label": "Account Type", "oldfieldname": "account_type", "oldfieldtype": "Select", - "options": "\nAccumulated Depreciation\nAsset Received But Not Billed\nBank\nCash\nChargeable\nCapital Work in Progress\nCost of Goods Sold\nDepreciation\nEquity\nExpense Account\nExpenses Included In Asset Valuation\nExpenses Included In Valuation\nFixed Asset\nIncome Account\nPayable\nReceivable\nRound Off\nStock\nStock Adjustment\nStock Received But Not Billed\nTax\nTemporary" + "options": "\nAccumulated Depreciation\nAsset Received But Not Billed\nBank\nCash\nChargeable\nCapital Work in Progress\nCost of Goods Sold\nDepreciation\nEquity\nExpense Account\nExpenses Included In Asset Valuation\nExpenses Included In Valuation\nFixed Asset\nIncome Account\nPayable\nReceivable\nRound Off\nStock\nStock Adjustment\nStock Received But Not Billed\nService Received But Not Billed\nTax\nTemporary", + "show_days": 1, + "show_seconds": 1 }, { "description": "Rate at which this tax is applied", @@ -138,7 +164,9 @@ "fieldtype": "Float", "label": "Rate", "oldfieldname": "tax_rate", - "oldfieldtype": "Currency" + "oldfieldtype": "Currency", + "show_days": 1, + "show_seconds": 1 }, { "description": "If the account is frozen, entries are allowed to restricted users.", @@ -147,13 +175,17 @@ "label": "Frozen", "oldfieldname": "freeze_account", "oldfieldtype": "Select", - "options": "No\nYes" + "options": "No\nYes", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "balance_must_be", "fieldtype": "Select", "label": "Balance must be", - "options": "\nDebit\nCredit" + "options": "\nDebit\nCredit", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "lft", @@ -162,7 +194,9 @@ "label": "Lft", "print_hide": 1, "read_only": 1, - "search_index": 1 + "search_index": 1, + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "rgt", @@ -171,7 +205,9 @@ "label": "Rgt", "print_hide": 1, "read_only": 1, - "search_index": 1 + "search_index": 1, + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "old_parent", @@ -179,27 +215,33 @@ "hidden": 1, "label": "Old Parent", "print_hide": 1, - "read_only": 1 + "read_only": 1, + "show_days": 1, + "show_seconds": 1 }, { "default": "0", "depends_on": "eval:(doc.report_type == 'Profit and Loss' && !doc.is_group)", "fieldname": "include_in_gross", "fieldtype": "Check", - "label": "Include in gross" + "label": "Include in gross", + "show_days": 1, + "show_seconds": 1 }, { "default": "0", "fieldname": "disabled", "fieldtype": "Check", - "label": "Disable" + "label": "Disable", + "show_days": 1, + "show_seconds": 1 } ], "icon": "fa fa-money", "idx": 1, "is_tree": 1, "links": [], - "modified": "2020-03-18 17:57:52.063233", + "modified": "2020-06-11 15:15:54.338622", "modified_by": "Administrator", "module": "Accounts", "name": "Account", diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 870718c22d..1e548c00b7 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -587,6 +587,18 @@ class PurchaseInvoice(BuyingController): else: amount = flt(item.base_net_amount + item.item_tax_amount, item.precision("base_net_amount")) + auto_accounting_for_non_stock_items = cint(frappe.db.get_single_value('Stock Settings', 'enable_perpetual_inventory_for_non_stock_items')) + service_received_but_not_billed_account = self.get_company_default("service_received_but_not_billed") + + if item.purchase_receipt and auto_accounting_for_non_stock_items: + # Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt + expense_booked_in_pr = frappe.db.get_value('GL Entry', {'is_cancelled': 0, + 'voucher_type': 'Purchase Receipt', 'voucher_no': item.purchase_receipt, 'voucher_detail_no': item.pr_detail, + 'account':service_received_but_not_billed_account}, ['name']) + + if expense_booked_in_pr: + expense_account = service_received_but_not_billed_account + gl_entries.append(self.get_gl_dict({ "account": expense_account, "against": self.supplier, diff --git a/erpnext/setup/doctype/company/company.js b/erpnext/setup/doctype/company/company.js index 875904fe6f..7ae5385a23 100644 --- a/erpnext/setup/doctype/company/company.js +++ b/erpnext/setup/doctype/company/company.js @@ -264,7 +264,10 @@ erpnext.company.setup_queries = function(frm) { ["expenses_included_in_valuation", {"root_type": "Expense", "account_type": "Expenses Included in Valuation"}], ["stock_received_but_not_billed", - {"root_type": "Liability", "account_type": "Stock Received But Not Billed"}] + {"root_type": "Liability", "account_type": "Stock Received But Not Billed"}], + ["service_received_but_not_billed", + {"root_type": "Liability", "account_type": "Service Received But Not Billed"}], + ], function(i, v) { erpnext.company.set_custom_query(frm, v); }); diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json index 020a93ff6a..0b91b70034 100644 --- a/erpnext/setup/doctype/company/company.json +++ b/erpnext/setup/doctype/company/company.json @@ -71,6 +71,7 @@ "stock_adjustment_account", "column_break_32", "stock_received_but_not_billed", + "service_received_but_not_billed", "expenses_included_in_valuation", "fixed_asset_depreciation_settings", "accumulated_depreciation_account", @@ -106,7 +107,9 @@ { "fieldname": "details", "fieldtype": "Section Break", - "oldfieldtype": "Section Break" + "oldfieldtype": "Section Break", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "company_name", @@ -115,6 +118,8 @@ "oldfieldname": "company_name", "oldfieldtype": "Data", "reqd": 1, + "show_days": 1, + "show_seconds": 1, "unique": 1 }, { @@ -123,36 +128,48 @@ "label": "Abbr", "oldfieldname": "abbr", "oldfieldtype": "Data", - "reqd": 1 + "reqd": 1, + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:!doc.__islocal && in_list(frappe.user_roles, \"System Manager\")", "fieldname": "change_abbr", "fieldtype": "Button", - "label": "Change Abbreviation" + "label": "Change Abbreviation", + "show_days": 1, + "show_seconds": 1 }, { "bold": 1, "default": "0", "fieldname": "is_group", "fieldtype": "Check", - "label": "Is Group" + "label": "Is Group", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "default_finance_book", "fieldtype": "Link", "label": "Default Finance Book", - "options": "Finance Book" + "options": "Finance Book", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "cb0", - "fieldtype": "Column Break" + "fieldtype": "Column Break", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "domain", "fieldtype": "Link", "label": "Domain", - "options": "Domain" + "options": "Domain", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "parent_company", @@ -160,24 +177,32 @@ "ignore_user_permissions": 1, "in_list_view": 1, "label": "Parent Company", - "options": "Company" + "options": "Company", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "company_logo", "fieldtype": "Attach Image", "hidden": 1, - "label": "Company Logo" + "label": "Company Logo", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "company_description", "fieldtype": "Text Editor", - "label": "Company Description" + "label": "Company Description", + "show_days": 1, + "show_seconds": 1 }, { "collapsible": 1, "fieldname": "sales_settings", "fieldtype": "Section Break", - "label": "Sales Settings" + "label": "Sales Settings", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "sales_monthly_history", @@ -185,7 +210,9 @@ "hidden": 1, "label": "Sales Monthly History", "no_copy": 1, - "read_only": 1 + "read_only": 1, + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "transactions_annual_history", @@ -193,17 +220,23 @@ "hidden": 1, "label": "Transactions Annual History", "no_copy": 1, - "read_only": 1 + "read_only": 1, + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "monthly_sales_target", "fieldtype": "Currency", "label": "Monthly Sales Target", - "options": "default_currency" + "options": "default_currency", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "column_break_goals", - "fieldtype": "Column Break" + "fieldtype": "Column Break", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "total_monthly_sales", @@ -211,12 +244,16 @@ "label": "Total Monthly Sales", "no_copy": 1, "options": "default_currency", - "read_only": 1 + "read_only": 1, + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "charts_section", "fieldtype": "Section Break", - "label": "Default Values" + "label": "Default Values", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "default_currency", @@ -224,34 +261,46 @@ "ignore_user_permissions": 1, "label": "Default Currency", "options": "Currency", - "reqd": 1 + "reqd": 1, + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "default_letter_head", "fieldtype": "Link", "label": "Default Letter Head", - "options": "Letter Head" + "options": "Letter Head", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "default_holiday_list", "fieldtype": "Link", "label": "Default Holiday List", - "options": "Holiday List" + "options": "Holiday List", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "standard_working_hours", "fieldtype": "Float", - "label": "Standard Working Hours" + "label": "Standard Working Hours", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "default_warehouse_for_sales_return", "fieldtype": "Link", "label": "Default warehouse for Sales Return", - "options": "Warehouse" + "options": "Warehouse", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "column_break_10", - "fieldtype": "Column Break" + "fieldtype": "Column Break", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "country", @@ -259,20 +308,26 @@ "in_list_view": 1, "label": "Country", "options": "Country", - "reqd": 1 + "reqd": 1, + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "create_chart_of_accounts_based_on", "fieldtype": "Select", "label": "Create Chart Of Accounts Based On", - "options": "\nStandard Template\nExisting Company" + "options": "\nStandard Template\nExisting Company", + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:doc.create_chart_of_accounts_based_on===\"Standard Template\"", "fieldname": "chart_of_accounts", "fieldtype": "Select", "label": "Chart Of Accounts Template", - "no_copy": 1 + "no_copy": 1, + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:doc.create_chart_of_accounts_based_on===\"Existing Company\"", @@ -281,23 +336,31 @@ "ignore_user_permissions": 1, "label": "Existing Company ", "no_copy": 1, - "options": "Company" + "options": "Company", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "tax_id", "fieldtype": "Data", - "label": "Tax ID" + "label": "Tax ID", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "date_of_establishment", "fieldtype": "Date", - "label": "Date of Establishment" + "label": "Date of Establishment", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "default_settings", "fieldtype": "Section Break", "label": "Accounts Settings", - "oldfieldtype": "Section Break" + "oldfieldtype": "Section Break", + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:!doc.__islocal", @@ -308,7 +371,9 @@ "no_copy": 1, "oldfieldname": "default_bank_account", "oldfieldtype": "Link", - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:!doc.__islocal", @@ -317,7 +382,9 @@ "ignore_user_permissions": 1, "label": "Default Cash Account", "no_copy": 1, - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:!doc.__islocal", @@ -328,54 +395,72 @@ "no_copy": 1, "oldfieldname": "receivables_group", "oldfieldtype": "Link", - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "round_off_account", "fieldtype": "Link", "label": "Round Off Account", - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "round_off_cost_center", "fieldtype": "Link", "label": "Round Off Cost Center", - "options": "Cost Center" + "options": "Cost Center", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "write_off_account", "fieldtype": "Link", "label": "Write Off Account", - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "discount_allowed_account", "fieldtype": "Link", "label": "Discount Allowed Account", - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "discount_received_account", "fieldtype": "Link", "label": "Discount Received Account", - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "exchange_gain_loss_account", "fieldtype": "Link", "label": "Exchange Gain / Loss Account", - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "unrealized_exchange_gain_loss_account", "fieldtype": "Link", "label": "Unrealized Exchange Gain/Loss Account", - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "column_break0", "fieldtype": "Column Break", "oldfieldtype": "Column Break", + "show_days": 1, + "show_seconds": 1, "width": "50%" }, { @@ -383,7 +468,9 @@ "depends_on": "eval:doc.parent_company", "fieldname": "allow_account_creation_against_child_company", "fieldtype": "Check", - "label": "Allow Account Creation Against Child Company" + "label": "Allow Account Creation Against Child Company", + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:!doc.__islocal", @@ -394,14 +481,18 @@ "no_copy": 1, "oldfieldname": "payables_group", "oldfieldtype": "Link", - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "default_employee_advance_account", "fieldtype": "Link", "label": "Default Employee Advance Account", "no_copy": 1, - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:!doc.__islocal", @@ -410,7 +501,9 @@ "ignore_user_permissions": 1, "label": "Default Cost of Goods Sold Account", "no_copy": 1, - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:!doc.__islocal", @@ -419,7 +512,9 @@ "ignore_user_permissions": 1, "label": "Default Income Account", "no_copy": 1, - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:!doc.__islocal", @@ -428,7 +523,9 @@ "ignore_user_permissions": 1, "label": "Default Deferred Revenue Account", "no_copy": 1, - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:!doc.__islocal", @@ -437,7 +534,9 @@ "ignore_user_permissions": 1, "label": "Default Deferred Expense Account", "no_copy": 1, - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:!doc.__islocal", @@ -446,7 +545,9 @@ "ignore_user_permissions": 1, "label": "Default Payroll Payable Account", "no_copy": 1, - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:!doc.__islocal", @@ -455,11 +556,15 @@ "ignore_user_permissions": 1, "label": "Default Expense Claim Payable Account", "no_copy": 1, - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "section_break_22", - "fieldtype": "Section Break" + "fieldtype": "Section Break", + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:!doc.__islocal", @@ -468,11 +573,15 @@ "ignore_user_permissions": 1, "label": "Default Cost Center", "no_copy": 1, - "options": "Cost Center" + "options": "Cost Center", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "column_break_26", - "fieldtype": "Column Break" + "fieldtype": "Column Break", + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:!doc.__islocal", @@ -481,31 +590,41 @@ "label": "Credit Limit", "oldfieldname": "credit_limit", "oldfieldtype": "Currency", - "options": "default_currency" + "options": "default_currency", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "payment_terms", "fieldtype": "Link", "label": "Default Payment Terms Template", - "options": "Payment Terms Template" + "options": "Payment Terms Template", + "show_days": 1, + "show_seconds": 1 }, { "depends_on": "eval:!doc.__islocal", "fieldname": "auto_accounting_for_stock_settings", "fieldtype": "Section Break", - "label": "Stock Settings" + "label": "Stock Settings", + "show_days": 1, + "show_seconds": 1 }, { "default": "1", "fieldname": "enable_perpetual_inventory", "fieldtype": "Check", - "label": "Enable Perpetual Inventory" + "label": "Enable Perpetual Inventory", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "default_inventory_account", "fieldtype": "Link", "label": "Default Inventory Account", - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "stock_adjustment_account", @@ -513,11 +632,15 @@ "ignore_user_permissions": 1, "label": "Stock Adjustment Account", "no_copy": 1, - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "column_break_32", - "fieldtype": "Column Break" + "fieldtype": "Column Break", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "stock_received_but_not_billed", @@ -525,7 +648,9 @@ "ignore_user_permissions": 1, "label": "Stock Received But Not Billed", "no_copy": 1, - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "expenses_included_in_valuation", @@ -533,108 +658,144 @@ "ignore_user_permissions": 1, "label": "Expenses Included In Valuation", "no_copy": 1, - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "collapsible": 1, "fieldname": "fixed_asset_depreciation_settings", "fieldtype": "Section Break", - "label": "Fixed Asset Depreciation Settings" + "label": "Fixed Asset Depreciation Settings", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "accumulated_depreciation_account", "fieldtype": "Link", "label": "Accumulated Depreciation Account", "no_copy": 1, - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "depreciation_expense_account", "fieldtype": "Link", "label": "Depreciation Expense Account", "no_copy": 1, - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "series_for_depreciation_entry", "fieldtype": "Data", - "label": "Series for Asset Depreciation Entry (Journal Entry)" + "label": "Series for Asset Depreciation Entry (Journal Entry)", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "expenses_included_in_asset_valuation", "fieldtype": "Link", "label": "Expenses Included In Asset Valuation", - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "column_break_40", - "fieldtype": "Column Break" + "fieldtype": "Column Break", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "disposal_account", "fieldtype": "Link", "label": "Gain/Loss Account on Asset Disposal", "no_copy": 1, - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "depreciation_cost_center", "fieldtype": "Link", "label": "Asset Depreciation Cost Center", "no_copy": 1, - "options": "Cost Center" + "options": "Cost Center", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "capital_work_in_progress_account", "fieldtype": "Link", "label": "Capital Work In Progress Account", - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "asset_received_but_not_billed", "fieldtype": "Link", "label": "Asset Received But Not Billed", - "options": "Account" + "options": "Account", + "show_days": 1, + "show_seconds": 1 }, { "collapsible": 1, "fieldname": "budget_detail", "fieldtype": "Section Break", - "label": "Budget Detail" + "label": "Budget Detail", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "exception_budget_approver_role", "fieldtype": "Link", "label": "Exception Budget Approver Role", - "options": "Role" + "options": "Role", + "show_days": 1, + "show_seconds": 1 }, { "collapsible": 1, "description": "For reference only.", "fieldname": "company_info", "fieldtype": "Section Break", - "label": "Company Info" + "label": "Company Info", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "date_of_incorporation", "fieldtype": "Date", - "label": "Date of Incorporation" + "label": "Date of Incorporation", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "address_html", - "fieldtype": "HTML" + "fieldtype": "HTML", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "column_break1", "fieldtype": "Column Break", "oldfieldtype": "Column Break", + "show_days": 1, + "show_seconds": 1, "width": "50%" }, { "depends_on": "eval:doc.date_of_incorporation", "fieldname": "date_of_commencement", "fieldtype": "Date", - "label": "Date of Commencement" + "label": "Date of Commencement", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "phone_no", @@ -642,7 +803,9 @@ "label": "Phone No", "oldfieldname": "phone_no", "oldfieldtype": "Data", - "options": "Phone" + "options": "Phone", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "fax", @@ -650,7 +813,9 @@ "label": "Fax", "oldfieldname": "fax", "oldfieldtype": "Data", - "options": "Phone" + "options": "Phone", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "email", @@ -658,19 +823,25 @@ "label": "Email", "oldfieldname": "email", "oldfieldtype": "Data", - "options": "Email" + "options": "Email", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "website", "fieldtype": "Data", "label": "Website", "oldfieldname": "website", - "oldfieldtype": "Data" + "oldfieldtype": "Data", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "registration_info", "fieldtype": "Section Break", "oldfieldtype": "Section Break", + "show_days": 1, + "show_seconds": 1, "width": "50%" }, { @@ -679,12 +850,16 @@ "fieldtype": "Code", "label": "Registration Details", "oldfieldname": "registration_details", - "oldfieldtype": "Code" + "oldfieldtype": "Code", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "delete_company_transactions", "fieldtype": "Button", - "label": "Delete Company Transactions" + "label": "Delete Company Transactions", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "lft", @@ -693,7 +868,9 @@ "label": "Lft", "print_hide": 1, "read_only": 1, - "search_index": 1 + "search_index": 1, + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "rgt", @@ -702,7 +879,9 @@ "label": "Rgt", "print_hide": 1, "read_only": 1, - "search_index": 1 + "search_index": 1, + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "old_parent", @@ -710,19 +889,35 @@ "hidden": 1, "label": "old_parent", "print_hide": 1, - "read_only": 1 + "read_only": 1, + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "default_selling_terms", "fieldtype": "Link", "label": "Default Selling Terms", - "options": "Terms and Conditions" + "options": "Terms and Conditions", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "default_buying_terms", "fieldtype": "Link", "label": "Default Buying Terms", - "options": "Terms and Conditions" + "options": "Terms and Conditions", + "show_days": 1, + "show_seconds": 1 + }, + { + "fieldname": "service_received_but_not_billed", + "fieldtype": "Link", + "ignore_user_permissions": 1, + "label": "Service Received But Not Billed", + "no_copy": 1, + "options": "Account", + "show_days": 1, + "show_seconds": 1 } ], "icon": "fa fa-building", @@ -730,7 +925,7 @@ "image_field": "company_logo", "is_tree": 1, "links": [], - "modified": "2020-03-21 18:09:53.534211", + "modified": "2020-06-11 15:32:59.147735", "modified_by": "Administrator", "module": "Setup", "name": "Company", diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index e6ab8d634d..94a6edd2c1 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -211,6 +211,8 @@ class PurchaseReceipt(BuyingController): stock_rbnb = self.get_company_default("stock_received_but_not_billed") landed_cost_entries = get_item_account_wise_additional_cost(self.name) expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") + service_received_but_not_billed_account = self.get_company_default("service_received_but_not_billed") + auto_accounting_for_non_stock_items = cint(frappe.db.get_single_value('Stock Settings', 'enable_perpetual_inventory_for_non_stock_items')) gl_entries = [] warehouse_with_no_account = [] @@ -301,6 +303,31 @@ class PurchaseReceipt(BuyingController): elif d.warehouse not in warehouse_with_no_account or \ d.rejected_warehouse not in warehouse_with_no_account: warehouse_with_no_account.append(d.warehouse) + elif d.item_code not in stock_items and flt(d.qty) and auto_accounting_for_non_stock_items: + + credit_currency = get_account_currency(service_received_but_not_billed_account) + + gl_entries.append(self.get_gl_dict({ + "account": service_received_but_not_billed_account, + "against": d.expense_account, + "cost_center": d.cost_center, + "remarks": self.get("remarks") or _("Accounting Entry for Service"), + "project": d.project, + "credit": d.amount, + "voucher_detail_no": d.name + }, credit_currency, item=d)) + + debit_currency = get_account_currency(d.expense_account) + + gl_entries.append(self.get_gl_dict({ + "account": d.expense_account, + "against": service_received_but_not_billed_account, + "cost_center": d.cost_center, + "remarks": self.get("remarks") or _("Accounting Entry for Service"), + "project": d.project, + "debit": d.amount, + "voucher_detail_no": d.name + }, debit_currency, item=d)) self.get_asset_gl_entry(gl_entries) # Cost center-wise amount breakup for other charges included for valuation diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.json b/erpnext/stock/doctype/stock_settings/stock_settings.json index c9a3527e91..a7ed620dca 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.json +++ b/erpnext/stock/doctype/stock_settings/stock_settings.json @@ -16,6 +16,7 @@ "action_if_quality_inspection_is_not_submitted", "show_barcode_field", "clean_description_html", + "enable_perpetual_inventory_for_non_stock_items", "section_break_7", "auto_insert_price_list_rate_if_missing", "allow_negative_stock", @@ -43,180 +44,248 @@ "fieldtype": "Select", "in_list_view": 1, "label": "Item Naming By", - "options": "Item Code\nNaming Series" + "options": "Item Code\nNaming Series", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "item_group", "fieldtype": "Link", "in_list_view": 1, "label": "Default Item Group", - "options": "Item Group" + "options": "Item Group", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "stock_uom", "fieldtype": "Link", "in_list_view": 1, "label": "Default Stock UOM", - "options": "UOM" + "options": "UOM", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "default_warehouse", "fieldtype": "Link", "label": "Default Warehouse", - "options": "Warehouse" + "options": "Warehouse", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "sample_retention_warehouse", "fieldtype": "Link", "label": "Sample Retention Warehouse", - "options": "Warehouse" + "options": "Warehouse", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "column_break_4", - "fieldtype": "Column Break" + "fieldtype": "Column Break", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "valuation_method", "fieldtype": "Select", "label": "Default Valuation Method", - "options": "FIFO\nMoving Average" + "options": "FIFO\nMoving Average", + "show_days": 1, + "show_seconds": 1 }, { "description": "Percentage you are allowed to receive or deliver more against the quantity ordered. For example: If you have ordered 100 units. and your Allowance is 10% then you are allowed to receive 110 units.", "fieldname": "over_delivery_receipt_allowance", "fieldtype": "Float", - "label": "Over Delivery/Receipt Allowance (%)" + "label": "Over Delivery/Receipt Allowance (%)", + "show_days": 1, + "show_seconds": 1 }, { "default": "Stop", "fieldname": "action_if_quality_inspection_is_not_submitted", "fieldtype": "Select", "label": "Action if Quality inspection is not submitted", - "options": "Stop\nWarn" + "options": "Stop\nWarn", + "show_days": 1, + "show_seconds": 1 }, { "default": "1", "fieldname": "show_barcode_field", "fieldtype": "Check", - "label": "Show Barcode Field" + "label": "Show Barcode Field", + "show_days": 1, + "show_seconds": 1 }, { "default": "1", "fieldname": "clean_description_html", "fieldtype": "Check", - "label": "Convert Item Description to Clean HTML" + "label": "Convert Item Description to Clean HTML", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "section_break_7", - "fieldtype": "Section Break" + "fieldtype": "Section Break", + "show_days": 1, + "show_seconds": 1 }, { "default": "0", "fieldname": "auto_insert_price_list_rate_if_missing", "fieldtype": "Check", - "label": "Auto insert Price List rate if missing" + "label": "Auto insert Price List rate if missing", + "show_days": 1, + "show_seconds": 1 }, { "default": "0", "fieldname": "allow_negative_stock", "fieldtype": "Check", - "label": "Allow Negative Stock" + "label": "Allow Negative Stock", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "column_break_10", - "fieldtype": "Column Break" + "fieldtype": "Column Break", + "show_days": 1, + "show_seconds": 1 }, { "default": "1", "fieldname": "automatically_set_serial_nos_based_on_fifo", "fieldtype": "Check", - "label": "Automatically Set Serial Nos based on FIFO" + "label": "Automatically Set Serial Nos based on FIFO", + "show_days": 1, + "show_seconds": 1 }, { "default": "1", "fieldname": "set_qty_in_transactions_based_on_serial_no_input", "fieldtype": "Check", - "label": "Set Qty in Transactions based on Serial No Input" + "label": "Set Qty in Transactions based on Serial No Input", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "auto_material_request", "fieldtype": "Section Break", - "label": "Auto Material Request" + "label": "Auto Material Request", + "show_days": 1, + "show_seconds": 1 }, { "default": "0", "fieldname": "auto_indent", "fieldtype": "Check", - "label": "Raise Material Request when stock reaches re-order level" + "label": "Raise Material Request when stock reaches re-order level", + "show_days": 1, + "show_seconds": 1 }, { "default": "0", "fieldname": "reorder_email_notify", "fieldtype": "Check", - "label": "Notify by Email on creation of automatic Material Request" + "label": "Notify by Email on creation of automatic Material Request", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "freeze_stock_entries", "fieldtype": "Section Break", - "label": "Freeze Stock Entries" + "label": "Freeze Stock Entries", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "stock_frozen_upto", "fieldtype": "Date", - "label": "Stock Frozen Upto" + "label": "Stock Frozen Upto", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "stock_frozen_upto_days", "fieldtype": "Int", - "label": "Freeze Stocks Older Than [Days]" + "label": "Freeze Stocks Older Than [Days]", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "stock_auth_role", "fieldtype": "Link", "label": "Role Allowed to edit frozen stock", - "options": "Role" + "options": "Role", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "batch_id_sb", "fieldtype": "Section Break", - "label": "Batch Identification" + "label": "Batch Identification", + "show_days": 1, + "show_seconds": 1 }, { "default": "0", "fieldname": "use_naming_series", "fieldtype": "Check", - "label": "Use Naming Series" + "label": "Use Naming Series", + "show_days": 1, + "show_seconds": 1 }, { "default": "BATCH-", "depends_on": "eval:doc.use_naming_series==1", "fieldname": "naming_series_prefix", "fieldtype": "Data", - "label": "Naming Series Prefix" + "label": "Naming Series Prefix", + "show_days": 1, + "show_seconds": 1 }, { "fieldname": "inter_warehouse_transfer_settings_section", "fieldtype": "Section Break", - "label": "Inter Warehouse Transfer Settings" + "label": "Inter Warehouse Transfer Settings", + "show_days": 1, + "show_seconds": 1 }, { "default": "0", "fieldname": "allow_from_dn", "fieldtype": "Check", - "label": "Allow Material Transfer From Delivery Note and Sales Invoice" + "label": "Allow Material Transfer From Delivery Note and Sales Invoice", + "show_days": 1, + "show_seconds": 1 }, { "default": "0", "fieldname": "allow_from_pr", "fieldtype": "Check", - "label": "Allow Material Transfer From Purchase Receipt and Purchase Invoice" + "label": "Allow Material Transfer From Purchase Receipt and Purchase Invoice", + "show_days": 1, + "show_seconds": 1 + }, + { + "default": "0", + "fieldname": "enable_perpetual_inventory_for_non_stock_items", + "fieldtype": "Check", + "label": "Enable Perpetual Inventory For Non Stock Items", + "show_days": 1, + "show_seconds": 1 } ], "icon": "icon-cog", "idx": 1, "issingle": 1, "links": [], - "modified": "2020-04-01 18:11:25.417678", + "modified": "2020-06-11 15:10:41.211638", "modified_by": "Administrator", "module": "Stock", "name": "Stock Settings", From 12f1f8e1111e4a89c9f90da9ff3ae3cf05600720 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sat, 20 Jun 2020 11:55:56 +0530 Subject: [PATCH 110/449] fix: Move check from Stock Settings to Company Master (cherry picked from commit 53d5d16abb52790d60c0ef050a9c7a6685fbc5df) --- .../purchase_invoice/purchase_invoice.py | 2 +- erpnext/setup/doctype/company/company.json | 373 +++++------------- .../purchase_receipt/purchase_receipt.py | 2 +- .../stock_settings/stock_settings.json | 131 ++---- 4 files changed, 130 insertions(+), 378 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 1e548c00b7..2f2f959f5d 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -587,7 +587,7 @@ class PurchaseInvoice(BuyingController): else: amount = flt(item.base_net_amount + item.item_tax_amount, item.precision("base_net_amount")) - auto_accounting_for_non_stock_items = cint(frappe.db.get_single_value('Stock Settings', 'enable_perpetual_inventory_for_non_stock_items')) + auto_accounting_for_non_stock_items = cint(frappe.db.get_value('Company', self.company, 'enable_perpetual_inventory_for_non_stock_items')) service_received_but_not_billed_account = self.get_company_default("service_received_but_not_billed") if item.purchase_receipt and auto_accounting_for_non_stock_items: diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json index 0b91b70034..c25edc5505 100644 --- a/erpnext/setup/doctype/company/company.json +++ b/erpnext/setup/doctype/company/company.json @@ -67,6 +67,7 @@ "payment_terms", "auto_accounting_for_stock_settings", "enable_perpetual_inventory", + "enable_perpetual_inventory_for_non_stock_items", "default_inventory_account", "stock_adjustment_account", "column_break_32", @@ -107,9 +108,7 @@ { "fieldname": "details", "fieldtype": "Section Break", - "oldfieldtype": "Section Break", - "show_days": 1, - "show_seconds": 1 + "oldfieldtype": "Section Break" }, { "fieldname": "company_name", @@ -118,8 +117,6 @@ "oldfieldname": "company_name", "oldfieldtype": "Data", "reqd": 1, - "show_days": 1, - "show_seconds": 1, "unique": 1 }, { @@ -128,48 +125,36 @@ "label": "Abbr", "oldfieldname": "abbr", "oldfieldtype": "Data", - "reqd": 1, - "show_days": 1, - "show_seconds": 1 + "reqd": 1 }, { "depends_on": "eval:!doc.__islocal && in_list(frappe.user_roles, \"System Manager\")", "fieldname": "change_abbr", "fieldtype": "Button", - "label": "Change Abbreviation", - "show_days": 1, - "show_seconds": 1 + "label": "Change Abbreviation" }, { "bold": 1, "default": "0", "fieldname": "is_group", "fieldtype": "Check", - "label": "Is Group", - "show_days": 1, - "show_seconds": 1 + "label": "Is Group" }, { "fieldname": "default_finance_book", "fieldtype": "Link", "label": "Default Finance Book", - "options": "Finance Book", - "show_days": 1, - "show_seconds": 1 + "options": "Finance Book" }, { "fieldname": "cb0", - "fieldtype": "Column Break", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "Column Break" }, { "fieldname": "domain", "fieldtype": "Link", "label": "Domain", - "options": "Domain", - "show_days": 1, - "show_seconds": 1 + "options": "Domain" }, { "fieldname": "parent_company", @@ -177,32 +162,24 @@ "ignore_user_permissions": 1, "in_list_view": 1, "label": "Parent Company", - "options": "Company", - "show_days": 1, - "show_seconds": 1 + "options": "Company" }, { "fieldname": "company_logo", "fieldtype": "Attach Image", "hidden": 1, - "label": "Company Logo", - "show_days": 1, - "show_seconds": 1 + "label": "Company Logo" }, { "fieldname": "company_description", "fieldtype": "Text Editor", - "label": "Company Description", - "show_days": 1, - "show_seconds": 1 + "label": "Company Description" }, { "collapsible": 1, "fieldname": "sales_settings", "fieldtype": "Section Break", - "label": "Sales Settings", - "show_days": 1, - "show_seconds": 1 + "label": "Sales Settings" }, { "fieldname": "sales_monthly_history", @@ -210,9 +187,7 @@ "hidden": 1, "label": "Sales Monthly History", "no_copy": 1, - "read_only": 1, - "show_days": 1, - "show_seconds": 1 + "read_only": 1 }, { "fieldname": "transactions_annual_history", @@ -220,23 +195,17 @@ "hidden": 1, "label": "Transactions Annual History", "no_copy": 1, - "read_only": 1, - "show_days": 1, - "show_seconds": 1 + "read_only": 1 }, { "fieldname": "monthly_sales_target", "fieldtype": "Currency", "label": "Monthly Sales Target", - "options": "default_currency", - "show_days": 1, - "show_seconds": 1 + "options": "default_currency" }, { "fieldname": "column_break_goals", - "fieldtype": "Column Break", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "Column Break" }, { "fieldname": "total_monthly_sales", @@ -244,16 +213,12 @@ "label": "Total Monthly Sales", "no_copy": 1, "options": "default_currency", - "read_only": 1, - "show_days": 1, - "show_seconds": 1 + "read_only": 1 }, { "fieldname": "charts_section", "fieldtype": "Section Break", - "label": "Default Values", - "show_days": 1, - "show_seconds": 1 + "label": "Default Values" }, { "fieldname": "default_currency", @@ -261,46 +226,34 @@ "ignore_user_permissions": 1, "label": "Default Currency", "options": "Currency", - "reqd": 1, - "show_days": 1, - "show_seconds": 1 + "reqd": 1 }, { "fieldname": "default_letter_head", "fieldtype": "Link", "label": "Default Letter Head", - "options": "Letter Head", - "show_days": 1, - "show_seconds": 1 + "options": "Letter Head" }, { "fieldname": "default_holiday_list", "fieldtype": "Link", "label": "Default Holiday List", - "options": "Holiday List", - "show_days": 1, - "show_seconds": 1 + "options": "Holiday List" }, { "fieldname": "standard_working_hours", "fieldtype": "Float", - "label": "Standard Working Hours", - "show_days": 1, - "show_seconds": 1 + "label": "Standard Working Hours" }, { "fieldname": "default_warehouse_for_sales_return", "fieldtype": "Link", "label": "Default warehouse for Sales Return", - "options": "Warehouse", - "show_days": 1, - "show_seconds": 1 + "options": "Warehouse" }, { "fieldname": "column_break_10", - "fieldtype": "Column Break", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "Column Break" }, { "fieldname": "country", @@ -308,26 +261,20 @@ "in_list_view": 1, "label": "Country", "options": "Country", - "reqd": 1, - "show_days": 1, - "show_seconds": 1 + "reqd": 1 }, { "fieldname": "create_chart_of_accounts_based_on", "fieldtype": "Select", "label": "Create Chart Of Accounts Based On", - "options": "\nStandard Template\nExisting Company", - "show_days": 1, - "show_seconds": 1 + "options": "\nStandard Template\nExisting Company" }, { "depends_on": "eval:doc.create_chart_of_accounts_based_on===\"Standard Template\"", "fieldname": "chart_of_accounts", "fieldtype": "Select", "label": "Chart Of Accounts Template", - "no_copy": 1, - "show_days": 1, - "show_seconds": 1 + "no_copy": 1 }, { "depends_on": "eval:doc.create_chart_of_accounts_based_on===\"Existing Company\"", @@ -336,31 +283,23 @@ "ignore_user_permissions": 1, "label": "Existing Company ", "no_copy": 1, - "options": "Company", - "show_days": 1, - "show_seconds": 1 + "options": "Company" }, { "fieldname": "tax_id", "fieldtype": "Data", - "label": "Tax ID", - "show_days": 1, - "show_seconds": 1 + "label": "Tax ID" }, { "fieldname": "date_of_establishment", "fieldtype": "Date", - "label": "Date of Establishment", - "show_days": 1, - "show_seconds": 1 + "label": "Date of Establishment" }, { "fieldname": "default_settings", "fieldtype": "Section Break", "label": "Accounts Settings", - "oldfieldtype": "Section Break", - "show_days": 1, - "show_seconds": 1 + "oldfieldtype": "Section Break" }, { "depends_on": "eval:!doc.__islocal", @@ -371,9 +310,7 @@ "no_copy": 1, "oldfieldname": "default_bank_account", "oldfieldtype": "Link", - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "depends_on": "eval:!doc.__islocal", @@ -382,9 +319,7 @@ "ignore_user_permissions": 1, "label": "Default Cash Account", "no_copy": 1, - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "depends_on": "eval:!doc.__islocal", @@ -395,72 +330,54 @@ "no_copy": 1, "oldfieldname": "receivables_group", "oldfieldtype": "Link", - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "round_off_account", "fieldtype": "Link", "label": "Round Off Account", - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "round_off_cost_center", "fieldtype": "Link", "label": "Round Off Cost Center", - "options": "Cost Center", - "show_days": 1, - "show_seconds": 1 + "options": "Cost Center" }, { "fieldname": "write_off_account", "fieldtype": "Link", "label": "Write Off Account", - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "discount_allowed_account", "fieldtype": "Link", "label": "Discount Allowed Account", - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "discount_received_account", "fieldtype": "Link", "label": "Discount Received Account", - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "exchange_gain_loss_account", "fieldtype": "Link", "label": "Exchange Gain / Loss Account", - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "unrealized_exchange_gain_loss_account", "fieldtype": "Link", "label": "Unrealized Exchange Gain/Loss Account", - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "column_break0", "fieldtype": "Column Break", "oldfieldtype": "Column Break", - "show_days": 1, - "show_seconds": 1, "width": "50%" }, { @@ -468,9 +385,7 @@ "depends_on": "eval:doc.parent_company", "fieldname": "allow_account_creation_against_child_company", "fieldtype": "Check", - "label": "Allow Account Creation Against Child Company", - "show_days": 1, - "show_seconds": 1 + "label": "Allow Account Creation Against Child Company" }, { "depends_on": "eval:!doc.__islocal", @@ -481,18 +396,14 @@ "no_copy": 1, "oldfieldname": "payables_group", "oldfieldtype": "Link", - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "default_employee_advance_account", "fieldtype": "Link", "label": "Default Employee Advance Account", "no_copy": 1, - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "depends_on": "eval:!doc.__islocal", @@ -501,9 +412,7 @@ "ignore_user_permissions": 1, "label": "Default Cost of Goods Sold Account", "no_copy": 1, - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "depends_on": "eval:!doc.__islocal", @@ -512,9 +421,7 @@ "ignore_user_permissions": 1, "label": "Default Income Account", "no_copy": 1, - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "depends_on": "eval:!doc.__islocal", @@ -523,9 +430,7 @@ "ignore_user_permissions": 1, "label": "Default Deferred Revenue Account", "no_copy": 1, - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "depends_on": "eval:!doc.__islocal", @@ -534,9 +439,7 @@ "ignore_user_permissions": 1, "label": "Default Deferred Expense Account", "no_copy": 1, - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "depends_on": "eval:!doc.__islocal", @@ -545,9 +448,7 @@ "ignore_user_permissions": 1, "label": "Default Payroll Payable Account", "no_copy": 1, - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "depends_on": "eval:!doc.__islocal", @@ -556,15 +457,11 @@ "ignore_user_permissions": 1, "label": "Default Expense Claim Payable Account", "no_copy": 1, - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "section_break_22", - "fieldtype": "Section Break", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "Section Break" }, { "depends_on": "eval:!doc.__islocal", @@ -573,15 +470,11 @@ "ignore_user_permissions": 1, "label": "Default Cost Center", "no_copy": 1, - "options": "Cost Center", - "show_days": 1, - "show_seconds": 1 + "options": "Cost Center" }, { "fieldname": "column_break_26", - "fieldtype": "Column Break", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "Column Break" }, { "depends_on": "eval:!doc.__islocal", @@ -590,41 +483,31 @@ "label": "Credit Limit", "oldfieldname": "credit_limit", "oldfieldtype": "Currency", - "options": "default_currency", - "show_days": 1, - "show_seconds": 1 + "options": "default_currency" }, { "fieldname": "payment_terms", "fieldtype": "Link", "label": "Default Payment Terms Template", - "options": "Payment Terms Template", - "show_days": 1, - "show_seconds": 1 + "options": "Payment Terms Template" }, { "depends_on": "eval:!doc.__islocal", "fieldname": "auto_accounting_for_stock_settings", "fieldtype": "Section Break", - "label": "Stock Settings", - "show_days": 1, - "show_seconds": 1 + "label": "Stock Settings" }, { "default": "1", "fieldname": "enable_perpetual_inventory", "fieldtype": "Check", - "label": "Enable Perpetual Inventory", - "show_days": 1, - "show_seconds": 1 + "label": "Enable Perpetual Inventory" }, { "fieldname": "default_inventory_account", "fieldtype": "Link", "label": "Default Inventory Account", - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "stock_adjustment_account", @@ -632,15 +515,11 @@ "ignore_user_permissions": 1, "label": "Stock Adjustment Account", "no_copy": 1, - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "column_break_32", - "fieldtype": "Column Break", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "Column Break" }, { "fieldname": "stock_received_but_not_billed", @@ -648,9 +527,7 @@ "ignore_user_permissions": 1, "label": "Stock Received But Not Billed", "no_copy": 1, - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "expenses_included_in_valuation", @@ -658,144 +535,108 @@ "ignore_user_permissions": 1, "label": "Expenses Included In Valuation", "no_copy": 1, - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "collapsible": 1, "fieldname": "fixed_asset_depreciation_settings", "fieldtype": "Section Break", - "label": "Fixed Asset Depreciation Settings", - "show_days": 1, - "show_seconds": 1 + "label": "Fixed Asset Depreciation Settings" }, { "fieldname": "accumulated_depreciation_account", "fieldtype": "Link", "label": "Accumulated Depreciation Account", "no_copy": 1, - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "depreciation_expense_account", "fieldtype": "Link", "label": "Depreciation Expense Account", "no_copy": 1, - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "series_for_depreciation_entry", "fieldtype": "Data", - "label": "Series for Asset Depreciation Entry (Journal Entry)", - "show_days": 1, - "show_seconds": 1 + "label": "Series for Asset Depreciation Entry (Journal Entry)" }, { "fieldname": "expenses_included_in_asset_valuation", "fieldtype": "Link", "label": "Expenses Included In Asset Valuation", - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "column_break_40", - "fieldtype": "Column Break", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "Column Break" }, { "fieldname": "disposal_account", "fieldtype": "Link", "label": "Gain/Loss Account on Asset Disposal", "no_copy": 1, - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "depreciation_cost_center", "fieldtype": "Link", "label": "Asset Depreciation Cost Center", "no_copy": 1, - "options": "Cost Center", - "show_days": 1, - "show_seconds": 1 + "options": "Cost Center" }, { "fieldname": "capital_work_in_progress_account", "fieldtype": "Link", "label": "Capital Work In Progress Account", - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "fieldname": "asset_received_but_not_billed", "fieldtype": "Link", "label": "Asset Received But Not Billed", - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" }, { "collapsible": 1, "fieldname": "budget_detail", "fieldtype": "Section Break", - "label": "Budget Detail", - "show_days": 1, - "show_seconds": 1 + "label": "Budget Detail" }, { "fieldname": "exception_budget_approver_role", "fieldtype": "Link", "label": "Exception Budget Approver Role", - "options": "Role", - "show_days": 1, - "show_seconds": 1 + "options": "Role" }, { "collapsible": 1, "description": "For reference only.", "fieldname": "company_info", "fieldtype": "Section Break", - "label": "Company Info", - "show_days": 1, - "show_seconds": 1 + "label": "Company Info" }, { "fieldname": "date_of_incorporation", "fieldtype": "Date", - "label": "Date of Incorporation", - "show_days": 1, - "show_seconds": 1 + "label": "Date of Incorporation" }, { "fieldname": "address_html", - "fieldtype": "HTML", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "HTML" }, { "fieldname": "column_break1", "fieldtype": "Column Break", "oldfieldtype": "Column Break", - "show_days": 1, - "show_seconds": 1, "width": "50%" }, { "depends_on": "eval:doc.date_of_incorporation", "fieldname": "date_of_commencement", "fieldtype": "Date", - "label": "Date of Commencement", - "show_days": 1, - "show_seconds": 1 + "label": "Date of Commencement" }, { "fieldname": "phone_no", @@ -803,9 +644,7 @@ "label": "Phone No", "oldfieldname": "phone_no", "oldfieldtype": "Data", - "options": "Phone", - "show_days": 1, - "show_seconds": 1 + "options": "Phone" }, { "fieldname": "fax", @@ -813,9 +652,7 @@ "label": "Fax", "oldfieldname": "fax", "oldfieldtype": "Data", - "options": "Phone", - "show_days": 1, - "show_seconds": 1 + "options": "Phone" }, { "fieldname": "email", @@ -823,25 +660,19 @@ "label": "Email", "oldfieldname": "email", "oldfieldtype": "Data", - "options": "Email", - "show_days": 1, - "show_seconds": 1 + "options": "Email" }, { "fieldname": "website", "fieldtype": "Data", "label": "Website", "oldfieldname": "website", - "oldfieldtype": "Data", - "show_days": 1, - "show_seconds": 1 + "oldfieldtype": "Data" }, { "fieldname": "registration_info", "fieldtype": "Section Break", "oldfieldtype": "Section Break", - "show_days": 1, - "show_seconds": 1, "width": "50%" }, { @@ -850,16 +681,12 @@ "fieldtype": "Code", "label": "Registration Details", "oldfieldname": "registration_details", - "oldfieldtype": "Code", - "show_days": 1, - "show_seconds": 1 + "oldfieldtype": "Code" }, { "fieldname": "delete_company_transactions", "fieldtype": "Button", - "label": "Delete Company Transactions", - "show_days": 1, - "show_seconds": 1 + "label": "Delete Company Transactions" }, { "fieldname": "lft", @@ -868,9 +695,7 @@ "label": "Lft", "print_hide": 1, "read_only": 1, - "search_index": 1, - "show_days": 1, - "show_seconds": 1 + "search_index": 1 }, { "fieldname": "rgt", @@ -879,9 +704,7 @@ "label": "Rgt", "print_hide": 1, "read_only": 1, - "search_index": 1, - "show_days": 1, - "show_seconds": 1 + "search_index": 1 }, { "fieldname": "old_parent", @@ -889,25 +712,19 @@ "hidden": 1, "label": "old_parent", "print_hide": 1, - "read_only": 1, - "show_days": 1, - "show_seconds": 1 + "read_only": 1 }, { "fieldname": "default_selling_terms", "fieldtype": "Link", "label": "Default Selling Terms", - "options": "Terms and Conditions", - "show_days": 1, - "show_seconds": 1 + "options": "Terms and Conditions" }, { "fieldname": "default_buying_terms", "fieldtype": "Link", "label": "Default Buying Terms", - "options": "Terms and Conditions", - "show_days": 1, - "show_seconds": 1 + "options": "Terms and Conditions" }, { "fieldname": "service_received_but_not_billed", @@ -915,9 +732,13 @@ "ignore_user_permissions": 1, "label": "Service Received But Not Billed", "no_copy": 1, - "options": "Account", - "show_days": 1, - "show_seconds": 1 + "options": "Account" + }, + { + "default": "0", + "fieldname": "enable_perpetual_inventory_for_non_stock_items", + "fieldtype": "Check", + "label": "Enable Perpetual Inventory For Non Stock Items" } ], "icon": "fa fa-building", @@ -925,7 +746,7 @@ "image_field": "company_logo", "is_tree": 1, "links": [], - "modified": "2020-06-11 15:32:59.147735", + "modified": "2020-06-20 11:38:43.178970", "modified_by": "Administrator", "module": "Setup", "name": "Company", diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 94a6edd2c1..15068ec510 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -212,7 +212,7 @@ class PurchaseReceipt(BuyingController): landed_cost_entries = get_item_account_wise_additional_cost(self.name) expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") service_received_but_not_billed_account = self.get_company_default("service_received_but_not_billed") - auto_accounting_for_non_stock_items = cint(frappe.db.get_single_value('Stock Settings', 'enable_perpetual_inventory_for_non_stock_items')) + auto_accounting_for_non_stock_items = cint(frappe.db.get_value('Company', self.company, 'enable_perpetual_inventory_for_non_stock_items')) gl_entries = [] warehouse_with_no_account = [] diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.json b/erpnext/stock/doctype/stock_settings/stock_settings.json index a7ed620dca..9c5d3d8340 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.json +++ b/erpnext/stock/doctype/stock_settings/stock_settings.json @@ -16,7 +16,6 @@ "action_if_quality_inspection_is_not_submitted", "show_barcode_field", "clean_description_html", - "enable_perpetual_inventory_for_non_stock_items", "section_break_7", "auto_insert_price_list_rate_if_missing", "allow_negative_stock", @@ -44,248 +43,180 @@ "fieldtype": "Select", "in_list_view": 1, "label": "Item Naming By", - "options": "Item Code\nNaming Series", - "show_days": 1, - "show_seconds": 1 + "options": "Item Code\nNaming Series" }, { "fieldname": "item_group", "fieldtype": "Link", "in_list_view": 1, "label": "Default Item Group", - "options": "Item Group", - "show_days": 1, - "show_seconds": 1 + "options": "Item Group" }, { "fieldname": "stock_uom", "fieldtype": "Link", "in_list_view": 1, "label": "Default Stock UOM", - "options": "UOM", - "show_days": 1, - "show_seconds": 1 + "options": "UOM" }, { "fieldname": "default_warehouse", "fieldtype": "Link", "label": "Default Warehouse", - "options": "Warehouse", - "show_days": 1, - "show_seconds": 1 + "options": "Warehouse" }, { "fieldname": "sample_retention_warehouse", "fieldtype": "Link", "label": "Sample Retention Warehouse", - "options": "Warehouse", - "show_days": 1, - "show_seconds": 1 + "options": "Warehouse" }, { "fieldname": "column_break_4", - "fieldtype": "Column Break", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "Column Break" }, { "fieldname": "valuation_method", "fieldtype": "Select", "label": "Default Valuation Method", - "options": "FIFO\nMoving Average", - "show_days": 1, - "show_seconds": 1 + "options": "FIFO\nMoving Average" }, { "description": "Percentage you are allowed to receive or deliver more against the quantity ordered. For example: If you have ordered 100 units. and your Allowance is 10% then you are allowed to receive 110 units.", "fieldname": "over_delivery_receipt_allowance", "fieldtype": "Float", - "label": "Over Delivery/Receipt Allowance (%)", - "show_days": 1, - "show_seconds": 1 + "label": "Over Delivery/Receipt Allowance (%)" }, { "default": "Stop", "fieldname": "action_if_quality_inspection_is_not_submitted", "fieldtype": "Select", "label": "Action if Quality inspection is not submitted", - "options": "Stop\nWarn", - "show_days": 1, - "show_seconds": 1 + "options": "Stop\nWarn" }, { "default": "1", "fieldname": "show_barcode_field", "fieldtype": "Check", - "label": "Show Barcode Field", - "show_days": 1, - "show_seconds": 1 + "label": "Show Barcode Field" }, { "default": "1", "fieldname": "clean_description_html", "fieldtype": "Check", - "label": "Convert Item Description to Clean HTML", - "show_days": 1, - "show_seconds": 1 + "label": "Convert Item Description to Clean HTML" }, { "fieldname": "section_break_7", - "fieldtype": "Section Break", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "Section Break" }, { "default": "0", "fieldname": "auto_insert_price_list_rate_if_missing", "fieldtype": "Check", - "label": "Auto insert Price List rate if missing", - "show_days": 1, - "show_seconds": 1 + "label": "Auto insert Price List rate if missing" }, { "default": "0", "fieldname": "allow_negative_stock", "fieldtype": "Check", - "label": "Allow Negative Stock", - "show_days": 1, - "show_seconds": 1 + "label": "Allow Negative Stock" }, { "fieldname": "column_break_10", - "fieldtype": "Column Break", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "Column Break" }, { "default": "1", "fieldname": "automatically_set_serial_nos_based_on_fifo", "fieldtype": "Check", - "label": "Automatically Set Serial Nos based on FIFO", - "show_days": 1, - "show_seconds": 1 + "label": "Automatically Set Serial Nos based on FIFO" }, { "default": "1", "fieldname": "set_qty_in_transactions_based_on_serial_no_input", "fieldtype": "Check", - "label": "Set Qty in Transactions based on Serial No Input", - "show_days": 1, - "show_seconds": 1 + "label": "Set Qty in Transactions based on Serial No Input" }, { "fieldname": "auto_material_request", "fieldtype": "Section Break", - "label": "Auto Material Request", - "show_days": 1, - "show_seconds": 1 + "label": "Auto Material Request" }, { "default": "0", "fieldname": "auto_indent", "fieldtype": "Check", - "label": "Raise Material Request when stock reaches re-order level", - "show_days": 1, - "show_seconds": 1 + "label": "Raise Material Request when stock reaches re-order level" }, { "default": "0", "fieldname": "reorder_email_notify", "fieldtype": "Check", - "label": "Notify by Email on creation of automatic Material Request", - "show_days": 1, - "show_seconds": 1 + "label": "Notify by Email on creation of automatic Material Request" }, { "fieldname": "freeze_stock_entries", "fieldtype": "Section Break", - "label": "Freeze Stock Entries", - "show_days": 1, - "show_seconds": 1 + "label": "Freeze Stock Entries" }, { "fieldname": "stock_frozen_upto", "fieldtype": "Date", - "label": "Stock Frozen Upto", - "show_days": 1, - "show_seconds": 1 + "label": "Stock Frozen Upto" }, { "fieldname": "stock_frozen_upto_days", "fieldtype": "Int", - "label": "Freeze Stocks Older Than [Days]", - "show_days": 1, - "show_seconds": 1 + "label": "Freeze Stocks Older Than [Days]" }, { "fieldname": "stock_auth_role", "fieldtype": "Link", "label": "Role Allowed to edit frozen stock", - "options": "Role", - "show_days": 1, - "show_seconds": 1 + "options": "Role" }, { "fieldname": "batch_id_sb", "fieldtype": "Section Break", - "label": "Batch Identification", - "show_days": 1, - "show_seconds": 1 + "label": "Batch Identification" }, { "default": "0", "fieldname": "use_naming_series", "fieldtype": "Check", - "label": "Use Naming Series", - "show_days": 1, - "show_seconds": 1 + "label": "Use Naming Series" }, { "default": "BATCH-", "depends_on": "eval:doc.use_naming_series==1", "fieldname": "naming_series_prefix", "fieldtype": "Data", - "label": "Naming Series Prefix", - "show_days": 1, - "show_seconds": 1 + "label": "Naming Series Prefix" }, { "fieldname": "inter_warehouse_transfer_settings_section", "fieldtype": "Section Break", - "label": "Inter Warehouse Transfer Settings", - "show_days": 1, - "show_seconds": 1 + "label": "Inter Warehouse Transfer Settings" }, { "default": "0", "fieldname": "allow_from_dn", "fieldtype": "Check", - "label": "Allow Material Transfer From Delivery Note and Sales Invoice", - "show_days": 1, - "show_seconds": 1 + "label": "Allow Material Transfer From Delivery Note and Sales Invoice" }, { "default": "0", "fieldname": "allow_from_pr", "fieldtype": "Check", - "label": "Allow Material Transfer From Purchase Receipt and Purchase Invoice", - "show_days": 1, - "show_seconds": 1 - }, - { - "default": "0", - "fieldname": "enable_perpetual_inventory_for_non_stock_items", - "fieldtype": "Check", - "label": "Enable Perpetual Inventory For Non Stock Items", - "show_days": 1, - "show_seconds": 1 + "label": "Allow Material Transfer From Purchase Receipt and Purchase Invoice" } ], "icon": "icon-cog", "idx": 1, "issingle": 1, "links": [], - "modified": "2020-06-11 15:10:41.211638", + "modified": "2020-06-20 11:39:15.344112", "modified_by": "Administrator", "module": "Stock", "name": "Stock Settings", From 51ce1e1d4e60b1e2b48fd86712f34654cb922ed4 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 22 Jun 2020 09:40:15 +0530 Subject: [PATCH 111/449] fix: Test Cases (cherry picked from commit ded3ab1cd778389ab348bcb5628379f129a8d02d) --- .../purchase_invoice/purchase_invoice.py | 18 ++++++++++-------- erpnext/setup/doctype/company/company.py | 7 +++++++ .../purchase_receipt/purchase_receipt.py | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 2f2f959f5d..3cd57d403a 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -588,16 +588,18 @@ class PurchaseInvoice(BuyingController): amount = flt(item.base_net_amount + item.item_tax_amount, item.precision("base_net_amount")) auto_accounting_for_non_stock_items = cint(frappe.db.get_value('Company', self.company, 'enable_perpetual_inventory_for_non_stock_items')) - service_received_but_not_billed_account = self.get_company_default("service_received_but_not_billed") - if item.purchase_receipt and auto_accounting_for_non_stock_items: - # Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt - expense_booked_in_pr = frappe.db.get_value('GL Entry', {'is_cancelled': 0, - 'voucher_type': 'Purchase Receipt', 'voucher_no': item.purchase_receipt, 'voucher_detail_no': item.pr_detail, - 'account':service_received_but_not_billed_account}, ['name']) + if auto_accounting_for_non_stock_items: + service_received_but_not_billed_account = self.get_company_default("service_received_but_not_billed") - if expense_booked_in_pr: - expense_account = service_received_but_not_billed_account + if item.purchase_receipt: + # Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt + expense_booked_in_pr = frappe.db.get_value('GL Entry', {'is_cancelled': 0, + 'voucher_type': 'Purchase Receipt', 'voucher_no': item.purchase_receipt, 'voucher_detail_no': item.pr_detail, + 'account':service_received_but_not_billed_account}, ['name']) + + if expense_booked_in_pr: + expense_account = service_received_but_not_billed_account gl_entries.append(self.get_gl_dict({ "account": expense_account, diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index 8bcaa28707..47b41a97ad 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -46,6 +46,7 @@ class Company(NestedSet): self.validate_currency() self.validate_coa_input() self.validate_perpetual_inventory() + self.validate_perpetual_inventory_for_non_stock_items() self.check_country_change() self.set_chart_of_accounts() self.validate_parent_company() @@ -182,6 +183,12 @@ class Company(NestedSet): frappe.msgprint(_("Set default inventory account for perpetual inventory"), alert=True, indicator='orange') + def validate_perpetual_inventory_for_non_stock_items(self): + if not self.get("__islocal"): + if cint(self.enable_perpetual_inventory_for_non_stock_items) == 1 and not self.service_received_but_not_billed: + frappe.throw(_("Set default {0} account for perpetual inventory for non stock items").format( + frappe.bold('Service Received But Not Billed'))) + def check_country_change(self): frappe.flags.country_change = False diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 15068ec510..d0ba001d7e 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -211,7 +211,6 @@ class PurchaseReceipt(BuyingController): stock_rbnb = self.get_company_default("stock_received_but_not_billed") landed_cost_entries = get_item_account_wise_additional_cost(self.name) expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") - service_received_but_not_billed_account = self.get_company_default("service_received_but_not_billed") auto_accounting_for_non_stock_items = cint(frappe.db.get_value('Company', self.company, 'enable_perpetual_inventory_for_non_stock_items')) gl_entries = [] @@ -305,6 +304,7 @@ class PurchaseReceipt(BuyingController): warehouse_with_no_account.append(d.warehouse) elif d.item_code not in stock_items and flt(d.qty) and auto_accounting_for_non_stock_items: + service_received_but_not_billed_account = self.get_company_default("service_received_but_not_billed") credit_currency = get_account_currency(service_received_but_not_billed_account) gl_entries.append(self.get_gl_dict({ From faa0c5624e8d7f53a53aa0c0fcf45a54f7310074 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 24 Jun 2020 17:49:50 +0530 Subject: [PATCH 112/449] fix: Update journal entry account timestamp --- .../doctype/journal_entry_account/journal_entry_account.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json index 26c84a6398..7bdc5a89b5 100644 --- a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json +++ b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json @@ -273,7 +273,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2020-04-25 01:47:49.060128", + "modified": "2020-06-26 14:06:54.833738", "modified_by": "Administrator", "module": "Accounts", "name": "Journal Entry Account", From 4c726b25eea7c56bde2c6df24ac1b94ee735224d Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Thu, 25 Jun 2020 15:37:04 +0530 Subject: [PATCH 113/449] fix: Add view ledger button for cancelled docs (#22433) * fix: Add view ledger button for cancelled docs * fix: Add moddified to date in Stock Ledger --- .../invoice_discounting/invoice_discounting.js | 7 ++++--- .../accounts/doctype/journal_entry/journal_entry.js | 7 ++++--- .../accounts/doctype/payment_entry/payment_entry.js | 11 ++++++----- .../period_closing_voucher/period_closing_voucher.js | 5 +++-- erpnext/education/doctype/fees/fees.js | 7 ++++--- erpnext/hr/doctype/expense_claim/expense_claim.js | 7 +++++-- erpnext/loan_management/loan_common.js | 7 +++++-- erpnext/public/js/controllers/stock_controller.js | 10 ++++++---- 8 files changed, 37 insertions(+), 24 deletions(-) diff --git a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.js b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.js index 0fab8b70f4..db4f7c423f 100644 --- a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.js +++ b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.js @@ -188,14 +188,15 @@ frappe.ui.form.on('Invoice Discounting', { }, show_general_ledger: (frm) => { - if(frm.doc.docstatus===1) { + if(frm.doc.docstatus > 0) { cur_frm.add_custom_button(__('Accounting Ledger'), function() { frappe.route_options = { voucher_no: frm.doc.name, from_date: frm.doc.posting_date, - to_date: frm.doc.posting_date, + to_date: moment(frm.doc.modified).format('YYYY-MM-DD'), company: frm.doc.company, - group_by: "Group by Voucher (Consolidated)" + group_by: "Group by Voucher (Consolidated)", + show_cancelled_entries: frm.doc.docstatus === 2 }; frappe.set_route("query-report", "General Ledger"); }, __("View")); diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index 5685f839fe..a09face791 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -13,15 +13,16 @@ frappe.ui.form.on("Journal Entry", { refresh: function(frm) { erpnext.toggle_naming_series(); - if(frm.doc.docstatus==1) { + if(frm.doc.docstatus > 0) { frm.add_custom_button(__('Ledger'), function() { frappe.route_options = { "voucher_no": frm.doc.name, "from_date": frm.doc.posting_date, - "to_date": frm.doc.posting_date, + "to_date": moment(frm.doc.modified).format('YYYY-MM-DD'), "company": frm.doc.company, "finance_book": frm.doc.finance_book, - "group_by_voucher": 0 + "group_by": '', + "show_cancelled_entries": frm.doc.docstatus === 2 }; frappe.set_route("query-report", "General Ledger"); }, __('View')); diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index a378a51cdf..42c9fdeba4 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -172,8 +172,8 @@ frappe.ui.form.on('Payment Entry', { frm.toggle_display("base_paid_amount", frm.doc.paid_from_account_currency != company_currency); frm.toggle_display("base_received_amount", ( - frm.doc.paid_to_account_currency != company_currency - && frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency + frm.doc.paid_to_account_currency != company_currency + && frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency && frm.doc.base_paid_amount != frm.doc.base_received_amount )); @@ -234,14 +234,15 @@ frappe.ui.form.on('Payment Entry', { }, show_general_ledger: function(frm) { - if(frm.doc.docstatus==1) { + if(frm.doc.docstatus > 0) { frm.add_custom_button(__('Ledger'), function() { frappe.route_options = { "voucher_no": frm.doc.name, "from_date": frm.doc.posting_date, - "to_date": frm.doc.posting_date, + "to_date": moment(frm.doc.modified).format('YYYY-MM-DD'), "company": frm.doc.company, - group_by: "" + "group_by": "", + "show_cancelled_entries": frm.doc.docstatus === 2 }; frappe.set_route("query-report", "General Ledger"); }, "fa fa-table"); diff --git a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.js b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.js index 87e02fef1b..e923d4ed5e 100644 --- a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.js +++ b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.js @@ -25,9 +25,10 @@ frappe.ui.form.on('Period Closing Voucher', { frappe.route_options = { "voucher_no": frm.doc.name, "from_date": frm.doc.posting_date, - "to_date": frm.doc.posting_date, + "to_date": moment(frm.doc.modified).format('YYYY-MM-DD'), "company": frm.doc.company, - group_by_voucher: 0 + "group_by": "", + "show_cancelled_entries": frm.doc.docstatus === 2 }; frappe.set_route("query-report", "General Ledger"); }, "fa fa-table"); diff --git a/erpnext/education/doctype/fees/fees.js b/erpnext/education/doctype/fees/fees.js index 17ef44954b..867866fbf1 100644 --- a/erpnext/education/doctype/fees/fees.js +++ b/erpnext/education/doctype/fees/fees.js @@ -55,14 +55,15 @@ frappe.ui.form.on("Fees", { frm.set_df_property('posting_date', 'read_only', 1); frm.set_df_property('posting_time', 'read_only', 1); } - if(frm.doc.docstatus===1) { + if(frm.doc.docstatus > 0) { frm.add_custom_button(__('Accounting Ledger'), function() { frappe.route_options = { voucher_no: frm.doc.name, from_date: frm.doc.posting_date, - to_date: frm.doc.posting_date, + to_date: moment(frm.doc.modified).format('YYYY-MM-DD'), company: frm.doc.company, - group_by_voucher: false + group_by: '', + show_cancelled_entries: frm.doc.docstatus === 2 }; frappe.set_route("query-report", "General Ledger"); }, __("View")); diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.js b/erpnext/hr/doctype/expense_claim/expense_claim.js index 6bb9af9826..fa63ec2834 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.js +++ b/erpnext/hr/doctype/expense_claim/expense_claim.js @@ -213,12 +213,15 @@ frappe.ui.form.on("Expense Claim", { refresh: function(frm) { frm.trigger("toggle_fields"); - if(frm.doc.docstatus === 1 && frm.doc.approval_status !== "Rejected") { + if(frm.doc.docstatus > 0 && frm.doc.approval_status !== "Rejected") { frm.add_custom_button(__('Accounting Ledger'), function() { frappe.route_options = { voucher_no: frm.doc.name, company: frm.doc.company, - group_by_voucher: false + from_date: frm.doc.posting_date, + to_date: moment(frm.doc.modified).format('YYYY-MM-DD'), + group_by: '', + show_cancelled_entries: frm.doc.docstatus === 2 }; frappe.set_route("query-report", "General Ledger"); }, __("View")); diff --git a/erpnext/loan_management/loan_common.js b/erpnext/loan_management/loan_common.js index 3a47a88cbe..d9dd415296 100644 --- a/erpnext/loan_management/loan_common.js +++ b/erpnext/loan_management/loan_common.js @@ -9,12 +9,15 @@ frappe.ui.form.on(cur_frm.doctype, { } if (['Loan Disbursement', 'Loan Repayment', 'Loan Interest Accrual'].includes(frm.doc.doctype) - && frm.doc.docstatus == 1) { + && frm.doc.docstatus > 0) { frm.add_custom_button(__("Accounting Ledger"), function() { frappe.route_options = { voucher_no: frm.doc.name, - company: frm.doc.company + company: frm.doc.company, + from_date: frm.doc.posting_date, + to_date: moment(frm.doc.modified).format('YYYY-MM-DD'), + show_cancelled_entries: frm.doc.docstatus === 2 }; frappe.set_route("query-report", "General Ledger"); diff --git a/erpnext/public/js/controllers/stock_controller.js b/erpnext/public/js/controllers/stock_controller.js index 2ce49e766b..87b21b78de 100644 --- a/erpnext/public/js/controllers/stock_controller.js +++ b/erpnext/public/js/controllers/stock_controller.js @@ -55,8 +55,9 @@ erpnext.stock.StockController = frappe.ui.form.Controller.extend({ frappe.route_options = { voucher_no: me.frm.doc.name, from_date: me.frm.doc.posting_date, - to_date: me.frm.doc.posting_date, - company: me.frm.doc.company + to_date: moment(me.frm.doc.modified).format('YYYY-MM-DD'), + company: me.frm.doc.company, + show_cancelled_entries: me.frm.doc.docstatus === 2 }; frappe.set_route("query-report", "Stock Ledger"); }, __("View")); @@ -71,9 +72,10 @@ erpnext.stock.StockController = frappe.ui.form.Controller.extend({ frappe.route_options = { voucher_no: me.frm.doc.name, from_date: me.frm.doc.posting_date, - to_date: me.frm.doc.posting_date, + to_date: moment(me.frm.doc.modified).format('YYYY-MM-DD'), company: me.frm.doc.company, - group_by: "Group by Voucher (Consolidated)" + group_by: "Group by Voucher (Consolidated)", + show_cancelled_entries: me.frm.doc.docstatus === 2 }; frappe.set_route("query-report", "General Ledger"); }, __("View")); From fce39f706da3a297fbf8d5344f2b837404572622 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 26 Jun 2020 16:21:56 +0530 Subject: [PATCH 114/449] fix: Send email to credit controllers to increase credit limit (#22473) (cherry picked from commit 0ff5af222a5842e93f4b9e1bdbc31011abbe105d) Co-authored-by: Nabin Hait --- erpnext/selling/doctype/customer/customer.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 682dfede72..d70c64fce4 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -388,8 +388,7 @@ def check_credit_limit(customer, company, ignore_outstanding_sales_order=False, credit_controller_users = get_users_with_role(credit_controller_role or "Sales Master Manager") # form a list of emails and names to show to the user - credit_controller_users_list = [user for user in credit_controller_users if frappe.db.exists("Employee", {"prefered_email": user})] - credit_controller_users = [get_formatted_email(user).replace("<", "(").replace(">", ")") for user in credit_controller_users_list] + credit_controller_users = [get_formatted_email(user).replace("<", "(").replace(">", ")") for user in credit_controller_users] if not credit_controller_users: frappe.throw(_("Please contact your administrator to extend the credit limits for {0}.".format(customer))) @@ -409,7 +408,7 @@ def check_credit_limit(customer, company, ignore_outstanding_sales_order=False, 'customer': customer, 'customer_outstanding': customer_outstanding, 'credit_limit': credit_limit, - 'credit_controller_users_list': credit_controller_users_list + 'credit_controller_users_list': credit_controller_users } } ) From 28c1e8ef771d40b101e258d1a63436ac55533b1f Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 19 Jun 2020 16:12:32 +0530 Subject: [PATCH 115/449] fix: handle hold time for custom statuses --- erpnext/support/doctype/issue/issue.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/erpnext/support/doctype/issue/issue.py b/erpnext/support/doctype/issue/issue.py index 883e603fd3..976aa8ed5b 100644 --- a/erpnext/support/doctype/issue/issue.py +++ b/erpnext/support/doctype/issue/issue.py @@ -79,7 +79,7 @@ class Issue(Document): def handle_hold_time(self, status): if self.service_level_agreement: - # set response and resolution variance as None as the issue is on Hold for status as Replied + # set response and resolution variance as None as the issue is on Hold pause_sla_on = frappe.db.get_all("Pause SLA On Status", fields=["status"], filters={"parent": self.service_level_agreement}) hold_statuses = [entry.status for entry in pause_sla_on] @@ -93,15 +93,14 @@ class Issue(Document): update_values['resolution_by'] = None update_values['resolution_by_variance'] = 0 - # calculate hold time when status is changed from Replied to any other status + # calculate hold time when status is changed from any hold status to any non-hold status if self.status not in hold_statuses and status in hold_statuses: hold_time = self.total_hold_time if self.total_hold_time else 0 now_time = frappe.flags.current_time or now_datetime() update_values['total_hold_time'] = hold_time + time_diff_in_seconds(now_time, self.on_hold_since) - # re-calculate SLA variables after issue changes from Replied to Open - # add hold time to SLA variables - if self.status == "Open" and status in hold_statuses: + # re-calculate SLA variables after issue changes from any hold status to any non-hold status + # add hold time to SLA variables start_date_time = get_datetime(self.service_level_agreement_creation) priority = get_priority(self) now_time = frappe.flags.current_time or now_datetime() @@ -109,13 +108,15 @@ class Issue(Document): if not self.first_responded_on: response_by = get_expected_time_for(parameter="response", service_level=priority, start_date_time=start_date_time) - update_values['response_by'] = add_to_date(response_by, seconds=round(hold_time)) - response_by_variance = round(time_diff_in_hours(self.response_by, now_time)) + response_by = add_to_date(response_by, seconds=round(hold_time)) + response_by_variance = round(time_diff_in_hours(response_by, now_time)) + update_values['response_by'] = response_by update_values['response_by_variance'] = response_by_variance + (hold_time // 3600) resolution_by = get_expected_time_for(parameter="resolution", service_level=priority, start_date_time=start_date_time) - update_values['resolution_by'] = add_to_date(resolution_by, seconds=round(hold_time)) - resolution_by_variance = round(time_diff_in_hours(self.resolution_by, now_time)) + resolution_by = add_to_date(resolution_by, seconds=round(hold_time)) + resolution_by_variance = round(time_diff_in_hours(resolution_by, now_time)) + update_values['resolution_by'] = resolution_by update_values['resolution_by_variance'] = resolution_by_variance + (hold_time // 3600) update_values['on_hold_since'] = None From 5dd4bcb229fedccdd66211c8a4cd185f9baf1761 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 19 Jun 2020 17:27:25 +0530 Subject: [PATCH 116/449] fix: set total hold time only if hold configurations are enabled --- erpnext/support/doctype/issue/issue.py | 66 ++++++++++++++------------ 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/erpnext/support/doctype/issue/issue.py b/erpnext/support/doctype/issue/issue.py index 976aa8ed5b..87168e151e 100644 --- a/erpnext/support/doctype/issue/issue.py +++ b/erpnext/support/doctype/issue/issue.py @@ -85,42 +85,46 @@ class Issue(Document): hold_statuses = [entry.status for entry in pause_sla_on] update_values = {} - if self.status in hold_statuses and status not in hold_statuses: - update_values['on_hold_since'] = frappe.flags.current_time or now_datetime() - if not self.first_responded_on: - update_values['response_by'] = None - update_values['response_by_variance'] = 0 - update_values['resolution_by'] = None - update_values['resolution_by_variance'] = 0 + if hold_statuses: + if self.status in hold_statuses and status not in hold_statuses: + update_values['on_hold_since'] = frappe.flags.current_time or now_datetime() + if not self.first_responded_on: + update_values['response_by'] = None + update_values['response_by_variance'] = 0 + update_values['resolution_by'] = None + update_values['resolution_by_variance'] = 0 - # calculate hold time when status is changed from any hold status to any non-hold status - if self.status not in hold_statuses and status in hold_statuses: - hold_time = self.total_hold_time if self.total_hold_time else 0 - now_time = frappe.flags.current_time or now_datetime() - update_values['total_hold_time'] = hold_time + time_diff_in_seconds(now_time, self.on_hold_since) + # calculate hold time when status is changed from any hold status to any non-hold status + if self.status not in hold_statuses and status in hold_statuses: + hold_time = self.total_hold_time if self.total_hold_time else 0 + now_time = frappe.flags.current_time or now_datetime() + last_hold_time = 0 + if self.on_hold_since: + # last_hold_time will be added to the sla variables + last_hold_time = time_diff_in_seconds(now_time, self.on_hold_since) + update_values['total_hold_time'] = hold_time + last_hold_time - # re-calculate SLA variables after issue changes from any hold status to any non-hold status - # add hold time to SLA variables - start_date_time = get_datetime(self.service_level_agreement_creation) - priority = get_priority(self) - now_time = frappe.flags.current_time or now_datetime() - hold_time = time_diff_in_seconds(now_time, self.on_hold_since) + # re-calculate SLA variables after issue changes from any hold status to any non-hold status + # add hold time to SLA variables + start_date_time = get_datetime(self.service_level_agreement_creation) + priority = get_priority(self) + now_time = frappe.flags.current_time or now_datetime() - if not self.first_responded_on: - response_by = get_expected_time_for(parameter="response", service_level=priority, start_date_time=start_date_time) - response_by = add_to_date(response_by, seconds=round(hold_time)) - response_by_variance = round(time_diff_in_hours(response_by, now_time)) - update_values['response_by'] = response_by - update_values['response_by_variance'] = response_by_variance + (hold_time // 3600) + if not self.first_responded_on: + response_by = get_expected_time_for(parameter="response", service_level=priority, start_date_time=start_date_time) + response_by = add_to_date(response_by, seconds=round(last_hold_time)) + response_by_variance = round(time_diff_in_hours(response_by, now_time)) + update_values['response_by'] = response_by + update_values['response_by_variance'] = response_by_variance + (last_hold_time // 3600) - resolution_by = get_expected_time_for(parameter="resolution", service_level=priority, start_date_time=start_date_time) - resolution_by = add_to_date(resolution_by, seconds=round(hold_time)) - resolution_by_variance = round(time_diff_in_hours(resolution_by, now_time)) - update_values['resolution_by'] = resolution_by - update_values['resolution_by_variance'] = resolution_by_variance + (hold_time // 3600) - update_values['on_hold_since'] = None + resolution_by = get_expected_time_for(parameter="resolution", service_level=priority, start_date_time=start_date_time) + resolution_by = add_to_date(resolution_by, seconds=round(last_hold_time)) + resolution_by_variance = round(time_diff_in_hours(resolution_by, now_time)) + update_values['resolution_by'] = resolution_by + update_values['resolution_by_variance'] = resolution_by_variance + (last_hold_time // 3600) + update_values['on_hold_since'] = None - self.db_set(update_values) + self.db_set(update_values) def update_agreement_status(self): if self.service_level_agreement and self.agreement_fulfilled == "Ongoing": From cf53305abb53a0cc1359687adb3f13e90217392e Mon Sep 17 00:00:00 2001 From: barredterra Date: Mon, 11 May 2020 18:36:57 +0200 Subject: [PATCH 117/449] fix(report view): explicitly set column width for (cherry picked from commit 7a7add5001f65c74237c0e8d04daaa50be9a7866) --- .../regional/report/datev/datev_constants.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/erpnext/regional/report/datev/datev_constants.py b/erpnext/regional/report/datev/datev_constants.py index a059ed365a..e063703005 100644 --- a/erpnext/regional/report/datev/datev_constants.py +++ b/erpnext/regional/report/datev/datev_constants.py @@ -465,60 +465,71 @@ QUERY_REPORT_COLUMNS = [ "label": "Umsatz (ohne Soll/Haben-Kz)", "fieldname": "Umsatz (ohne Soll/Haben-Kz)", "fieldtype": "Currency", + "width": 100 }, { "label": "Soll/Haben-Kennzeichen", "fieldname": "Soll/Haben-Kennzeichen", "fieldtype": "Data", + "width": 100 }, { "label": "Konto", "fieldname": "Konto", "fieldtype": "Data", + "width": 100 }, { "label": "Gegenkonto (ohne BU-Schlüssel)", "fieldname": "Gegenkonto (ohne BU-Schlüssel)", "fieldtype": "Data", + "width": 100 }, { "label": "Belegdatum", "fieldname": "Belegdatum", "fieldtype": "Date", + "width": 100 }, { "label": "Belegfeld 1", "fieldname": "Belegfeld 1", "fieldtype": "Data", + "width": 150 }, { "label": "Buchungstext", "fieldname": "Buchungstext", "fieldtype": "Text", + "width": 300 }, { "label": "Beleginfo - Art 1", "fieldname": "Beleginfo - Art 1", "fieldtype": "Link", - "options": "DocType" + "options": "DocType", + "width": 100 }, { "label": "Beleginfo - Inhalt 1", "fieldname": "Beleginfo - Inhalt 1", "fieldtype": "Dynamic Link", - "options": "Beleginfo - Art 1" + "options": "Beleginfo - Art 1", + "width": 150 }, { "label": "Beleginfo - Art 2", "fieldname": "Beleginfo - Art 2", "fieldtype": "Link", - "options": "DocType" + "options": "DocType", + "width": 100 }, { "label": "Beleginfo - Inhalt 2", "fieldname": "Beleginfo - Inhalt 2", "fieldtype": "Dynamic Link", - "options": "Beleginfo - Art 2" + "options": "Beleginfo - Art 2", + "width": 150 } ] From 3efe0d0e839e6d66cf0f387765126bd9e9e158d9 Mon Sep 17 00:00:00 2001 From: barredterra Date: Mon, 11 May 2020 18:50:02 +0200 Subject: [PATCH 118/449] refactor: query meta data only once (cherry picked from commit 55c048f56c1b2ed91e467edd4700cf8da448c514) --- erpnext/regional/report/datev/datev.py | 35 +++++++++++++++++--------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/erpnext/regional/report/datev/datev.py b/erpnext/regional/report/datev/datev.py index a8e40cc493..02296a9356 100644 --- a/erpnext/regional/report/datev/datev.py +++ b/erpnext/regional/report/datev/datev.py @@ -8,17 +8,18 @@ Provide a report and downloadable CSV according to the German DATEV format. all required columns. Used to import the data into the DATEV Software. """ from __future__ import unicode_literals + import datetime import json -import zlib import zipfile import six +import frappe +import pandas as pd + +from frappe import _ from csv import QUOTE_NONNUMERIC from six import BytesIO from six import string_types -import frappe -from frappe import _ -import pandas as pd from .datev_constants import DataCategory from .datev_constants import Transactions from .datev_constants import DebtorsCreditors @@ -287,9 +288,7 @@ def get_datev_csv(data, filters, csv_class): def get_header(filters, csv_class): - coa = frappe.get_value("Company", filters.get("company"), "chart_of_accounts") - description = filters.get("voucher_type", csv_class.FORMAT_NAME) - coa_used = "04" if "SKR04" in coa else ("03" if "SKR03" in coa else "") + description = filters.get('voucher_type', csv_class.FORMAT_NAME) header = [ # DATEV format @@ -316,13 +315,13 @@ def get_header(filters, csv_class): # J = Imported by -- stays empty '', # K = Tax consultant number (Beraternummer) - frappe.get_value("DATEV Settings", filters.get("company"), "consultant_number"), + filters.get('consultant_number', '0000000'), # L = Tax client number (Mandantennummer) - frappe.get_value("DATEV Settings", filters.get("company"), "client_number"), + filters.get('client_number', '00000'), # M = Start of the fiscal year (Wirtschaftsjahresbeginn) frappe.utils.formatdate(frappe.defaults.get_user_default("year_start_date"), "yyyyMMdd"), # N = Length of account numbers (Sachkontenlänge) - '4', + '%d' % filters.get('acc_len', 4), # O = Transaction batch start date (YYYYMMDD) frappe.utils.formatdate(filters.get('from_date'), "yyyyMMdd"), # P = Transaction batch end date (YYYYMMDD) @@ -348,7 +347,7 @@ def get_header(filters, csv_class): # TODO: Filter by Accounting Period. In export for closed Accounting Period, this will be "1" '0', # V = Default currency, for example, "EUR" - '"%s"' % frappe.get_value("Company", filters.get("company"), "default_currency"), + '"%s"' % filters.get('default_currency', 'EUR'), # reserviert '', # Derivatskennzeichen @@ -358,7 +357,7 @@ def get_header(filters, csv_class): # reserviert '', # SKR - '"%s"' % coa_used, + '"%s"' % filters.get('skr', '04'), # Branchen-Lösungs-ID '', # reserviert @@ -389,6 +388,18 @@ def download_datev_csv(filters=None): validate(filters) + # set chart of accounts used + coa = frappe.get_value('Company', filters.get('company'), 'chart_of_accounts') + filters['skr'] = '04' if 'SKR04' in coa else ('03' if 'SKR03' in coa else '') + + # set account number length + account_numbers = frappe.get_list('Account', fields=['account_number'], filters={'is_group': 0, 'account_number': ('!=', '')}) + filters['acc_len'] = max([len(a.account_number) for a in account_numbers]) + + filters['consultant_number'] = frappe.get_value('DATEV Settings', filters.get('company'), 'consultant_number') + filters['client_number'] = frappe.get_value('DATEV Settings', filters.get('company'), 'client_number') + filters['default_currency'] = frappe.get_value('Company', filters.get('company'), 'default_currency') + # This is where my zip will be written zip_buffer = BytesIO() # This is my zip file From 6adb617ede8094a8617c571f333597a969a0f143 Mon Sep 17 00:00:00 2001 From: barredterra Date: Mon, 11 May 2020 19:15:03 +0200 Subject: [PATCH 119/449] fix: truncate account names to max length (cherry picked from commit 2976831560ddf9e16aae6b500f0e4f1b621e60d2) --- erpnext/regional/report/datev/datev.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/erpnext/regional/report/datev/datev.py b/erpnext/regional/report/datev/datev.py index 02296a9356..51ddfc780d 100644 --- a/erpnext/regional/report/datev/datev.py +++ b/erpnext/regional/report/datev/datev.py @@ -227,9 +227,18 @@ def get_suppliers(filters): def get_account_names(filters): - return frappe.get_list("Account", - fields=["account_number as Konto", "name as Kontenbeschriftung"], - filters={"company": filters.get("company"), "is_group": "0"}) + return frappe.db.sql(""" + SELECT + + account_number as 'Konto', + LEFT(account_name, 40) as 'Kontenbeschriftung', + 'de-DE' as 'Sprach-ID' + + FROM `tabAccount` + WHERE company = %(company)s + AND is_group = 0 + AND account_number != '' + """, filters, as_dict=1) def get_datev_csv(data, filters, csv_class): From 8f7d21485325e623dddfae22c3156afe8b808ab4 Mon Sep 17 00:00:00 2001 From: barredterra Date: Mon, 11 May 2020 19:15:49 +0200 Subject: [PATCH 120/449] fix: customer and supplier data (cherry picked from commit 53445aa25adc664d5eac55ba9e16a1eb4365ea38) --- erpnext/regional/report/datev/datev.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/erpnext/regional/report/datev/datev.py b/erpnext/regional/report/datev/datev.py index 51ddfc780d..d7036c55af 100644 --- a/erpnext/regional/report/datev/datev.py +++ b/erpnext/regional/report/datev/datev.py @@ -131,8 +131,10 @@ def get_customers(filters): SELECT acc.account_number as 'Konto', - cus.customer_name as 'Name (Adressatentyp Unternehmen)', - case cus.customer_type when 'Individual' then 1 when 'Company' then 2 else 0 end as 'Adressatentyp', + CASE cus.customer_type WHEN 'Company' THEN cus.customer_name ELSE null END as 'Name (Adressatentyp Unternehmen)', + CASE cus.customer_type WHEN 'Individual' THEN con.last_name ELSE null END as 'Name (Adressatentyp natürl. Person)', + CASE cus.customer_type WHEN 'Individual' THEN con.first_name ELSE null END as 'Vorname (Adressatentyp natürl. Person)', + CASE cus.customer_type WHEN 'Individual' THEN '1' WHEN 'Company' THEN '2' ELSE '0' end as 'Adressatentyp', adr.address_line1 as 'Straße', adr.pincode as 'Postleitzahl', adr.city as 'Ort', @@ -141,8 +143,7 @@ def get_customers(filters): con.email_id as 'E-Mail', coalesce(con.mobile_no, con.phone) as 'Telefon', cus.website as 'Internet', - cus.tax_id as 'Steuernummer', - ccl.credit_limit as 'Kreditlimit (Debitor)' + cus.tax_id as 'Steuernummer' FROM `tabParty Account` par @@ -161,10 +162,6 @@ def get_customers(filters): left join `tabContact` con on con.name = cus.customer_primary_contact - left join `tabCustomer Credit Limit` ccl - on ccl.parent = cus.name - and ccl.company = par.company - WHERE par.company = %(company)s AND par.parenttype = 'Customer'""", filters, as_dict=1) @@ -180,8 +177,10 @@ def get_suppliers(filters): SELECT acc.account_number as 'Konto', - sup.supplier_name as 'Name (Adressatentyp Unternehmen)', - case sup.supplier_type when 'Individual' then '1' when 'Company' then '2' else '0' end as 'Adressatentyp', + CASE sup.supplier_type WHEN 'Company' THEN sup.supplier_name ELSE null END as 'Name (Adressatentyp Unternehmen)', + CASE sup.supplier_type WHEN 'Individual' THEN con.last_name ELSE null END as 'Name (Adressatentyp natürl. Person)', + CASE sup.supplier_type WHEN 'Individual' THEN con.first_name ELSE null END as 'Vorname (Adressatentyp natürl. Person)', + CASE sup.supplier_type WHEN 'Individual' THEN '1' WHEN 'Company' THEN '2' ELSE '0' end as 'Adressatentyp', adr.address_line1 as 'Straße', adr.pincode as 'Postleitzahl', adr.city as 'Ort', From 7df5de94687e1f747771287cd4278e9f130f7ee7 Mon Sep 17 00:00:00 2001 From: barredterra Date: Mon, 11 May 2020 19:23:54 +0200 Subject: [PATCH 121/449] fix: hide transaction-specific for master data (cherry picked from commit 30d194d8a7eab77d056999aac61d00666518c005) --- erpnext/regional/report/datev/datev.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/erpnext/regional/report/datev/datev.py b/erpnext/regional/report/datev/datev.py index d7036c55af..7fec94e740 100644 --- a/erpnext/regional/report/datev/datev.py +++ b/erpnext/regional/report/datev/datev.py @@ -331,11 +331,11 @@ def get_header(filters, csv_class): # N = Length of account numbers (Sachkontenlänge) '%d' % filters.get('acc_len', 4), # O = Transaction batch start date (YYYYMMDD) - frappe.utils.formatdate(filters.get('from_date'), "yyyyMMdd"), + frappe.utils.formatdate(filters.get('from_date'), "yyyyMMdd") if csv_class.DATA_CATEGORY == DataCategory.TRANSACTIONS else '', # P = Transaction batch end date (YYYYMMDD) - frappe.utils.formatdate(filters.get('to_date'), "yyyyMMdd"), + frappe.utils.formatdate(filters.get('to_date'), "yyyyMMdd") if csv_class.DATA_CATEGORY == DataCategory.TRANSACTIONS else '', # Q = Description (for example, "Sales Invoice") Max. 30 chars - '"{}"'.format(_(description)), + '"{}"'.format(_(description)) if csv_class.DATA_CATEGORY == DataCategory.TRANSACTIONS else '', # R = Diktatkürzel '', # S = Buchungstyp @@ -350,12 +350,12 @@ def get_header(filters, csv_class): # 40 = Kalkulatorik # 11 = Reserviert # 12 = Reserviert - '0', + '0' if csv_class.DATA_CATEGORY == DataCategory.TRANSACTIONS else '', # U = Festschreibung # TODO: Filter by Accounting Period. In export for closed Accounting Period, this will be "1" '0', # V = Default currency, for example, "EUR" - '"%s"' % filters.get('default_currency', 'EUR'), + '"%s"' % filters.get('default_currency', 'EUR') if csv_class.DATA_CATEGORY == DataCategory.TRANSACTIONS else '', # reserviert '', # Derivatskennzeichen From 47a3524a7d66a9d9a9c9aa1c1f2c853e9d2c813c Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 29 Jun 2020 18:24:25 +0530 Subject: [PATCH 122/449] fix: Stock Onboarding typo and reorder (#22499) (#22503) (cherry picked from commit 8732b8caf618037b402ebcbe3097402e15c65494) Co-authored-by: Marica --- .../stock/doctype/stock_settings/stock_settings.js | 2 +- erpnext/stock/module_onboarding/stock/stock.json | 11 +++++------ .../create_a_supplier/create_a_supplier.json | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.js b/erpnext/stock/doctype/stock_settings/stock_settings.js index d5049ac6ed..48624e0f25 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.js +++ b/erpnext/stock/doctype/stock_settings/stock_settings.js @@ -20,7 +20,7 @@ frappe.tour['Stock Settings'] = [ { fieldname: "item_naming_by", title: __("Item Naming By"), - description: __("By default, the Item Name is set as per the Item Code entered. If you want Items to be named by a") + "Naming Series" + __(" choose the 'Naming Series' option."), + description: __("By default, the Item Name is set as per the Item Code entered. If you want Items to be named by a ") + "Naming Series" + __(" choose the 'Naming Series' option."), }, { fieldname: "default_warehouse", diff --git a/erpnext/stock/module_onboarding/stock/stock.json b/erpnext/stock/module_onboarding/stock/stock.json index de24575a14..10f05d4520 100644 --- a/erpnext/stock/module_onboarding/stock/stock.json +++ b/erpnext/stock/module_onboarding/stock/stock.json @@ -19,7 +19,7 @@ "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/stock", "idx": 0, "is_complete": 0, - "modified": "2020-05-19 19:03:23.602423", + "modified": "2020-06-29 16:41:09.440378", "modified_by": "Administrator", "module": "Stock", "name": "Stock", @@ -31,15 +31,15 @@ { "step": "Create a Product" }, + { + "step": "Create a Supplier" + }, { "step": "Introduction to Stock Entry" }, { "step": "Create a Stock Entry" }, - { - "step": "Create a Supplier" - }, { "step": "Create a Purchase Receipt" }, @@ -49,6 +49,5 @@ ], "subtitle": "Inventory, Warehouses, Analysis and more.", "success_message": "The Stock Module is all set up!", - "title": "Let's Setup the Stock Module.", - "user_can_dismiss": 1 + "title": "Let's Set Up the Stock Module." } \ No newline at end of file diff --git a/erpnext/stock/onboarding_step/create_a_supplier/create_a_supplier.json b/erpnext/stock/onboarding_step/create_a_supplier/create_a_supplier.json index 7a64224bd4..4e753f4d84 100644 --- a/erpnext/stock/onboarding_step/create_a_supplier/create_a_supplier.json +++ b/erpnext/stock/onboarding_step/create_a_supplier/create_a_supplier.json @@ -8,7 +8,7 @@ "is_mandatory": 0, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-14 22:09:10.043554", + "modified": "2020-06-29 16:36:53.948242", "modified_by": "Administrator", "name": "Create a Supplier", "owner": "Administrator", From c312b3af13bc5cc1837c963aa516009b076711f3 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 29 Jun 2020 19:10:57 +0530 Subject: [PATCH 123/449] fix: job offer validation fix (#22504) (#22505) (cherry picked from commit 343651fc393055ed07e6ac6b56203248e0818058) Co-authored-by: Anurag Mishra <32095923+Anurag810@users.noreply.github.com> --- erpnext/hr/doctype/job_offer/job_offer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/hr/doctype/job_offer/job_offer.py b/erpnext/hr/doctype/job_offer/job_offer.py index 9a2c4c64eb..f9ee44a4de 100644 --- a/erpnext/hr/doctype/job_offer/job_offer.py +++ b/erpnext/hr/doctype/job_offer/job_offer.py @@ -32,7 +32,8 @@ class JobOffer(Document): return frappe.get_all("Job Offer", filters={ "offer_date": ['between', (from_date, to_date)], "designation": self.designation, - "company": self.company + "company": self.company, + "docstatus": 1 }, fields=['name']) def update_job_applicant(status, job_applicant): From 9cba6bddde879418cd67e96d26d9235ae8972f78 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 29 Jun 2020 20:07:57 +0530 Subject: [PATCH 124/449] fixes: Payroll module pre relese test fixes (#22500) (#22506) * fix: salary payment based on payments * fix: bank remittance report * fix: Payroll period onboarding * fix: provident-fund-deductions report * fix: Considered unmarked days * fix: onboarding paYroll * feat: quick entry in payroll entry (cherry picked from commit c2523e845340addec214ea36e42992ba89d9b210) Co-authored-by: Anurag Mishra <32095923+Anurag810@users.noreply.github.com> --- .../payroll/doctype/payroll_period/payroll_period.json | 3 ++- erpnext/payroll/doctype/salary_slip/salary_slip.py | 8 +++----- erpnext/payroll/module_onboarding/payroll/payroll.json | 2 +- .../create_payroll_period/create_payroll_period.json | 2 +- .../payroll_settings/payroll_settings.json | 10 +++++----- .../payroll/report/bank_remittance/bank_remittance.py | 5 ++++- .../salary_payments_based_on_payment_mode.py | 2 ++ .../provident_fund_deductions.py | 2 +- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/erpnext/payroll/doctype/payroll_period/payroll_period.json b/erpnext/payroll/doctype/payroll_period/payroll_period.json index c919b4fe13..0e0948475c 100644 --- a/erpnext/payroll/doctype/payroll_period/payroll_period.json +++ b/erpnext/payroll/doctype/payroll_period/payroll_period.json @@ -53,7 +53,7 @@ } ], "links": [], - "modified": "2020-06-22 20:12:32.684189", + "modified": "2020-06-29 17:17:12.689089", "modified_by": "Administrator", "module": "Payroll", "name": "Payroll Period", @@ -96,6 +96,7 @@ "write": 1 } ], + "quick_entry": 1, "sort_field": "modified", "sort_order": "DESC", "track_changes": 1 diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index 2da19b0397..1e2983e421 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -207,7 +207,7 @@ class SalarySlip(TransactionBase): frappe.throw(_("There are more holidays than working days this month.")) if not payroll_based_on: - frappe.throw(_("Please set Payroll based on in HR settings")) + frappe.throw(_("Please set Payroll based on in Payroll settings")) if payroll_based_on == "Attendance": actual_lwp, absent = self.calculate_lwp_and_absent_days_based_on_attendance(holidays) @@ -244,15 +244,13 @@ class SalarySlip(TransactionBase): for holiday in holidays: if not frappe.db.exists("Attendance", {"employee": self.employee, "attendance_date": holiday, "docstatus": 1 }): self.payment_days += 1 - - else: self.payment_days = 0 def get_unmarked_days(self): marked_days = frappe.get_all("Attendance", filters = { - "attendance_date": ["between", ['2020-05-1',"2020-05-30"]], - "employee": 'HR-EMP-00003', + "attendance_date": ["between", [self.start_date, self.end_date]], + "employee": self.employee, "docstatus": 1 }, fields = ["COUNT(*) as marked_days"])[0].marked_days diff --git a/erpnext/payroll/module_onboarding/payroll/payroll.json b/erpnext/payroll/module_onboarding/payroll/payroll.json index a4ea53640e..7ed786faee 100644 --- a/erpnext/payroll/module_onboarding/payroll/payroll.json +++ b/erpnext/payroll/module_onboarding/payroll/payroll.json @@ -13,7 +13,7 @@ "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/human-resources/payroll-entry", "idx": 0, "is_complete": 0, - "modified": "2020-06-04 16:35:30.650792", + "modified": "2020-06-29 17:00:25.113341", "modified_by": "Administrator", "module": "Payroll", "name": "Payroll", diff --git a/erpnext/payroll/onboarding_step/create_payroll_period/create_payroll_period.json b/erpnext/payroll/onboarding_step/create_payroll_period/create_payroll_period.json index 4bae67546c..b1a7cc2734 100644 --- a/erpnext/payroll/onboarding_step/create_payroll_period/create_payroll_period.json +++ b/erpnext/payroll/onboarding_step/create_payroll_period/create_payroll_period.json @@ -8,7 +8,7 @@ "is_mandatory": 1, "is_single": 0, "is_skipped": 0, - "modified": "2020-06-01 11:53:54.553947", + "modified": "2020-06-29 11:53:54.553947", "modified_by": "Administrator", "name": "Create Payroll Period", "owner": "Administrator", diff --git a/erpnext/payroll/onboarding_step/payroll_settings/payroll_settings.json b/erpnext/payroll/onboarding_step/payroll_settings/payroll_settings.json index 946b8c8707..a7cf7bf988 100644 --- a/erpnext/payroll/onboarding_step/payroll_settings/payroll_settings.json +++ b/erpnext/payroll/onboarding_step/payroll_settings/payroll_settings.json @@ -1,19 +1,19 @@ { - "action": "Go to Page", + "action": "Update Settings", "creation": "2020-06-04 16:34:29.664917", "docstatus": 0, "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, "is_mandatory": 0, - "is_single": 0, + "is_single": 1, "is_skipped": 0, - "modified": "2020-06-04 16:34:29.664917", + "modified": "2020-06-29 16:34:29.664917", "modified_by": "Administrator", "name": "Payroll Settings", "owner": "Administrator", - "path": "#Form/Payroll Settings", + "reference_document": "Payroll Settings", "show_full_form": 0, "title": "Payroll Settings", - "validate_action": 1 + "validate_action": 0 } \ No newline at end of file diff --git a/erpnext/payroll/report/bank_remittance/bank_remittance.py b/erpnext/payroll/report/bank_remittance/bank_remittance.py index a35d8e550e..4b052bf5c4 100644 --- a/erpnext/payroll/report/bank_remittance/bank_remittance.py +++ b/erpnext/payroll/report/bank_remittance/bank_remittance.py @@ -152,6 +152,9 @@ def set_company_account(payment_accounts, payroll_entries): company_accounts_map[acc.account] = acc for entry in payroll_entries: - entry["company_account"] = company_accounts_map[entry.payment_account]['bank_account_no'] + company_account = '' + if entry.payment_account in company_accounts_map: + company_account = company_accounts_map[entry.payment_account]['bank_account_no'] + entry["company_account"] = company_account return payroll_entries diff --git a/erpnext/payroll/report/salary_payments_based_on_payment_mode/salary_payments_based_on_payment_mode.py b/erpnext/payroll/report/salary_payments_based_on_payment_mode/salary_payments_based_on_payment_mode.py index 7f0c2e2e00..a0dab63654 100644 --- a/erpnext/payroll/report/salary_payments_based_on_payment_mode/salary_payments_based_on_payment_mode.py +++ b/erpnext/payroll/report/salary_payments_based_on_payment_mode/salary_payments_based_on_payment_mode.py @@ -100,6 +100,8 @@ def get_data(filters, mode_of_payments): total_row = get_total_based_on_mode_of_payment(data, mode_of_payments) total_deductions = gross_pay - total_row.get("total") + report_summary = [] + if data: data.append(total_row) data.append({}) diff --git a/erpnext/regional/report/provident_fund_deductions/provident_fund_deductions.py b/erpnext/regional/report/provident_fund_deductions/provident_fund_deductions.py index 9f58957fed..86f2b5b05e 100644 --- a/erpnext/regional/report/provident_fund_deductions/provident_fund_deductions.py +++ b/erpnext/regional/report/provident_fund_deductions/provident_fund_deductions.py @@ -97,7 +97,7 @@ def prepare_data(entry,component_type_dict): "employee": d.employee, "employee_name": d.employee_name, "pf_account": employee_account_dict.get(d.employee), - "component_type": d.amount + component_type: d.amount }) return data_list From 0efda4e457f017689ca0fe22423c09f049648aad Mon Sep 17 00:00:00 2001 From: Marica Date: Tue, 30 Jun 2020 08:20:35 +0530 Subject: [PATCH 125/449] fix: Added Missing Trends Reports to Buying/Selling Desk (#22509) * fix: Added Missing Trends Reports to Buying/Selling Desk * fix: Move Reports to Other Reports --- erpnext/buying/desk_page/buying/buying.json | 4 ++-- erpnext/selling/desk_page/selling/selling.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/buying/desk_page/buying/buying.json b/erpnext/buying/desk_page/buying/buying.json index bddb9573ad..565d39c3c8 100644 --- a/erpnext/buying/desk_page/buying/buying.json +++ b/erpnext/buying/desk_page/buying/buying.json @@ -33,7 +33,7 @@ { "hidden": 0, "label": "Other Reports", - "links": "[\n {\n \"is_query_report\": true,\n \"label\": \"Items To Be Requested\",\n \"name\": \"Items To Be Requested\",\n \"onboard\": 1,\n \"reference_doctype\": \"Item\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Item-wise Purchase History\",\n \"name\": \"Item-wise Purchase History\",\n \"onboard\": 1,\n \"reference_doctype\": \"Item\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Subcontracted Raw Materials To Be Transferred\",\n \"name\": \"Subcontracted Raw Materials To Be Transferred\",\n \"reference_doctype\": \"Purchase Order\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Subcontracted Item To Be Received\",\n \"name\": \"Subcontracted Item To Be Received\",\n \"reference_doctype\": \"Purchase Order\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Quoted Item Comparison\",\n \"name\": \"Quoted Item Comparison\",\n \"onboard\": 1,\n \"reference_doctype\": \"Supplier Quotation\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Material Requests for which Supplier Quotations are not created\",\n \"name\": \"Material Requests for which Supplier Quotations are not created\",\n \"reference_doctype\": \"Material Request\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Supplier Addresses And Contacts\",\n \"name\": \"Address And Contacts\",\n \"reference_doctype\": \"Address\",\n \"route_options\": {\n \"party_type\": \"Supplier\"\n },\n \"type\": \"report\"\n }\n]" + "links": "[\n {\n \"is_query_report\": true,\n \"label\": \"Items To Be Requested\",\n \"name\": \"Items To Be Requested\",\n \"onboard\": 1,\n \"reference_doctype\": \"Item\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Item-wise Purchase History\",\n \"name\": \"Item-wise Purchase History\",\n \"onboard\": 1,\n \"reference_doctype\": \"Item\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Purchase Receipt Trends\",\n \"name\": \"Purchase Receipt Trends\",\n \"reference_doctype\": \"Purchase Receipt\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Purchase Invoice Trends\",\n \"name\": \"Purchase Invoice Trends\",\n \"reference_doctype\": \"Purchase Invoice\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Subcontracted Raw Materials To Be Transferred\",\n \"name\": \"Subcontracted Raw Materials To Be Transferred\",\n \"reference_doctype\": \"Purchase Order\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Subcontracted Item To Be Received\",\n \"name\": \"Subcontracted Item To Be Received\",\n \"reference_doctype\": \"Purchase Order\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Quoted Item Comparison\",\n \"name\": \"Quoted Item Comparison\",\n \"onboard\": 1,\n \"reference_doctype\": \"Supplier Quotation\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Material Requests for which Supplier Quotations are not created\",\n \"name\": \"Material Requests for which Supplier Quotations are not created\",\n \"reference_doctype\": \"Material Request\",\n \"type\": \"report\"\n },\n {\n \"is_query_report\": true,\n \"label\": \"Supplier Addresses And Contacts\",\n \"name\": \"Address And Contacts\",\n \"reference_doctype\": \"Address\",\n \"route_options\": {\n \"party_type\": \"Supplier\"\n },\n \"type\": \"report\"\n }\n]" }, { "hidden": 0, @@ -60,7 +60,7 @@ "idx": 0, "is_standard": 1, "label": "Buying", - "modified": "2020-05-28 13:32:49.960574", + "modified": "2020-06-29 19:30:24.983050", "modified_by": "Administrator", "module": "Buying", "name": "Buying", diff --git a/erpnext/selling/desk_page/selling/selling.json b/erpnext/selling/desk_page/selling/selling.json index 60b15326e8..225238233a 100644 --- a/erpnext/selling/desk_page/selling/selling.json +++ b/erpnext/selling/desk_page/selling/selling.json @@ -23,7 +23,7 @@ { "hidden": 0, "label": "Other Reports", - "links": "[\n {\n \"dependencies\": [\n \"Lead\"\n ],\n \"doctype\": \"Lead\",\n \"is_query_report\": true,\n \"label\": \"Lead Details\",\n \"name\": \"Lead Details\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Address\"\n ],\n \"doctype\": \"Address\",\n \"is_query_report\": true,\n \"label\": \"Customer Addresses And Contacts\",\n \"name\": \"Address And Contacts\",\n \"route_options\": {\n \"party_type\": \"Customer\"\n },\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Item\"\n ],\n \"doctype\": \"Item\",\n \"is_query_report\": true,\n \"label\": \"Available Stock for Packing Items\",\n \"name\": \"Available Stock for Packing Items\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Order\"\n ],\n \"doctype\": \"Sales Order\",\n \"is_query_report\": true,\n \"label\": \"Pending SO Items For Purchase Request\",\n \"name\": \"Pending SO Items For Purchase Request\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Customer\"\n ],\n \"doctype\": \"Customer\",\n \"is_query_report\": true,\n \"label\": \"Customer Credit Balance\",\n \"name\": \"Customer Credit Balance\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Customer\"\n ],\n \"doctype\": \"Customer\",\n \"is_query_report\": true,\n \"label\": \"Customers Without Any Sales Transactions\",\n \"name\": \"Customers Without Any Sales Transactions\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Customer\"\n ],\n \"doctype\": \"Customer\",\n \"is_query_report\": true,\n \"label\": \"Sales Partners Commission\",\n \"name\": \"Sales Partners Commission\",\n \"type\": \"report\"\n }\n]" + "links": "[\n {\n \"dependencies\": [\n \"Lead\"\n ],\n \"doctype\": \"Lead\",\n \"is_query_report\": true,\n \"label\": \"Lead Details\",\n \"name\": \"Lead Details\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Address\"\n ],\n \"doctype\": \"Address\",\n \"is_query_report\": true,\n \"label\": \"Customer Addresses And Contacts\",\n \"name\": \"Address And Contacts\",\n \"route_options\": {\n \"party_type\": \"Customer\"\n },\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Item\"\n ],\n \"doctype\": \"Item\",\n \"is_query_report\": true,\n \"label\": \"Available Stock for Packing Items\",\n \"name\": \"Available Stock for Packing Items\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Order\"\n ],\n \"doctype\": \"Sales Order\",\n \"is_query_report\": true,\n \"label\": \"Pending SO Items For Purchase Request\",\n \"name\": \"Pending SO Items For Purchase Request\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Delivery Note\"\n ],\n \"doctype\": \"Delivery Note\",\n \"is_query_report\": true,\n \"label\": \"Delivery Note Trends\",\n \"name\": \"Delivery Note Trends\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Invoice\"\n ],\n \"doctype\": \"Sales Invoice\",\n \"is_query_report\": true,\n \"label\": \"Sales Invoice Trends\",\n \"name\": \"Sales Invoice Trends\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Customer\"\n ],\n \"doctype\": \"Customer\",\n \"is_query_report\": true,\n \"label\": \"Customer Credit Balance\",\n \"name\": \"Customer Credit Balance\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Customer\"\n ],\n \"doctype\": \"Customer\",\n \"is_query_report\": true,\n \"label\": \"Customers Without Any Sales Transactions\",\n \"name\": \"Customers Without Any Sales Transactions\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Customer\"\n ],\n \"doctype\": \"Customer\",\n \"is_query_report\": true,\n \"label\": \"Sales Partners Commission\",\n \"name\": \"Sales Partners Commission\",\n \"type\": \"report\"\n }\n]" } ], "category": "Modules", @@ -44,7 +44,7 @@ "idx": 0, "is_standard": 1, "label": "Selling", - "modified": "2020-06-19 13:23:24.861706", + "modified": "2020-06-29 19:26:35.139097", "modified_by": "Administrator", "module": "Selling", "name": "Selling", From 7ca8022b8f3b53eb1f05ff3811b9a0010140616f Mon Sep 17 00:00:00 2001 From: Marica Date: Tue, 30 Jun 2020 08:20:58 +0530 Subject: [PATCH 126/449] fix: Set Root as Parent if no parent in new tree view node (#22508) --- erpnext/setup/doctype/customer_group/customer_group.py | 5 ++++- erpnext/setup/doctype/sales_person/sales_person.py | 5 ++++- erpnext/setup/doctype/territory/territory.py | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/erpnext/setup/doctype/customer_group/customer_group.py b/erpnext/setup/doctype/customer_group/customer_group.py index f62613ea1b..68e1ccb635 100644 --- a/erpnext/setup/doctype/customer_group/customer_group.py +++ b/erpnext/setup/doctype/customer_group/customer_group.py @@ -6,9 +6,12 @@ import frappe from frappe import _ -from frappe.utils.nestedset import NestedSet +from frappe.utils.nestedset import NestedSet, get_root_of class CustomerGroup(NestedSet): nsm_parent_field = 'parent_customer_group' + def validate(self): + if not self.parent_customer_group: + self.parent_customer_group = get_root_of("Customer Group") def on_update(self): self.validate_name_with_customer() diff --git a/erpnext/setup/doctype/sales_person/sales_person.py b/erpnext/setup/doctype/sales_person/sales_person.py index 3379534cf8..19c2e5b954 100644 --- a/erpnext/setup/doctype/sales_person/sales_person.py +++ b/erpnext/setup/doctype/sales_person/sales_person.py @@ -5,13 +5,16 @@ from __future__ import unicode_literals import frappe from frappe import _ from frappe.utils import flt -from frappe.utils.nestedset import NestedSet +from frappe.utils.nestedset import NestedSet, get_root_of from erpnext import get_default_currency class SalesPerson(NestedSet): nsm_parent_field = 'parent_sales_person' def validate(self): + if not self.parent_sales_person: + self.parent_sales_person = get_root_of("Sales Person") + for d in self.get('targets') or []: if not flt(d.target_qty) and not flt(d.target_amount): frappe.throw(_("Either target qty or target amount is mandatory.")) diff --git a/erpnext/setup/doctype/territory/territory.py b/erpnext/setup/doctype/territory/territory.py index 808b5386ab..05e8f666cf 100644 --- a/erpnext/setup/doctype/territory/territory.py +++ b/erpnext/setup/doctype/territory/territory.py @@ -6,12 +6,14 @@ import frappe from frappe.utils import flt from frappe import _ -from frappe.utils.nestedset import NestedSet +from frappe.utils.nestedset import NestedSet, get_root_of class Territory(NestedSet): nsm_parent_field = 'parent_territory' def validate(self): + if not self.parent_territory: + self.parent_territory = get_root_of("Territory") for d in self.get('targets') or []: if not flt(d.target_qty) and not flt(d.target_amount): From e0388a169af5ff98ef994733fdd743b49d05e251 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2020 08:57:26 +0530 Subject: [PATCH 127/449] fix: manufacturing dashboard grammar (#22510) (#22516) * fix: manufacturing dashboard grammar * Update manufacturing.json (cherry picked from commit 7056cd3782161f0bfb1ba5c0519e87d40c09ce8d) Co-authored-by: rohitwaghchaure --- erpnext/manufacturing/dashboard_fixtures.py | 8 ++++---- .../module_onboarding/manufacturing/manufacturing.json | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/erpnext/manufacturing/dashboard_fixtures.py b/erpnext/manufacturing/dashboard_fixtures.py index 64e4bc6ed0..0e9a21c026 100644 --- a/erpnext/manufacturing/dashboard_fixtures.py +++ b/erpnext/manufacturing/dashboard_fixtures.py @@ -192,7 +192,7 @@ def get_number_cards(): ]), "function": "Count", "is_public": 1, - "label": _("Monthly Total Work Order"), + "label": _("Monthly Total Work Orders"), "show_percentage_stats": 1, "stats_time_interval": "Weekly" }, @@ -207,7 +207,7 @@ def get_number_cards(): ]), "function": "Count", "is_public": 1, - "label": _("Monthly Completed Work Order"), + "label": _("Monthly Completed Work Orders"), "show_percentage_stats": 1, "stats_time_interval": "Weekly" }, @@ -221,7 +221,7 @@ def get_number_cards(): ]), "function": "Count", "is_public": 1, - "label": _("Ongoing Job Card"), + "label": _("Ongoing Job Cards"), "show_percentage_stats": 1, "stats_time_interval": "Weekly" }, @@ -235,7 +235,7 @@ def get_number_cards(): ]), "function": "Count", "is_public": 1, - "label": _("Monthly Quality Inspection"), + "label": _("Monthly Quality Inspections"), "show_percentage_stats": 1, "stats_time_interval": "Weekly" }] \ No newline at end of file diff --git a/erpnext/manufacturing/module_onboarding/manufacturing/manufacturing.json b/erpnext/manufacturing/module_onboarding/manufacturing/manufacturing.json index 952d1f0e07..a36b63a1d9 100644 --- a/erpnext/manufacturing/module_onboarding/manufacturing/manufacturing.json +++ b/erpnext/manufacturing/module_onboarding/manufacturing/manufacturing.json @@ -19,7 +19,7 @@ "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/manufacturing", "idx": 0, "is_complete": 0, - "modified": "2020-05-19 12:51:42.744570", + "modified": "2020-06-29 20:25:36.899106", "modified_by": "Administrator", "module": "Manufacturing", "name": "Manufacturing", @@ -52,6 +52,5 @@ ], "subtitle": "Products, Raw Materials, BOM, Work Order and more.", "success_message": "Manufacturing module is all setup!", - "title": "Let's Setup Manufacturing Module", - "user_can_dismiss": 1 -} \ No newline at end of file + "title": "Let's Set Up the Manufacturing Module" +} From 7db00dde2d2a34872af4f38810bb9a40629cde6a Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2020 09:33:18 +0530 Subject: [PATCH 128/449] fix: Dashboard label in Projects and Assets module (#22517) (#22518) (cherry picked from commit fdbd10f1939a47511d2288dbaf4aad138f81eec8) Co-authored-by: Nabin Hait --- erpnext/assets/desk_page/assets/assets.json | 2 +- .../desk_page/manufacturing/manufacturing.json | 14 +++++++------- erpnext/projects/desk_page/projects/projects.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/erpnext/assets/desk_page/assets/assets.json b/erpnext/assets/desk_page/assets/assets.json index 94939fdd2a..449a5facb0 100644 --- a/erpnext/assets/desk_page/assets/assets.json +++ b/erpnext/assets/desk_page/assets/assets.json @@ -58,7 +58,7 @@ "type": "Report" }, { - "label": "Assets Dashboard", + "label": "Dashboard", "link_to": "Asset", "type": "Dashboard" } diff --git a/erpnext/manufacturing/desk_page/manufacturing/manufacturing.json b/erpnext/manufacturing/desk_page/manufacturing/manufacturing.json index 763f533a94..8d11294164 100644 --- a/erpnext/manufacturing/desk_page/manufacturing/manufacturing.json +++ b/erpnext/manufacturing/desk_page/manufacturing/manufacturing.json @@ -93,12 +93,6 @@ "stats_filter": "{ \n \"status\": [\"not in\", [\"Completed\"]]\n}", "type": "DocType" }, - { - "label": "Dashboard", - "link_to": "Manufacturing", - "restrict_to_domain": "Manufacturing", - "type": "Dashboard" - }, { "label": "Forecasting", "link_to": "Exponential Smoothing Forecasting", @@ -119,6 +113,12 @@ "label": "Production Planning Report", "link_to": "Production Planning Report", "type": "Report" - } + }, + { + "label": "Dashboard", + "link_to": "Manufacturing", + "restrict_to_domain": "Manufacturing", + "type": "Dashboard" + } ] } \ No newline at end of file diff --git a/erpnext/projects/desk_page/projects/projects.json b/erpnext/projects/desk_page/projects/projects.json index d91fe5304a..e24cf3081c 100644 --- a/erpnext/projects/desk_page/projects/projects.json +++ b/erpnext/projects/desk_page/projects/projects.json @@ -68,7 +68,7 @@ "type": "Report" }, { - "label": "Project Dashboard", + "label": "Dashboard", "link_to": "Project", "type": "Dashboard" } From 7813cabfd39f68bc8fa463fc139b97c76adcca2d Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 30 Jun 2020 11:35:30 +0530 Subject: [PATCH 129/449] chore: Added Change Log --- erpnext/change_log/v13/v13_0_0-beta_3.md | 66 ++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 erpnext/change_log/v13/v13_0_0-beta_3.md diff --git a/erpnext/change_log/v13/v13_0_0-beta_3.md b/erpnext/change_log/v13/v13_0_0-beta_3.md new file mode 100644 index 0000000000..09ea90087d --- /dev/null +++ b/erpnext/change_log/v13/v13_0_0-beta_3.md @@ -0,0 +1,66 @@ +### Version 13.0.0 Beta 3 Release Notes + +#### Features and Enhancements +- Dedicated Payroll module with Onboarding and Dashboard ([#21990](https://github.com/frappe/erpnext/pull/21990)) +- New Payroll Reports + - Income Tax Deductions + - Professional Tax Deductions + - Provident Fund Deductions + - Total Salary Payments Based on Payment Mode + - Salary Payments via ECS +- Distributed Cost Center ([#21531](https://github.com/frappe/erpnext/pull/21531)) +- More controlled deferred revenue booking ([#21671](https://github.com/frappe/erpnext/pull/21671)) + - Book deferred accounting via Journal Entry, provision to keep in draft + - Provision to book deferred revenue/expense on a monthly basis rather than by days +- Selling Desk, Dashboard and Onboarding ([#22055](https://github.com/frappe/erpnext/pull/22055)) +- Help Articles on support portal ([#22194](https://github.com/frappe/erpnext/pull/22194)) +- Issue Metrics and SLA Enhancements ([#21617](https://github.com/frappe/erpnext/pull/21617)) +- Multi UOM support in Request for Quotation ([#22249](https://github.com/frappe/erpnext/pull/22249)) +- The ability for a contract to be authorized internally using a signature field ([#22095](https://github.com/frappe/erpnext/pull/22095)) +- Gross Profit In Quotation ([#21795](https://github.com/frappe/erpnext/pull/21795)) +- Notify credit controller users for credit limit extension via Email ([#22213](https://github.com/frappe/erpnext/pull/22213)) +- Added In and Out time in attendance ([#21547](https://github.com/frappe/erpnext/pull/21547)) +- Renamed Loan Management to Loan on Desk Page ([#21877](https://github.com/frappe/erpnext/pull/21877)) +- Document tour to manufacturing settings ([#21962](https://github.com/frappe/erpnext/pull/21962)) +- Added Expense Approver field in Employee master ([#22244](https://github.com/frappe/erpnext/pull/22244)) + + +#### Fixes +- Bill all hours by default on Timesheet ([#22155](https://github.com/frappe/erpnext/pull/22155)) +- Unable to cancel employee advance ([#22374](https://github.com/frappe/erpnext/pull/22374)) +- Status error in purchase invoice ([#22351](https://github.com/frappe/erpnext/pull/22351)) +- Item-wise sales and purchase register export ([#22184](https://github.com/frappe/erpnext/pull/22184)) +- Billing address in for Purchase documents ([#22233](https://github.com/frappe/erpnext/pull/22233)) +- Handle canceled entries in financial statements ([#22231](https://github.com/frappe/erpnext/pull/22231)) +- Default period start date and period end date for financial statements ([#22011](https://github.com/frappe/erpnext/pull/22011)) +- Update Packed Items via Update Items in Sales Order ([#22392](https://github.com/frappe/erpnext/pull/22392)) +- Hide delete company transactions button if not system manager ([#21839](https://github.com/frappe/erpnext/pull/21839)) +- Skipping total row for tree-view reports ([#22350](https://github.com/frappe/erpnext/pull/22350)) +- Cancelled entries in tds payable monthly report ([#22131](https://github.com/frappe/erpnext/pull/22131)) +- Inter-company Invoice currency for multicurrency transactions ([#21984](https://github.com/frappe/erpnext/pull/21984)) +- Filter batches based on item and warehouse in Pick List (develop) ([#21780](https://github.com/frappe/erpnext/pull/21780)) +- Set cost center in Expense Claim child based on parent (if missing) ([#22175](https://github.com/frappe/erpnext/pull/22175)) +- Item wise backdated stock entry posting for immutable ledger ([#22366](https://github.com/frappe/erpnext/pull/22366)) +- Shopping cart UI fixes ([#22137](https://github.com/frappe/erpnext/pull/22137)) +- Filter Leave Type based on allocation for a particular employee ([#22050](https://github.com/frappe/erpnext/pull/22050)) +- Party validation for inter-warehouse transaction ([#22186](https://github.com/frappe/erpnext/pull/22186)) +- Manufacturing dashboard and work order summary chart ([#21946](https://github.com/frappe/erpnext/pull/21946)) +- IP Admission and Discharge, Minor fixes ([#21817](https://github.com/frappe/erpnext/pull/21817)) +- Validation of Purchase Order against Material Request missing ([#22192](https://github.com/frappe/erpnext/pull/22192)) +- Staffing Plan validation ([#22379](https://github.com/frappe/erpnext/pull/22379)) +- Do not allow backdated stock transactions in previous fiscal year ([#21967](https://github.com/frappe/erpnext/pull/21967)) +- Employee Advance Return not working ([#21812](https://github.com/frappe/erpnext/pull/21812)) +- Added card for reports on education desk ([#21853](https://github.com/frappe/erpnext/pull/21853)) +- Refactored project summary report ([#21943](https://github.com/frappe/erpnext/pull/21943)) +- Revenue and Customer Count only in date range in Customer Acquitition Report ([#22210](https://github.com/frappe/erpnext/pull/22210)) +- Alternative item not working for subcontract ([#22386](https://github.com/frappe/erpnext/pull/22386)) +- Unable to create batched Item ([#22393](https://github.com/frappe/erpnext/pull/22393)) +- Filters for the manufacturing reports ([#21960](https://github.com/frappe/erpnext/pull/21960)) +- Raw material warehouse in Production Planning Report ([#21982](https://github.com/frappe/erpnext/pull/21982)) +- Allowed LWP leave types to select in Leave Application even if there is no allocation against them ([#22197](https://github.com/frappe/erpnext/pull/22197)) +- Report not working on parameter Grade ([#21951](https://github.com/frappe/erpnext/pull/21951)) +- Allow to enter Relieving date if employee status is Left ([#22242](https://github.com/frappe/erpnext/pull/22242)) +- Resetting lost reason in opportunity and quotation ([#22378](https://github.com/frappe/erpnext/pull/22378)) +- Filtering issues in opening invoice creation tool ([#21969](https://github.com/frappe/erpnext/pull/21969)) +- Set default reference Id for "On Previous Row Amount" and "On Previous Row Total" ([#22346](https://github.com/frappe/erpnext/pull/22346)) +- UX date range field separated in from and to date fields. ([#21765](https://github.com/frappe/erpnext/pull/21765)) From dca65de1b600562007a7d64ba06724033f0400cb Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2020 11:45:40 +0530 Subject: [PATCH 130/449] fix: Salary deductions report fixes (bp #22397) (#22520) * feat: added year filters (cherry picked from commit d0d9b53361c57d362e7e975f16b48ccbfdc021a8) * Fix: if there is no component (cherry picked from commit f9ca29cebd0a0963ec58b8971283d7e0d2868f2b) * fix: test_tax_for_payroll_period (cherry picked from commit ece9508eb5a02962a994fbaad0e989e323d3f56c) Co-authored-by: Anurag Mishra --- .../doctype/salary_slip/test_salary_slip.py | 1 + .../income_tax_deductions.py | 12 ++++++--- .../salary_payments_via_ecs.py | 8 +++--- .../salary_slip_deductions_report_filters.js | 25 ++++++++++++++++--- .../professional_tax_deductions.py | 5 +++- .../provident_fund_deductions.py | 25 +++++++++++++++---- 6 files changed, 61 insertions(+), 15 deletions(-) diff --git a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py index f42b9ad11d..be9a2d3728 100644 --- a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py @@ -271,6 +271,7 @@ class TestSalarySlip(unittest.TestCase): # as per assigned salary structure 40500 in monthly salary so 236000*5/100/12 frappe.db.sql("""delete from `tabPayroll Period`""") frappe.db.sql("""delete from `tabSalary Component`""") + frappe.db.sql("""delete from `tabAdditional Salary`""") payroll_period = create_payroll_period() diff --git a/erpnext/payroll/report/income_tax_deductions/income_tax_deductions.py b/erpnext/payroll/report/income_tax_deductions/income_tax_deductions.py index 3bad5879bb..8a79416edb 100644 --- a/erpnext/payroll/report/income_tax_deductions/income_tax_deductions.py +++ b/erpnext/payroll/report/income_tax_deductions/income_tax_deductions.py @@ -6,8 +6,8 @@ import frappe, erpnext from frappe import _ def execute(filters=None): - columns = get_columns(filters) data = get_data(filters) + columns = get_columns(filters) if len(data) else [] return columns, data @@ -78,8 +78,11 @@ def get_conditions(filters): if filters.get("company"): conditions.append("sal.company = '%s' " % (filters["company"]) ) - if filters.get("period"): - conditions.append("month(sal.start_date) = '%s' " % (filters["period"])) + if filters.get("month"): + conditions.append("month(sal.start_date) = '%s' " % (filters["month"])) + + if filters.get("year"): + conditions.append("year(start_date) = '%s' " % (filters["year"])) return " and ".join(conditions) @@ -96,6 +99,9 @@ def get_data(filters): component_types = [comp_type[0] for comp_type in component_types] + if not len(component_types): + return [] + conditions = get_conditions(filters) entry = frappe.db.sql(""" select sal.employee, sal.employee_name, sal.posting_date, ded.salary_component, ded.amount,sal.gross_pay diff --git a/erpnext/payroll/report/salary_payments_via_ecs/salary_payments_via_ecs.py b/erpnext/payroll/report/salary_payments_via_ecs/salary_payments_via_ecs.py index 073bd91300..d09745c37b 100644 --- a/erpnext/payroll/report/salary_payments_via_ecs/salary_payments_via_ecs.py +++ b/erpnext/payroll/report/salary_payments_via_ecs/salary_payments_via_ecs.py @@ -84,9 +84,11 @@ def get_conditions(filters): if filters.get("company"): conditions.append("company = '%s' " % (filters["company"]) ) - if filters.get("period"): - conditions.append("month(start_date) = '%s' " % (filters["period"])) - conditions.append("year(start_date) = '%s' " % (frappe.utils.getdate().year)) + if filters.get("month"): + conditions.append("month(start_date) = '%s' " % (filters["month"])) + + if filters.get("year"): + conditions.append("year(start_date) = '%s' " % (filters["year"])) return " and ".join(conditions) diff --git a/erpnext/public/js/salary_slip_deductions_report_filters.js b/erpnext/public/js/salary_slip_deductions_report_filters.js index 242037991a..2b30e65075 100644 --- a/erpnext/public/js/salary_slip_deductions_report_filters.js +++ b/erpnext/public/js/salary_slip_deductions_report_filters.js @@ -11,8 +11,8 @@ erpnext.salary_slip_deductions_report_filters = { default: frappe.defaults.get_user_default("Company"), }, { - fieldname: "period", - label: __("Period"), + fieldname: "month", + label: __("Month"), fieldtype: "Select", reqd: 1 , options: [ @@ -31,6 +31,12 @@ erpnext.salary_slip_deductions_report_filters = { ], default: frappe.datetime.str_to_obj(frappe.datetime.get_today()).getMonth() + 1 }, + { + fieldname:"year", + label: __("Year"), + fieldtype: "Select", + reqd: 1 + }, { fieldname: "department", label: __("Department"), @@ -43,5 +49,18 @@ erpnext.salary_slip_deductions_report_filters = { fieldtype: "Link", options: "Branch", } - ] + ], + + "onload": function() { + return frappe.call({ + method: "erpnext.regional.report.provident_fund_deductions.provident_fund_deductions.get_years", + callback: function(r) { + var year_filter = frappe.query_report.get_filter('year'); + year_filter.df.options = r.message; + year_filter.df.default = r.message.split("\n")[0]; + year_filter.refresh(); + year_filter.set_input(year_filter.df.default); + } + }); + } } \ No newline at end of file diff --git a/erpnext/regional/report/professional_tax_deductions/professional_tax_deductions.py b/erpnext/regional/report/professional_tax_deductions/professional_tax_deductions.py index 900fe963b4..acde68a942 100644 --- a/erpnext/regional/report/professional_tax_deductions/professional_tax_deductions.py +++ b/erpnext/regional/report/professional_tax_deductions/professional_tax_deductions.py @@ -7,8 +7,8 @@ from frappe import _ from erpnext.regional.report.provident_fund_deductions.provident_fund_deductions import get_conditions def execute(filters=None): - columns = get_columns(filters) data = get_data(filters) + columns = get_columns(filters) if len(data) else [] return columns, data @@ -45,6 +45,9 @@ def get_data(filters): component_type_dict = frappe._dict(frappe.db.sql(""" select name, component_type from `tabSalary Component` where component_type = 'Professional Tax' """)) + if not len(component_type_dict): + return [] + conditions = get_conditions(filters) entry = frappe.db.sql(""" select sal.employee, sal.employee_name, ded.salary_component, ded.amount diff --git a/erpnext/regional/report/provident_fund_deductions/provident_fund_deductions.py b/erpnext/regional/report/provident_fund_deductions/provident_fund_deductions.py index 86f2b5b05e..597072c53a 100644 --- a/erpnext/regional/report/provident_fund_deductions/provident_fund_deductions.py +++ b/erpnext/regional/report/provident_fund_deductions/provident_fund_deductions.py @@ -3,11 +3,12 @@ from __future__ import unicode_literals import frappe +from frappe.utils import getdate from frappe import _ def execute(filters=None): - columns = get_columns(filters) data = get_data(filters) + columns = get_columns(filters) if len(data) else [] return columns, data @@ -71,10 +72,13 @@ def get_conditions(filters): conditions.append("sal.branch = '%s' " % (filters["branch"]) ) if filters.get("company"): - conditions.append("sal.company = '%s' " % (filters["company"]) ) + conditions.append("sal.company = '%s' " % (filters["company"])) - if filters.get("period"): - conditions.append("month(sal.start_date) = '%s' " % (filters["period"])) + if filters.get("month"): + conditions.append("month(sal.start_date) = '%s' " % (filters["month"])) + + if filters.get("year"): + conditions.append("year(start_date) = '%s' " % (filters["year"])) if filters.get("mode_of_payment"): conditions.append("sal.mode_of_payment = '%s' " % (filters["mode_of_payment"])) @@ -114,6 +118,9 @@ def get_data(filters): component_type_dict = frappe._dict(frappe.db.sql(""" select name, component_type from `tabSalary Component` where component_type in ('Provident Fund', 'Additional Provident Fund', 'Provident Fund Loan')""")) + if not len(component_type_dict): + return [] + entry = frappe.db.sql(""" select sal.name, sal.employee, sal.employee_name, ded.salary_component, ded.amount from `tabSalary Slip` sal, `tabSalary Detail` ded where sal.name = ded.parent @@ -150,4 +157,12 @@ def get_data(filters): data.append(employee) - return data \ No newline at end of file + return data + +@frappe.whitelist() +def get_years(): + year_list = frappe.db.sql_list("""select distinct YEAR(end_date) from `tabSalary Slip` ORDER BY YEAR(end_date) DESC""") + if not year_list: + year_list = [getdate().year] + + return "\n".join(str(year) for year in year_list) \ No newline at end of file From f278425c01134acbf1f9cdfd3bf6a6a796c9d97d Mon Sep 17 00:00:00 2001 From: Sahil Khan Date: Tue, 30 Jun 2020 19:06:02 +0550 Subject: [PATCH 131/449] bumped to version 13.0.0-beta.3 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 530a6e4880..18294f3604 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0-beta.2' +__version__ = '13.0.0-beta.3' def get_default_company(user=None): '''Get default company for user''' From 762f6297f6746a164c566047703cefdb97e3ef3f Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Fri, 24 Jul 2020 18:05:13 +0530 Subject: [PATCH 132/449] fix(payment-request): do not set guest as administrator (#22804) --- erpnext/accounts/doctype/payment_request/payment_request.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 287e00f70f..e93ec951fb 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -140,9 +140,6 @@ class PaymentRequest(Document): }) def set_as_paid(self): - if frappe.session.user == "Guest": - frappe.set_user("Administrator") - payment_entry = self.create_payment_entry() self.make_invoice() @@ -254,7 +251,7 @@ class PaymentRequest(Document): if status in ["Authorized", "Completed"]: redirect_to = None - self.run_method("set_as_paid") + self.set_as_paid() # if shopping cart enabled and in session if (shopping_cart_settings.enabled and hasattr(frappe.local, "session") From abc3227480b772189f65bfc4bc17123ab37f74a8 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 24 Jul 2020 21:02:15 +0530 Subject: [PATCH 133/449] chore: Added change log --- erpnext/change_log/v13/v13_0_0-beta_4.md | 72 ++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 erpnext/change_log/v13/v13_0_0-beta_4.md diff --git a/erpnext/change_log/v13/v13_0_0-beta_4.md b/erpnext/change_log/v13/v13_0_0-beta_4.md new file mode 100644 index 0000000000..b835cec211 --- /dev/null +++ b/erpnext/change_log/v13/v13_0_0-beta_4.md @@ -0,0 +1,72 @@ +### Version 13.0.0 Beta 4 Release Notes + +#### Features and Enhancements +- New and refreshed POS ([#20789](https://github.com/frappe/erpnext/pull/20789)) +- Introduced Dunning ([#22559](https://github.com/frappe/erpnext/pull/22559)) +- Taxjar Integration ([#21047](https://github.com/frappe/erpnext/pull/21047)) +- Patient Progress Page ([#22474](https://github.com/frappe/erpnext/pull/22474)) +- Provision to make RFQ against Opportunity ([#22765](https://github.com/frappe/erpnext/pull/22765)) +- Added form dashboards and refactored custom buttons in Education module ([#22727](https://github.com/frappe/erpnext/pull/22727)) +- Student Attendance and Leave Enhancements ([#22623](https://github.com/frappe/erpnext/pull/22623)) +- Recruitment analytics ([#21732](https://github.com/frappe/erpnext/pull/21732)) +- Add medical coding fields to Healthcare DocTypes ([#22501](https://github.com/frappe/erpnext/pull/22501)) +- Autofill Supplier pop-up when only 1 Supplier in RFQ ([#22512](https://github.com/frappe/erpnext/pull/22512)) +- Accounting entries for service item in Purchase receipt ([#22223](https://github.com/frappe/erpnext/pull/22223)) +- Enhancement in subscription ([#22263](https://github.com/frappe/erpnext/pull/22263)) +- Laboratory Module Enhancements ([#22416](https://github.com/frappe/erpnext/pull/22416)) +- Added columns to get complete analysis for material request ([#22607](https://github.com/frappe/erpnext/pull/22607)) +- Added all companies option in employee tree to view employee across all companies ([#22573](https://github.com/frappe/erpnext/pull/22573)) +- Email Group Option In Email Campaign ([#22731](https://github.com/frappe/erpnext/pull/22731)) +- Added range for age in stock ageing ([#22622](https://github.com/frappe/erpnext/pull/22622)) +- Refactored shopping cart ([#22617](https://github.com/frappe/erpnext/pull/22617)) + +#### Fixes: +- Enable show_configure_button when shopping cart is enabled ([#22468](https://github.com/frappe/erpnext/pull/22468)) +- Setup status indicators for Job Offer and Job Applicant (develop) ([#22445](https://github.com/frappe/erpnext/pull/22445)) +- Item-wise sales history report ([#22783](https://github.com/frappe/erpnext/pull/22783)) +- Setting filter for project in kanban board ([#22717](https://github.com/frappe/erpnext/pull/22717)) +- Dashboard For Timesheet ([#22750](https://github.com/frappe/erpnext/pull/22750)) +- Handle custom statuses for the pause SLA configuration ([#22349](https://github.com/frappe/erpnext/pull/22349)) +- Quality Feedback and Template ([#22571](https://github.com/frappe/erpnext/pull/22571)) +- Unable to change link from new lead to existing customer ([#22787](https://github.com/frappe/erpnext/pull/22787)) +- Job applicant fixes ([#22448](https://github.com/frappe/erpnext/pull/22448)) +- Move Issue List actions under 'Actions' dropdown (ux) ([#22710](https://github.com/frappe/erpnext/pull/22710)) +- Cost center should only show option of selected company ([#22598](https://github.com/frappe/erpnext/pull/22598)) +- Serial No Rename does not affect Stock Ledger Entry ([#22746](https://github.com/frappe/erpnext/pull/22746)) +- Descriptions not copied while creating Fees from Fee Structure ([#22792](https://github.com/frappe/erpnext/pull/22792)) +- Company filter for cost_center and expense_account in all sales and purchase transactions ([#22478](https://github.com/frappe/erpnext/pull/22478)) +- Arrangements of filters for reports accounts payable & receivable ([#22636](https://github.com/frappe/erpnext/pull/22636)) +- Update the project after task deletion so that the % completed shows correct value ([#22591](https://github.com/frappe/erpnext/pull/22591)) +- Block Invalid Serial No updates in Maintenance Schedule ([#22665](https://github.com/frappe/erpnext/pull/22665)) +- Fetch item price in sales invoice based on it's validity ([#22563](https://github.com/frappe/erpnext/pull/22563)) +- Add view ledger button for cancelled docs ([#22432](https://github.com/frappe/erpnext/pull/22432)) +- Allow creating SLA documents even if SLA tracking is not enabled ([#22608](https://github.com/frappe/erpnext/pull/22608)) +- Quotation list view blank if quotation_to field not set as a standard filter ([#22672](https://github.com/frappe/erpnext/pull/22672)) +- Salary deductions report fixes ([#22397](https://github.com/frappe/erpnext/pull/22397)) +22727)) +- Incorrect delivered qty in Supplier-Wise Sales Analytics ([#22631](https://github.com/frappe/erpnext/pull/22631)) +- Moved parent warehouse to top section also added a section break ([#22708](https://github.com/frappe/erpnext/pull/22708)) +- Skip Progress and Completed by fields on Task Duplication ([#22565](https://github.com/frappe/erpnext/pull/22565)) +- Incorrect stock after merging the items ([#22526](https://github.com/frappe/erpnext/pull/22526)) +- Letter head not found in opening invoice creation tool ([#22488](https://github.com/frappe/erpnext/pull/22488)) +- Cannot cancel asset and asset movement ([#22441](https://github.com/frappe/erpnext/pull/22441)) +- Fetch project-related info in Timesheet ([#22423](https://github.com/frappe/erpnext/pull/22423)) +- Currency symbol not showing as per company currency in stock balance report ([#22724](https://github.com/frappe/erpnext/pull/22724)) +- Add default cost center in payment reconciliation JV ([#22614](https://github.com/frappe/erpnext/pull/22614)) +- Stock Reconciliation Invalid Quantity for Batched Item ([#22726](https://github.com/frappe/erpnext/pull/22726)) +- Project link not set in accounts other than profit and loss accounts ([#22051](https://github.com/frappe/erpnext/pull/22051)) +- Buying price for non stock item in gross profit report ([#22616](https://github.com/frappe/erpnext/pull/22616)) +- Heatmap in Vehicle ([#22743](https://github.com/frappe/erpnext/pull/22743)) +- Added Project Field in Purchase Receipt for Stock Ledger Tagging ([#22666](https://github.com/frappe/erpnext/pull/22666)) +- Multi currency payment reconciliation ([#22738](https://github.com/frappe/erpnext/pull/22738)) +- Cannot cancel assets with repair pending ([#22440](https://github.com/frappe/erpnext/pull/22440)) +- Reset homepage to home after unchecking products page ([#22736](https://github.com/frappe/erpnext/pull/22736)) +- Add project filter in parent task field ([#22655](https://github.com/frappe/erpnext/pull/22655)) +- Generic Message in previous doc validation for buying and selling ([#22546](https://github.com/frappe/erpnext/pull/22546)) +- Cess amount in GSTR 3B report ([#22701](https://github.com/frappe/erpnext/pull/22701)) +- Expense claim outstanding while making payment entry ([#22735](https://github.com/frappe/erpnext/pull/22735)) +- Take parent cost center for child if no cost center at child in expense claim ([#22496](https://github.com/frappe/erpnext/pull/22496)) +- Consider company fiscal year for getting balance ([#22577](https://github.com/frappe/erpnext/pull/22577)) +- Pick List empty table and Serial-Batch items handling ([#22426](https://github.com/frappe/erpnext/pull/22426)) +- Show total row in print format of financial statement ([#22693](https://github.com/frappe/erpnext/pull/22693)) +- Set Root as Parent if no parent in new tree view node ([#22497](https://github.com/frappe/erpnext/pull/22497)) \ No newline at end of file From fa28e600b5c32066cb12ae6c4641abd5218341a9 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Tue, 28 Jul 2020 08:49:21 +0530 Subject: [PATCH 134/449] fix: Unable to submit backdated stock transactions for different items (#22822) * fix: Unable to submit backdated stock transactions for different items * fix: Test cases * fix: Test Cases * fix: Test Cases * fix: Test for stock account JV * fix: Journal Entry Test * fix: Delete unwanted code --- .../doctype/coupon_code/test_coupon_code.py | 27 ++++++------ .../journal_entry/test_journal_entry.py | 42 +++++++++++++++---- erpnext/accounts/general_ledger.py | 5 ++- erpnext/stock/doctype/item/item.py | 4 +- .../doctype/stock_entry/test_stock_entry.py | 26 +++++++++--- 5 files changed, 75 insertions(+), 29 deletions(-) diff --git a/erpnext/accounts/doctype/coupon_code/test_coupon_code.py b/erpnext/accounts/doctype/coupon_code/test_coupon_code.py index 990b896fde..3a0d4162ae 100644 --- a/erpnext/accounts/doctype/coupon_code/test_coupon_code.py +++ b/erpnext/accounts/doctype/coupon_code/test_coupon_code.py @@ -26,22 +26,22 @@ def test_create_test_data(): "item_group": "_Test Item Group", "item_name": "_Test Tesla Car", "apply_warehouse_wise_reorder_level": 0, - "warehouse":"_Test Warehouse - _TC", + "warehouse":"Stores - TCP1", "gst_hsn_code": "999800", "valuation_rate": 5000, "standard_rate":5000, "item_defaults": [{ - "company": "_Test Company", - "default_warehouse": "_Test Warehouse - _TC", + "company": "_Test Company with perpetual inventory", + "default_warehouse": "Stores - TCP1", "default_price_list":"_Test Price List", - "expense_account": "_Test Account Cost for Goods Sold - _TC", - "buying_cost_center": "_Test Cost Center - _TC", - "selling_cost_center": "_Test Cost Center - _TC", - "income_account": "Sales - _TC" + "expense_account": "Cost of Goods Sold - TCP1", + "buying_cost_center": "Main - TCP1", + "selling_cost_center": "Main - TCP1", + "income_account": "Sales - TCP1" }], "show_in_website": 1, "route":"-test-tesla-car", - "website_warehouse": "_Test Warehouse - _TC" + "website_warehouse": "Stores - TCP1" }) item.insert() # create test item price @@ -63,12 +63,12 @@ def test_create_test_data(): "items": [{ "item_code": "_Test Tesla Car" }], - "warehouse":"_Test Warehouse - _TC", + "warehouse":"Stores - TCP1", "coupon_code_based":1, "selling": 1, "rate_or_discount": "Discount Percentage", "discount_percentage": 30, - "company": "_Test Company", + "company": "_Test Company with perpetual inventory", "currency":"INR", "for_price_list":"_Test Price List" }) @@ -112,7 +112,10 @@ class TestCouponCode(unittest.TestCase): self.assertEqual(coupon_code.get("used"),0) def test_2_sales_order_with_coupon_code(self): - so = make_sales_order(customer="_Test Customer",selling_price_list="_Test Price List",item_code="_Test Tesla Car", rate=5000,qty=1, do_not_submit=True) + so = make_sales_order(company='_Test Company with perpetual inventory', warehouse='Stores - TCP1', + customer="_Test Customer", selling_price_list="_Test Price List", item_code="_Test Tesla Car", rate=5000,qty=1, + do_not_submit=True) + so = frappe.get_doc('Sales Order', so.name) # check item price before coupon code is applied self.assertEqual(so.items[0].rate, 5000) @@ -120,7 +123,7 @@ class TestCouponCode(unittest.TestCase): so.sales_partner='_Test Coupon Partner' so.save() # check item price after coupon code is applied - self.assertEqual(so.items[0].rate, 3500) + self.assertEqual(so.items[0].rate, 3500) so.submit() def test_3_check_coupon_code_used_after_so(self): diff --git a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py index 23ad1eef14..479d4b64bb 100644 --- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py @@ -6,6 +6,7 @@ import unittest, frappe from frappe.utils import flt, nowdate from erpnext.accounts.doctype.account.test_account import get_inventory_account from erpnext.exceptions import InvalidAccountCurrency +from erpnext.accounts.general_ledger import StockAccountInvalidTransaction class TestJournalEntry(unittest.TestCase): def test_journal_entry_with_against_jv(self): @@ -81,19 +82,46 @@ class TestJournalEntry(unittest.TestCase): from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory set_perpetual_inventory() - jv = frappe.copy_doc(test_records[0]) + jv = frappe.copy_doc({ + "cheque_date": nowdate(), + "cheque_no": "33", + "company": "_Test Company with perpetual inventory", + "doctype": "Journal Entry", + "accounts": [ + { + "account": "Debtors - TCP1", + "party_type": "Customer", + "party": "_Test Customer", + "credit_in_account_currency": 400.0, + "debit_in_account_currency": 0.0, + "doctype": "Journal Entry Account", + "parentfield": "accounts", + "cost_center": "Main - TCP1" + }, + { + "account": "_Test Bank - TCP1", + "credit_in_account_currency": 0.0, + "debit_in_account_currency": 400.0, + "doctype": "Journal Entry Account", + "parentfield": "accounts", + "cost_center": "Main - TCP1" + } + ], + "naming_series": "_T-Journal Entry-", + "posting_date": nowdate(), + "user_remark": "test", + "voucher_type": "Bank Entry" + }) + jv.get("accounts")[0].update({ - "account": get_inventory_account('_Test Company'), - "company": "_Test Company", + "account": get_inventory_account('_Test Company with perpetual inventory'), + "company": "_Test Company with perpetual inventory", "party_type": None, "party": None }) - jv.insert() - - from erpnext.accounts.general_ledger import StockAccountInvalidTransaction self.assertRaises(StockAccountInvalidTransaction, jv.submit) - + jv.cancel() set_perpetual_inventory(0) def test_multi_currency(self): diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index a245d63f52..cf3deb828f 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -158,8 +158,10 @@ def validate_account_for_perpetual_inventory(gl_map): if account not in aii_accounts: continue + # Always use current date to get stock and account balance as there can future entries for + # other items account_bal, stock_bal, warehouse_list = get_stock_and_account_balance(account, - gl_map[0].posting_date, gl_map[0].company) + getdate(), gl_map[0].company) if gl_map[0].voucher_type=="Journal Entry": # In case of Journal Entry, there are no corresponding SL entries, @@ -169,7 +171,6 @@ def validate_account_for_perpetual_inventory(gl_map): frappe.throw(_("Account: {0} can only be updated via Stock Transactions") .format(account), StockAccountInvalidTransaction) - # This has been comment for a temporary, will add this code again on release of immutable ledger elif account_bal != stock_bal: precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"), currency=frappe.get_cached_value('Company', gl_map[0].company, "default_currency")) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index d5f479ff82..991ec4743d 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -13,7 +13,7 @@ from erpnext.controllers.item_variant import (ItemVariantExistsError, from erpnext.setup.doctype.item_group.item_group import (get_parent_item_groups, invalidate_cache_for) from frappe import _, msgprint from frappe.utils import (cint, cstr, flt, formatdate, get_timestamp, getdate, - now_datetime, random_string, strip, get_link_to_form) + now_datetime, random_string, strip, get_link_to_form, nowtime) from frappe.utils.html_utils import clean_html from frappe.website.doctype.website_slideshow.website_slideshow import \ get_slideshow @@ -194,7 +194,7 @@ class Item(WebsiteGenerator): if default_warehouse: stock_entry = make_stock_entry(item_code=self.name, target=default_warehouse, qty=self.opening_stock, - rate=self.valuation_rate, company=default.company) + rate=self.valuation_rate, company=default.company, posting_date=getdate(), posting_time=nowtime()) stock_entry.add_comment("Comment", _("Opening Stock")) diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index 0fbc63101e..8e25804511 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -413,7 +413,7 @@ class TestStockEntry(unittest.TestCase): def test_serial_item_error(self): se, serial_nos = self.test_serial_by_series() if not frappe.db.exists('Serial No', 'ABCD'): - make_serialized_item("_Test Serialized Item", "ABCD\nEFGH") + make_serialized_item(item_code="_Test Serialized Item", serial_no="ABCD\nEFGH") se = frappe.copy_doc(test_records[0]) se.purpose = "Material Transfer" @@ -823,15 +823,29 @@ class TestStockEntry(unittest.TestCase): ]) ) -def make_serialized_item(item_code=None, serial_no=None, target_warehouse=None): +def make_serialized_item(**args): + args = frappe._dict(args) se = frappe.copy_doc(test_records[0]) - se.get("items")[0].item_code = item_code or "_Test Serialized Item With Series" - se.get("items")[0].serial_no = serial_no + + if args.company: + se.company = args.company + + se.get("items")[0].item_code = args.item_code or "_Test Serialized Item With Series" + + if args.serial_no: + se.get("items")[0].serial_no = args.serial_no + + if args.cost_center: + se.get("items")[0].cost_center = args.cost_center + + if args.expense_account: + se.get("items")[0].expense_account = args.expense_account + se.get("items")[0].qty = 2 se.get("items")[0].transfer_qty = 2 - if target_warehouse: - se.get("items")[0].t_warehouse = target_warehouse + if args.target_warehouse: + se.get("items")[0].t_warehouse = args.target_warehouse se.set_stock_entry_type() se.insert() From b7602d29f2f52a5bfb6a7ac4628eb5c113fa5466 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 28 Jul 2020 09:13:42 +0530 Subject: [PATCH 135/449] fix: POS patch fix (#22827) --- erpnext/patches/v12_0/rename_pos_closing_doctype.py | 4 ++-- erpnext/patches/v13_0/replace_pos_payment_mode_table.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/patches/v12_0/rename_pos_closing_doctype.py b/erpnext/patches/v12_0/rename_pos_closing_doctype.py index 8ca92ef65c..0577f81234 100644 --- a/erpnext/patches/v12_0/rename_pos_closing_doctype.py +++ b/erpnext/patches/v12_0/rename_pos_closing_doctype.py @@ -12,11 +12,11 @@ def execute(): frappe.rename_doc('DocType', 'POS Closing Voucher Taxes', 'POS Closing Entry Taxes', force=True) if not frappe.db.exists('DocType', 'POS Closing Voucher Details'): - frappe.rename_doc('DocType', 'POS Closing Voucher Details', 'POS Closing Entry Details', force=True) + frappe.rename_doc('DocType', 'POS Closing Voucher Details', 'POS Closing Entry Detail', force=True) frappe.reload_doc('Accounts', 'doctype', 'POS Closing Entry') frappe.reload_doc('Accounts', 'doctype', 'POS Closing Entry Taxes') - frappe.reload_doc('Accounts', 'doctype', 'POS Closing Entry Details') + frappe.reload_doc('Accounts', 'doctype', 'POS Closing Entry Detail') if frappe.db.exists("DocType", "POS Closing Voucher"): frappe.delete_doc("DocType", "POS Closing Voucher") diff --git a/erpnext/patches/v13_0/replace_pos_payment_mode_table.py b/erpnext/patches/v13_0/replace_pos_payment_mode_table.py index 4a621b6a51..1ca211bf1b 100644 --- a/erpnext/patches/v13_0/replace_pos_payment_mode_table.py +++ b/erpnext/patches/v13_0/replace_pos_payment_mode_table.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import frappe def execute(): - frappe.reload_doc("Selling", "doctype", "POS Payment Method") + frappe.reload_doc("accounts", "doctype", "POS Payment Method") pos_profiles = frappe.get_all("POS Profile") for pos_profile in pos_profiles: From 60cdef7d5751954c3ed44b8d681023a73edebb1e Mon Sep 17 00:00:00 2001 From: prssanna Date: Wed, 29 Jul 2020 14:51:38 +0530 Subject: [PATCH 136/449] fix: add range filters to oldest items chart --- erpnext/stock/dashboard_chart/oldest_items/oldest_items.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/dashboard_chart/oldest_items/oldest_items.json b/erpnext/stock/dashboard_chart/oldest_items/oldest_items.json index 6da3b28baf..9c10a5346b 100644 --- a/erpnext/stock/dashboard_chart/oldest_items/oldest_items.json +++ b/erpnext/stock/dashboard_chart/oldest_items/oldest_items.json @@ -6,11 +6,11 @@ "docstatus": 0, "doctype": "Dashboard Chart", "dynamic_filters_json": "{\"company\":\"frappe.defaults.get_user_default(\\\"Company\\\")\",\"to_date\":\"frappe.datetime.nowdate()\"}", - "filters_json": "{\"show_warehouse_wise_stock\":0}", + "filters_json": "{\"range1\":30,\"range2\":60,\"range3\":90,\"show_warehouse_wise_stock\":0}", "idx": 0, "is_public": 1, "is_standard": 1, - "modified": "2020-07-22 13:04:36.271198", + "modified": "2020-07-29 14:50:26.846482", "modified_by": "Administrator", "module": "Stock", "name": "Oldest Items", From 38d5c2e04fa94b9b00dd84ff3d6256dccbf16e38 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 30 Jul 2020 20:52:20 +0530 Subject: [PATCH 137/449] fix: Ignore cancelled gl entries to get account balance --- erpnext/accounts/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 824b2f2efb..51ac7cfbfa 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -122,7 +122,7 @@ def get_balance_on(account=None, date=None, party_type=None, party=None, company cost_center = frappe.form_dict.get("cost_center") - cond = [] + cond = ["is_cancelled=0"] if date: cond.append("posting_date <= %s" % frappe.db.escape(cstr(date))) else: @@ -206,7 +206,7 @@ def get_balance_on(account=None, date=None, party_type=None, party=None, company return flt(bal) def get_count_on(account, fieldname, date): - cond = [] + cond = ["is_cancelled=0"] if date: cond.append("posting_date <= %s" % frappe.db.escape(cstr(date))) else: From 804426023f7bd6d0b1a9a865bcc94aa3c4c464bc Mon Sep 17 00:00:00 2001 From: Anurag Mishra <32095923+Anurag810@users.noreply.github.com> Date: Mon, 3 Aug 2020 08:57:49 +0530 Subject: [PATCH 138/449] fix: minor payroll_dashboard fixes (#22832) * fix: minor payroll_dashboard fixes * Update erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.js Co-authored-by: Rucha Mahabal Co-authored-by: Nabin Hait Co-authored-by: Rucha Mahabal --- .../job_application_status/job_application_status.json | 6 +++--- .../monthly_attendance_sheet.js | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/erpnext/hr/dashboard_chart/job_application_status/job_application_status.json b/erpnext/hr/dashboard_chart/job_application_status/job_application_status.json index bfcfa96752..42a830970e 100644 --- a/erpnext/hr/dashboard_chart/job_application_status/job_application_status.json +++ b/erpnext/hr/dashboard_chart/job_application_status/job_application_status.json @@ -7,14 +7,14 @@ "doctype": "Dashboard Chart", "document_type": "Job Applicant", "dynamic_filters_json": "", - "filters_json": "[[\"Job Applicant\",\"creation\",\"Previous\",\"1 month\"]]", + "filters_json": "[[\"Job Applicant\",\"creation\",\"Timespan\",\"last month\",false]]", "group_by_based_on": "status", "group_by_type": "Count", "idx": 0, "is_public": 1, "is_standard": 1, - "last_synced_on": "2020-07-22 14:27:40.118498", - "modified": "2020-07-22 14:33:00.404144", + "last_synced_on": "2020-07-28 16:19:12.109979", + "modified": "2020-07-28 16:19:45.279490", "modified_by": "Administrator", "module": "HR", "name": "Job Application Status", diff --git a/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.js b/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.js index 4b9b928640..42f7cdb50f 100644 --- a/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.js +++ b/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.js @@ -35,7 +35,15 @@ frappe.query_reports["Monthly Attendance Sheet"] = { "fieldname":"employee", "label": __("Employee"), "fieldtype": "Link", - "options": "Employee" + "options": "Employee", + get_query: () => { + var company = frappe.query_report.get_filter_value('company'); + return { + filters: { + 'company': company + } + }; + } }, { "fieldname":"company", From 826158c79235684addbcbfaad5247471a43dc1ee Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 3 Aug 2020 09:34:55 +0530 Subject: [PATCH 139/449] fix: Update modified timestamp in accounts settings (#22874) --- .../accounts/doctype/accounts_settings/accounts_settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json index 8ca8b71ef8..b2e8b090c7 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json @@ -225,7 +225,7 @@ "idx": 1, "issingle": 1, "links": [], - "modified": "2020-06-22 20:13:26.043092", + "modified": "2020-08-03 20:13:26.043092", "modified_by": "Administrator", "module": "Accounts", "name": "Accounts Settings", From 1a64d1a4ab299477c15f9200c79be2ee64aa3b72 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 3 Aug 2020 10:43:56 +0530 Subject: [PATCH 140/449] Reset home page based on product settings (#22876) --- erpnext/portal/doctype/products_settings/products_settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/portal/doctype/products_settings/products_settings.py b/erpnext/portal/doctype/products_settings/products_settings.py index b984aeb67d..ae7dc68020 100644 --- a/erpnext/portal/doctype/products_settings/products_settings.py +++ b/erpnext/portal/doctype/products_settings/products_settings.py @@ -11,9 +11,9 @@ from frappe.model.document import Document class ProductsSettings(Document): def validate(self): if self.home_page_is_products: - frappe.db.set_value("Website Settings", "home_page", "products") + frappe.db.set_value("Website Settings", None, "home_page", "products") elif frappe.db.get_single_value("Website Settings", "home_page") == 'products': - frappe.db.set_value("Website Settings", "home_page", "home") + frappe.db.set_value("Website Settings", None, "home_page", "home") self.validate_field_filters() self.validate_attribute_filters() From 4e0989d0cb35563c3658a4aa742286ddd6490b67 Mon Sep 17 00:00:00 2001 From: Marica Date: Mon, 3 Aug 2020 14:56:20 +0530 Subject: [PATCH 141/449] fix: Misleading description in Warehouse (#22878) --- erpnext/stock/doctype/warehouse/warehouse.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/warehouse/warehouse.json b/erpnext/stock/doctype/warehouse/warehouse.json index 3b49c4ca52..c0c9fbc92d 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.json +++ b/erpnext/stock/doctype/warehouse/warehouse.json @@ -45,7 +45,6 @@ "oldfieldtype": "Section Break" }, { - "description": "If blank, parent Warehouse Account or company default will be considered", "fieldname": "warehouse_name", "fieldtype": "Data", "label": "Warehouse Name", @@ -236,7 +235,7 @@ "idx": 1, "is_tree": 1, "links": [], - "modified": "2020-07-16 15:43:50.653256", + "modified": "2020-08-03 11:19:35.943330", "modified_by": "Administrator", "module": "Stock", "name": "Warehouse", From b44ee186cd8be03034c6badecbed0de074649248 Mon Sep 17 00:00:00 2001 From: Prssanna Desai Date: Mon, 3 Aug 2020 15:18:35 +0530 Subject: [PATCH 142/449] fix: check if row['delay'] exists (#22892) --- .../selling/report/sales_order_analysis/sales_order_analysis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/selling/report/sales_order_analysis/sales_order_analysis.py b/erpnext/selling/report/sales_order_analysis/sales_order_analysis.py index 7e8e6e9e8b..f5feb95f1a 100644 --- a/erpnext/selling/report/sales_order_analysis/sales_order_analysis.py +++ b/erpnext/selling/report/sales_order_analysis/sales_order_analysis.py @@ -96,7 +96,7 @@ def prepare_data(data, filters): # prepare data for report view row["qty_to_bill"] = flt(row["qty"]) - flt(row["billed_qty"]) - row["delay"] = 0 if row["delay"] < 0 else row["delay"] + row["delay"] = 0 if row["delay"] and row["delay"] < 0 else row["delay"] if filters.get("group_by_so"): so_name = row["sales_order"] From 25ee4328d35eb6dcf1c756ad78c6e0b213e0ccbe Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Mon, 3 Aug 2020 19:39:55 +0530 Subject: [PATCH 143/449] card company issue (#22900) --- .../shopping_cart_settings.js | 6 ++++++ .../shopping_cart_settings.json | 13 +++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.js b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.js index 14500ba6b3..21fa4c3065 100644 --- a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.js +++ b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.js @@ -12,5 +12,11 @@ frappe.ui.form.on("Shopping Cart Settings", { if (frm.doc.enabled === 1) { frm.set_value('enable_variants', 1); } + else { + frm.set_value('company', ''); + frm.set_value('price_list', ''); + frm.set_value('default_customer_group', ''); + frm.set_value('quotation_series', ''); + } } }); diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json index c574afa68c..271895f2a4 100644 --- a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json +++ b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json @@ -95,15 +95,16 @@ "fieldtype": "Link", "in_list_view": 1, "label": "Company", + "mandatory_depends_on": "eval: doc.enabled === 1", "options": "Company", - "remember_last_selected_value": 1, - "reqd": 1 + "remember_last_selected_value": 1 }, { "description": "Prices will not be shown if Price List is not set", "fieldname": "price_list", "fieldtype": "Link", "label": "Price List", + "mandatory_depends_on": "eval: doc.enabled === 1", "options": "Price List" }, { @@ -115,14 +116,14 @@ "fieldtype": "Link", "ignore_user_permissions": 1, "label": "Default Customer Group", - "options": "Customer Group", - "reqd": 1 + "mandatory_depends_on": "eval: doc.enabled === 1", + "options": "Customer Group" }, { "fieldname": "quotation_series", "fieldtype": "Select", "label": "Quotation Series", - "reqd": 1 + "mandatory_depends_on": "eval: doc.enabled === 1" }, { "collapsible": 1, @@ -171,7 +172,7 @@ "idx": 1, "issingle": 1, "links": [], - "modified": "2020-07-17 17:53:22.667228", + "modified": "2020-08-03 19:32:27.958221", "modified_by": "Administrator", "module": "Shopping Cart", "name": "Shopping Cart Settings", From cb665dc4d1f5f1df12c716303d548312192682df Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Mon, 3 Aug 2020 19:43:17 +0530 Subject: [PATCH 144/449] fix: Assessment Result child table not visible when accessed via dashboard (#22881) --- .../assessment_result/assessment_result.js | 11 +- .../assessment_result/assessment_result.json | 648 ++---------------- .../assessment_result_detail.json | 242 ++----- 3 files changed, 111 insertions(+), 790 deletions(-) diff --git a/erpnext/education/doctype/assessment_result/assessment_result.js b/erpnext/education/doctype/assessment_result/assessment_result.js index 12fdd91c25..63d1aee0cb 100644 --- a/erpnext/education/doctype/assessment_result/assessment_result.js +++ b/erpnext/education/doctype/assessment_result/assessment_result.js @@ -6,10 +6,11 @@ frappe.ui.form.on('Assessment Result', { if (!frm.doc.__islocal) { frm.trigger('setup_chart'); } + frm.set_df_property('details', 'read_only', 1); }, onload: function(frm) { - frm.set_query('assessment_plan', function(){ + frm.set_query('assessment_plan', function() { return { filters: { docstatus: 1 @@ -27,14 +28,14 @@ frappe.ui.form.on('Assessment Result', { }, callback: function(r) { if (r.message) { - frm.doc.details = []; + frappe.model.clear_table(frm.doc, 'details'); $.each(r.message, function(i, d) { - var row = frappe.model.add_child(frm.doc, 'Assessment Result Detail', 'details'); + var row = frm.add_child('details'); row.assessment_criteria = d.assessment_criteria; row.maximum_score = d.maximum_score; }); + frm.refresh_field('details'); } - refresh_field('details'); } }); } @@ -80,7 +81,7 @@ frappe.ui.form.on('Assessment Result Detail', { score: function(frm, cdt, cdn) { var d = locals[cdt][cdn]; - if(!d.maximum_score || !frm.doc.grading_scale) { + if (!d.maximum_score || !frm.doc.grading_scale) { d.score = ''; frappe.throw(__('Please fill in all the details to generate Assessment Result.')); } diff --git a/erpnext/education/doctype/assessment_result/assessment_result.json b/erpnext/education/doctype/assessment_result/assessment_result.json index 212d47cff0..7a893aabb8 100644 --- a/erpnext/education/doctype/assessment_result/assessment_result.json +++ b/erpnext/education/doctype/assessment_result/assessment_result.json @@ -1,724 +1,182 @@ { - "allow_copy": 0, - "allow_guest_to_view": 0, + "actions": [], "allow_import": 1, - "allow_rename": 0, "autoname": "EDU-RES-.YYYY.-.#####", - "beta": 0, "creation": "2015-11-13 17:18:06.468332", - "custom": 0, - "docstatus": 0, "doctype": "DocType", - "document_type": "", "editable_grid": 1, "engine": "InnoDB", + "field_order": [ + "assessment_plan", + "program", + "course", + "academic_year", + "academic_term", + "column_break_3", + "student", + "student_name", + "student_group", + "assessment_group", + "grading_scale", + "section_break_5", + "details", + "section_break_8", + "maximum_score", + "column_break_11", + "total_score", + "grade", + "section_break_13", + "comment", + "amended_from" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "assessment_plan", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, "label": "Assessment Plan", - "length": 0, - "no_copy": 0, "options": "Assessment Plan", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "reqd": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fetch_from": "assessment_plan.program", "fieldname": "program", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Program", - "length": 0, - "no_copy": 0, - "options": "Program", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "options": "Program" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fetch_from": "assessment_plan.course", "fieldname": "course", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Course", - "length": 0, - "no_copy": 0, - "options": "Course", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "options": "Course" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fetch_from": "assessment_plan.academic_year", "fieldname": "academic_year", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Academic Year", - "length": 0, - "no_copy": 0, - "options": "Academic Year", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "options": "Academic Year" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fetch_from": "assessment_plan.academic_term", "fieldname": "academic_term", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Academic Term", - "length": 0, - "no_copy": 0, - "options": "Academic Term", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "options": "Academic Term" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "column_break_3", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Column Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "student", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, "in_global_search": 1, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Student", - "length": 0, - "no_copy": 0, "options": "Student", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "reqd": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fetch_from": "student.title", "fieldname": "student_name", "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, "in_global_search": 1, "in_list_view": 1, - "in_standard_filter": 0, "label": "Student Name", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "read_only": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fetch_from": "assessment_plan.student_group", "fieldname": "student_group", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Student Group", - "length": 0, - "no_copy": 0, - "options": "Student Group", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "options": "Student Group" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fetch_from": "assessment_plan.assessment_group", "fieldname": "assessment_group", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Assessment Group", - "length": 0, - "no_copy": 0, - "options": "Assessment Group", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "options": "Assessment Group" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fetch_from": "assessment_plan.grading_scale", "fieldname": "grading_scale", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Grading Scale", - "length": 0, - "no_copy": 0, "options": "Grading Scale", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "read_only": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "section_break_5", "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Result", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Result" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "depends_on": "", "fieldname": "details", "fieldtype": "Table", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Details", - "length": 0, - "no_copy": 0, "options": "Assessment Result Detail", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "reqd": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "section_break_8", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Section Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fetch_from": "assessment_plan.maximum_assessment_score", "fieldname": "maximum_score", "fieldtype": "Float", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Maximum Score", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "read_only": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fetch_from": "assessment_plan.maximum_assessment_score", "fieldname": "column_break_11", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Column Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "total_score", "fieldtype": "Float", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, "label": "Total Score", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "read_only": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "grade", "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, "label": "Grade", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "read_only": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "section_break_13", "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Summary", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Summary" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "comment", "fieldtype": "Small Text", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Comment", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Comment" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "amended_from", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Amended From", - "length": 0, "no_copy": 1, "options": "Assessment Result", - "permlevel": 0, "print_hide": 1, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "read_only": 1 } ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, "is_submittable": 1, - "issingle": 0, - "istable": 0, - "max_attachments": 0, - "modified": "2018-08-30 02:10:36.813413", + "links": [], + "modified": "2020-08-03 11:47:54.119486", "modified_by": "Administrator", "module": "Education", "name": "Assessment Result", - "name_case": "", "owner": "Administrator", "permissions": [ { @@ -728,28 +186,18 @@ "delete": 1, "email": 1, "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, "print": 1, "read": 1, "report": 1, "role": "Academics User", - "set_user_permissions": 0, "share": 1, "submit": 1, "write": 1 } ], - "quick_entry": 0, - "read_only": 0, - "read_only_onload": 0, "restrict_to_domain": "Education", "show_name_in_global_search": 1, "sort_field": "modified", "sort_order": "DESC", - "title_field": "student_name", - "track_changes": 0, - "track_seen": 0, - "track_views": 0 + "title_field": "student_name" } \ No newline at end of file diff --git a/erpnext/education/doctype/assessment_result_detail/assessment_result_detail.json b/erpnext/education/doctype/assessment_result_detail/assessment_result_detail.json index 85d943beaa..450f41cbbb 100644 --- a/erpnext/education/doctype/assessment_result_detail/assessment_result_detail.json +++ b/erpnext/education/doctype/assessment_result_detail/assessment_result_detail.json @@ -1,194 +1,66 @@ { - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "autoname": "", - "beta": 0, - "creation": "2016-12-14 17:44:35.583123", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "", - "editable_grid": 1, - "engine": "InnoDB", + "actions": [], + "creation": "2016-12-14 17:44:35.583123", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "assessment_criteria", + "maximum_score", + "column_break_2", + "score", + "grade" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 4, - "fieldname": "assessment_criteria", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Assessment Criteria", - "length": 0, - "no_copy": 0, - "options": "Assessment Criteria", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, + "columns": 4, + "fieldname": "assessment_criteria", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Assessment Criteria", + "options": "Assessment Criteria", + "read_only": 1, + "reqd": 1 + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 2, - "fieldname": "maximum_score", - "fieldtype": "Float", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Maximum Score", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, + "columns": 2, + "fieldname": "maximum_score", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Maximum Score", + "read_only": 1 + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "column_break_2", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, + "fieldname": "column_break_2", + "fieldtype": "Column Break" + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 2, - "fieldname": "score", - "fieldtype": "Float", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Score", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, + "columns": 2, + "fieldname": "score", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Score", + "reqd": 1 + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 2, - "fieldname": "grade", - "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Grade", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 + "columns": 2, + "fieldname": "grade", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Grade", + "read_only": 1 } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 1, - "max_attachments": 0, - "modified": "2017-11-10 19:11:14.362410", - "modified_by": "Administrator", - "module": "Education", - "name": "Assessment Result Detail", - "name_case": "", - "owner": "Administrator", - "permissions": [], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "restrict_to_domain": "Education", - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 0, - "track_seen": 0 + ], + "istable": 1, + "links": [], + "modified": "2020-07-31 13:27:17.699022", + "modified_by": "Administrator", + "module": "Education", + "name": "Assessment Result Detail", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "restrict_to_domain": "Education", + "sort_field": "modified", + "sort_order": "DESC" } \ No newline at end of file From 5e548b43875b85ebe92c14dd2c292c34bffa0332 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 3 Aug 2020 20:39:15 +0530 Subject: [PATCH 145/449] Dunning cleanup beta (#22899) * fix: Dunning cleanup * fix: Added dashboard for Dunning --- erpnext/accounts/doctype/dunning/dunning.js | 19 ++++++++++++++++--- erpnext/accounts/doctype/dunning/dunning.json | 8 ++++---- erpnext/accounts/doctype/dunning/dunning.py | 16 +++++++++------- .../doctype/dunning/dunning_dashboard.py | 17 +++++++++++++++++ .../sales_invoice/sales_invoice_dashboard.py | 2 +- 5 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 erpnext/accounts/doctype/dunning/dunning_dashboard.py diff --git a/erpnext/accounts/doctype/dunning/dunning.js b/erpnext/accounts/doctype/dunning/dunning.js index c563368894..9909c6c2ab 100644 --- a/erpnext/accounts/doctype/dunning/dunning.js +++ b/erpnext/accounts/doctype/dunning/dunning.js @@ -44,6 +44,19 @@ frappe.ui.form.on("Dunning", { ); frm.page.set_inner_btn_group_as_primary(__("Create")); } + + if(frm.doc.docstatus > 0) { + frm.add_custom_button(__('Ledger'), function() { + frappe.route_options = { + "voucher_no": frm.doc.name, + "from_date": frm.doc.posting_date, + "to_date": frm.doc.posting_date, + "company": frm.doc.company, + "show_cancelled_entries": frm.doc.docstatus === 2 + }; + frappe.set_route("query-report", "General Ledger"); + }, __('View')); + } }, overdue_days: function (frm) { frappe.db.get_value( @@ -125,9 +138,9 @@ frappe.ui.form.on("Dunning", { }, calculate_interest_and_amount: function (frm) { const interest_per_year = frm.doc.outstanding_amount * frm.doc.rate_of_interest / 100; - const interest_amount = interest_per_year / 365 * frm.doc.overdue_days || 0; - const dunning_amount = interest_amount + frm.doc.dunning_fee; - const grand_total = frm.doc.outstanding_amount + dunning_amount; + const interest_amount = flt((interest_per_year * cint(frm.doc.overdue_days)) / 365 || 0, precision('interest_amount')); + const dunning_amount = flt(interest_amount + frm.doc.dunning_fee, precision('dunning_amount')); + const grand_total = flt(frm.doc.outstanding_amount + dunning_amount, precision('grand_total')); frm.set_value("interest_amount", interest_amount); frm.set_value("dunning_amount", dunning_amount); frm.set_value("grand_total", grand_total); diff --git a/erpnext/accounts/doctype/dunning/dunning.json b/erpnext/accounts/doctype/dunning/dunning.json index b3eddf5f22..d55bfd1ac4 100644 --- a/erpnext/accounts/doctype/dunning/dunning.json +++ b/erpnext/accounts/doctype/dunning/dunning.json @@ -29,10 +29,10 @@ "company_address_display", "section_break_6", "dunning_type", - "interest_amount", + "dunning_fee", "column_break_8", "rate_of_interest", - "dunning_fee", + "interest_amount", "section_break_12", "dunning_amount", "grand_total", @@ -215,7 +215,7 @@ }, { "default": "0", - "fetch_from": "dunning_type.interest_rate", + "fetch_from": "dunning_type.rate_of_interest", "fetch_if_empty": 1, "fieldname": "rate_of_interest", "fieldtype": "Float", @@ -315,7 +315,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-07-21 18:20:23.512151", + "modified": "2020-08-03 18:55:43.683053", "modified_by": "Administrator", "module": "Accounts", "name": "Dunning", diff --git a/erpnext/accounts/doctype/dunning/dunning.py b/erpnext/accounts/doctype/dunning/dunning.py index 0be6a480c9..3e372affa1 100644 --- a/erpnext/accounts/doctype/dunning/dunning.py +++ b/erpnext/accounts/doctype/dunning/dunning.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import frappe import json from six import string_types -from frappe.utils import getdate, get_datetime, rounded, flt +from frappe.utils import getdate, get_datetime, rounded, flt, cint from erpnext.loan_management.doctype.loan_interest_accrual.loan_interest_accrual import days_in_year from erpnext.accounts.general_ledger import make_gl_entries, make_reverse_gl_entries from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions @@ -27,11 +27,11 @@ class Dunning(AccountsController): amounts = calculate_interest_and_amount( self.posting_date, self.outstanding_amount, self.rate_of_interest, self.dunning_fee, self.overdue_days) if self.interest_amount != amounts.get('interest_amount'): - self.interest_amount = amounts.get('interest_amount') + self.interest_amount = flt(amounts.get('interest_amount'), self.precision('interest_amount')) if self.dunning_amount != amounts.get('dunning_amount'): - self.dunning_amount = amounts.get('dunning_amount') + self.dunning_amount = flt(amounts.get('dunning_amount'), self.precision('dunning_amount')) if self.grand_total != amounts.get('grand_total'): - self.grand_total = amounts.get('grand_total') + self.grand_total = flt(amounts.get('grand_total'), self.precision('grand_total')) def on_submit(self): self.make_gl_entries() @@ -47,10 +47,13 @@ class Dunning(AccountsController): gl_entries = [] invoice_fields = ["project", "cost_center", "debit_to", "party_account_currency", "conversion_rate", "cost_center"] inv = frappe.db.get_value("Sales Invoice", self.sales_invoice, invoice_fields, as_dict=1) + accounting_dimensions = get_accounting_dimensions() invoice_fields.extend(accounting_dimensions) + dunning_in_company_currency = flt(self.dunning_amount * inv.conversion_rate) default_cost_center = frappe.get_cached_value('Company', self.company, 'cost_center') + gl_entries.append( self.get_gl_dict({ "account": inv.debit_to, @@ -91,9 +94,8 @@ def resolve_dunning(doc, state): def calculate_interest_and_amount(posting_date, outstanding_amount, rate_of_interest, dunning_fee, overdue_days): interest_amount = 0 if rate_of_interest: - interest_per_year = rounded(flt(outstanding_amount) * flt(rate_of_interest))/100 - interest_amount = ( - interest_per_year / days_in_year(get_datetime(posting_date).year)) * int(overdue_days) + interest_per_year = flt(outstanding_amount) * flt(rate_of_interest) / 100 + interest_amount = (interest_per_year * cint(overdue_days)) / 365 grand_total = flt(outstanding_amount) + flt(interest_amount) + flt(dunning_fee) dunning_amount = flt(interest_amount) + flt(dunning_fee) return { diff --git a/erpnext/accounts/doctype/dunning/dunning_dashboard.py b/erpnext/accounts/doctype/dunning/dunning_dashboard.py new file mode 100644 index 0000000000..19a73ddfa4 --- /dev/null +++ b/erpnext/accounts/doctype/dunning/dunning_dashboard.py @@ -0,0 +1,17 @@ +from __future__ import unicode_literals +from frappe import _ + +def get_data(): + return { + 'fieldname': 'dunning', + 'non_standard_fieldnames': { + 'Journal Entry': 'reference_name', + 'Payment Entry': 'reference_name' + }, + 'transactions': [ + { + 'label': _('Payment'), + 'items': ['Payment Entry', 'Journal Entry'] + } + ] + } \ No newline at end of file diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py index 4a8fcc03fd..f1069282ed 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py @@ -18,7 +18,7 @@ def get_data(): 'transactions': [ { 'label': _('Payment'), - 'items': ['Payment Entry', 'Payment Request', 'Journal Entry', 'Invoice Discounting'] + 'items': ['Payment Entry', 'Payment Request', 'Journal Entry', 'Invoice Discounting', 'Dunning'] }, { 'label': _('Reference'), From a1d3537f2a151d364803decee9ab693fa7cd7b69 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 3 Aug 2020 20:42:00 +0530 Subject: [PATCH 146/449] fix: Bank Clearance of POS purchase invoice (#22883) --- .../doctype/bank_clearance/bank_clearance.py | 21 +++++++++++++++---- .../purchase_invoice/purchase_invoice.json | 8 ++++--- .../sales_invoice_payment.json | 3 ++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/doctype/bank_clearance/bank_clearance.py b/erpnext/accounts/doctype/bank_clearance/bank_clearance.py index 6fec3ab368..76d82e7339 100644 --- a/erpnext/accounts/doctype/bank_clearance/bank_clearance.py +++ b/erpnext/accounts/doctype/bank_clearance/bank_clearance.py @@ -60,12 +60,12 @@ class BankClearance(Document): """.format(condition=condition), {"account": self.account, "from":self.from_date, "to": self.to_date, "bank_account": self.bank_account}, as_dict=1) - pos_entries = [] + pos_sales_invoices, pos_purchase_invoices = [], [] if self.include_pos_transactions: - pos_entries = frappe.db.sql(""" + pos_sales_invoices = frappe.db.sql(""" select "Sales Invoice Payment" as payment_document, sip.name as payment_entry, sip.amount as debit, - si.posting_date, si.debit_to as against_account, sip.clearance_date, + si.posting_date, si.customer as against_account, sip.clearance_date, account.account_currency, 0 as credit from `tabSales Invoice Payment` sip, `tabSales Invoice` si, `tabAccount` account where @@ -75,7 +75,20 @@ class BankClearance(Document): si.posting_date ASC, si.name DESC """, {"account":self.account, "from":self.from_date, "to":self.to_date}, as_dict=1) - entries = sorted(list(payment_entries)+list(journal_entries+list(pos_entries)), + pos_purchase_invoices = frappe.db.sql(""" + select + "Purchase Invoice" as payment_document, pi.name as payment_entry, pi.paid_amount as credit, + pi.posting_date, pi.supplier as against_account, pi.clearance_date, + account.account_currency, 0 as debit + from `tabPurchase Invoice` pi, `tabAccount` account + where + pi.cash_bank_account=%(account)s and pi.docstatus=1 and account.name = pi.cash_bank_account + and pi.posting_date >= %(from)s and pi.posting_date <= %(to)s + order by + pi.posting_date ASC, pi.name DESC + """, {"account": self.account, "from": self.from_date, "to": self.to_date}, as_dict=1) + + entries = sorted(list(payment_entries) + list(journal_entries + list(pos_sales_invoices) + list(pos_purchase_invoices)), key=lambda k: k['posting_date'] or getdate(nowdate())) self.set('payment_entries', []) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index df77dc8417..2e91c8ef19 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -969,8 +969,10 @@ { "fieldname": "clearance_date", "fieldtype": "Date", - "hidden": 1, - "label": "Clearance Date" + "label": "Clearance Date", + "no_copy": 1, + "print_hide": 1, + "read_only": 1 }, { "fieldname": "col_br_payments", @@ -1332,7 +1334,7 @@ "idx": 204, "is_submittable": 1, "links": [], - "modified": "2020-07-24 09:46:40.405463", + "modified": "2020-08-03 12:46:01.411074", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice", diff --git a/erpnext/accounts/doctype/sales_invoice_payment/sales_invoice_payment.json b/erpnext/accounts/doctype/sales_invoice_payment/sales_invoice_payment.json index 2f9d381c92..5ab46b7fd5 100644 --- a/erpnext/accounts/doctype/sales_invoice_payment/sales_invoice_payment.json +++ b/erpnext/accounts/doctype/sales_invoice_payment/sales_invoice_payment.json @@ -64,6 +64,7 @@ "fieldname": "clearance_date", "fieldtype": "Date", "label": "Clearance Date", + "no_copy": 1, "print_hide": 1, "read_only": 1 }, @@ -78,7 +79,7 @@ ], "istable": 1, "links": [], - "modified": "2020-05-05 16:51:20.091441", + "modified": "2020-08-03 12:45:39.986598", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice Payment", From 6823e8ed034665459b074d5cb9cf052cb7947610 Mon Sep 17 00:00:00 2001 From: marination Date: Tue, 4 Aug 2020 14:04:15 +0530 Subject: [PATCH 147/449] fix: Remove Duplicate Banket order method --- erpnext/controllers/queries.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index 5c59fe0e1d..b402204072 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -395,20 +395,6 @@ def get_account_list(doctype, txt, searchfield, start, page_len, filters): fields = ["name", "parent_account"], limit_start=start, limit_page_length=page_len, as_list=True) -def get_blanket_orders(doctype, txt, searchfield, start, page_len, filters): - return frappe.db.sql("""select distinct bo.name, bo.blanket_order_type, bo.to_date - from `tabBlanket Order` bo, `tabBlanket Order Item` boi - where - boi.parent = bo.name - and boi.item_code = {item_code} - and bo.blanket_order_type = '{blanket_order_type}' - and bo.company = {company} - and bo.docstatus = 1""" - .format(item_code = frappe.db.escape(filters.get("item")), - blanket_order_type = filters.get("blanket_order_type"), - company = frappe.db.escape(filters.get("company")) - )) - @frappe.whitelist() def get_blanket_orders(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql("""select distinct bo.name, bo.blanket_order_type, bo.to_date From 8d055142608a403e205fe81dd7da961c97930d25 Mon Sep 17 00:00:00 2001 From: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> Date: Wed, 5 Aug 2020 20:07:30 +0530 Subject: [PATCH 148/449] refactor: Format and sanitise user inputs to search queries. (#22922) * refactor: Sanitize whitelisted method inputs Co-authored-by: Prssanna Desai Co-authored-by: Shivam Mishra * refactor: Format and sanitize tax_account_query inputs Co-authored-by: Nabin Hait Co-authored-by: Prssanna Desai Co-authored-by: Shivam Mishra * refactor: Validate and sanitize search inputs via decorator Co-authored-by: Nabin Hait Co-authored-by: Prssanna Desai Co-authored-by: Shivam Mishra * style: Minor formatting fix * refactor: Validate and sanitize search inputs using decorator * fix: Typo * fix: Remove unwanted import statement * refactor: Repalce validate_and_sanitize_search_inputs() with validate_and_sanitize_search_inputs Co-authored-by: Prssanna Desai Co-authored-by: Shivam Mishra Co-authored-by: Prssanna Desai Co-authored-by: Shivam Mishra Co-authored-by: Nabin Hait --- erpnext/accounts/doctype/account/account.py | 2 + .../doctype/journal_entry/journal_entry.py | 32 +++++++-- .../doctype/payment_order/payment_order.py | 2 + .../pos_closing_entry/pos_closing_entry.py | 13 ++-- .../doctype/pos_profile/pos_profile.py | 1 + .../doctype/pricing_rule/pricing_rule.py | 12 ++-- .../bank_reconciliation.py | 3 + .../asset_maintenance/asset_maintenance.py | 1 + .../asset_maintenance_log.py | 1 + .../request_for_quotation.py | 1 + erpnext/controllers/queries.py | 71 ++++++++++++++----- .../program_enrollment/program_enrollment.py | 2 + .../doctype/student_group/student_group.py | 1 + .../healthcare_practitioner.py | 1 + .../inpatient_record/inpatient_record.py | 1 + .../department_approver.py | 1 + erpnext/manufacturing/doctype/bom/bom.py | 1 + .../doctype/work_order/work_order.py | 1 + .../bom_variance_report.py | 5 +- .../production_planning_report.py | 3 - .../employee_benefit_application.py | 1 + .../doctype/payroll_entry/payroll_entry.py | 1 + erpnext/projects/doctype/project/project.py | 1 + erpnext/projects/doctype/task/task.py | 1 + .../projects/doctype/timesheet/timesheet.py | 1 + erpnext/projects/utils.py | 1 + erpnext/selling/doctype/customer/customer.py | 2 + .../doctype/product_bundle/product_bundle.py | 1 + .../doctype/sales_order/sales_order.py | 1 + .../page/point_of_sale/point_of_sale.py | 13 ++-- .../setup/doctype/party_type/party_type.py | 1 + .../item_alternative/item_alternative.py | 1 + .../material_request/material_request.py | 2 + .../doctype/packing_slip/packing_slip.py | 1 + .../quality_inspection/quality_inspection.py | 2 + 35 files changed, 138 insertions(+), 47 deletions(-) diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py index c6de6410eb..164f120067 100644 --- a/erpnext/accounts/doctype/account/account.py +++ b/erpnext/accounts/doctype/account/account.py @@ -244,6 +244,8 @@ class Account(NestedSet): super(Account, self).on_trash(True) +@frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_parent_account(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql("""select name from tabAccount where is_group = 1 and docstatus != 2 and company = %s diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index cfdae936a4..dda17082a2 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -841,13 +841,33 @@ def get_opening_accounts(company): @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_against_jv(doctype, txt, searchfield, start, page_len, filters): - return frappe.db.sql("""select jv.name, jv.posting_date, jv.user_remark - from `tabJournal Entry` jv, `tabJournal Entry Account` jv_detail - where jv_detail.parent = jv.name and jv_detail.account = %s and ifnull(jv_detail.party, '') = %s - and (jv_detail.reference_type is null or jv_detail.reference_type = '') - and jv.docstatus = 1 and jv.`{0}` like %s order by jv.name desc limit %s, %s""".format(searchfield), - (filters.get("account"), cstr(filters.get("party")), "%{0}%".format(txt), start, page_len)) + if not frappe.db.has_column('Journal Entry', searchfield): + return [] + + return frappe.db.sql(""" + SELECT jv.name, jv.posting_date, jv.user_remark + FROM `tabJournal Entry` jv, `tabJournal Entry Account` jv_detail + WHERE jv_detail.parent = jv.name + AND jv_detail.account = %(account)s + AND IFNULL(jv_detail.party, '') = %(party)s + AND ( + jv_detail.reference_type IS NULL + OR jv_detail.reference_type = '' + ) + AND jv.docstatus = 1 + AND jv.`{0}` LIKE %(txt)s + ORDER BY jv.name DESC + LIMIT %(offset)s, %(limit)s + """.format(searchfield), dict( + account=filters.get("account"), + party=cstr(filters.get("party")), + txt="%{0}%".format(txt), + offset=start, + limit=page_len + ) + ) @frappe.whitelist() diff --git a/erpnext/accounts/doctype/payment_order/payment_order.py b/erpnext/accounts/doctype/payment_order/payment_order.py index 4702e58cef..e5880aa67a 100644 --- a/erpnext/accounts/doctype/payment_order/payment_order.py +++ b/erpnext/accounts/doctype/payment_order/payment_order.py @@ -27,6 +27,7 @@ class PaymentOrder(Document): frappe.db.set_value(self.payment_order_type, d.get(frappe.scrub(self.payment_order_type)), ref_field, status) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_mop_query(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql(""" select mode_of_payment from `tabPayment Order Reference` where parent = %(parent)s and mode_of_payment like %(txt)s @@ -38,6 +39,7 @@ def get_mop_query(doctype, txt, searchfield, start, page_len, filters): }) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_supplier_query(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql(""" select supplier from `tabPayment Order Reference` where parent = %(parent)s and supplier like %(txt)s and diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py index 8eb0a222a4..9899219bdc 100644 --- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py +++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py @@ -24,7 +24,7 @@ class POSClosingEntry(Document): if user: frappe.throw(_("POS Closing Entry {} against {} between selected period" .format(frappe.bold("already exists"), frappe.bold(self.user))), title=_("Invalid Period")) - + if frappe.db.get_value("POS Opening Entry", self.pos_opening_entry, "status") != "Open": frappe.throw(_("Selected POS Opening Entry should be open."), title=_("Invalid Opening Entry")) @@ -41,6 +41,7 @@ class POSClosingEntry(Document): {"data": self, "currency": currency}) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_cashiers(doctype, txt, searchfield, start, page_len, filters): cashiers_list = frappe.get_all("POS Profile User", filters=filters, fields=['user']) return [c['user'] for c in cashiers_list] @@ -48,12 +49,12 @@ def get_cashiers(doctype, txt, searchfield, start, page_len, filters): @frappe.whitelist() def get_pos_invoices(start, end, user): data = frappe.db.sql(""" - select + select name, timestamp(posting_date, posting_time) as "timestamp" - from + from `tabPOS Invoice` - where - owner = %s and docstatus = 1 and + where + owner = %s and docstatus = 1 and (consolidated_invoice is NULL or consolidated_invoice = '') """, (user), as_dict=1) @@ -101,7 +102,7 @@ def make_closing_entry_from_opening(opening_entry): for t in d.taxes: existing_tax = [tx for tx in taxes if tx.account_head == t.account_head and tx.rate == t.rate] if existing_tax: - existing_tax[0].amount += flt(t.tax_amount); + existing_tax[0].amount += flt(t.tax_amount); else: taxes.append(frappe._dict({ 'account_head': t.account_head, diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.py b/erpnext/accounts/doctype/pos_profile/pos_profile.py index 8655b4bf3a..789b4c3bd9 100644 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.py +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.py @@ -105,6 +105,7 @@ def get_series(): return frappe.get_meta("POS Invoice").get_field("naming_series").options or "s" @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def pos_profile_query(doctype, txt, searchfield, start, page_len, filters): user = frappe.session['user'] company = filters.get('company') or frappe.defaults.get_user_default('company') diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index d90ae28e5a..cff7d5ba22 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -433,14 +433,14 @@ def make_pricing_rule(doctype, docname): return doc @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_item_uoms(doctype, txt, searchfield, start, page_len, filters): items = [filters.get('value')] if filters.get('apply_on') != 'Item Code': field = frappe.scrub(filters.get('apply_on')) + items = [d.name for d in frappe.db.get_all("Item", filters={field: filters.get('value')})] - items = frappe.db.sql_list("""select name - from `tabItem` where {0} = %s""".format(field), filters.get('value')) - - return frappe.get_all('UOM Conversion Detail', - filters = {'parent': ('in', items), 'uom': ("like", "{0}%".format(txt))}, - fields = ["distinct uom"], as_list=1) + return frappe.get_all('UOM Conversion Detail', filters={ + 'parent': ('in', items), + 'uom': ("like", "{0}%".format(txt)) + }, fields = ["distinct uom"], as_list=1) diff --git a/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.py b/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.py index 7df090bf62..ce6baa6846 100644 --- a/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.py +++ b/erpnext/accounts/page/bank_reconciliation/bank_reconciliation.py @@ -290,6 +290,7 @@ def get_matching_transactions_payments(description_matching): return [] @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def payment_entry_query(doctype, txt, searchfield, start, page_len, filters): account = frappe.db.get_value("Bank Account", filters.get("bank_account"), "account") if not account: @@ -319,6 +320,7 @@ def payment_entry_query(doctype, txt, searchfield, start, page_len, filters): ) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def journal_entry_query(doctype, txt, searchfield, start, page_len, filters): account = frappe.db.get_value("Bank Account", filters.get("bank_account"), "account") @@ -355,6 +357,7 @@ def journal_entry_query(doctype, txt, searchfield, start, page_len, filters): ) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def sales_invoices_query(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql(""" SELECT diff --git a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py index 1869a29c8d..60c528bcc4 100644 --- a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py +++ b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py @@ -106,6 +106,7 @@ def update_maintenance_log(asset_maintenance, item_code, item_name, task): maintenance_log.save() @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_team_members(doctype, txt, searchfield, start, page_len, filters): return frappe.db.get_values('Maintenance Team Member', { 'parent': filters.get("maintenance_team") }) diff --git a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.py b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.py index f169f01616..148357f392 100644 --- a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.py +++ b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.py @@ -41,6 +41,7 @@ class AssetMaintenanceLog(Document): asset_maintenance_doc.save() @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_maintenance_tasks(doctype, txt, searchfield, start, page_len, filters): asset_maintenance_tasks = frappe.db.get_values('Asset Maintenance Task', {'parent':filters.get("asset_maintenance")}, 'maintenance_task') return asset_maintenance_tasks diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py index 4b852300e5..b54a585b97 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py @@ -207,6 +207,7 @@ def get_list_context(context=None): return list_context @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_supplier_contacts(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql("""select `tabContact`.name from `tabContact`, `tabDynamic Link` where `tabDynamic Link`.link_doctype = 'Supplier' and (`tabDynamic Link`.link_name=%(name)s diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index b402204072..babc5bdd79 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -12,6 +12,7 @@ from frappe.utils import unique # searches for active employees @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def employee_query(doctype, txt, searchfield, start, page_len, filters): conditions = [] fields = get_fields("Employee", ["name", "employee_name"]) @@ -42,6 +43,7 @@ def employee_query(doctype, txt, searchfield, start, page_len, filters): # searches for leads which are not converted @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def lead_query(doctype, txt, searchfield, start, page_len, filters): fields = get_fields("Lead", ["name", "lead_name", "company_name"]) @@ -72,6 +74,7 @@ def lead_query(doctype, txt, searchfield, start, page_len, filters): # searches for customer @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def customer_query(doctype, txt, searchfield, start, page_len, filters): conditions = [] cust_master_name = frappe.defaults.get_user_default("cust_master_name") @@ -110,8 +113,10 @@ def customer_query(doctype, txt, searchfield, start, page_len, filters): # searches for supplier @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def supplier_query(doctype, txt, searchfield, start, page_len, filters): supp_master_name = frappe.defaults.get_user_default("supp_master_name") + if supp_master_name == "Supplier Name": fields = ["name", "supplier_group"] else: @@ -142,32 +147,49 @@ def supplier_query(doctype, txt, searchfield, start, page_len, filters): @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def tax_account_query(doctype, txt, searchfield, start, page_len, filters): company_currency = erpnext.get_company_currency(filters.get('company')) - tax_accounts = frappe.db.sql("""select name, parent_account from tabAccount - where tabAccount.docstatus!=2 - and account_type in (%s) - and is_group = 0 - and company = %s - and account_currency = %s - and `%s` LIKE %s - order by idx desc, name - limit %s, %s""" % - (", ".join(['%s']*len(filters.get("account_type"))), "%s", "%s", searchfield, "%s", "%s", "%s"), - tuple(filters.get("account_type") + [filters.get("company"), company_currency, "%%%s%%" % txt, - start, page_len])) + def get_accounts(with_account_type_filter): + account_type_condition = '' + if with_account_type_filter: + account_type_condition = "AND account_type in %(account_types)s" + + accounts = frappe.db.sql(""" + SELECT name, parent_account + FROM `tabAccount` + WHERE `tabAccount`.docstatus!=2 + {account_type_condition} + AND is_group = 0 + AND company = %(company)s + AND account_currency = %(currency)s + AND `{searchfield}` LIKE %(txt)s + ORDER BY idx DESC, name + LIMIT %(offset)s, %(limit)s + """.format(account_type_condition=account_type_condition, searchfield=searchfield), + dict( + account_types=filters.get("account_type"), + company=filters.get("company"), + currency=company_currency, + txt="%{}%".format(txt), + offset=start, + limit=page_len + ) + ) + + return accounts + + tax_accounts = get_accounts(True) + if not tax_accounts: - tax_accounts = frappe.db.sql("""select name, parent_account from tabAccount - where tabAccount.docstatus!=2 and is_group = 0 - and company = %s and account_currency = %s and `%s` LIKE %s limit %s, %s""" #nosec - % ("%s", "%s", searchfield, "%s", "%s", "%s"), - (filters.get("company"), company_currency, "%%%s%%" % txt, start, page_len)) + tax_accounts = get_accounts(False) return tax_accounts @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=False): conditions = [] @@ -215,7 +237,6 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals idx desc, name, item_name limit %(start)s, %(page_len)s """.format( - key=searchfield, columns=columns, scond=searchfields, fcond=get_filters_cond(doctype, filters, conditions).replace('%', '%%'), @@ -231,6 +252,7 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def bom(doctype, txt, searchfield, start, page_len, filters): conditions = [] fields = get_fields("BOM", ["name", "item"]) @@ -258,6 +280,7 @@ def bom(doctype, txt, searchfield, start, page_len, filters): @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_project_name(doctype, txt, searchfield, start, page_len, filters): cond = '' if filters.get('customer'): @@ -285,6 +308,7 @@ def get_project_name(doctype, txt, searchfield, start, page_len, filters): @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_delivery_notes_to_be_billed(doctype, txt, searchfield, start, page_len, filters, as_dict): fields = get_fields("Delivery Note", ["name", "customer", "posting_date"]) @@ -315,6 +339,7 @@ def get_delivery_notes_to_be_billed(doctype, txt, searchfield, start, page_len, @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_batch_no(doctype, txt, searchfield, start, page_len, filters): cond = "" if filters.get("posting_date"): @@ -373,6 +398,7 @@ def get_batch_no(doctype, txt, searchfield, start, page_len, filters): @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_account_list(doctype, txt, searchfield, start, page_len, filters): filter_list = [] @@ -396,6 +422,7 @@ def get_account_list(doctype, txt, searchfield, start, page_len, filters): limit_start=start, limit_page_length=page_len, as_list=True) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_blanket_orders(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql("""select distinct bo.name, bo.blanket_order_type, bo.to_date from `tabBlanket Order` bo, `tabBlanket Order Item` boi @@ -412,6 +439,7 @@ def get_blanket_orders(doctype, txt, searchfield, start, page_len, filters): @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_income_account(doctype, txt, searchfield, start, page_len, filters): from erpnext.controllers.queries import get_match_cond @@ -438,6 +466,7 @@ def get_income_account(doctype, txt, searchfield, start, page_len, filters): @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_expense_account(doctype, txt, searchfield, start, page_len, filters): from erpnext.controllers.queries import get_match_cond @@ -462,6 +491,7 @@ def get_expense_account(doctype, txt, searchfield, start, page_len, filters): @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def warehouse_query(doctype, txt, searchfield, start, page_len, filters): # Should be used when item code is passed in filters. conditions, bin_conditions = [], [] @@ -505,6 +535,7 @@ def get_doctype_wise_filters(filters): @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_batch_numbers(doctype, txt, searchfield, start, page_len, filters): query = """select batch_id from `tabBatch` where disabled = 0 @@ -518,6 +549,7 @@ def get_batch_numbers(doctype, txt, searchfield, start, page_len, filters): @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def item_manufacturer_query(doctype, txt, searchfield, start, page_len, filters): item_filters = [ ['manufacturer', 'like', '%' + txt + '%'], @@ -536,6 +568,7 @@ def item_manufacturer_query(doctype, txt, searchfield, start, page_len, filters) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_purchase_receipts(doctype, txt, searchfield, start, page_len, filters): query = """ select pr.name @@ -550,6 +583,7 @@ def get_purchase_receipts(doctype, txt, searchfield, start, page_len, filters): @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_purchase_invoices(doctype, txt, searchfield, start, page_len, filters): query = """ select pi.name @@ -564,6 +598,7 @@ def get_purchase_invoices(doctype, txt, searchfield, start, page_len, filters): @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_tax_template(doctype, txt, searchfield, start, page_len, filters): item_doc = frappe.get_cached_doc('Item', filters.get('item_code')) diff --git a/erpnext/education/doctype/program_enrollment/program_enrollment.py b/erpnext/education/doctype/program_enrollment/program_enrollment.py index 7536172891..3e27670d05 100644 --- a/erpnext/education/doctype/program_enrollment/program_enrollment.py +++ b/erpnext/education/doctype/program_enrollment/program_enrollment.py @@ -97,6 +97,7 @@ class ProgramEnrollment(Document): return quiz_progress @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_program_courses(doctype, txt, searchfield, start, page_len, filters): if filters.get('program'): return frappe.db.sql("""select course, course_name from `tabProgram Course` @@ -115,6 +116,7 @@ def get_program_courses(doctype, txt, searchfield, start, page_len, filters): }) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_students(doctype, txt, searchfield, start, page_len, filters): if not filters.get("academic_term"): filters["academic_term"] = frappe.defaults.get_defaults().academic_term diff --git a/erpnext/education/doctype/student_group/student_group.py b/erpnext/education/doctype/student_group/student_group.py index 8b61c899bc..0260b80864 100644 --- a/erpnext/education/doctype/student_group/student_group.py +++ b/erpnext/education/doctype/student_group/student_group.py @@ -108,6 +108,7 @@ def get_program_enrollment(academic_year, academic_term=None, program=None, batc @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def fetch_students(doctype, txt, searchfield, start, page_len, filters): if filters.get("group_based_on") != "Activity": enrolled_students = get_program_enrollment(filters.get('academic_year'), filters.get('academic_term'), diff --git a/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.py b/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.py index 3dc7c1ec39..5da5a0657c 100644 --- a/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.py +++ b/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.py @@ -71,6 +71,7 @@ def validate_service_item(item, msg): frappe.throw(_(msg)) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_practitioner_list(doctype, txt, searchfield, start, page_len, filters=None): fields = ['name', 'practitioner_name', 'mobile_phone'] diff --git a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py index cf63b65f4d..b4a4e295f0 100644 --- a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py +++ b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py @@ -217,6 +217,7 @@ def patient_leave_service_unit(inpatient_record, check_out, leave_from): inpatient_record.save(ignore_permissions = True) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_leave_from(doctype, txt, searchfield, start, page_len, filters): docname = filters['docname'] diff --git a/erpnext/hr/doctype/department_approver/department_approver.py b/erpnext/hr/doctype/department_approver/department_approver.py index d4c118f802..afd54b8346 100644 --- a/erpnext/hr/doctype/department_approver/department_approver.py +++ b/erpnext/hr/doctype/department_approver/department_approver.py @@ -11,6 +11,7 @@ class DepartmentApprover(Document): pass @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_approvers(doctype, txt, searchfield, start, page_len, filters): if not filters.get("employee"): diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 8062342cfc..c51f655a66 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -911,6 +911,7 @@ def get_bom_diff(bom1, bom2): return out @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def item_query(doctype, txt, searchfield, start, page_len, filters): meta = frappe.get_meta("Item", cached=True) searchfields = meta.get_search_fields() diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index f962a1157b..b7d968e974 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -632,6 +632,7 @@ class WorkOrder(Document): return bom @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_bom_operations(doctype, txt, searchfield, start, page_len, filters): if txt: filters['operation'] = ('like', '%%%s%%' % txt) diff --git a/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.py b/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.py index e3e440ebc6..dc424b7605 100644 --- a/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.py +++ b/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.py @@ -30,7 +30,7 @@ def get_columns(filters): "width": 180 } ]) - + columns.extend([ { "label": _("Finished Good"), @@ -73,7 +73,7 @@ def get_columns(filters): ]) return columns - + def get_data(filters): cond = "1=1" @@ -95,6 +95,7 @@ def get_data(filters): return results @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_work_orders(doctype, txt, searchfield, start, page_len, filters): cond = "1=1" if filters.get('bom_no'): diff --git a/erpnext/manufacturing/report/production_planning_report/production_planning_report.py b/erpnext/manufacturing/report/production_planning_report/production_planning_report.py index 5ac3923187..ebc01c65af 100644 --- a/erpnext/manufacturing/report/production_planning_report/production_planning_report.py +++ b/erpnext/manufacturing/report/production_planning_report/production_planning_report.py @@ -369,6 +369,3 @@ class ProductionPlanReport(object): "fieldtype": "Float", "width": 140 }]) - -def document_query(doctype, txt, searchfield, start, page_len, filters): - pass \ No newline at end of file diff --git a/erpnext/payroll/doctype/employee_benefit_application/employee_benefit_application.py b/erpnext/payroll/doctype/employee_benefit_application/employee_benefit_application.py index d7d00e6480..ef844fbd3b 100644 --- a/erpnext/payroll/doctype/employee_benefit_application/employee_benefit_application.py +++ b/erpnext/payroll/doctype/employee_benefit_application/employee_benefit_application.py @@ -223,6 +223,7 @@ def get_benefit_amount_based_on_pro_rata(sal_struct, component_max_benefit): return benefit_amount @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_earning_components(doctype, txt, searchfield, start, page_len, filters): if len(filters) < 2: return {} diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py index ad9b6d86c8..554484febb 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py @@ -540,6 +540,7 @@ def submit_salary_slips_for_employees(payroll_entry, salary_slips, publish_progr frappe.msgprint(_("Could not submit some Salary Slips")) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_payroll_entries_for_jv(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql(""" select name from `tabPayroll Entry` diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py index 6350f86abb..5bbd29c4c4 100644 --- a/erpnext/projects/doctype/project/project.py +++ b/erpnext/projects/doctype/project/project.py @@ -239,6 +239,7 @@ def get_list_context(context=None): } @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_users_for_project(doctype, txt, searchfield, start, page_len, filters): conditions = [] return frappe.db.sql("""select name, concat_ws(' ', first_name, middle_name, last_name) diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py index cf2fd26e57..fb84094ffe 100755 --- a/erpnext/projects/doctype/task/task.py +++ b/erpnext/projects/doctype/task/task.py @@ -193,6 +193,7 @@ def check_if_child_exists(name): @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_project(doctype, txt, searchfield, start, page_len, filters): from erpnext.controllers.queries import get_match_cond return frappe.db.sql(""" select name from `tabProject` diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py index 7fe22bec4b..9e807f728e 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.py +++ b/erpnext/projects/doctype/timesheet/timesheet.py @@ -214,6 +214,7 @@ def get_projectwise_timesheet_data(project, parent=None): and sales_invoice is null""".format(cond), {'project': project, 'parent': parent}, as_dict=1) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_timesheet(doctype, txt, searchfield, start, page_len, filters): if not filters: filters = {} diff --git a/erpnext/projects/utils.py b/erpnext/projects/utils.py index d0d88ebdf0..c39f908e43 100644 --- a/erpnext/projects/utils.py +++ b/erpnext/projects/utils.py @@ -7,6 +7,7 @@ from __future__ import unicode_literals import frappe @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def query_task(doctype, txt, searchfield, start, page_len, filters): from frappe.desk.reportview import build_match_conditions diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index e614acdb82..ca62488a8c 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -340,6 +340,7 @@ def get_loyalty_programs(doc): return lp_details @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_customer_list(doctype, txt, searchfield, start, page_len, filters=None): from erpnext.controllers.queries import get_fields fields = ["name", "customer_name", "customer_group", "territory"] @@ -542,6 +543,7 @@ def make_address(args, is_primary_address=1): return address @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_customer_primary_contact(doctype, txt, searchfield, start, page_len, filters): customer = filters.get('customer') return frappe.db.sql(""" diff --git a/erpnext/selling/doctype/product_bundle/product_bundle.py b/erpnext/selling/doctype/product_bundle/product_bundle.py index 0c85a1b53c..d3281f733f 100644 --- a/erpnext/selling/doctype/product_bundle/product_bundle.py +++ b/erpnext/selling/doctype/product_bundle/product_bundle.py @@ -29,6 +29,7 @@ class ProductBundle(Document): frappe.throw(_("Row #{0}: Child Item should not be a Product Bundle. Please remove Item {1} and Save").format(item.idx, frappe.bold(item.item_code))) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_new_item_code(doctype, txt, searchfield, start, page_len, filters): from erpnext.controllers.queries import get_match_cond diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index ffb66354fa..f88289871e 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -888,6 +888,7 @@ def make_purchase_order(source_name, for_supplier=None, selected_items=[], targe @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_supplier(doctype, txt, searchfield, start, page_len, filters): supp_master_name = frappe.defaults.get_user_default("supp_master_name") if supp_master_name == "Supplier Name": diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.py b/erpnext/selling/page/point_of_sale/point_of_sale.py index f7b7ed8b89..9f8410f40b 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -160,6 +160,7 @@ def get_item_group_condition(pos_profile): return cond % tuple(item_groups) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def item_group_query(doctype, txt, searchfield, start, page_len, filters): item_groups = [] cond = "1=1" @@ -179,12 +180,12 @@ def item_group_query(doctype, txt, searchfield, start, page_len, filters): @frappe.whitelist() def check_opening_entry(user): - open_vouchers = frappe.db.get_all("POS Opening Entry", - filters = { - "user": user, + open_vouchers = frappe.db.get_all("POS Opening Entry", + filters = { + "user": user, "pos_closing_entry": ["in", ["", None]], "docstatus": 1 - }, + }, fields = ["name", "company", "pos_profile", "period_start_date"], order_by = "period_start_date desc" ) @@ -229,7 +230,7 @@ def get_past_order_list(search_term, status, limit=20): invoice_list = frappe.db.get_all('POS Invoice', filters={ 'status': status }, fields=fields) - + return invoice_list @frappe.whitelist() @@ -244,7 +245,7 @@ def set_customer_info(fieldname, customer, value=""): if fieldname == 'email_id': contact_doc.set('email_ids', [{ 'email_id': value, 'is_primary': 1}]) frappe.db.set_value('Customer', customer, 'email_id', value) - elif fieldname == 'mobile_no': + elif fieldname == 'mobile_no': contact_doc.set('phone_nos', [{ 'phone': value, 'is_primary_mobile_no': 1}]) frappe.db.set_value('Customer', customer, 'mobile_no', value) contact_doc.save() \ No newline at end of file diff --git a/erpnext/setup/doctype/party_type/party_type.py b/erpnext/setup/doctype/party_type/party_type.py index b29c305ee7..96e60936a4 100644 --- a/erpnext/setup/doctype/party_type/party_type.py +++ b/erpnext/setup/doctype/party_type/party_type.py @@ -10,6 +10,7 @@ class PartyType(Document): pass @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_party_type(doctype, txt, searchfield, start, page_len, filters): cond = '' if filters and filters.get('account'): diff --git a/erpnext/stock/doctype/item_alternative/item_alternative.py b/erpnext/stock/doctype/item_alternative/item_alternative.py index 522dfc67a9..190cb62e99 100644 --- a/erpnext/stock/doctype/item_alternative/item_alternative.py +++ b/erpnext/stock/doctype/item_alternative/item_alternative.py @@ -43,6 +43,7 @@ class ItemAlternative(Document): frappe.throw(_("Already record exists for the item {0}").format(self.item_code)) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_alternative_items(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql(""" (select alternative_item_code from `tabItem Alternative` where item_code = %(item_code)s and alternative_item_code like %(txt)s) diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py index 25f1ed9505..335175f21d 100644 --- a/erpnext/stock/doctype/material_request/material_request.py +++ b/erpnext/stock/doctype/material_request/material_request.py @@ -370,6 +370,7 @@ def get_items_based_on_default_supplier(supplier): return supplier_items @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_material_requests_based_on_supplier(doctype, txt, searchfield, start, page_len, filters): conditions = "" if txt: @@ -403,6 +404,7 @@ def get_material_requests_based_on_supplier(doctype, txt, searchfield, start, pa return material_requests @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def get_default_supplier_query(doctype, txt, searchfield, start, page_len, filters): doc = frappe.get_doc("Material Request", filters.get("doc")) item_list = [] diff --git a/erpnext/stock/doctype/packing_slip/packing_slip.py b/erpnext/stock/doctype/packing_slip/packing_slip.py index 4f831d7a85..a7a29cca7f 100644 --- a/erpnext/stock/doctype/packing_slip/packing_slip.py +++ b/erpnext/stock/doctype/packing_slip/packing_slip.py @@ -176,6 +176,7 @@ class PackingSlip(Document): self.update_item_details() @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def item_details(doctype, txt, searchfield, start, page_len, filters): from erpnext.controllers.queries import get_match_cond return frappe.db.sql("""select name, item_name, description from `tabItem` diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.py b/erpnext/stock/doctype/quality_inspection/quality_inspection.py index 568e742876..c3bb514184 100644 --- a/erpnext/stock/doctype/quality_inspection/quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.py @@ -59,6 +59,7 @@ class QualityInspection(Document): (quality_inspection, self.modified, self.reference_name, self.item_code)) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def item_query(doctype, txt, searchfield, start, page_len, filters): if filters.get("from"): from frappe.desk.reportview import get_match_cond @@ -88,6 +89,7 @@ def item_query(doctype, txt, searchfield, start, page_len, filters): {'parent': filters.get('parent'), 'txt': "%%%s%%" % txt}) @frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs def quality_inspection_query(doctype, txt, searchfield, start, page_len, filters): return frappe.get_all('Quality Inspection', limit_start=start, From 5ad9c2a1a004c43101be217288347fbfce97981f Mon Sep 17 00:00:00 2001 From: Saurabh Date: Thu, 6 Aug 2020 13:50:20 +0550 Subject: [PATCH 149/449] bumped to version 13.0.0-beta.4 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 18294f3604..9f658253ef 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0-beta.3' +__version__ = '13.0.0-beta.4' def get_default_company(user=None): '''Get default company for user''' From aa4f8cf4fcac0f7da62e9f50ccfd6b67f31ca705 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 6 Aug 2020 17:08:14 +0530 Subject: [PATCH 150/449] fix: handle product_info null --- erpnext/templates/generators/item/item_configure.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/erpnext/templates/generators/item/item_configure.js b/erpnext/templates/generators/item/item_configure.js index 163c955c56..284eb25218 100644 --- a/erpnext/templates/generators/item/item_configure.js +++ b/erpnext/templates/generators/item/item_configure.js @@ -194,9 +194,16 @@ class ItemConfigure { filtered_items[0] : ''; // Allow Add to Cart if adding out of stock items enabled in Shopping Cart else check stock. - const in_stock = product_info.allow_items_not_in_stock ? 1 : product_info.in_stock; - const add_to_cart = `${__('Add to cart')}`; - const product_action = in_stock ? add_to_cart : `${__('Not in Stock')}`; + var in_stock; + var add_to_cart; + var product_action; + if (product_info) { + in_stock = product_info.allow_items_not_in_stock ? 1 : product_info.in_stock; + add_to_cart = `${__('Add to cart')}`; + product_action = in_stock ? add_to_cart : `${__('Not in Stock')}`; + } else { + product_info = ''; + } const item_add_to_cart = one_item ? `
- +
Date: {{ frappe.utils.formatdate(doc.creation) }}
Date: {{ frappe.utils.format_date(doc.creation) }}
diff --git a/erpnext/accounts/print_format/journal_auditing_voucher/journal_auditing_voucher.html b/erpnext/accounts/print_format/journal_auditing_voucher/journal_auditing_voucher.html index 1351517981..0ca940f8bd 100644 --- a/erpnext/accounts/print_format/journal_auditing_voucher/journal_auditing_voucher.html +++ b/erpnext/accounts/print_format/journal_auditing_voucher/journal_auditing_voucher.html @@ -17,7 +17,7 @@
- +
Date: {{ frappe.utils.formatdate(doc.creation) }}
Date: {{ frappe.utils.format_date(doc.creation) }}
diff --git a/erpnext/accounts/print_format/payment_receipt_voucher/payment_receipt_voucher.html b/erpnext/accounts/print_format/payment_receipt_voucher/payment_receipt_voucher.html index f2e65d3334..283d505e3b 100644 --- a/erpnext/accounts/print_format/payment_receipt_voucher/payment_receipt_voucher.html +++ b/erpnext/accounts/print_format/payment_receipt_voucher/payment_receipt_voucher.html @@ -5,7 +5,7 @@ {{ add_header(0, 1, doc, letter_head, no_letterhead, print_settings) }} {%- for label, value in ( - (_("Received On"), frappe.utils.formatdate(doc.voucher_date)), + (_("Received On"), frappe.utils.format_date(doc.voucher_date)), (_("Received From"), doc.pay_to_recd_from), (_("Amount"), "" + doc.get_formatted("total_amount") + "
" + (doc.total_amount_in_words or "") + "
"), (_("Remarks"), doc.remark) diff --git a/erpnext/accounts/print_format/purchase_auditing_voucher/purchase_auditing_voucher.html b/erpnext/accounts/print_format/purchase_auditing_voucher/purchase_auditing_voucher.html index a7c3bce0b4..043ac254ed 100644 --- a/erpnext/accounts/print_format/purchase_auditing_voucher/purchase_auditing_voucher.html +++ b/erpnext/accounts/print_format/purchase_auditing_voucher/purchase_auditing_voucher.html @@ -8,7 +8,7 @@
- + @@ -17,7 +17,7 @@
Supplier Name: {{ doc.supplier }}
Due Date: {{ frappe.utils.formatdate(doc.due_date) }}
Due Date: {{ frappe.utils.format_date(doc.due_date) }}
Address: {{doc.address_display}}
Contact: {{doc.contact_display}}
Mobile no: {{doc.contact_mobile}}
- +
Voucher No: {{ doc.name }}
Date: {{ frappe.utils.formatdate(doc.creation) }}
Date: {{ frappe.utils.format_date(doc.creation) }}
diff --git a/erpnext/accounts/print_format/sales_auditing_voucher/sales_auditing_voucher.html b/erpnext/accounts/print_format/sales_auditing_voucher/sales_auditing_voucher.html index ef4ada14a3..a53b593a72 100644 --- a/erpnext/accounts/print_format/sales_auditing_voucher/sales_auditing_voucher.html +++ b/erpnext/accounts/print_format/sales_auditing_voucher/sales_auditing_voucher.html @@ -8,7 +8,7 @@
- + @@ -17,7 +17,7 @@
Customer Name: {{ doc.customer }}
Due Date: {{ frappe.utils.formatdate(doc.due_date) }}
Due Date: {{ frappe.utils.format_date(doc.due_date) }}
Address: {{doc.address_display}}
Contact: {{doc.contact_display}}
Mobile no: {{doc.contact_mobile}}
- +
Voucher No: {{ doc.name }}
Date: {{ frappe.utils.formatdate(doc.creation) }}
Date: {{ frappe.utils.format_date(doc.creation) }}
diff --git a/erpnext/templates/pages/material_request_info.html b/erpnext/templates/pages/material_request_info.html index 9d189895b6..c7a78027b1 100644 --- a/erpnext/templates/pages/material_request_info.html +++ b/erpnext/templates/pages/material_request_info.html @@ -25,7 +25,7 @@
- {{ frappe.utils.formatdate(doc.transaction_date, 'medium') }} + {{ frappe.utils.format_date(doc.transaction_date, 'medium') }}
diff --git a/erpnext/templates/pages/order.html b/erpnext/templates/pages/order.html index 01b5f6df6c..af7af11677 100644 --- a/erpnext/templates/pages/order.html +++ b/erpnext/templates/pages/order.html @@ -42,10 +42,10 @@
- {{ frappe.utils.formatdate(doc.transaction_date, 'medium') }} + {{ frappe.utils.format_date(doc.transaction_date, 'medium') }} {% if doc.valid_till %}

- {{ _("Valid Till") }}: {{ frappe.utils.formatdate(doc.valid_till, 'medium') }} + {{ _("Valid Till") }}: {{ frappe.utils.format_date(doc.valid_till, 'medium') }}

{% endif %}
From 886b680e1b050548aabeacf8aac4833ced60aa35 Mon Sep 17 00:00:00 2001 From: Anupam Date: Fri, 6 Nov 2020 16:48:39 +0530 Subject: [PATCH 200/449] revert changes --- .../controllers/website_list_for_contact.py | 2 +- erpnext/crm/doctype/parameter/__init__.py | 0 erpnext/crm/doctype/parameter/parameter.js | 8 +++ erpnext/crm/doctype/parameter/parameter.json | 56 +++++++++++++++++++ erpnext/crm/doctype/parameter/parameter.py | 10 ++++ .../crm/doctype/parameter/test_parameter.py | 10 ++++ erpnext/shopping_cart/cart.py | 4 +- .../shopping_cart_settings.json | 9 +-- .../templates/includes/transaction_row.html | 6 +- erpnext/templates/pages/order.html | 31 +++++----- 10 files changed, 104 insertions(+), 32 deletions(-) create mode 100644 erpnext/crm/doctype/parameter/__init__.py create mode 100644 erpnext/crm/doctype/parameter/parameter.js create mode 100644 erpnext/crm/doctype/parameter/parameter.json create mode 100644 erpnext/crm/doctype/parameter/parameter.py create mode 100644 erpnext/crm/doctype/parameter/test_parameter.py diff --git a/erpnext/controllers/website_list_for_contact.py b/erpnext/controllers/website_list_for_contact.py index 801c405732..ecf041efd1 100644 --- a/erpnext/controllers/website_list_for_contact.py +++ b/erpnext/controllers/website_list_for_contact.py @@ -25,7 +25,7 @@ def get_transaction_list(doctype, txt=None, filters=None, limit_start=0, limit_p if not filters: filters = [] - if doctype in ['Supplier Quotation', 'Purchase Invoice', 'Quotation']: + if doctype in ['Supplier Quotation', 'Purchase Invoice']: filters.append((doctype, 'docstatus', '<', 2)) else: filters.append((doctype, 'docstatus', '=', 1)) diff --git a/erpnext/crm/doctype/parameter/__init__.py b/erpnext/crm/doctype/parameter/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/crm/doctype/parameter/parameter.js b/erpnext/crm/doctype/parameter/parameter.js new file mode 100644 index 0000000000..0a2b13be5e --- /dev/null +++ b/erpnext/crm/doctype/parameter/parameter.js @@ -0,0 +1,8 @@ +// Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Parameter', { + // refresh: function(frm) { + + // } +}); diff --git a/erpnext/crm/doctype/parameter/parameter.json b/erpnext/crm/doctype/parameter/parameter.json new file mode 100644 index 0000000000..7b2eb3edfc --- /dev/null +++ b/erpnext/crm/doctype/parameter/parameter.json @@ -0,0 +1,56 @@ +{ + "actions": [], + "creation": "2020-11-02 16:04:08.280141", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "parameter_name", + "value_based", + "uom" + ], + "fields": [ + { + "fieldname": "parameter_name", + "fieldtype": "Data", + "label": "Parameter Name" + }, + { + "default": "0", + "fieldname": "value_based", + "fieldtype": "Check", + "label": "Value Based" + }, + { + "fieldname": "uom", + "fieldtype": "Link", + "label": "UOM", + "options": "UOM" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2020-11-02 16:04:08.280141", + "modified_by": "Administrator", + "module": "CRM", + "name": "Parameter", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/crm/doctype/parameter/parameter.py b/erpnext/crm/doctype/parameter/parameter.py new file mode 100644 index 0000000000..9943bc45b9 --- /dev/null +++ b/erpnext/crm/doctype/parameter/parameter.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +# import frappe +from frappe.model.document import Document + +class Parameter(Document): + pass diff --git a/erpnext/crm/doctype/parameter/test_parameter.py b/erpnext/crm/doctype/parameter/test_parameter.py new file mode 100644 index 0000000000..80bb8652c0 --- /dev/null +++ b/erpnext/crm/doctype/parameter/test_parameter.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +# import frappe +import unittest + +class TestParameter(unittest.TestCase): + pass diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py index 0ccc0252c3..a7e8388be9 100644 --- a/erpnext/shopping_cart/cart.py +++ b/erpnext/shopping_cart/cart.py @@ -96,9 +96,7 @@ def place_order(): def request_for_quotation(): quotation = _get_cart_quotation() quotation.flags.ignore_permissions = True - quotation.save() - if not get_shopping_cart_settings().save_quotations_as_draft: - quotation.submit() + quotation.submit() return quotation.name @frappe.whitelist() diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json index 9d61e7d0ec..98a7eeda23 100644 --- a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json +++ b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json @@ -167,20 +167,13 @@ "fieldname": "enable_variants", "fieldtype": "Check", "label": "Enable Variants" - }, - { - "default": "0", - "depends_on": "eval: doc.enable_checkout == 0", - "fieldname": "save_quotations_as_draft", - "fieldtype": "Check", - "label": "Save Quotations as Draft" } ], "icon": "fa fa-shopping-cart", "idx": 1, "issingle": 1, "links": [], - "modified": "2020-09-24 16:28:07.192525", + "modified": "2020-08-02 18:21:43.873303", "modified_by": "Administrator", "module": "Shopping Cart", "name": "Shopping Cart Settings", diff --git a/erpnext/templates/includes/transaction_row.html b/erpnext/templates/includes/transaction_row.html index fd4835ed99..80a542f74b 100644 --- a/erpnext/templates/includes/transaction_row.html +++ b/erpnext/templates/includes/transaction_row.html @@ -14,11 +14,7 @@
- {% if doc.doctype == "Quotation" and not doc.docstatus %} - {{ _("Pending") }} - {% else %} - {{ doc.get_formatted("grand_total") }} - {% endif %} + {{ doc.get_formatted("grand_total") }}
Link diff --git a/erpnext/templates/pages/order.html b/erpnext/templates/pages/order.html index af7af11677..896954a287 100644 --- a/erpnext/templates/pages/order.html +++ b/erpnext/templates/pages/order.html @@ -12,21 +12,22 @@ {% endblock %} {% block header_actions %} - + + {% endblock %} {% block page_content %} From 14ef229b126a24b8ac9bd6c0dc74456513a2921c Mon Sep 17 00:00:00 2001 From: Anupam Date: Fri, 6 Nov 2020 16:50:15 +0530 Subject: [PATCH 201/449] Revert "Update item_add_to_cart.html" This reverts commit 5b3af82e75f60aeb9f9a9c8a4523ab8a5c1e273b. --- erpnext/templates/generators/item/item_add_to_cart.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/templates/generators/item/item_add_to_cart.html b/erpnext/templates/generators/item/item_add_to_cart.html index dbf15de1e4..c619963a91 100644 --- a/erpnext/templates/generators/item/item_add_to_cart.html +++ b/erpnext/templates/generators/item/item_add_to_cart.html @@ -11,7 +11,7 @@ ({{ product_info.price.formatted_price }} / {{ product_info.uom }}) {% else %} - {{ _("Unit of Measurement") }} : {{ product_info.uom }} + {{ _("UOM") }} : {{ product_info.uom }} {% endif %} {% if cart_settings.show_stock_availability %} From ec7002625f35dbd177a4bd36f8c9aa030ddfcdf9 Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Fri, 6 Nov 2020 17:11:33 +0530 Subject: [PATCH 202/449] Delete __init__.py --- erpnext/crm/doctype/parameter/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 erpnext/crm/doctype/parameter/__init__.py diff --git a/erpnext/crm/doctype/parameter/__init__.py b/erpnext/crm/doctype/parameter/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 From b4bad63e2594e0dd9dc1bd1c20a3e2c6e2da59a5 Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Fri, 6 Nov 2020 17:11:47 +0530 Subject: [PATCH 203/449] Delete parameter.js --- erpnext/crm/doctype/parameter/parameter.js | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 erpnext/crm/doctype/parameter/parameter.js diff --git a/erpnext/crm/doctype/parameter/parameter.js b/erpnext/crm/doctype/parameter/parameter.js deleted file mode 100644 index 0a2b13be5e..0000000000 --- a/erpnext/crm/doctype/parameter/parameter.js +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors -// For license information, please see license.txt - -frappe.ui.form.on('Parameter', { - // refresh: function(frm) { - - // } -}); From c7f8204997c1050fb7a2f588b002ea1eef6660e8 Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Fri, 6 Nov 2020 17:12:21 +0530 Subject: [PATCH 204/449] Delete parameter.json --- erpnext/crm/doctype/parameter/parameter.json | 56 -------------------- 1 file changed, 56 deletions(-) delete mode 100644 erpnext/crm/doctype/parameter/parameter.json diff --git a/erpnext/crm/doctype/parameter/parameter.json b/erpnext/crm/doctype/parameter/parameter.json deleted file mode 100644 index 7b2eb3edfc..0000000000 --- a/erpnext/crm/doctype/parameter/parameter.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "actions": [], - "creation": "2020-11-02 16:04:08.280141", - "doctype": "DocType", - "editable_grid": 1, - "engine": "InnoDB", - "field_order": [ - "parameter_name", - "value_based", - "uom" - ], - "fields": [ - { - "fieldname": "parameter_name", - "fieldtype": "Data", - "label": "Parameter Name" - }, - { - "default": "0", - "fieldname": "value_based", - "fieldtype": "Check", - "label": "Value Based" - }, - { - "fieldname": "uom", - "fieldtype": "Link", - "label": "UOM", - "options": "UOM" - } - ], - "index_web_pages_for_search": 1, - "links": [], - "modified": "2020-11-02 16:04:08.280141", - "modified_by": "Administrator", - "module": "CRM", - "name": "Parameter", - "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "System Manager", - "share": 1, - "write": 1 - } - ], - "quick_entry": 1, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1 -} \ No newline at end of file From a739554b7da312fd015818cbcd71816d1ad00cad Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Fri, 6 Nov 2020 17:12:44 +0530 Subject: [PATCH 205/449] Delete parameter.py --- erpnext/crm/doctype/parameter/parameter.py | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 erpnext/crm/doctype/parameter/parameter.py diff --git a/erpnext/crm/doctype/parameter/parameter.py b/erpnext/crm/doctype/parameter/parameter.py deleted file mode 100644 index 9943bc45b9..0000000000 --- a/erpnext/crm/doctype/parameter/parameter.py +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - -from __future__ import unicode_literals -# import frappe -from frappe.model.document import Document - -class Parameter(Document): - pass From bdb8a4023a8e50d5a77f8e9c30e03805c4c6ba0f Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Fri, 6 Nov 2020 17:13:02 +0530 Subject: [PATCH 206/449] Delete test_parameter.py --- erpnext/crm/doctype/parameter/test_parameter.py | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 erpnext/crm/doctype/parameter/test_parameter.py diff --git a/erpnext/crm/doctype/parameter/test_parameter.py b/erpnext/crm/doctype/parameter/test_parameter.py deleted file mode 100644 index 80bb8652c0..0000000000 --- a/erpnext/crm/doctype/parameter/test_parameter.py +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors -# See license.txt -from __future__ import unicode_literals - -# import frappe -import unittest - -class TestParameter(unittest.TestCase): - pass From 109018120408e30df73bff41c23cae20712cd663 Mon Sep 17 00:00:00 2001 From: Saqib Date: Fri, 6 Nov 2020 18:19:26 +0530 Subject: [PATCH 207/449] fix: auto fetch sr nos with modifed conversion factor (#23855) --- erpnext/accounts/doctype/pos_invoice/pos_invoice.py | 8 ++++++-- erpnext/selling/page/point_of_sale/pos_controller.js | 2 ++ erpnext/selling/page/point_of_sale/pos_item_details.js | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index 61263ac788..f763d302c7 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -131,15 +131,19 @@ class POSInvoice(SalesInvoice): msg = "" item_code = frappe.bold(d.item_code) + serial_nos = get_serial_nos(d.serial_no) if serialized and batched and (no_batch_selected or no_serial_selected): msg = (_('Row #{}: Please select a serial no and batch against item: {} or remove it to complete transaction.') .format(d.idx, item_code)) - if serialized and no_serial_selected: + elif serialized and no_serial_selected: msg = (_('Row #{}: No serial number selected against item: {}. Please select one or remove it to complete transaction.') .format(d.idx, item_code)) - if batched and no_batch_selected: + elif batched and no_batch_selected: msg = (_('Row #{}: No batch selected against item: {}. Please select a batch or remove it to complete transaction.') .format(d.idx, item_code)) + elif serialized and not no_serial_selected and len(serial_nos) != d.qty: + msg = (_("Row #{}: You must select {} serial numbers for item {}.").format(d.idx, frappe.bold(cint(d.qty)), item_code)) + if msg: error_msg.append(msg) diff --git a/erpnext/selling/page/point_of_sale/pos_controller.js b/erpnext/selling/page/point_of_sale/pos_controller.js index f7d1fa4ded..970d840665 100644 --- a/erpnext/selling/page/point_of_sale/pos_controller.js +++ b/erpnext/selling/page/point_of_sale/pos_controller.js @@ -555,6 +555,8 @@ erpnext.PointOfSale.Controller = class { frappe.utils.play_sound("error"); return; } + if (!item_code) return; + item_selected_from_selector && (value = flt(value)) const args = { item_code, batch_no, [field]: value }; diff --git a/erpnext/selling/page/point_of_sale/pos_item_details.js b/erpnext/selling/page/point_of_sale/pos_item_details.js index 9874d1b5f9..a4de9f165d 100644 --- a/erpnext/selling/page/point_of_sale/pos_item_details.js +++ b/erpnext/selling/page/point_of_sale/pos_item_details.js @@ -372,12 +372,13 @@ erpnext.PointOfSale.ItemDetails = class { this.$form_container.on('click', '.auto-fetch-btn', () => { this.batch_no_control && this.batch_no_control.set_value(''); let qty = this.qty_control.get_value(); + let conversion_factor = this.conversion_factor_control.get_value(); let expiry_date = this.item_row.has_batch_no ? this.events.get_frm().doc.posting_date : ""; let numbers = frappe.call({ method: "erpnext.stock.doctype.serial_no.serial_no.auto_fetch_serial_number", args: { - qty, + qty: qty * conversion_factor, item_code: this.current_item.item_code, warehouse: this.warehouse_control.get_value() || '', batch_nos: this.current_item.batch_no || '', From 8cbcd54f3b17e00eb045314ac6ab41ab4a9035c1 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Fri, 6 Nov 2020 18:48:34 +0530 Subject: [PATCH 208/449] chore: change log for v13-beta-pre-release-5 (#23846) --- erpnext/change_log/v13/v13_0_0-beta_5.md | 89 ++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 erpnext/change_log/v13/v13_0_0-beta_5.md diff --git a/erpnext/change_log/v13/v13_0_0-beta_5.md b/erpnext/change_log/v13/v13_0_0-beta_5.md new file mode 100644 index 0000000000..8374c775fe --- /dev/null +++ b/erpnext/change_log/v13/v13_0_0-beta_5.md @@ -0,0 +1,89 @@ +### Version 13.0.0 Beta 5 Release Notes + +#### Features and Enhancements +- Add company and correct filter in bank reconciliation statement ([#23614](https://github.com/frappe/erpnext/pull/23614)) +- Process Statement Of Accounts ([#22901](https://github.com/frappe/erpnext/pull/22901)) +- Added Condition field in Pricing Rule ([#23014](https://github.com/frappe/erpnext/pull/23014)) +- Material Request and Stock Entry Enhancement ([#22671](https://github.com/frappe/erpnext/pull/22671)) +- Added sequence id in routing for the completion of operations sequentially ([#23641](https://github.com/frappe/erpnext/pull/23641)) +- Appraisal form Enhancements ([#23500](https://github.com/frappe/erpnext/pull/23500)) +- Crm reports cleanup ([#22844](https://github.com/frappe/erpnext/pull/22844)) +- Open lead status on next contact date ([#23445](https://github.com/frappe/erpnext/pull/23445)) +- Quoted Item Comparison Report Enhancements v2 ([#23127](https://github.com/frappe/erpnext/pull/23127)) +- Added phone field in product Inquiry ([#23170](https://github.com/frappe/erpnext/pull/23170)) +- Added address template for luxembourg ([#23621](https://github.com/frappe/erpnext/pull/23621)) +- Provision to draft quotation from portal ([#23416](https://github.com/frappe/erpnext/pull/23416)) +- M-pesa integration ([#23439](https://github.com/frappe/erpnext/pull/23439)) +- Education Desk, Dashboard, and Onboarding ([#22825](https://github.com/frappe/erpnext/pull/22825)) +- Added search to support page ([#22447](https://github.com/frappe/erpnext/pull/22447)) +- Balance Serial Nos in Stock Ledger report ([#23675](https://github.com/frappe/erpnext/pull/23675)) +- Added POS Register report ([#23313](https://github.com/frappe/erpnext/pull/23313)) +- Added Project in Sales Analytics report ([#23309](https://github.com/frappe/erpnext/pull/23309)) +- Enhancement in Loan Topups ([#23049](https://github.com/frappe/erpnext/pull/23049)) +- Inpatient Medication Order and Entry ([#23473](https://github.com/frappe/erpnext/pull/23473)) +- Option to print UOM after quantity ([#23263](https://github.com/frappe/erpnext/pull/23263)) +- Supplier Quotation Comparison report ([#23323](https://github.com/frappe/erpnext/pull/23323)) +- Supplier Sourced Items in BOM ([#23557](https://github.com/frappe/erpnext/pull/23557)) +- Therapy Plan Template ([#23558](https://github.com/frappe/erpnext/pull/23558)) +- Youtube interactions via Video ([#22867](https://github.com/frappe/erpnext/pull/22867)) +- Laboratory Module ([#22853](https://github.com/frappe/erpnext/pull/22853)) +- Shift management ([#22262](https://github.com/frappe/erpnext/pull/22262)) + +#### Fixes +- Multiple pos issues ([#23725](https://github.com/frappe/erpnext/pull/23725)) +- Calculate taxes if tax is based on item quantity and inclusive on item price ([#23001](https://github.com/frappe/erpnext/pull/23001)) +- Contact us button not visible in the website for the non variant items ([#23217](https://github.com/frappe/erpnext/pull/23217)) +- Loan Security shortfall calculation fixes ([#22866](https://github.com/frappe/erpnext/pull/22866)) +- Not able to make Material Request from Sales Order ([#23669](https://github.com/frappe/erpnext/pull/23669)) +- Capture advance payments in payment order ([#23256](https://github.com/frappe/erpnext/pull/23256)) +- Program and Course Enrollment fixes ([#23333](https://github.com/frappe/erpnext/pull/23333)) +- Cannot create asset if cwip disabled and account not set ([#23580](https://github.com/frappe/erpnext/pull/23580)) +- Cannot merge pos invoices with inclusive tax ([#23541](https://github.com/frappe/erpnext/pull/23541)) +- Do not allow Company as accounting dimension ([#23755](https://github.com/frappe/erpnext/pull/23755)) +- Set value of wrong Bank Account field in Payment Entry ([#22302](https://github.com/frappe/erpnext/pull/22302)) +- Reverse journal entry for multi-currency ([#23165](https://github.com/frappe/erpnext/pull/23165)) +- Updated integrations desk page ([#23772](https://github.com/frappe/erpnext/pull/23772)) +- Assessment Result child table not visible when accessed via Assessment Plan dashboard ([#22880](https://github.com/frappe/erpnext/pull/22880)) +- Conversion factor fixes in Stock Entry ([#23407](https://github.com/frappe/erpnext/pull/23407)) +- Total calculations for multi-currency RCM invoices ([#23072](https://github.com/frappe/erpnext/pull/23072)) +- Show accounts in financial statements upto level 20 ([#23718](https://github.com/frappe/erpnext/pull/23718)) +- Consolidated financial statement sums values into wrong parent ([#23288](https://github.com/frappe/erpnext/pull/23288)) +- Set SLA variance in seconds for Duration fieldtype ([#23765](https://github.com/frappe/erpnext/pull/23765)) +- Added missing reports on selling desk ([#23548](https://github.com/frappe/erpnext/pull/23548)) +- Fixed heading in the mobile view ([#23145](https://github.com/frappe/erpnext/pull/23145)) +- Misleading filters on Item tax Template Link field ([#22918](https://github.com/frappe/erpnext/pull/22918)) +- Do not consider opening entries for TDS calculation ([#23597](https://github.com/frappe/erpnext/pull/23597)) +- Attendance calendar map fix ([#23245](https://github.com/frappe/erpnext/pull/23245)) +- Post cancellation accounting entry on posting date instead of current ([#23361](https://github.com/frappe/erpnext/pull/23361)) +- Set Customer only if Contact is present ([#23704](https://github.com/frappe/erpnext/pull/23704)) +- Add Delivery Note Count in Sales Invoice Dashboard ([#23161](https://github.com/frappe/erpnext/pull/23161)) +- Breadcrumbs for Maintenance Visit and Schedule ([#23369](https://github.com/frappe/erpnext/pull/23369)) +- Raise Error on over receipt/consumption for sub-contracted PR ([#23195](https://github.com/frappe/erpnext/pull/23195)) +- Validate if company not set in the Payment Entry ([#23419](https://github.com/frappe/erpnext/pull/23419)) +- Ignore company and bank account doctype while deleting company transactions ([#22953](https://github.com/frappe/erpnext/pull/22953)) +- Sales funnel data is inconsistent ([#23110](https://github.com/frappe/erpnext/pull/23110)) +- Credit Limit Email not working ([#23059](https://github.com/frappe/erpnext/pull/23059)) +- Add Company in list fields to fetch for Expense Claim ([#23007](https://github.com/frappe/erpnext/pull/23007)) +- Issue form cleaned up and renamed Minutes to First Response field ([#23066](https://github.com/frappe/erpnext/pull/23066)) +- Quotation lost reason options fix ([#22814](https://github.com/frappe/erpnext/pull/22814)) +- Tax amounts in HSN Wise Outward summary ([#23076](https://github.com/frappe/erpnext/pull/23076)) +- Patient Appointment not able to save ([#23434](https://github.com/frappe/erpnext/pull/23434)) +- Removed Working Hours field from Company ([#23009](https://github.com/frappe/erpnext/pull/23009)) +- Added check-in time validation in the Inpatient Record - Transfer ([#22958](https://github.com/frappe/erpnext/pull/22958)) +- Handle Blank from/to range in Numeric Item Attribute ([#23483](https://github.com/frappe/erpnext/pull/23483)) +- Sequence Matcher error in Bank Reconciliation ([#23539](https://github.com/frappe/erpnext/pull/23539)) +- Fixed Conversion Factor rate for the BOM Exploded Item ([#23151](https://github.com/frappe/erpnext/pull/23151)) +- Payment Schedule not fetching ([#23476](https://github.com/frappe/erpnext/pull/23476)) +- Validate if removed Item Attributes exist in variant items ([#22911](https://github.com/frappe/erpnext/pull/22911)) +- Set default billing address for purchase documents ([#22950](https://github.com/frappe/erpnext/pull/22950)) +- Added help link in navbar settings ([#22943](https://github.com/frappe/erpnext/pull/22943)) +- Apply TDS on Purchase Invoice creation from Purchase Order and Purchase Receipt ([#23282](https://github.com/frappe/erpnext/pull/23282)) +- Education Module fixes ([#23714](https://github.com/frappe/erpnext/pull/23714)) +- Filter out cancelled entries in customer ledger summary ([#23205](https://github.com/frappe/erpnext/pull/23205)) +- Fiscal Year and Tax Rates for Italy ([#23623](https://github.com/frappe/erpnext/pull/23623)) +- Production Plan incorrect Work Order qty ([#23264](https://github.com/frappe/erpnext/pull/23264)) +- Added new filters in the Batch-wise Balance History report ([#23676](https://github.com/frappe/erpnext/pull/23676)) +- Update state code and union territory for Daman and Diu ([#22988](https://github.com/frappe/erpnext/pull/22988)) +- Set Stock UOM in item while creating Material Request from Stock Entry ([#23436](https://github.com/frappe/erpnext/pull/23436)) +- Sales Order to Purchase Order flow improvement ([#23357](https://github.com/frappe/erpnext/pull/23357)) +- Student Admission and Student Applicant fixes ([#23515](https://github.com/frappe/erpnext/pull/23515)) From e7ab61da9a69c146c74ec69572011947b14e4ae6 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Fri, 6 Nov 2020 19:23:55 +0550 Subject: [PATCH 209/449] bumped to version 13.0.0-beta.5 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 9f658253ef..2e281d6824 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0-beta.4' +__version__ = '13.0.0-beta.5' def get_default_company(user=None): '''Get default company for user''' From 30c704a4cb755c51ad7f46acd32d6cccfa6b3dc4 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 13 Nov 2020 22:17:07 +0530 Subject: [PATCH 210/449] fix: not able to save bom --- erpnext/manufacturing/doctype/bom/bom.py | 31 +++++++++--------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 2ab1b98707..8888a96768 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -76,6 +76,7 @@ class BOM(WebsiteGenerator): self.set_routing_operations() self.validate_operations() self.calculate_cost() + self.update_stock_qty() self.update_cost(update_parent=False, from_child_bom=True, save=False) def get_context(self, context): @@ -84,8 +85,6 @@ class BOM(WebsiteGenerator): def on_update(self): frappe.cache().hdel('bom_children', self.name) self.check_recursion() - self.update_stock_qty() - self.update_exploded_items() def on_submit(self): self.manage_default_bom() @@ -237,7 +236,8 @@ class BOM(WebsiteGenerator): self.calculate_cost() if save: self.db_update() - self.update_exploded_items() + + self.update_exploded_items(save=save) # update parent BOMs if self.total_cost != existing_bom_cost and update_parent: @@ -318,8 +318,6 @@ class BOM(WebsiteGenerator): m.uom = m.stock_uom m.qty = m.stock_qty - m.db_update() - def validate_uom_is_interger(self): from erpnext.utilities.transaction_base import validate_uom_is_integer validate_uom_is_integer(self, "uom", "qty", "BOM Item") @@ -372,15 +370,6 @@ class BOM(WebsiteGenerator): if raise_exception: frappe.throw(_("BOM recursion: {0} cannot be parent or child of {1}").format(self.name, self.name)) - def update_cost_and_exploded_items(self, bom_list=[]): - bom_list = self.traverse_tree(bom_list) - for bom in bom_list: - bom_obj = frappe.get_doc("BOM", bom) - bom_obj.check_recursion(bom_list=bom_list) - bom_obj.update_exploded_items() - - return bom_list - def traverse_tree(self, bom_list=None): def _get_children(bom_no): children = frappe.cache().hget('bom_children', bom_no) @@ -472,10 +461,10 @@ class BOM(WebsiteGenerator): d.rate = rate d.amount = (d.stock_qty or d.qty) * rate - def update_exploded_items(self): + def update_exploded_items(self, save=True): """ Update Flat BOM, following will be correct data""" self.get_exploded_items() - self.add_exploded_items() + self.add_exploded_items(save=save) def get_exploded_items(self): """ Get all raw materials including items from child bom""" @@ -544,11 +533,13 @@ class BOM(WebsiteGenerator): 'sourced_by_supplier': d.get('sourced_by_supplier', 0) })) - def add_exploded_items(self): + def add_exploded_items(self, save=True): "Add items to Flat BOM table" - frappe.db.sql("""delete from `tabBOM Explosion Item` where parent=%s""", self.name) self.set('exploded_items', []) + if save: + frappe.db.sql("""delete from `tabBOM Explosion Item` where parent=%s""", self.name) + for d in sorted(self.cur_exploded_items, key=itemgetter(0)): ch = self.append('exploded_items', {}) for i in self.cur_exploded_items[d].keys(): @@ -556,7 +547,9 @@ class BOM(WebsiteGenerator): ch.amount = flt(ch.stock_qty) * flt(ch.rate) ch.qty_consumed_per_unit = flt(ch.stock_qty) / flt(self.quantity) ch.docstatus = self.docstatus - ch.db_insert() + + if save: + ch.db_insert() def validate_bom_links(self): if not self.is_active: From b6ef59f8e95dc3947be7532201f9f7812b361236 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 18 Nov 2020 17:57:35 +0530 Subject: [PATCH 211/449] fix: incorrect delink serial no and batch --- erpnext/controllers/stock_controller.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 9f69bd610d..4aa1cad85e 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -229,8 +229,10 @@ class StockController(AccountsController): def check_expense_account(self, item): if not item.get("expense_account"): - frappe.throw(_("Row #{0}: Expense Account not set for Item {1}. Please set an Expense Account in the Items table") - .format(item.idx, frappe.bold(item.item_code)), title=_("Expense Account Missing")) + msg = _("Please set an Expense Account in the Items table") + frappe.throw(_("Row #{0}: Expense Account not set for the Item {1}. {2}") + .format(item.idx, frappe.bold(item.item_code), msg), title=_("Expense Account Missing")) + else: is_expense_account = frappe.db.get_value("Account", item.get("expense_account"), "report_type")=="Profit and Loss" @@ -245,15 +247,16 @@ class StockController(AccountsController): for d in self.items: if not d.batch_no: continue - serial_nos = [sr.name for sr in frappe.get_all("Serial No", {'batch_no': d.batch_no})] - if serial_nos: - frappe.db.set_value("Serial No", { 'name': ['in', serial_nos] }, "batch_no", None) - d.batch_no = None d.db_set("batch_no", None) for data in frappe.get_all("Batch", {'reference_name': self.name, 'reference_doctype': self.doctype}): + + serial_nos = [sr.name for sr in frappe.get_all("Serial No", {'batch_no': data.name})] + if serial_nos: + frappe.db.set_value("Serial No", { 'name': ['in', serial_nos] }, "batch_no", None) + frappe.delete_doc("Batch", data.name) def get_sl_entries(self, d, args): From 0b7180146201beda0a0bb0cff30faf0ef2157f31 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 20 Nov 2020 12:59:00 +0530 Subject: [PATCH 212/449] fix: incorrect delink serial no and batch --- erpnext/controllers/stock_controller.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 4aa1cad85e..2d2fff8fd5 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -247,16 +247,17 @@ class StockController(AccountsController): for d in self.items: if not d.batch_no: continue + serial_nos = [sr.name for sr in frappe.get_all("Serial No", + {'batch_no': d.batch_no, 'status': 'Inactive'})] + + if serial_nos: + frappe.db.set_value("Serial No", { 'name': ['in', serial_nos] }, "batch_no", None) + d.batch_no = None d.db_set("batch_no", None) for data in frappe.get_all("Batch", {'reference_name': self.name, 'reference_doctype': self.doctype}): - - serial_nos = [sr.name for sr in frappe.get_all("Serial No", {'batch_no': data.name})] - if serial_nos: - frappe.db.set_value("Serial No", { 'name': ['in', serial_nos] }, "batch_no", None) - frappe.delete_doc("Batch", data.name) def get_sl_entries(self, d, args): From ecc50c8c24f322339bbdc3eae1e5062b85841382 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Fri, 20 Nov 2020 15:22:00 +0550 Subject: [PATCH 213/449] bumped to version 13.0.0-beta.6 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 2e281d6824..14d3563262 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0-beta.5' +__version__ = '13.0.0-beta.6' def get_default_company(user=None): '''Get default company for user''' From 6273d3ada64546541f416ee14fe7d68d8ed09203 Mon Sep 17 00:00:00 2001 From: prssanna Date: Wed, 28 Oct 2020 11:02:02 +0530 Subject: [PATCH 214/449] fix: override field_map for job card gantt --- .../doctype/job_card/job_card_calendar.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/erpnext/manufacturing/doctype/job_card/job_card_calendar.js b/erpnext/manufacturing/doctype/job_card/job_card_calendar.js index cf07698ad6..f4877fdca0 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card_calendar.js +++ b/erpnext/manufacturing/doctype/job_card/job_card_calendar.js @@ -8,7 +8,17 @@ frappe.views.calendar["Job Card"] = { "allDay": "allDay", "progress": "progress" }, - gantt: true, + gantt: { + field_map: { + "start": "started_time", + "end": "started_time", + "id": "name", + "title": "subject", + "color": "color", + "allDay": "allDay", + "progress": "progress" + } + }, filters: [ { "fieldtype": "Link", From ad59726f20ef279c5149aa50c9347a3c74f406bf Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 16 Dec 2020 13:00:55 +0530 Subject: [PATCH 215/449] fix: Tax template update on customer address change --- erpnext/regional/india/taxes.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/erpnext/regional/india/taxes.js b/erpnext/regional/india/taxes.js index 4d36cff1e6..3c70ca8e10 100644 --- a/erpnext/regional/india/taxes.js +++ b/erpnext/regional/india/taxes.js @@ -9,6 +9,9 @@ erpnext.setup_auto_gst_taxation = (doctype) => { tax_category: function(frm) { frm.trigger('get_tax_template'); }, + customer_address: function(frm) { + frm.trigger('get_tax_template'); + }, get_tax_template: function(frm) { let party_details = { 'shipping_address': frm.doc.shipping_address || '', From e77e3aa36d8cd7865f6ea658b69b22cd8b58a485 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 17 Dec 2020 18:46:59 +0530 Subject: [PATCH 216/449] fix: Typo in tax category doctype query --- erpnext/regional/india/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index 4a547a2931..95ff291516 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -53,7 +53,7 @@ def validate_gstin_for_india(doc, method): .format(doc.gst_state_number)) def validate_tax_category(doc, method): - if doc.get('gst_state') and frappe.db.get_value('Tax category', {'gst_state': doc.gst_state, 'is_inter_state': doc.is_inter_state}): + if doc.get('gst_state') and frappe.db.get_value('Tax Category', {'gst_state': doc.gst_state, 'is_inter_state': doc.is_inter_state}): if doc.is_inter_state: frappe.throw(_("Inter State tax category for GST State {0} already exists").format(doc.gst_state)) else: From bd4bdca6ada2a5a2c4d5987958cca4a674254252 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 21 Dec 2020 20:03:59 +0530 Subject: [PATCH 217/449] feat: Repost item costing (#24183) * Repost item valuation (#24031) * feat: Reposting logic for future finished/transferred item * feat: added fields to identify needs to recalculate rate while reposting * refactor: Set rate for outgoing and finished items * refactor: Arranged fields in Stock Entry item table and added fields to identify finished and scrap item * refactor: Arranged fields in Stock Entry item table and added fields to identify finished and scrap item * refactor: Get outgoing rate for purchase return * refactor: Get incoming rate for sales return * test: Added tests for reposting valuation of transferred/finished/returned items * feat: added incoming rate field in DN, SI and Packed Item table * feat: get incoming rate for returned item * fix: no error while getting valuation rate in stock entry * fix: update stock ledger for DN and SI * feat: update item valuation rate in PR and PI based on supplied items cost * feat: SLE reposting logic for sales return and subcontracted item with test cases * feat: update qty in future sle * feat: repost future sle and gle via Repost Item Valuation * fix: Skip unwanted function calling while reposting * fix: repost sle for specific item and warehouse * test: Modified tests for backdated stock reco * fix: ignore cancelled sle in few methods * feat: role allowed to do backdated entry * feat: Show reposting status on stock valuation related reports * fix: minor fixes * fix: fixed sider issues * fix: serial no fix related to immutable ledger * fix: Test cases fixes related to perpetual inventory * fix: Test cases fixed * fix: Fixed reposting on cancel and test cases * feat: Restart reposting item valuation * refactor: Code cleanup using small functions and test case fixes * fix: minor fixes * fix: Raise on error while reposting item valuation * fix: minor fix * fix: Tests fixed * fix: skip some validation ig gle made from reposting * fix: test fixes * fix: debugging stock and account validation * fix: debugging stock and account validation * fix: debugging travis for stock and account sync validation * fix: debugging travis * fix: debugging travis * fix: debugging travis * fix: removed duplicate field from pos profile --- .../accounts/doctype/account/test_account.py | 2 +- .../doctype/coupon_code/test_coupon_code.py | 50 +- erpnext/accounts/doctype/gl_entry/gl_entry.py | 24 +- .../journal_entry/test_journal_entry.py | 68 +- .../loyalty_program/test_loyalty_program.py | 2 - .../doctype/pos_profile/pos_profile.json | 3 +- .../purchase_invoice/purchase_invoice.py | 19 +- .../purchase_invoice/test_purchase_invoice.py | 72 +-- .../doctype/sales_invoice/sales_invoice.py | 17 +- .../doctype/sales_invoice/test_records.json | 3 +- .../sales_invoice/test_sales_invoice.py | 128 ++-- .../sales_invoice_item.json | 30 +- erpnext/accounts/general_ledger.py | 38 +- erpnext/accounts/utils.py | 24 +- .../purchase_order_item.json | 2 +- erpnext/controllers/buying_controller.py | 129 ++-- .../controllers/sales_and_purchase_return.py | 42 ++ erpnext/controllers/selling_controller.py | 116 ++-- erpnext/controllers/stock_controller.py | 101 +-- .../doctype/work_order/test_work_order.py | 2 - .../sales_order_item/sales_order_item.json | 2 +- .../setup/doctype/company/test_records.json | 18 +- erpnext/stock/doctype/batch/test_batch.py | 5 - erpnext/stock/doctype/bin/bin.py | 14 +- .../doctype/delivery_note/delivery_note.py | 4 +- .../delivery_note/test_delivery_note.py | 7 +- .../delivery_note_item.json | 11 +- erpnext/stock/doctype/item/test_records.json | 10 + .../item_alternative/test_item_alternative.py | 2 - .../landed_cost_taxes_and_charges.json | 8 +- .../landed_cost_voucher.py | 18 +- .../test_landed_cost_voucher.py | 12 +- .../material_request/test_material_request.py | 3 - .../doctype/packed_item/packed_item.json | 18 +- .../purchase_receipt/purchase_receipt.py | 4 +- .../purchase_receipt/test_purchase_receipt.py | 188 +++--- .../purchase_receipt_item.json | 2 +- .../doctype/repost_item_valuation/__init__.py | 0 .../repost_item_valuation.js | 52 ++ .../repost_item_valuation.json | 215 +++++++ .../repost_item_valuation.py | 89 +++ .../test_repost_item_valuation.py | 10 + erpnext/stock/doctype/serial_no/serial_no.py | 33 +- .../stock/doctype/serial_no/test_serial_no.py | 3 - .../stock/doctype/stock_entry/stock_entry.js | 25 +- .../doctype/stock_entry/stock_entry.json | 3 +- .../stock/doctype/stock_entry/stock_entry.py | 303 +++++---- .../doctype/stock_entry/test_stock_entry.py | 83 +-- .../stock_entry_detail.json | 74 ++- .../stock_ledger_entry.json | 62 +- .../stock_ledger_entry/stock_ledger_entry.py | 45 +- .../test_stock_ledger_entry.py | 395 +++++++++++- .../stock_reconciliation.py | 4 +- .../test_stock_reconciliation.py | 47 +- .../stock_settings/stock_settings.json | 31 +- .../stock/doctype/warehouse/test_warehouse.py | 61 +- erpnext/stock/doctype/warehouse/warehouse.py | 1 - .../report/stock_analytics/stock_analytics.py | 2 + .../report/stock_balance/stock_balance.py | 3 +- .../stock/report/stock_ledger/stock_ledger.py | 3 +- .../stock_projected_qty.py | 3 +- ...rehouse_wise_item_balance_age_and_value.py | 2 + erpnext/stock/stock_balance.py | 18 +- erpnext/stock/stock_ledger.py | 597 +++++++++++++----- erpnext/stock/utils.py | 11 +- 65 files changed, 2337 insertions(+), 1036 deletions(-) create mode 100644 erpnext/stock/doctype/repost_item_valuation/__init__.py create mode 100644 erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js create mode 100644 erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json create mode 100644 erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py create mode 100644 erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py diff --git a/erpnext/accounts/doctype/account/test_account.py b/erpnext/accounts/doctype/account/test_account.py index 0605d89a7e..113bea0064 100644 --- a/erpnext/accounts/doctype/account/test_account.py +++ b/erpnext/accounts/doctype/account/test_account.py @@ -172,7 +172,7 @@ class TestAccount(unittest.TestCase): frappe.delete_doc("Account", doc) -def _make_test_records(verbose): +def _make_test_records(verbose=None): from frappe.test_runner import make_test_objects accounts = [ diff --git a/erpnext/accounts/doctype/coupon_code/test_coupon_code.py b/erpnext/accounts/doctype/coupon_code/test_coupon_code.py index 340b9dd58a..622bd33e20 100644 --- a/erpnext/accounts/doctype/coupon_code/test_coupon_code.py +++ b/erpnext/accounts/doctype/coupon_code/test_coupon_code.py @@ -28,22 +28,22 @@ def test_create_test_data(): "item_group": "_Test Item Group", "item_name": "_Test Tesla Car", "apply_warehouse_wise_reorder_level": 0, - "warehouse":"Stores - TCP1", + "warehouse":"Stores - _TC", "gst_hsn_code": "999800", "valuation_rate": 5000, "standard_rate":5000, "item_defaults": [{ - "company": "_Test Company with perpetual inventory", - "default_warehouse": "Stores - TCP1", + "company": "_Test Company", + "default_warehouse": "Stores - _TC", "default_price_list":"_Test Price List", - "expense_account": "Cost of Goods Sold - TCP1", - "buying_cost_center": "Main - TCP1", - "selling_cost_center": "Main - TCP1", - "income_account": "Sales - TCP1" + "expense_account": "Cost of Goods Sold - _TC", + "buying_cost_center": "Main - _TC", + "selling_cost_center": "Main - _TC", + "income_account": "Sales - _TC" }], "show_in_website": 1, "route":"-test-tesla-car", - "website_warehouse": "Stores - TCP1" + "website_warehouse": "Stores - _TC" }) item.insert() # create test item price @@ -65,12 +65,12 @@ def test_create_test_data(): "items": [{ "item_code": "_Test Tesla Car" }], - "warehouse":"Stores - TCP1", + "warehouse":"Stores - _TC", "coupon_code_based":1, "selling": 1, "rate_or_discount": "Discount Percentage", "discount_percentage": 30, - "company": "_Test Company with perpetual inventory", + "company": "_Test Company", "currency":"INR", "for_price_list":"_Test Price List" }) @@ -85,7 +85,7 @@ def test_create_test_data(): }) sales_partner.insert() # create test item coupon code - if not frappe.db.exists("Coupon Code","SAVE30"): + if not frappe.db.exists("Coupon Code", "SAVE30"): coupon_code = frappe.get_doc({ "doctype": "Coupon Code", "coupon_name":"SAVE30", @@ -102,35 +102,27 @@ class TestCouponCode(unittest.TestCase): test_create_test_data() def tearDown(self): - frappe.set_user("Administrator") + frappe.set_user("Administrator") - def test_1_check_coupon_code_used_before_so(self): - coupon_code = frappe.get_doc("Coupon Code", frappe.db.get_value("Coupon Code", {"coupon_name":"SAVE30"})) - # reset used coupon code count - coupon_code.used=0 - coupon_code.save() - # check no coupon code is used before sales order is made - self.assertEqual(coupon_code.get("used"),0) + def test_sales_order_with_coupon_code(self): + frappe.db.set_value("Coupon Code", "SAVE30", "used", 0) - def test_2_sales_order_with_coupon_code(self): - so = make_sales_order(company='_Test Company with perpetual inventory', warehouse='Stores - TCP1', - customer="_Test Customer", selling_price_list="_Test Price List", item_code="_Test Tesla Car", rate=5000,qty=1, + so = make_sales_order(company='_Test Company', warehouse='Stores - _TC', + customer="_Test Customer", selling_price_list="_Test Price List", + item_code="_Test Tesla Car", rate=5000, qty=1, do_not_submit=True) - so = frappe.get_doc('Sales Order', so.name) - # check item price before coupon code is applied self.assertEqual(so.items[0].rate, 5000) + so.coupon_code='SAVE30' so.sales_partner='_Test Coupon Partner' so.save() + # check item price after coupon code is applied self.assertEqual(so.items[0].rate, 3500) + so.submit() - - def test_3_check_coupon_code_used_after_so(self): - doc = frappe.get_doc("Coupon Code", frappe.db.get_value("Coupon Code", {"coupon_name":"SAVE30"})) - # check no coupon code is used before sales order is made - self.assertEqual(doc.get("used"),1) + self.assertEqual(frappe.db.get_value("Coupon Code", "SAVE30", "used"), 1) diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py index def9ed6803..c441274908 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py @@ -30,20 +30,22 @@ class GLEntry(Document): self.pl_must_have_cost_center() self.validate_cost_center() - self.check_pl_account() - self.validate_party() - self.validate_currency() + if not self.flags.from_repost: + self.check_pl_account() + self.validate_party() + self.validate_currency() - def on_update_with_args(self, adv_adj, update_outstanding = 'Yes'): - self.validate_account_details(adv_adj) - self.validate_dimensions_for_pl_and_bs() + def on_update_with_args(self, adv_adj, update_outstanding = 'Yes', from_repost=False): + if not from_repost: + self.validate_account_details(adv_adj) + self.validate_dimensions_for_pl_and_bs() validate_frozen_account(self.account, adv_adj) validate_balance_type(self.account, adv_adj) # Update outstanding amt on against voucher if self.against_voucher_type in ['Journal Entry', 'Sales Invoice', 'Purchase Invoice', 'Fees'] \ - and self.against_voucher and update_outstanding == 'Yes': + and self.against_voucher and update_outstanding == 'Yes' and not from_repost: update_outstanding_amt(self.account, self.party_type, self.party, self.against_voucher_type, self.against_voucher) @@ -106,8 +108,8 @@ class GLEntry(Document): from tabAccount where name=%s""", self.account, as_dict=1)[0] if ret.is_group==1: - frappe.throw(_('''{0} {1}: Account {2} is a Group Account and group accounts cannot be used in - transactions''').format(self.voucher_type, self.voucher_no, self.account)) + frappe.throw(_('''{0} {1}: Account {2} is a Group Account and group accounts cannot be used in transactions''') + .format(self.voucher_type, self.voucher_no, self.account)) if ret.docstatus==2: frappe.throw(_("{0} {1}: Account {2} is inactive") @@ -136,8 +138,8 @@ class GLEntry(Document): .format(self.voucher_type, self.voucher_no, self.cost_center, self.company)) if self.cost_center and _check_is_group(): - frappe.throw(_("""{0} {1}: Cost Center {2} is a group cost center and group cost centers cannot - be used in transactions""").format(self.voucher_type, self.voucher_no, frappe.bold(self.cost_center))) + frappe.throw(_("""{0} {1}: Cost Center {2} is a group cost center and group cost centers cannot be used in transactions""") + .format(self.voucher_type, self.voucher_no, frappe.bold(self.cost_center))) def validate_party(self): validate_party_frozen_disabled(self.party_type, self.party) diff --git a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py index 53c07583d8..1d2eacdb80 100644 --- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py @@ -75,54 +75,40 @@ class TestJournalEntry(unittest.TestCase): elif test_voucher.doctype in ["Sales Order", "Purchase Order"]: # if test_voucher is a Sales Order/Purchase Order, test error on cancellation of test_voucher + frappe.db.set_value("Accounts Settings", "Accounts Settings", + "unlink_advance_payment_on_cancelation_of_order", 0) submitted_voucher = frappe.get_doc(test_voucher.doctype, test_voucher.name) self.assertRaises(frappe.LinkExistsError, submitted_voucher.cancel) def test_jv_against_stock_account(self): - from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory - set_perpetual_inventory() + company = "_Test Company with perpetual inventory" + stock_account = get_inventory_account(company) - jv = frappe.copy_doc({ - "cheque_date": nowdate(), - "cheque_no": "33", - "company": "_Test Company with perpetual inventory", - "doctype": "Journal Entry", - "accounts": [ - { - "account": "Debtors - TCP1", - "party_type": "Customer", - "party": "_Test Customer", - "credit_in_account_currency": 400.0, - "debit_in_account_currency": 0.0, - "doctype": "Journal Entry Account", - "parentfield": "accounts", - "cost_center": "Main - TCP1" - }, - { - "account": "_Test Bank - TCP1", - "credit_in_account_currency": 0.0, - "debit_in_account_currency": 400.0, - "doctype": "Journal Entry Account", - "parentfield": "accounts", - "cost_center": "Main - TCP1" - } - ], - "naming_series": "_T-Journal Entry-", - "posting_date": nowdate(), - "user_remark": "test", - "voucher_type": "Bank Entry" - }) - - jv.get("accounts")[0].update({ - "account": get_inventory_account('_Test Company with perpetual inventory'), - "company": "_Test Company with perpetual inventory", - "party_type": None, - "party": None + jv = frappe.new_doc("Journal Entry") + jv.company = company + jv.posting_date = nowdate() + jv.append("accounts", { + "account": stock_account, + "cost_center": "Main - TCP1", + "debit_in_account_currency": 100 }) + + jv.append("accounts", { + "account": "Stock Adjustment - TCP1", + "credit_in_account_currency": 100, + "cost_center": "Main - TCP1", + }) + jv.insert() - self.assertRaises(StockAccountInvalidTransaction, jv.submit) - jv.cancel() - set_perpetual_inventory(0) + from erpnext.accounts.utils import get_stock_and_account_balance + account_bal, stock_bal, warehouse_list = get_stock_and_account_balance(stock_account, nowdate(), company) + + if account_bal == stock_bal: + self.assertRaises(StockAccountInvalidTransaction, jv.submit) + frappe.db.rollback() + else: + jv.submit() + jv.cancel() def test_multi_currency(self): jv = make_journal_entry("_Test Bank USD - _TC", diff --git a/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py b/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py index 5278d8b241..31994885aa 100644 --- a/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py +++ b/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py @@ -8,12 +8,10 @@ import unittest from frappe.utils import today, cint, flt, getdate from erpnext.accounts.doctype.loyalty_program.loyalty_program import get_loyalty_program_details_with_points from erpnext.accounts.party import get_dashboard_info -from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory class TestLoyaltyProgram(unittest.TestCase): @classmethod def setUpClass(self): - set_perpetual_inventory(0) # create relevant item, customer, loyalty program, etc create_records() diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.json b/erpnext/accounts/doctype/pos_profile/pos_profile.json index 830896b736..750ed82d15 100644 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.json +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.json @@ -14,7 +14,6 @@ "column_break_9", "update_stock", "ignore_pricing_rule", - "hide_unavailable_items", "warehouse", "campaign", "company_address", @@ -336,7 +335,7 @@ "idx": 1, "index_web_pages_for_search": 1, "links": [], - "modified": "2020-12-10 13:59:28.877572", + "modified": "2020-12-20 13:59:28.877572", "modified_by": "Administrator", "module": "Accounts", "name": "POS Profile", diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index d94d261c6b..b52678e8d3 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -410,10 +410,13 @@ class PurchaseInvoice(BuyingController): # this sequence because outstanding may get -negative self.make_gl_entries() + if self.update_stock == 1: + self.repost_future_sle_and_gle() + self.update_project() update_linked_doc(self.doctype, self.name, self.inter_company_invoice_reference) - def make_gl_entries(self, gl_entries=None): + def make_gl_entries(self, gl_entries=None, from_repost=False): if not gl_entries: gl_entries = self.get_gl_entries() @@ -421,7 +424,7 @@ class PurchaseInvoice(BuyingController): update_outstanding = "No" if (cint(self.is_paid) or self.write_off_account) else "Yes" if self.docstatus == 1: - make_gl_entries(gl_entries, update_outstanding=update_outstanding, merge_entries=False) + make_gl_entries(gl_entries, update_outstanding=update_outstanding, merge_entries=False, from_repost=from_repost) elif self.docstatus == 2: make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name) @@ -436,9 +439,11 @@ class PurchaseInvoice(BuyingController): self.auto_accounting_for_stock = erpnext.is_perpetual_inventory_enabled(self.company) if self.auto_accounting_for_stock: self.stock_received_but_not_billed = self.get_company_default("stock_received_but_not_billed") + self.expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") else: self.stock_received_but_not_billed = None - self.expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") + self.expenses_included_in_valuation = None + self.negative_expense_to_be_booked = 0.0 gl_entries = [] @@ -452,7 +457,7 @@ class PurchaseInvoice(BuyingController): self.make_internal_transfer_gl_entries(gl_entries) gl_entries = make_regional_gl_entries(gl_entries, self) - + gl_entries = merge_similar_entries(gl_entries) self.make_payment_gl_entries(gl_entries) @@ -994,11 +999,15 @@ class PurchaseInvoice(BuyingController): self.delete_auto_created_batches() self.make_gl_entries_on_cancel() + + if self.update_stock == 1: + self.repost_future_sle_and_gle() + self.update_project() frappe.db.set(self, 'status', 'Cancelled') unlink_inter_company_doc(self.doctype, self.name, self.inter_company_invoice_reference) - self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry') + self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry', 'Repost Item Valuation') def update_project(self): project_list = [] diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index f2499d24b5..c0506ba97f 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -9,8 +9,7 @@ import frappe.model from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from frappe.utils import cint, flt, today, nowdate, add_days, getdate import frappe.defaults -from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory, \ - test_records as pr_test_records, make_purchase_receipt, get_taxes +from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt, get_taxes from erpnext.controllers.accounts_controller import get_payment_terms from erpnext.exceptions import InvalidCurrency from erpnext.stock.doctype.stock_entry.test_stock_entry import get_qty_after_transaction @@ -33,13 +32,10 @@ class TestPurchaseInvoice(unittest.TestCase): def test_gl_entries_without_perpetual_inventory(self): frappe.db.set_value("Company", "_Test Company", "round_off_account", "Round Off - _TC") - wrapper = frappe.copy_doc(test_records[0]) - set_perpetual_inventory(0, wrapper.company) - self.assertTrue(not cint(erpnext.is_perpetual_inventory_enabled(wrapper.company))) - wrapper.insert() - wrapper.submit() - wrapper.load_from_db() - dl = wrapper + pi = frappe.copy_doc(test_records[0]) + self.assertTrue(not cint(erpnext.is_perpetual_inventory_enabled(pi.company))) + pi.insert() + pi.submit() expected_gl_entries = { "_Test Payable - _TC": [0, 1512.0], @@ -54,12 +50,16 @@ class TestPurchaseInvoice(unittest.TestCase): "Round Off - _TC": [0, 0.3] } gl_entries = frappe.db.sql("""select account, debit, credit from `tabGL Entry` - where voucher_type = 'Purchase Invoice' and voucher_no = %s""", dl.name, as_dict=1) + where voucher_type = 'Purchase Invoice' and voucher_no = %s""", pi.name, as_dict=1) for d in gl_entries: self.assertEqual([d.debit, d.credit], expected_gl_entries.get(d.account)) def test_gl_entries_with_perpetual_inventory(self): - pi = make_purchase_invoice(company="_Test Company with perpetual inventory", supplier_warehouse="Work In Progress - TCP1", warehouse= "Stores - TCP1", cost_center = "Main - TCP1", expense_account ="_Test Account Cost for Goods Sold - TCP1", get_taxes_and_charges=True, qty=10) + pi = make_purchase_invoice(company="_Test Company with perpetual inventory", + warehouse= "Stores - TCP1", cost_center = "Main - TCP1", + expense_account ="_Test Account Cost for Goods Sold - TCP1", + get_taxes_and_charges=True, qty=10) + self.assertTrue(cint(erpnext.is_perpetual_inventory_enabled(pi.company)), 1) self.check_gle_for_pi(pi.name) @@ -198,8 +198,6 @@ class TestPurchaseInvoice(unittest.TestCase): pr = make_purchase_receipt(company="_Test Company with perpetual inventory", supplier_warehouse="Work In Progress - TCP1", warehouse= "Stores - TCP1", cost_center = "Main - TCP1", get_taxes_and_charges=True,) - self.assertTrue(cint(erpnext.is_perpetual_inventory_enabled(pr.company)), 1) - pi = make_purchase_invoice(company="_Test Company with perpetual inventory", supplier_warehouse="Work In Progress - TCP1", warehouse= "Stores - TCP1", cost_center = "Main - TCP1", expense_account ="_Test Account Cost for Goods Sold - TCP1", get_taxes_and_charges=True, qty=10,do_not_save= "True") for d in pi.items: @@ -247,17 +245,11 @@ class TestPurchaseInvoice(unittest.TestCase): self.assertRaises(frappe.CannotChangeConstantError, pi.save) - def test_gl_entries_with_aia_for_non_stock_items(self): - pi = frappe.copy_doc(test_records[1]) - set_perpetual_inventory(1, pi.company) - self.assertTrue(cint(erpnext.is_perpetual_inventory_enabled(pi.company)), 1) - pi.get("items")[0].item_code = "_Test Non Stock Item" - pi.get("items")[0].expense_account = "_Test Account Cost for Goods Sold - _TC" - pi.get("taxes").pop(0) - pi.get("taxes").pop(1) - pi.insert() - pi.submit() - pi.load_from_db() + def test_gl_entries_for_non_stock_items_with_perpetual_inventory(self): + pi = make_purchase_invoice(item_code = "_Test Non Stock Item", + company = "_Test Company with perpetual inventory", warehouse= "Stores - TCP1", + cost_center = "Main - TCP1", expense_account ="_Test Account Cost for Goods Sold - TCP1") + self.assertTrue(pi.status, "Unpaid") gl_entries = frappe.db.sql("""select account, debit, credit @@ -265,17 +257,15 @@ class TestPurchaseInvoice(unittest.TestCase): order by account asc""", pi.name, as_dict=1) self.assertTrue(gl_entries) - expected_values = sorted([ - ["_Test Payable - _TC", 0, 620], - ["_Test Account Cost for Goods Sold - _TC", 500.0, 0], - ["_Test Account VAT - _TC", 120.0, 0], - ]) + expected_values = [ + ["_Test Account Cost for Goods Sold - TCP1", 250.0, 0], + ["Creditors - TCP1", 0, 250] + ] for i, gle in enumerate(gl_entries): self.assertEqual(expected_values[i][0], gle.account) self.assertEqual(expected_values[i][1], gle.debit) self.assertEqual(expected_values[i][2], gle.credit) - set_perpetual_inventory(0, pi.company) def test_purchase_invoice_calculation(self): pi = frappe.copy_doc(test_records[0]) @@ -457,12 +447,13 @@ class TestPurchaseInvoice(unittest.TestCase): pi.cancel() self.assertEqual(frappe.db.get_value("Project", "_Test Project", "total_purchase_cost"), existing_purchase_cost) - def test_return_purchase_invoice(self): - set_perpetual_inventory() + def test_return_purchase_invoice_with_perpetual_inventory(self): + pi = make_purchase_invoice(company = "_Test Company with perpetual inventory", warehouse= "Stores - TCP1", + cost_center = "Main - TCP1", expense_account ="_Test Account Cost for Goods Sold - TCP1") - pi = make_purchase_invoice() - - return_pi = make_purchase_invoice(is_return=1, return_against=pi.name, qty=-2) + return_pi = make_purchase_invoice(is_return=1, return_against=pi.name, qty=-2, + company = "_Test Company with perpetual inventory", warehouse= "Stores - TCP1", + cost_center = "Main - TCP1", expense_account ="_Test Account Cost for Goods Sold - TCP1") # check gl entries for return @@ -473,19 +464,15 @@ class TestPurchaseInvoice(unittest.TestCase): self.assertTrue(gl_entries) expected_values = { - "Creditors - _TC": [100.0, 0.0], - "Stock Received But Not Billed - _TC": [0.0, 100.0], + "Creditors - TCP1": [100.0, 0.0], + "Stock Received But Not Billed - TCP1": [0.0, 100.0], } for gle in gl_entries: self.assertEqual(expected_values[gle.account][0], gle.debit) self.assertEqual(expected_values[gle.account][1], gle.credit) - set_perpetual_inventory(0) - def test_multi_currency_gle(self): - set_perpetual_inventory(0) - pi = make_purchase_invoice(supplier="_Test Supplier USD", credit_to="_Test Payable USD - _TC", currency="USD", conversion_rate=50) @@ -640,10 +627,9 @@ class TestPurchaseInvoice(unittest.TestCase): self.assertEqual(len(pi.get("supplied_items")), 2) rm_supp_cost = sum([d.amount for d in pi.get("supplied_items")]) - self.assertEqual(pi.get("items")[0].rm_supp_cost, flt(rm_supp_cost, 2)) + self.assertEqual(flt(pi.get("items")[0].rm_supp_cost, 2), flt(rm_supp_cost, 2)) def test_rejected_serial_no(self): - set_perpetual_inventory(0) pi = make_purchase_invoice(item_code="_Test Serialized Item With Series", received_qty=2, qty=1, rejected_qty=1, rate=500, update_stock=1, rejected_warehouse = "_Test Rejected Warehouse - _TC") diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index ca6f22cc30..50734c865c 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -179,6 +179,9 @@ class SalesInvoice(SellingController): # this sequence because outstanding may get -ve self.make_gl_entries() + + if self.update_stock == 1: + self.repost_future_sle_and_gle() if not self.is_return: self.update_billing_status_for_zero_amount_refdoc("Delivery Note") @@ -258,6 +261,10 @@ class SalesInvoice(SellingController): self.update_stock_ledger() self.make_gl_entries_on_cancel() + + if self.update_stock == 1: + self.repost_future_sle_and_gle() + frappe.db.set(self, 'status', 'Cancelled') if frappe.db.get_single_value('Selling Settings', 'sales_update_frequency') == "Each Transaction": @@ -279,7 +286,7 @@ class SalesInvoice(SellingController): if "Healthcare" in active_domains: manage_invoice_submit_cancel(self, "on_cancel") - self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry') + self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry', 'Repost Item Valuation') def update_status_updater_args(self): if cint(self.update_stock): @@ -722,22 +729,20 @@ class SalesInvoice(SellingController): if d.delivery_note and frappe.db.get_value("Delivery Note", d.delivery_note, "docstatus") != 1: throw(_("Delivery Note {0} is not submitted").format(d.delivery_note)) - def make_gl_entries(self, gl_entries=None): - from erpnext.accounts.general_ledger import make_reverse_gl_entries + def make_gl_entries(self, gl_entries=None, from_repost=False): + from erpnext.accounts.general_ledger import make_gl_entries, make_reverse_gl_entries auto_accounting_for_stock = erpnext.is_perpetual_inventory_enabled(self.company) if not gl_entries: gl_entries = self.get_gl_entries() if gl_entries: - from erpnext.accounts.general_ledger import make_gl_entries - # if POS and amount is written off, updating outstanding amt after posting all gl entries update_outstanding = "No" if (cint(self.is_pos) or self.write_off_account or cint(self.redeem_loyalty_points)) else "Yes" if self.docstatus == 1: - make_gl_entries(gl_entries, update_outstanding=update_outstanding, merge_entries=False) + make_gl_entries(gl_entries, update_outstanding=update_outstanding, merge_entries=False, from_repost=from_repost) elif self.docstatus == 2: make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name) diff --git a/erpnext/accounts/doctype/sales_invoice/test_records.json b/erpnext/accounts/doctype/sales_invoice/test_records.json index 11ebe6a573..ee6419db20 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_records.json +++ b/erpnext/accounts/doctype/sales_invoice/test_records.json @@ -17,7 +17,8 @@ "description": "138-CMS Shoe", "doctype": "Sales Invoice Item", "income_account": "Sales - _TC", - "expense_account": "_Test Account Cost for Goods Sold - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "item_code": "138-CMS Shoe", "item_name": "138-CMS Shoe", "parentfield": "items", "qty": 1.0, diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 22a4f33654..ceb7907989 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -10,7 +10,6 @@ from frappe.model.dynamic_links import get_dynamic_link_map from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry, get_qty_after_transaction from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import unlink_payment_on_cancel_of_invoice from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profile -from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory from erpnext.exceptions import InvalidAccountCurrency, InvalidCurrency from erpnext.stock.doctype.serial_no.serial_no import SerialNoWarehouseError from frappe.model.naming import make_autoname @@ -659,7 +658,6 @@ class TestSalesInvoice(unittest.TestCase): def test_sales_invoice_gl_entry_without_perpetual_inventory(self): si = frappe.copy_doc(test_records[1]) - set_perpetual_inventory(0, si.company) si.insert() si.submit() @@ -815,7 +813,6 @@ class TestSalesInvoice(unittest.TestCase): frappe.db.sql("delete from `tabPOS Profile`") def test_pos_si_without_payment(self): - set_perpetual_inventory() make_pos_profile() pos = copy.deepcopy(test_records[1]) @@ -829,9 +826,8 @@ class TestSalesInvoice(unittest.TestCase): self.assertRaises(frappe.ValidationError, si.submit) def test_sales_invoice_gl_entry_with_perpetual_inventory_no_item_code(self): - set_perpetual_inventory() - - si = frappe.get_doc(test_records[1]) + si = create_sales_invoice(company="_Test Company with perpetual inventory", debit_to = "Debtors - TCP1", + income_account="Sales - TCP1", cost_center = "Main - TCP1", do_not_save=True) si.get("items")[0].item_code = None si.insert() si.submit() @@ -842,24 +838,16 @@ class TestSalesInvoice(unittest.TestCase): self.assertTrue(gl_entries) expected_values = dict((d[0], d) for d in [ - [si.debit_to, 630.0, 0.0], - [test_records[1]["items"][0]["income_account"], 0.0, 500.0], - [test_records[1]["taxes"][0]["account_head"], 0.0, 80.0], - [test_records[1]["taxes"][1]["account_head"], 0.0, 50.0], + ["Debtors - TCP1", 100.0, 0.0], + ["Sales - TCP1", 0.0, 100.0] ]) for i, gle in enumerate(gl_entries): self.assertEqual(expected_values[gle.account][0], gle.account) self.assertEqual(expected_values[gle.account][1], gle.debit) self.assertEqual(expected_values[gle.account][2], gle.credit) - set_perpetual_inventory(0) - def test_sales_invoice_gl_entry_with_perpetual_inventory_non_stock_item(self): - set_perpetual_inventory() - si = frappe.get_doc(test_records[1]) - si.get("items")[0].item_code = "_Test Non Stock Item" - si.insert() - si.submit() + si = create_sales_invoice(item="_Test Non Stock Item") gl_entries = frappe.db.sql("""select account, debit, credit from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s @@ -867,17 +855,14 @@ class TestSalesInvoice(unittest.TestCase): self.assertTrue(gl_entries) expected_values = dict((d[0], d) for d in [ - [si.debit_to, 630.0, 0.0], - [test_records[1]["items"][0]["income_account"], 0.0, 500.0], - [test_records[1]["taxes"][0]["account_head"], 0.0, 80.0], - [test_records[1]["taxes"][1]["account_head"], 0.0, 50.0], + [si.debit_to, 100.0, 0.0], + [test_records[1]["items"][0]["income_account"], 0.0, 100.0] ]) for i, gle in enumerate(gl_entries): self.assertEqual(expected_values[gle.account][0], gle.account) self.assertEqual(expected_values[gle.account][1], gle.debit) self.assertEqual(expected_values[gle.account][2], gle.credit) - set_perpetual_inventory(0) def _insert_purchase_receipt(self): from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import test_records \ @@ -1106,7 +1091,6 @@ class TestSalesInvoice(unittest.TestCase): self.assertEqual(si.grand_total, 859.43) def test_multi_currency_gle(self): - set_perpetual_inventory(0) si = create_sales_invoice(customer="_Test Customer USD", debit_to="_Test Receivable USD - _TC", currency="USD", conversion_rate=50) @@ -1776,64 +1760,69 @@ class TestSalesInvoice(unittest.TestCase): si.submit() target_doc = make_inter_company_transaction("Sales Invoice", si.name) + target_doc.items[0].update({ + "expense_account": "Cost of Goods Sold - _TC1", + "cost_center": "Main - _TC1", + "warehouse": "Stores - _TC1" + }) target_doc.submit() self.assertEqual(target_doc.company, "_Test Company 1") self.assertEqual(target_doc.supplier, "_Test Internal Supplier") - def test_internal_transfer_gl_entry(self): - ## Create internal transfer account - account = create_account(account_name="Unrealized Profit", - parent_account="Current Liabilities - TCP1", company="_Test Company with perpetual inventory") + # def test_internal_transfer_gl_entry(self): + # ## Create internal transfer account + # account = create_account(account_name="Unrealized Profit", + # parent_account="Current Liabilities - TCP1", company="_Test Company with perpetual inventory") - frappe.db.set_value('Company', '_Test Company with perpetual inventory', - 'unrealized_profit_loss_account', account) + # frappe.db.set_value('Company', '_Test Company with perpetual inventory', + # 'unrealized_profit_loss_account', account) - customer = create_internal_customer("_Test Internal Customer 2", "_Test Company with perpetual inventory", - "_Test Company with perpetual inventory") + # customer = create_internal_customer("_Test Internal Customer 2", "_Test Company with perpetual inventory", + # "_Test Company with perpetual inventory") - create_internal_supplier("_Test Internal Supplier 2", "_Test Company with perpetual inventory", - "_Test Company with perpetual inventory") + # create_internal_supplier("_Test Internal Supplier 2", "_Test Company with perpetual inventory", + # "_Test Company with perpetual inventory") - si = create_sales_invoice( - company = "_Test Company with perpetual inventory", - customer = customer, - debit_to = "Debtors - TCP1", - warehouse = "Stores - TCP1", - income_account = "Sales - TCP1", - expense_account = "Cost of Goods Sold - TCP1", - cost_center = "Main - TCP1", - currency = "INR", - do_not_save = 1 - ) + # si = create_sales_invoice( + # company = "_Test Company with perpetual inventory", + # customer = customer, + # debit_to = "Debtors - TCP1", + # warehouse = "Stores - TCP1", + # income_account = "Sales - TCP1", + # expense_account = "Cost of Goods Sold - TCP1", + # cost_center = "Main - TCP1", + # currency = "INR", + # do_not_save = 1 + # ) - si.selling_price_list = "_Test Price List Rest of the World" - si.update_stock = 1 - si.items[0].target_warehouse = 'Work In Progress - TCP1' - add_taxes(si) - si.save() - si.submit() + # si.selling_price_list = "_Test Price List Rest of the World" + # si.update_stock = 1 + # si.items[0].target_warehouse = 'Work In Progress - TCP1' + # add_taxes(si) + # si.save() + # si.submit() - target_doc = make_inter_company_transaction("Sales Invoice", si.name) - target_doc.company = '_Test Company with perpetual inventory' - target_doc.items[0].warehouse = 'Finished Goods - TCP1' - add_taxes(target_doc) - target_doc.save() - target_doc.submit() + # target_doc = make_inter_company_transaction("Sales Invoice", si.name) + # target_doc.company = '_Test Company with perpetual inventory' + # target_doc.items[0].warehouse = 'Finished Goods - TCP1' + # add_taxes(target_doc) + # target_doc.save() + # target_doc.submit() - si_gl_entries = [ - ["_Test Account Excise Duty - TCP1", 0.0, 12.0, nowdate()], - ["Unrealized Profit - TCP1", 12.0, 0.0, nowdate()] - ] + # si_gl_entries = [ + # ["_Test Account Excise Duty - TCP1", 0.0, 12.0, nowdate()], + # ["Unrealized Profit - TCP1", 12.0, 0.0, nowdate()] + # ] - check_gl_entries(self, si.name, si_gl_entries, add_days(nowdate(), -1)) + # check_gl_entries(self, si.name, si_gl_entries, add_days(nowdate(), -1)) - pi_gl_entries = [ - ["_Test Account Excise Duty - TCP1", 12.0 , 0.0, nowdate()], - ["Unrealized Profit - TCP1", 0.0, 12.0, nowdate()] - ] + # pi_gl_entries = [ + # ["_Test Account Excise Duty - TCP1", 12.0 , 0.0, nowdate()], + # ["Unrealized Profit - TCP1", 0.0, 12.0, nowdate()] + # ] - check_gl_entries(self, target_doc.name, pi_gl_entries, add_days(nowdate(), -1)) + # check_gl_entries(self, target_doc.name, pi_gl_entries, add_days(nowdate(), -1)) def test_eway_bill_json(self): if not frappe.db.exists('Address', '_Test Address for Eway bill-Billing'): @@ -1991,14 +1980,19 @@ def create_sales_invoice(**args): si.append("items", { "item_code": args.item or args.item_code or "_Test Item", + "item_name": args.item_name or "_Test Item", + "description": args.description or "_Test Item", "gst_hsn_code": "999800", "warehouse": args.warehouse or "_Test Warehouse - _TC", "qty": args.qty or 1, + "uom": args.uom or "Nos", + "stock_uom": args.uom or "Nos", "rate": args.rate if args.get("rate") is not None else 100, "income_account": args.income_account or "Sales - _TC", "expense_account": args.expense_account or "Cost of Goods Sold - _TC", "cost_center": args.cost_center or "_Test Cost Center - _TC", - "serial_no": args.serial_no + "serial_no": args.serial_no, + "conversion_factor": 1 }) if not args.do_not_save: diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json index fb3dd6a92a..3695075798 100644 --- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json +++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json @@ -1,4 +1,5 @@ { + "actions": [], "autoname": "hash", "creation": "2013-06-04 11:02:19", "doctype": "DocType", @@ -51,6 +52,7 @@ "column_break_24", "base_net_rate", "base_net_amount", + "incoming_rate", "drop_ship", "delivered_by_supplier", "accounting", @@ -792,20 +794,28 @@ "options": "Project" }, { - "depends_on": "eval:parent.update_stock == 1", - "fieldname": "sales_invoice_item", - "fieldtype": "Data", - "ignore_user_permissions": 1, - "label": "Sales Invoice Item", - "no_copy": 1, - "print_hide": 1, - "read_only": 1 - } + "depends_on": "eval:parent.update_stock == 1", + "fieldname": "sales_invoice_item", + "fieldtype": "Data", + "ignore_user_permissions": 1, + "label": "Sales Invoice Item", + "no_copy": 1, + "print_hide": 1, + "read_only": 1 + }, + { + "fieldname": "incoming_rate", + "fieldtype": "Currency", + "label": "Incoming Rate", + "no_copy": 1, + "print_hide": 1, + "read_only": 1 + } ], "idx": 1, "istable": 1, "links": [], - "modified": "2020-08-20 11:24:41.749986", + "modified": "2020-09-23 19:59:04.879322", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice Item", diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 9a091bf57b..c7f0c8781c 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -15,13 +15,13 @@ class ClosedAccountingPeriod(frappe.ValidationError): pass class StockAccountInvalidTransaction(frappe.ValidationError): pass class StockValueAndAccountBalanceOutOfSync(frappe.ValidationError): pass -def make_gl_entries(gl_map, cancel=False, adv_adj=False, merge_entries=True, update_outstanding='Yes'): +def make_gl_entries(gl_map, cancel=False, adv_adj=False, merge_entries=True, update_outstanding='Yes', from_repost=False): if gl_map: if not cancel: validate_accounting_period(gl_map) gl_map = process_gl_map(gl_map, merge_entries) if gl_map and len(gl_map) > 1: - save_entries(gl_map, adv_adj, update_outstanding) + save_entries(gl_map, adv_adj, update_outstanding, from_repost) else: frappe.throw(_("Incorrect number of General Ledger Entries found. You might have selected a wrong Account in the transaction.")) else: @@ -119,8 +119,9 @@ def check_if_in_list(gle, gl_map, dimensions=None): if same_head: return e -def save_entries(gl_map, adv_adj, update_outstanding): - validate_cwip_accounts(gl_map) +def save_entries(gl_map, adv_adj, update_outstanding, from_repost=False): + if not from_repost: + validate_cwip_accounts(gl_map) round_off_debit_credit(gl_map) @@ -128,24 +129,24 @@ def save_entries(gl_map, adv_adj, update_outstanding): check_freezing_date(gl_map[0]["posting_date"], adv_adj) for entry in gl_map: - make_entry(entry, adv_adj, update_outstanding) + make_entry(entry, adv_adj, update_outstanding, from_repost) - # check against budget - validate_expense_against_budget(entry) - - validate_account_for_perpetual_inventory(gl_map) + if not from_repost: + validate_account_for_perpetual_inventory(gl_map) -def make_entry(args, adv_adj, update_outstanding): +def make_entry(args, adv_adj, update_outstanding, from_repost=False): gle = frappe.new_doc("GL Entry") gle.update(args) gle.flags.ignore_permissions = 1 + gle.flags.from_repost = from_repost gle.insert() - gle.run_method("on_update_with_args", adv_adj, update_outstanding) + gle.run_method("on_update_with_args", adv_adj, update_outstanding, from_repost) gle.submit() # check against budget - validate_expense_against_budget(args) + if not from_repost: + validate_expense_against_budget(args) def validate_account_for_perpetual_inventory(gl_map): if cint(erpnext.is_perpetual_inventory_enabled(gl_map[0].company)): @@ -161,7 +162,7 @@ def validate_account_for_perpetual_inventory(gl_map): # Always use current date to get stock and account balance as there can future entries for # other items account_bal, stock_bal, warehouse_list = get_stock_and_account_balance(account, - getdate(), gl_map[0].company) + gl_map[0].posting_date, gl_map[0].company) if gl_map[0].voucher_type=="Journal Entry": # In case of Journal Entry, there are no corresponding SL entries, @@ -176,8 +177,8 @@ def validate_account_for_perpetual_inventory(gl_map): currency=frappe.get_cached_value('Company', gl_map[0].company, "default_currency")) diff = flt(stock_bal - account_bal, precision) - error_reason = _("Stock Value ({0}) and Account Balance ({1}) are out of sync for account {2} and it's linked warehouses.").format( - stock_bal, account_bal, frappe.bold(account)) + error_reason = _("Stock Value ({0}) and Account Balance ({1}) are out of sync for account {2} and it's linked warehouses on {3}.").format( + stock_bal, account_bal, frappe.bold(account), gl_map[0].posting_date) error_resolution = _("Please create adjustment Journal Entry for amount {0} ").format(frappe.bold(diff)) stock_adjustment_account = frappe.db.get_value("Company",gl_map[0].company,"stock_adjustment_account") @@ -185,9 +186,10 @@ def validate_account_for_perpetual_inventory(gl_map): db_or_cr_stock_adjustment_account = ('debit_in_account_currency' if diff < 0 else 'credit_in_account_currency') journal_entry_args = { - 'accounts':[ - {'account': account, db_or_cr_warehouse_account : abs(diff)}, - {'account': stock_adjustment_account, db_or_cr_stock_adjustment_account : abs(diff) }] + 'accounts':[ + {'account': account, db_or_cr_warehouse_account : abs(diff)}, + {'account': stock_adjustment_account, db_or_cr_stock_adjustment_account : abs(diff)} + ] } frappe.msgprint(msg="""{0}

{1}

""".format(error_reason, error_resolution), diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 550aaef404..540ac84182 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -928,7 +928,7 @@ def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for if expected_gle: if not existing_gle or not compare_existing_and_expected_gle(existing_gle, expected_gle): _delete_gl_entries(voucher_type, voucher_no) - voucher_obj.make_gl_entries(gl_entries=expected_gle, repost_future_gle=False, from_repost=True) + voucher_obj.make_gl_entries(gl_entries=expected_gle, from_repost=True) else: _delete_gl_entries(voucher_type, voucher_no) @@ -947,7 +947,10 @@ def get_future_stock_vouchers(posting_date, posting_time, for_warehouses=None, f for d in frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no from `tabStock Ledger Entry` sle - where timestamp(sle.posting_date, sle.posting_time) >= timestamp(%s, %s) {condition} + where + timestamp(sle.posting_date, sle.posting_time) >= timestamp(%s, %s) + and is_cancelled = 0 + {condition} order by timestamp(sle.posting_date, sle.posting_time) asc, creation asc for update""".format(condition=condition), tuple([posting_date, posting_time] + values), as_dict=True): future_stock_vouchers.append([d.voucher_type, d.voucher_no]) @@ -964,3 +967,20 @@ def get_voucherwise_gl_entries(future_stock_vouchers, posting_date): gl_entries.setdefault((d.voucher_type, d.voucher_no), []).append(d) return gl_entries + +def compare_existing_and_expected_gle(existing_gle, expected_gle): + matched = True + for entry in expected_gle: + account_existed = False + for e in existing_gle: + if entry.account == e.account: + account_existed = True + if entry.account == e.account and entry.against_account == e.against_account \ + and (not entry.cost_center or not e.cost_center or entry.cost_center == e.cost_center) \ + and (entry.debit != e.debit or entry.credit != e.credit): + matched = False + break + if not account_existed: + matched = False + break + return matched \ No newline at end of file diff --git a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json index 10db240a44..c691e9f9f8 100644 --- a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json +++ b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json @@ -732,7 +732,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2020-10-30 11:59:47.670951", + "modified": "2020-12-07 11:59:47.670951", "modified_by": "Administrator", "module": "Buying", "name": "Purchase Order Item", diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 286c4f4451..dc61870df3 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -16,6 +16,8 @@ from frappe.contacts.doctype.address.address import get_address_display from erpnext.accounts.doctype.budget.budget import validate_expense_against_budget from erpnext.controllers.stock_controller import StockController +from erpnext.controllers.sales_and_purchase_return import get_rate_for_return +from erpnext.stock.utils import get_incoming_rate class BuyingController(StockController): def __setup__(self): @@ -63,7 +65,7 @@ class BuyingController(StockController): self.set_landed_cost_voucher_amount() if self.doctype in ("Purchase Receipt", "Purchase Invoice"): - self.update_valuation_rate("items") + self.update_valuation_rate() def set_missing_values(self, for_validate=False): super(BuyingController, self).set_missing_values(for_validate) @@ -177,7 +179,7 @@ class BuyingController(StockController): self.in_words = money_in_words(amount, self.currency) # update valuation rate - def update_valuation_rate(self, parentfield): + def update_valuation_rate(self, reset_outgoing_rate=True): """ item_tax_amount is the total tax amount applied on that item stored for valuation @@ -188,7 +190,7 @@ class BuyingController(StockController): stock_and_asset_items_qty, stock_and_asset_items_amount = 0, 0 last_item_idx = 1 - for d in self.get(parentfield): + for d in self.get("items"): if d.item_code and d.item_code in stock_and_asset_items: stock_and_asset_items_qty += flt(d.qty) stock_and_asset_items_amount += flt(d.base_net_amount) @@ -198,7 +200,7 @@ class BuyingController(StockController): if d.category in ["Valuation", "Valuation and Total"]]) valuation_amount_adjustment = total_valuation_amount - for i, item in enumerate(self.get(parentfield)): + for i, item in enumerate(self.get("items")): if item.item_code and item.qty and item.item_code in stock_and_asset_items: item_proportion = flt(item.base_net_amount) / stock_and_asset_items_amount if stock_and_asset_items_amount \ else flt(item.qty) / stock_and_asset_items_qty @@ -216,16 +218,34 @@ class BuyingController(StockController): item.conversion_factor = get_conversion_factor(item.item_code, item.uom).get("conversion_factor") or 1.0 qty_in_stock_uom = flt(item.qty * item.conversion_factor) - rm_supp_cost = flt(item.rm_supp_cost) if self.doctype in ["Purchase Receipt", "Purchase Invoice"] else 0.0 - - landed_cost_voucher_amount = flt(item.landed_cost_voucher_amount) \ - if self.doctype in ["Purchase Receipt", "Purchase Invoice"] else 0.0 - - item.valuation_rate = ((item.base_net_amount + item.item_tax_amount + rm_supp_cost - + landed_cost_voucher_amount) / qty_in_stock_uom) + item.rm_supp_cost = self.get_supplied_items_cost(item.name, reset_outgoing_rate) + item.valuation_rate = ((item.base_net_amount + item.item_tax_amount + item.rm_supp_cost + + flt(item.landed_cost_voucher_amount)) / qty_in_stock_uom) else: item.valuation_rate = 0.0 + def get_supplied_items_cost(self, item_row_id, reset_outgoing_rate=True): + supplied_items_cost = 0.0 + for d in self.get("supplied_items"): + if d.reference_name == item_row_id: + if reset_outgoing_rate and frappe.db.get_value('Item', d.rm_item_code, 'is_stock_item'): + rate = get_incoming_rate({ + "item_code": d.rm_item_code, + "warehouse": self.supplier_warehouse, + "posting_date": self.posting_date, + "posting_time": self.posting_time, + "qty": -1 * d.consumed_qty, + "serial_no": d.serial_no + }) + + if rate > 0: + d.rate = rate + + d.amount = flt(d.consumed_qty) * flt(d.rate) + supplied_items_cost += flt(d.amount) + + return supplied_items_cost + def validate_for_subcontracting(self): if not self.is_subcontracted and self.sub_contracted_items: frappe.throw(_("Please enter 'Is Subcontracted' as Yes or No")) @@ -352,35 +372,17 @@ class BuyingController(StockController): else: self.append_raw_material_to_be_backflushed(item, raw_material, qty) - def append_raw_material_to_be_backflushed(self, fg_item_doc, raw_material_data, qty): + def append_raw_material_to_be_backflushed(self, fg_item_row, raw_material_data, qty): rm = self.append('supplied_items', {}) rm.update(raw_material_data) if not rm.main_item_code: - rm.main_item_code = fg_item_doc.item_code + rm.main_item_code = fg_item_row.item_code - rm.reference_name = fg_item_doc.name + rm.reference_name = fg_item_row.name rm.required_qty = qty rm.consumed_qty = qty - if not raw_material_data.get('non_stock_item'): - from erpnext.stock.utils import get_incoming_rate - rm.rate = get_incoming_rate({ - "item_code": raw_material_data.rm_item_code, - "warehouse": self.supplier_warehouse, - "posting_date": self.posting_date, - "posting_time": self.posting_time, - "qty": -1 * qty, - "serial_no": rm.serial_no - }) - - if not rm.rate: - rm.rate = get_valuation_rate(raw_material_data.rm_item_code, self.supplier_warehouse, - self.doctype, self.name, currency=self.company_currency, company=self.company) - - rm.amount = qty * flt(rm.rate) - fg_item_doc.rm_supp_cost += rm.amount - def update_raw_materials_supplied_based_on_bom(self, item, raw_material_table): exploded_item = 1 if hasattr(item, 'include_exploded_items'): @@ -389,7 +391,7 @@ class BuyingController(StockController): bom_items = get_items_from_bom(item.item_code, item.bom, exploded_item) used_alternative_items = [] - if self.doctype == 'Purchase Receipt' and item.purchase_order: + if self.doctype in ["Purchase Receipt", "Purchase Invoice"] and item.purchase_order: used_alternative_items = get_used_alternative_items(purchase_order = item.purchase_order) raw_materials_cost = 0 @@ -406,7 +408,7 @@ class BuyingController(StockController): reserve_warehouse = None conversion_factor = item.conversion_factor - if (self.doctype == 'Purchase Receipt' and item.purchase_order and + if (self.doctype in ["Purchase Receipt", "Purchase Invoice"] and item.purchase_order and bom_item.item_code in used_alternative_items): alternative_item_data = used_alternative_items.get(bom_item.item_code) bom_item.item_code = alternative_item_data.item_code @@ -434,9 +436,7 @@ class BuyingController(StockController): rm.rm_item_code = bom_item.item_code rm.stock_uom = bom_item.stock_uom rm.required_qty = required_qty - if self.doctype == "Purchase Order" and not rm.reserve_warehouse: - rm.reserve_warehouse = reserve_warehouse - + rm.rate = bom_item.rate rm.conversion_factor = conversion_factor if self.doctype in ["Purchase Receipt", "Purchase Invoice"]: @@ -444,29 +444,8 @@ class BuyingController(StockController): rm.description = bom_item.description if item.batch_no and frappe.db.get_value("Item", rm.rm_item_code, "has_batch_no") and not rm.batch_no: rm.batch_no = item.batch_no - - # get raw materials rate - if self.doctype == "Purchase Receipt": - from erpnext.stock.utils import get_incoming_rate - rm.rate = get_incoming_rate({ - "item_code": bom_item.item_code, - "warehouse": self.supplier_warehouse, - "posting_date": self.posting_date, - "posting_time": self.posting_time, - "qty": -1 * required_qty, - "serial_no": rm.serial_no - }) - if not rm.rate: - rm.rate = get_valuation_rate(bom_item.item_code, self.supplier_warehouse, - self.doctype, self.name, currency=self.company_currency, company = self.company) - else: - rm.rate = bom_item.rate - - rm.amount = required_qty * flt(rm.rate) - raw_materials_cost += flt(rm.amount) - - if self.doctype in ("Purchase Receipt", "Purchase Invoice"): - item.rm_supp_cost = raw_materials_cost + elif not rm.reserve_warehouse: + rm.reserve_warehouse = reserve_warehouse def cleanup_raw_materials_supplied(self, parent_items, raw_material_table): """Remove all those child items which are no longer present in main item table""" @@ -579,7 +558,8 @@ class BuyingController(StockController): or (cint(self.is_return) and self.docstatus==2)): from_warehouse_sle = self.get_sl_entries(d, { "actual_qty": -1 * pr_qty, - "warehouse": d.from_warehouse + "warehouse": d.from_warehouse, + "dependant_sle_voucher_detail_no": d.name }) sl_entries.append(from_warehouse_sle) @@ -589,28 +569,20 @@ class BuyingController(StockController): "serial_no": cstr(d.serial_no).strip() }) if self.is_return: - filters = { - "voucher_type": self.doctype, - "voucher_no": self.return_against, - "item_code": d.item_code - } - - if (self.doctype == "Purchase Invoice" and self.update_stock - and d.get("purchase_invoice_item")): - filters["voucher_detail_no"] = d.purchase_invoice_item - elif self.doctype == "Purchase Receipt" and d.get("purchase_receipt_item"): - filters["voucher_detail_no"] = d.purchase_receipt_item - - original_incoming_rate = frappe.db.get_value("Stock Ledger Entry", filters, "incoming_rate") + outgoing_rate = get_rate_for_return(self.doctype, self.name, d.item_code, self.return_against, item_row=d) sle.update({ - "outgoing_rate": original_incoming_rate + "outgoing_rate": outgoing_rate, + "recalculate_rate": 1 }) + if d.from_warehouse: + sle.dependant_sle_voucher_detail_no = d.name else: val_rate_db_precision = 6 if cint(self.precision("valuation_rate", d)) <= 6 else 9 incoming_rate = flt(d.valuation_rate, val_rate_db_precision) sle.update({ - "incoming_rate": incoming_rate + "incoming_rate": incoming_rate, + "recalculate_rate": 1 if (self.is_subcontracted and d.bom) or d.from_warehouse else 0 }) sl_entries.append(sle) @@ -618,7 +590,8 @@ class BuyingController(StockController): or (cint(self.is_return) and self.docstatus==1)): from_warehouse_sle = self.get_sl_entries(d, { "actual_qty": -1 * pr_qty, - "warehouse": d.from_warehouse + "warehouse": d.from_warehouse, + "recalculate_rate": 1 }) sl_entries.append(from_warehouse_sle) @@ -666,6 +639,7 @@ class BuyingController(StockController): "item_code": d.rm_item_code, "warehouse": self.supplier_warehouse, "actual_qty": -1*flt(d.consumed_qty), + "dependant_sle_voucher_detail_no": d.reference_name })) def on_submit(self): @@ -857,6 +831,7 @@ class BuyingController(StockController): else: validate_item_type(self, "is_purchase_item", "purchase") + def get_items_from_bom(item_code, bom, exploded_item=1): doctype = "BOM Item" if not exploded_item else "BOM Explosion Item" diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index 5299b25601..8f65c31f3d 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -365,3 +365,45 @@ def make_return_doc(doctype, source_name, target_doc=None): }, target_doc, set_missing_values) return doclist + +def get_rate_for_return(voucher_type, voucher_no, item_code, return_against=None, item_row=None, voucher_detail_no=None): + if not return_against: + return_against = frappe.get_cached_value(voucher_type, voucher_no, "return_against") + + return_against_item_field = get_return_against_item_fields(voucher_type) + + filters = get_filters(voucher_type, voucher_no, voucher_detail_no, + return_against, item_code, return_against_item_field, item_row) + + if voucher_type in ("Purchase Receipt", "Purchase Invoice"): + select_field = "incoming_rate" + else: + select_field = "abs(stock_value_difference / actual_qty)" + + return flt(frappe.db.get_value("Stock Ledger Entry", filters, select_field)) + +def get_return_against_item_fields(voucher_type): + return_against_item_fields = { + "Purchase Receipt": "purchase_receipt_item", + "Purchase Invoice": "purchase_invoice_item", + "Delivery Note": "dn_detail", + "Sales Invoice": "sales_invoice_item" + } + return return_against_item_fields[voucher_type] + +def get_filters(voucher_type, voucher_no, voucher_detail_no, return_against, item_code, return_against_item_field, item_row): + filters = { + "voucher_type": voucher_type, + "voucher_no": return_against, + "item_code": item_code + } + + if item_row: + reference_voucher_detail_no = item_row.get(return_against_item_field) + else: + reference_voucher_detail_no = frappe.db.get_value(voucher_type + " Item", voucher_detail_no, return_against_item_field) + + if reference_voucher_detail_no: + filters["voucher_detail_no"] = reference_voucher_detail_no + + return filters \ No newline at end of file diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 4dbd7bfa18..85cfb951fc 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -13,6 +13,7 @@ from frappe.contacts.doctype.address.address import get_address_display from erpnext.controllers.accounts_controller import get_taxes_and_charges from erpnext.controllers.stock_controller import StockController +from erpnext.controllers.sales_and_purchase_return import get_rate_for_return class SellingController(StockController): def __setup__(self): @@ -48,6 +49,7 @@ class SellingController(StockController): self.set_customer_address() self.validate_for_duplicate_items() self.validate_target_warehouse() + self.set_incoming_rate() def set_missing_values(self, for_validate=False): @@ -230,7 +232,8 @@ class SellingController(StockController): 'voucher_type': self.doctype, 'allow_zero_valuation': d.allow_zero_valuation_rate, 'sales_invoice_item': d.get("sales_invoice_item"), - 'delivery_note_item': d.get("dn_detail") + 'dn_detail': d.get("dn_detail"), + 'incoming_rate': p.incoming_rate })) else: il.append(frappe._dict({ @@ -248,7 +251,8 @@ class SellingController(StockController): 'voucher_type': self.doctype, 'allow_zero_valuation': d.allow_zero_valuation_rate, 'sales_invoice_item': d.get("sales_invoice_item"), - 'delivery_note_item': d.get("dn_detail") + 'dn_detail': d.get("dn_detail"), + 'incoming_rate': d.incoming_rate })) return il @@ -307,69 +311,89 @@ class SellingController(StockController): sales_order.update_reserved_qty(so_item_rows) + def set_incoming_rate(self): + if self.doctype not in ("Delivery Note", "Sales Invoice"): + return + + items = self.get("items") + (self.get("packed_items") or []) + for d in items: + if not cint(self.get("is_return")): + # Get incoming rate based on original item cost based on valuation method + d.incoming_rate = get_incoming_rate({ + "item_code": d.item_code, + "warehouse": d.warehouse, + "posting_date": self.posting_date, + "posting_time": self.posting_time, + "qty": -1*flt(d.qty), + "serial_no": d.serial_no, + "company": self.company, + "voucher_type": self.doctype, + "voucher_no": self.name, + "allow_zero_valuation": d.get("allow_zero_valuation") + }, raise_error_if_no_rate=False) + elif self.get("return_against"): + # Get incoming rate of return entry from reference document + # based on original item cost as per valuation method + d.incoming_rate = get_rate_for_return(self.doctype, self.name, d.item_code, self.return_against, item_row=d) + def update_stock_ledger(self): self.update_reserved_qty() sl_entries = [] + # Loop over items and packed items table for d in self.get_item_list(): if frappe.get_cached_value("Item", d.item_code, "is_stock_item") == 1 and flt(d.qty): if flt(d.conversion_factor)==0.0: d.conversion_factor = get_conversion_factor(d.item_code, d.uom).get("conversion_factor") or 1.0 - return_rate = 0 - if cint(self.is_return) and self.return_against and self.docstatus==1: - against_document_no = (d.get("sales_invoice_item") - if self.doctype == "Sales Invoice" else d.get("delivery_note_item")) - return_rate = self.get_incoming_rate_for_return(d.item_code, - self.return_against, against_document_no) - - # On cancellation or if return entry submission, make stock ledger entry for + # On cancellation or return entry submission, make stock ledger entry for # target warehouse first, to update serial no values properly if d.warehouse and ((not cint(self.is_return) and self.docstatus==1) or (cint(self.is_return) and self.docstatus==2)): - sl_entries.append(self.get_sl_entries(d, { - "actual_qty": -1*flt(d.qty), - "incoming_rate": return_rate - })) + sl_entries.append(self.get_sle_for_source_warehouse(d)) if d.target_warehouse: - target_warehouse_sle = self.get_sl_entries(d, { - "actual_qty": flt(d.qty), - "warehouse": d.target_warehouse - }) - - if self.docstatus == 1: - if not cint(self.is_return): - args = frappe._dict({ - "item_code": d.item_code, - "warehouse": d.warehouse, - "posting_date": self.posting_date, - "posting_time": self.posting_time, - "qty": -1*flt(d.qty), - "serial_no": d.serial_no, - "company": d.company, - "voucher_type": d.voucher_type, - "voucher_no": d.name, - "allow_zero_valuation": d.allow_zero_valuation - }) - target_warehouse_sle.update({ - "incoming_rate": get_incoming_rate(args) - }) - else: - target_warehouse_sle.update({ - "outgoing_rate": return_rate - }) - sl_entries.append(target_warehouse_sle) + sl_entries.append(self.get_sle_for_target_warehouse(d)) if d.warehouse and ((not cint(self.is_return) and self.docstatus==2) or (cint(self.is_return) and self.docstatus==1)): - sl_entries.append(self.get_sl_entries(d, { - "actual_qty": -1*flt(d.qty), - "incoming_rate": return_rate - })) + sl_entries.append(self.get_sle_for_source_warehouse(d)) + self.make_sl_entries(sl_entries) + def get_sle_for_source_warehouse(self, item_row): + sle = self.get_sl_entries(item_row, { + "actual_qty": -1*flt(item_row.qty), + "incoming_rate": item_row.incoming_rate, + "recalculate_rate": cint(self.is_return) + }) + if item_row.target_warehouse and not cint(self.is_return): + sle.dependant_sle_voucher_detail_no = item_row.name + + return sle + + def get_sle_for_target_warehouse(self, item_row): + sle = self.get_sl_entries(item_row, { + "actual_qty": flt(item_row.qty), + "warehouse": item_row.target_warehouse + }) + + if self.docstatus == 1: + if not cint(self.is_return): + sle.update({ + "incoming_rate": item_row.incoming_rate, + "recalculate_rate": 1 + }) + else: + sle.update({ + "outgoing_rate": item_row.incoming_rate + }) + if item_row.warehouse: + sle.dependant_sle_voucher_detail_no = item_row.name + + return sle + def set_po_nos(self, for_validate=False): if self.doctype == 'Sales Invoice' and hasattr(self, "items"): if for_validate and self.po_no: @@ -463,4 +487,4 @@ def set_default_income_account_for_item(obj): for d in obj.get("items"): if d.item_code: if getattr(d, "income_account", None): - set_item_default(d.item_code, obj.company, 'income_account', d.income_account) + set_item_default(d.item_code, obj.company, 'income_account', d.income_account) \ No newline at end of file diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 683d7f77b5..51c063c2c0 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -24,7 +24,7 @@ class StockController(AccountsController): self.validate_serialized_batch() self.validate_customer_provided_item() - def make_gl_entries(self, gl_entries=None): + def make_gl_entries(self, gl_entries=None, from_repost=False): if self.docstatus == 2: make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name) @@ -34,12 +34,12 @@ class StockController(AccountsController): if self.docstatus==1: if not gl_entries: gl_entries = self.get_gl_entries(warehouse_account) - make_gl_entries(gl_entries) + make_gl_entries(gl_entries, from_repost=from_repost) elif self.doctype in ['Purchase Receipt', 'Purchase Invoice'] and self.docstatus == 1: gl_entries = [] gl_entries = self.get_asset_gl_entry(gl_entries) - make_gl_entries(gl_entries) + make_gl_entries(gl_entries, from_repost=from_repost) def validate_serialized_batch(self): from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos @@ -70,7 +70,6 @@ class StockController(AccountsController): gl_list = [] warehouse_with_no_account = [] - precision = frappe.get_precision("GL Entry", "debit_in_account_currency") for item_row in voucher_details: sle_list = sle_map.get(item_row.name) @@ -125,7 +124,7 @@ class StockController(AccountsController): if warehouse_with_no_account: for wh in warehouse_with_no_account: if frappe.db.get_value("Warehouse", wh, "company"): - frappe.throw(_("Warehouse {0} is not linked to any account, please mention the account in the warehouse record or set default inventory account in company {1}.").format(wh, self.company)) + frappe.throw(_("Warehouse {0} is not linked to any account, please mention the account in the warehouse record or set default inventory account in company {1}.").format(wh, self.company)) return process_gl_map(gl_list) @@ -309,23 +308,6 @@ class StockController(AccountsController): return serialized_items - def get_incoming_rate_for_return(self, item_code, against_document, against_document_no=None): - incoming_rate = 0.0 - cond = '' - if against_document and item_code: - if against_document_no: - cond = " and voucher_detail_no = %s" %(frappe.db.escape(against_document_no)) - - incoming_rate = frappe.db.sql("""select abs(stock_value_difference / actual_qty) - from `tabStock Ledger Entry` - where voucher_type = %s and voucher_no = %s - and item_code = %s {0} limit 1""".format(cond), - (self.doctype, against_document, item_code)) - - incoming_rate = incoming_rate[0][0] if incoming_rate else 0.0 - - return incoming_rate - def validate_warehouse(self): from erpnext.stock.utils import validate_warehouse_company @@ -409,19 +391,64 @@ class StockController(AccountsController): if frappe.db.get_value('Item', d.item_code, 'is_customer_provided_item'): d.allow_zero_valuation_rate = 1 -def compare_existing_and_expected_gle(existing_gle, expected_gle): - matched = True - for entry in expected_gle: - account_existed = False - for e in existing_gle: - if entry.account == e.account: - account_existed = True - if entry.account == e.account and entry.against_account == e.against_account \ - and (not entry.cost_center or not e.cost_center or entry.cost_center == e.cost_center) \ - and (entry.debit != e.debit or entry.credit != e.credit): - matched = False - break - if not account_existed: - matched = False + def repost_future_sle_and_gle(self): + args = frappe._dict({ + "posting_date": self.posting_date, + "posting_time": self.posting_time, + "voucher_type": self.doctype, + "voucher_no": self.name, + "company": self.company + }) + + if check_if_future_sle_exists(args): + create_repost_item_valuation_entry(args) + +def check_if_future_sle_exists(args): + sl_entries = frappe.db.get_all("Stock Ledger Entry", + filters={"voucher_type": args.voucher_type, "voucher_no": args.voucher_no}, + fields=["item_code", "warehouse"], + order_by="creation asc") + + distinct_item_warehouses = list(set([(d.item_code, d.warehouse) for d in sl_entries])) + + sle_exists = False + for item_code, warehouse in distinct_item_warehouses: + args.update({ + "item_code": item_code, + "warehouse": warehouse + }) + if get_sle(args): + sle_exists = True break - return matched + return sle_exists + +def get_sle(args): + return frappe.db.sql(""" + select name + from `tabStock Ledger Entry` + where + item_code=%(item_code)s + and warehouse=%(warehouse)s + and timestamp(posting_date, posting_time) >= timestamp(%(posting_date)s, %(posting_time)s) + and voucher_no != %(voucher_no)s + and is_cancelled = 0 + limit 1 + """, args) + +def create_repost_item_valuation_entry(args): + args = frappe._dict(args) + repost_entry = frappe.new_doc("Repost Item Valuation") + repost_entry.based_on = args.based_on + if not args.based_on: + repost_entry.based_on = 'Transaction' if args.voucher_no else "Item and Warehouse" + repost_entry.voucher_type = args.voucher_type + repost_entry.voucher_no = args.voucher_no + repost_entry.item_code = args.item_code + repost_entry.warehouse = args.warehouse + repost_entry.posting_date = args.posting_date + repost_entry.posting_time = args.posting_time + repost_entry.company = args.company + repost_entry.allow_zero_rate = args.allow_zero_rate + repost_entry.flags.ignore_links = True + repost_entry.save() + repost_entry.submit() \ No newline at end of file diff --git a/erpnext/manufacturing/doctype/work_order/test_work_order.py b/erpnext/manufacturing/doctype/work_order/test_work_order.py index 2bf3fbf75e..ce9699e1b3 100644 --- a/erpnext/manufacturing/doctype/work_order/test_work_order.py +++ b/erpnext/manufacturing/doctype/work_order/test_work_order.py @@ -6,7 +6,6 @@ from __future__ import unicode_literals import unittest import frappe from frappe.utils import flt, time_diff_in_hours, now, add_months, cint, today -from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory from erpnext.manufacturing.doctype.work_order.work_order import (make_stock_entry, ItemHasVariantError, stop_unstop, StockOverProductionError, OverProductionError, CapacityError) from erpnext.stock.doctype.stock_entry import test_stock_entry @@ -18,7 +17,6 @@ from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse class TestWorkOrder(unittest.TestCase): def setUp(self): - set_perpetual_inventory(0) self.warehouse = '_Test Warehouse 2 - _TC' self.item = '_Test Item' diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.json b/erpnext/selling/doctype/sales_order_item/sales_order_item.json index eff17f8bc7..159655b74b 100644 --- a/erpnext/selling/doctype/sales_order_item/sales_order_item.json +++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.json @@ -785,7 +785,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2020-05-29 20:54:32.309460", + "modified": "2020-012-07 20:54:32.309460", "modified_by": "Administrator", "module": "Selling", "name": "Sales Order Item", diff --git a/erpnext/setup/doctype/company/test_records.json b/erpnext/setup/doctype/company/test_records.json index 21302417d2..9e55702ddc 100644 --- a/erpnext/setup/doctype/company/test_records.json +++ b/erpnext/setup/doctype/company/test_records.json @@ -7,7 +7,8 @@ "doctype": "Company", "domain": "Manufacturing", "chart_of_accounts": "Standard", - "default_holiday_list": "_Test Holiday List" + "default_holiday_list": "_Test Holiday List", + "enable_perpetual_inventory": 0 }, { "abbr": "_TC1", @@ -17,7 +18,8 @@ "doctype": "Company", "domain": "Retail", "chart_of_accounts": "Standard", - "default_holiday_list": "_Test Holiday List" + "default_holiday_list": "_Test Holiday List", + "enable_perpetual_inventory": 0 }, { "abbr": "_TC2", @@ -27,7 +29,8 @@ "doctype": "Company", "domain": "Retail", "chart_of_accounts": "Standard", - "default_holiday_list": "_Test Holiday List" + "default_holiday_list": "_Test Holiday List", + "enable_perpetual_inventory": 0 }, { "abbr": "_TC3", @@ -38,7 +41,8 @@ "doctype": "Company", "domain": "Manufacturing", "chart_of_accounts": "Standard", - "default_holiday_list": "_Test Holiday List" + "default_holiday_list": "_Test Holiday List", + "enable_perpetual_inventory": 0 }, { "abbr": "_TC4", @@ -50,7 +54,8 @@ "doctype": "Company", "domain": "Manufacturing", "chart_of_accounts": "Standard", - "default_holiday_list": "_Test Holiday List" + "default_holiday_list": "_Test Holiday List", + "enable_perpetual_inventory": 0 }, { "abbr": "_TC5", @@ -61,7 +66,8 @@ "doctype": "Company", "domain": "Manufacturing", "chart_of_accounts": "Standard", - "default_holiday_list": "_Test Holiday List" + "default_holiday_list": "_Test Holiday List", + "enable_perpetual_inventory": 0 }, { "abbr": "TCP1", diff --git a/erpnext/stock/doctype/batch/test_batch.py b/erpnext/stock/doctype/batch/test_batch.py index c2a3d3c151..e41f1a8aaa 100644 --- a/erpnext/stock/doctype/batch/test_batch.py +++ b/erpnext/stock/doctype/batch/test_batch.py @@ -8,13 +8,8 @@ import unittest from erpnext.stock.doctype.batch.batch import get_batch_qty, UnableToSelectBatchError, get_batch_no from frappe.utils import cint, flt -from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory class TestBatch(unittest.TestCase): - - def setUp(self): - set_perpetual_inventory(0) - def test_item_has_batch_enabled(self): self.assertRaises(ValidationError, frappe.get_doc({ "doctype": "Batch", diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py index 7acdec728b..ab19b77ad8 100644 --- a/erpnext/stock/doctype/bin/bin.py +++ b/erpnext/stock/doctype/bin/bin.py @@ -16,22 +16,30 @@ class Bin(Document): def update_stock(self, args, allow_negative_stock=False, via_landed_cost_voucher=False): '''Called from erpnext.stock.utils.update_bin''' self.update_qty(args) - if args.get("actual_qty") or args.get("voucher_type") == "Stock Reconciliation": - from erpnext.stock.stock_ledger import update_entries_after + from erpnext.stock.stock_ledger import update_entries_after, update_qty_in_future_sle if not args.get("posting_date"): args["posting_date"] = nowdate() + if args.get("is_cancelled") and via_landed_cost_voucher: + return + + # Reposts only current voucher SL Entries + # Updates valuation rate, stock value, stock queue for current transaction update_entries_after({ "item_code": self.item_code, "warehouse": self.warehouse, "posting_date": args.get("posting_date"), "posting_time": args.get("posting_time"), + "voucher_type": args.get("voucher_type"), "voucher_no": args.get("voucher_no"), - "sle_id": args.sle_id + "sle_id": args.name }, allow_negative_stock=allow_negative_stock, via_landed_cost_voucher=via_landed_cost_voucher) + # Update qty_after_transaction in future SLEs of this item and warehouse + update_qty_in_future_sle(args) + def update_qty(self, args): # update the stock values (for current quantities) if args.get("voucher_type")=="Stock Reconciliation": diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index 3f3407e350..1a6a555092 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -217,6 +217,7 @@ class DeliveryNote(SellingController): # because updating reserved qty in bin depends upon updated delivered qty in SO self.update_stock_ledger() self.make_gl_entries() + self.repost_future_sle_and_gle() def on_cancel(self): super(DeliveryNote, self).on_cancel() @@ -234,7 +235,8 @@ class DeliveryNote(SellingController): self.cancel_packing_slips() self.make_gl_entries_on_cancel() - self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry') + self.repost_future_sle_and_gle() + self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry', 'Repost Item Valuation') def check_credit_limit(self): from erpnext.selling.doctype.customer.customer import check_credit_limit diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py index 6b4663a688..559f8be0de 100644 --- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py @@ -10,8 +10,7 @@ import frappe.defaults from frappe.utils import cint, nowdate, nowtime, cstr, add_days, flt, today from erpnext.stock.stock_ledger import get_previous_sle from erpnext.accounts.utils import get_balance_on -from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt \ - import get_gl_entries, set_perpetual_inventory +from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import get_gl_entries from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_invoice, make_delivery_trip from erpnext.stock.doctype.stock_entry.test_stock_entry \ import make_stock_entry, make_serialized_item, get_qty_after_transaction @@ -24,9 +23,6 @@ from erpnext.stock.doctype.warehouse.test_warehouse import get_warehouse from erpnext.stock.doctype.item.test_item import create_item class TestDeliveryNote(unittest.TestCase): - def setUp(self): - set_perpetual_inventory(0) - def test_over_billing_against_dn(self): frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) @@ -43,7 +39,6 @@ class TestDeliveryNote(unittest.TestCase): def test_delivery_note_no_gl_entry(self): company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC', 'company') - set_perpetual_inventory(0, company) make_stock_entry(target="_Test Warehouse - _TC", qty=5, basic_rate=100) stock_queue = json.loads(get_previous_sle({ diff --git a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json index 7b471874af..4bbf3de594 100644 --- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json +++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json @@ -56,6 +56,7 @@ "base_net_rate", "base_net_amount", "billed_amt", + "incoming_rate", "item_weight_details", "weight_per_unit", "total_weight", @@ -732,16 +733,22 @@ "depends_on": "returned_qty", "fieldname": "returned_qty", "fieldtype": "Float", - "label": "Returned Qty in Stock UOM", + "label": "Returned Qty in Stock UOM" + }, + { + "fieldname": "incoming_rate", + "fieldtype": "Currency", + "label": "Incoming Rate", "no_copy": 1, "print_hide": 1, "read_only": 1 } ], "idx": 1, + "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2020-07-31 20:12:43.054342", + "modified": "2020-12-07 19:59:27.119856", "modified_by": "Administrator", "module": "Stock", "name": "Delivery Note Item", diff --git a/erpnext/stock/doctype/item/test_records.json b/erpnext/stock/doctype/item/test_records.json index 9ca887c77e..8f437b13f0 100644 --- a/erpnext/stock/doctype/item/test_records.json +++ b/erpnext/stock/doctype/item/test_records.json @@ -458,5 +458,15 @@ "item_tax_template": "_Test Item Tax Template 1" } ] + }, + { + "description": "_Test", + "doctype": "Item", + "is_stock_item": 1, + "item_code": "138-CMS Shoe", + "item_group": "_Test Item Group", + "item_name": "138-CMS Shoe", + "stock_uom": "_Test UOM", + "gst_hsn_code": "999800" } ] diff --git a/erpnext/stock/doctype/item_alternative/test_item_alternative.py b/erpnext/stock/doctype/item_alternative/test_item_alternative.py index f045e4f911..d5700fe514 100644 --- a/erpnext/stock/doctype/item_alternative/test_item_alternative.py +++ b/erpnext/stock/doctype/item_alternative/test_item_alternative.py @@ -12,11 +12,9 @@ from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import from erpnext.manufacturing.doctype.work_order.test_work_order import make_wo_order_test_record from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt, make_rm_stock_entry import unittest -from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory class TestItemAlternative(unittest.TestCase): def setUp(self): - set_perpetual_inventory(0) make_items() def test_alternative_item_for_subcontract_rm(self): diff --git a/erpnext/stock/doctype/landed_cost_taxes_and_charges/landed_cost_taxes_and_charges.json b/erpnext/stock/doctype/landed_cost_taxes_and_charges/landed_cost_taxes_and_charges.json index 0cc243d4cb..64331c7d57 100644 --- a/erpnext/stock/doctype/landed_cost_taxes_and_charges/landed_cost_taxes_and_charges.json +++ b/erpnext/stock/doctype/landed_cost_taxes_and_charges/landed_cost_taxes_and_charges.json @@ -1,4 +1,5 @@ { + "actions": [], "creation": "2014-07-11 11:51:00.453717", "doctype": "DocType", "editable_grid": 1, @@ -31,16 +32,19 @@ "reqd": 1 }, { + "depends_on": "eval:cint(erpnext.is_perpetual_inventory_enabled(parent.company))", "fieldname": "expense_account", "fieldtype": "Link", "in_list_view": 1, "label": "Expense Account", + "mandatory_depends_on": "eval:cint(erpnext.is_perpetual_inventory_enabled(parent.company))", "options": "Account", - "reqd": 1 + "print_hide": 1 } ], "istable": 1, - "modified": "2019-09-30 18:28:32.070655", + "links": [], + "modified": "2020-12-04 00:22:14.373312", "modified_by": "Administrator", "module": "Stock", "name": "Landed Cost Taxes and Charges", diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py index bc3d3266ad..9ec6b8946c 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py +++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py @@ -77,9 +77,9 @@ class LandedCostVoucher(Document): company_currency = erpnext.get_company_currency(self.company) for account in self.taxes: if get_account_currency(account.expense_account) != company_currency: - frappe.throw(msg=_(""" Row {0}: Expense account currency should be same as company's default currency. - Please select expense account with account currency as {1}""") - .format(account.idx, frappe.bold(company_currency)), title=_("Invalid Account Currency")) + frappe.throw(_("Row {}: Expense account currency should be same as company's default currency.").format(account.idx) + + _("Please select expense account with account currency as {}.").format(frappe.bold(company_currency)), + title=_("Invalid Account Currency")) def set_total_taxes_and_charges(self): self.total_taxes_and_charges = sum([flt(d.amount) for d in self.get("taxes")]) @@ -121,7 +121,7 @@ class LandedCostVoucher(Document): doc.set_landed_cost_voucher_amount() # set valuation amount in pr item - doc.update_valuation_rate("items") + doc.update_valuation_rate(reset_outgoing_rate=False) # db_update will update and save landed_cost_voucher_amount and voucher_amount in PR for item in doc.get("items"): @@ -143,6 +143,7 @@ class LandedCostVoucher(Document): doc.docstatus = 1 doc.update_stock_ledger(allow_negative_stock=True, via_landed_cost_voucher=True) doc.make_gl_entries() + doc.repost_future_sle_and_gle() def validate_asset_qty_and_status(self, receipt_document_type, receipt_document): for item in self.get('items'): @@ -152,14 +153,13 @@ class LandedCostVoucher(Document): docs = frappe.db.get_all('Asset', filters={ receipt_document_type: item.receipt_document, 'item_code': item.item_code }, fields=['name', 'docstatus']) if not docs or len(docs) != item.qty: - frappe.throw(_('There are not enough asset created or linked to {0}. \ - Please create or link {1} Assets with respective document.').format(item.receipt_document, item.qty)) + frappe.throw(_('There are not enough asset created or linked to {0}.').format(item.receipt_document) + + _('Please create or link {0} Assets with respective document.').format(item.qty)) if docs: for d in docs: if d.docstatus == 1: - frappe.throw(_('{2} {0} has submitted Assets.\ - Remove Item {1} from table to continue.').format( - item.receipt_document, item.item_code, item.receipt_document_type)) + frappe.throw(_('{0} {1} has submitted Assets. Remove Item {2} from table to continue.') + .format(item.receipt_document_type, frappe.bold(item.receipt_document), frappe.bold(item.item_code))) def update_rate_in_serial_no_for_non_asset_items(self, receipt_document): for item in receipt_document.get("items"): diff --git a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py index 3f2c5daf66..b97213e4fb 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py +++ b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py @@ -7,7 +7,7 @@ import unittest import frappe from frappe.utils import flt from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt \ - import set_perpetual_inventory, get_gl_entries, test_records as pr_test_records, make_purchase_receipt + import get_gl_entries, test_records as pr_test_records, make_purchase_receipt from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.accounts.doctype.account.test_account import get_inventory_account @@ -27,7 +27,7 @@ class TestLandedCostVoucher(unittest.TestCase): }, fieldname=["qty_after_transaction", "stock_value"], as_dict=1) - submit_landed_cost_voucher("Purchase Receipt", pr.name, pr.company) + create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company) pr_lc_value = frappe.db.get_value("Purchase Receipt Item", {"parent": pr.name}, "landed_cost_voucher_amount") self.assertEqual(pr_lc_value, 25.0) @@ -89,7 +89,7 @@ class TestLandedCostVoucher(unittest.TestCase): }, fieldname=["qty_after_transaction", "stock_value"], as_dict=1) - submit_landed_cost_voucher("Purchase Invoice", pi.name, pi.company) + create_landed_cost_voucher("Purchase Invoice", pi.name, pi.company) pi_lc_value = frappe.db.get_value("Purchase Invoice Item", {"parent": pi.name}, "landed_cost_voucher_amount") @@ -137,7 +137,7 @@ class TestLandedCostVoucher(unittest.TestCase): serial_no_rate = frappe.db.get_value("Serial No", "SN001", "purchase_rate") - submit_landed_cost_voucher("Purchase Receipt", pr.name, pr.company) + create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company) serial_no = frappe.db.get_value("Serial No", "SN001", ["warehouse", "purchase_rate"], as_dict=1) @@ -160,7 +160,7 @@ class TestLandedCostVoucher(unittest.TestCase): }) pr.submit() - lcv = submit_landed_cost_voucher("Purchase Receipt", pr.name, pr.company, 123.22) + lcv = create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company, 123.22) self.assertEqual(lcv.items[0].applicable_charges, 41.07) self.assertEqual(lcv.items[2].applicable_charges, 41.08) @@ -236,7 +236,7 @@ def make_landed_cost_voucher(** args): return lcv -def submit_landed_cost_voucher(receipt_document_type, receipt_document, company, charges=50): +def create_landed_cost_voucher(receipt_document_type, receipt_document, company, charges=50): ref_doc = frappe.get_doc(receipt_document_type, receipt_document) lcv = frappe.new_doc("Landed Cost Voucher") diff --git a/erpnext/stock/doctype/material_request/test_material_request.py b/erpnext/stock/doctype/material_request/test_material_request.py index 19924b1636..0a29fa05e1 100644 --- a/erpnext/stock/doctype/material_request/test_material_request.py +++ b/erpnext/stock/doctype/material_request/test_material_request.py @@ -12,9 +12,6 @@ from erpnext.stock.doctype.material_request.material_request \ from erpnext.stock.doctype.item.test_item import create_item class TestMaterialRequest(unittest.TestCase): - def setUp(self): - erpnext.set_perpetual_inventory(0) - def test_make_purchase_order(self): mr = frappe.copy_doc(test_records[0]).insert() diff --git a/erpnext/stock/doctype/packed_item/packed_item.json b/erpnext/stock/doctype/packed_item/packed_item.json index 2ac5c426c0..f1d7f8c8c9 100644 --- a/erpnext/stock/doctype/packed_item/packed_item.json +++ b/erpnext/stock/doctype/packed_item/packed_item.json @@ -1,4 +1,5 @@ { + "actions": [], "creation": "2013-02-22 01:28:00", "doctype": "DocType", "editable_grid": 1, @@ -14,6 +15,7 @@ "target_warehouse", "column_break_9", "qty", + "uom", "section_break_9", "serial_no", "column_break_11", @@ -23,7 +25,7 @@ "actual_qty", "projected_qty", "column_break_16", - "uom", + "incoming_rate", "page_break", "prevdoc_doctype", "parent_detail_docname" @@ -199,11 +201,21 @@ "no_copy": 1, "print_hide": 1, "read_only": 1 + }, + { + "fieldname": "incoming_rate", + "fieldtype": "Currency", + "label": "Incoming Rate", + "no_copy": 1, + "print_hide": 1, + "read_only": 1 } ], "idx": 1, + "index_web_pages_for_search": 1, "istable": 1, - "modified": "2019-11-26 20:09:59.400960", + "links": [], + "modified": "2020-09-24 09:25:13.050151", "modified_by": "Administrator", "module": "Stock", "name": "Packed Item", @@ -212,4 +224,4 @@ "sort_field": "modified", "sort_order": "DESC", "track_changes": 1 -} +} \ No newline at end of file diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 97e0fa738c..226064bae7 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -181,6 +181,7 @@ class PurchaseReceipt(BuyingController): update_serial_nos_after_submit(self, "items") self.make_gl_entries() + self.repost_future_sle_and_gle() def check_next_docstatus(self): submit_rv = frappe.db.sql("""select t1.name @@ -209,7 +210,8 @@ class PurchaseReceipt(BuyingController): # because updating ordered qty in bin depends upon updated ordered qty in PO self.update_stock_ledger() self.make_gl_entries_on_cancel() - self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry') + self.repost_future_sle_and_gle() + self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry', 'Repost Item Valuation') self.delete_auto_created_batches() def get_current_stock(self): diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 9b8eeed1a1..83012d355f 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -9,14 +9,15 @@ import frappe.defaults from frappe.utils import cint, flt, cstr, today, random_string, add_days from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice from erpnext.stock.doctype.item.test_item import create_item -from erpnext import set_perpetual_inventory from erpnext.stock.doctype.serial_no.serial_no import SerialNoDuplicateError from erpnext.accounts.doctype.account.test_account import get_inventory_account from erpnext.stock.doctype.item.test_item import make_item from six import iteritems +from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse + + class TestPurchaseReceipt(unittest.TestCase): def setUp(self): - set_perpetual_inventory(0) frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1) def test_reverse_purchase_receipt_sle(self): @@ -112,6 +113,8 @@ class TestPurchaseReceipt(unittest.TestCase): self.assertFalse(get_gl_entries("Purchase Receipt", pr.name)) + pr.cancel() + def test_batched_serial_no_purchase(self): item = frappe.db.exists("Item", {'item_name': 'Batched Serialized Item'}) if not item: @@ -183,22 +186,30 @@ class TestPurchaseReceipt(unittest.TestCase): rm_supp_cost = sum([d.amount for d in pr.get("supplied_items")]) self.assertEqual(pr.get("items")[0].rm_supp_cost, flt(rm_supp_cost, 2)) + + pr.cancel() def test_subcontracting_gle_fg_item_rate_zero(self): from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry - set_perpetual_inventory() frappe.db.set_value("Buying Settings", None, "backflush_raw_materials_of_subcontract_based_on", "BOM") - make_stock_entry(item_code="_Test Item", target="Work In Progress - TCP1", qty=100, basic_rate=100, company="_Test Company with perpetual inventory") - make_stock_entry(item_code="_Test Item Home Desktop 100", target="Work In Progress - TCP1", + + se1 = make_stock_entry(item_code="_Test Item", target="Work In Progress - TCP1", qty=100, basic_rate=100, company="_Test Company with perpetual inventory") + + se2 = make_stock_entry(item_code="_Test Item Home Desktop 100", target="Work In Progress - TCP1", + qty=100, basic_rate=100, company="_Test Company with perpetual inventory") + pr = make_purchase_receipt(item_code="_Test FG Item", qty=10, rate=0, is_subcontracted="Yes", - company="_Test Company with perpetual inventory", warehouse='Stores - TCP1', supplier_warehouse='Work In Progress - TCP1') + company="_Test Company with perpetual inventory", warehouse='Stores - TCP1', + supplier_warehouse='Work In Progress - TCP1') gl_entries = get_gl_entries("Purchase Receipt", pr.name) self.assertFalse(gl_entries) - set_perpetual_inventory(0) + pr.cancel() + se1.cancel() + se2.cancel() def test_subcontracting_over_receipt(self): """ @@ -216,13 +227,13 @@ class TestPurchaseReceipt(unittest.TestCase): item_code = "_Test Subcontracted FG Item 1" make_subcontracted_item(item_code=item_code) - po = create_purchase_order(item_code=item_code, qty=1, + po = create_purchase_order(item_code=item_code, qty=1, include_exploded_items=0, is_subcontracted="Yes", supplier_warehouse="_Test Warehouse 1 - _TC") #stock raw materials in a warehouse before transfer - make_stock_entry(target="_Test Warehouse - _TC", - item_code = "Test Extra Item 1", qty=1, basic_rate=100) - make_stock_entry(target="_Test Warehouse - _TC", + se1 = make_stock_entry(target="_Test Warehouse - _TC", + item_code = "Test Extra Item 1", qty=10, basic_rate=100) + se2 = make_stock_entry(target="_Test Warehouse - _TC", item_code = "_Test FG Item", qty=1, basic_rate=100) rm_items = [ { @@ -254,6 +265,13 @@ class TestPurchaseReceipt(unittest.TestCase): pr1.submit() self.assertRaises(frappe.ValidationError, pr2.submit) + pr1.cancel() + se.cancel() + se1.cancel() + se2.cancel() + po.reload() + po.cancel() + def test_serial_no_supplier(self): pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1) self.assertEqual(frappe.db.get_value("Serial No", pr.get("items")[0].serial_no, "supplier"), @@ -284,6 +302,8 @@ class TestPurchaseReceipt(unittest.TestCase): self.assertEqual(frappe.db.get_value("Serial No", serial_no, "warehouse"), pr.get("items")[0].rejected_warehouse) + pr.cancel() + def test_purchase_return_partial(self): pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1") @@ -371,6 +391,9 @@ class TestPurchaseReceipt(unittest.TestCase): self.assertEqual(pr.per_returned, 100) self.assertEqual(pr.status, 'Return Issued') + return_pr.cancel() + pr.cancel() + def test_purchase_return_for_rejected_qty(self): from erpnext.stock.doctype.warehouse.test_warehouse import get_warehouse @@ -388,6 +411,9 @@ class TestPurchaseReceipt(unittest.TestCase): self.assertEqual(actual_qty, -2) + return_pr.cancel() + pr.cancel() + def test_purchase_return_for_serialized_items(self): def _check_serial_no_values(serial_no, field_values): @@ -415,6 +441,10 @@ class TestPurchaseReceipt(unittest.TestCase): "delivery_document_no": return_pr.name }) + return_pr.cancel() + pr.reload() + pr.cancel() + def test_purchase_return_for_multi_uom(self): item_code = "_Test Purchase Return For Multi-UOM" if not frappe.db.exists('Item', item_code): @@ -431,6 +461,9 @@ class TestPurchaseReceipt(unittest.TestCase): self.assertEqual(abs(return_pr.items[0].stock_qty), 1.0) + return_pr.cancel() + pr.cancel() + def test_closed_purchase_receipt(self): from erpnext.stock.doctype.purchase_receipt.purchase_receipt import update_purchase_receipt_status @@ -440,6 +473,9 @@ class TestPurchaseReceipt(unittest.TestCase): update_purchase_receipt_status(pr.name, "Closed") self.assertEqual(frappe.db.get_value("Purchase Receipt", pr.name, "status"), "Closed") + pr.reload() + pr.cancel() + def test_pr_billing_status(self): # PO -> PR1 -> PI and PO -> PI and PO -> PR2 from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order @@ -482,6 +518,16 @@ class TestPurchaseReceipt(unittest.TestCase): self.assertEqual(pr2.per_billed, 80) self.assertEqual(pr2.status, "To Bill") + pr2.cancel() + pi2.reload() + pi2.cancel() + pi1.reload() + pi1.cancel() + pr1.reload() + pr1.cancel() + po.reload() + po.cancel() + def test_serial_no_against_purchase_receipt(self): from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos @@ -509,6 +555,8 @@ class TestPurchaseReceipt(unittest.TestCase): self.assertEqual(serial_no, frappe.db.get_value("Serial No", {"purchase_document_type": "Purchase Receipt", "purchase_document_no": new_pr_doc.name}, "name")) + new_pr_doc.cancel() + def test_not_accept_duplicate_serial_no(self): from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note @@ -519,16 +567,19 @@ class TestPurchaseReceipt(unittest.TestCase): item_code = item.name serial_no = random_string(5) - make_purchase_receipt(item_code=item_code, qty=1, serial_no=serial_no) - create_delivery_note(item_code=item_code, qty=1, serial_no=serial_no) + pr1 = make_purchase_receipt(item_code=item_code, qty=1, serial_no=serial_no) + dn = create_delivery_note(item_code=item_code, qty=1, serial_no=serial_no) - pr = make_purchase_receipt(item_code=item_code, qty=1, serial_no=serial_no, do_not_submit=True) - self.assertRaises(SerialNoDuplicateError, pr.submit) + pr2 = make_purchase_receipt(item_code=item_code, qty=1, serial_no=serial_no, do_not_submit=True) + self.assertRaises(SerialNoDuplicateError, pr2.submit) se = make_stock_entry(item_code=item_code, target="_Test Warehouse - _TC", qty=1, serial_no=serial_no, basic_rate=100, do_not_submit=True) self.assertRaises(SerialNoDuplicateError, se.submit) + dn.cancel() + pr1.cancel() + def test_auto_asset_creation(self): asset_item = "Test Asset Item" @@ -549,7 +600,7 @@ class TestPurchaseReceipt(unittest.TestCase): 'company_name': '_Test Company', 'fixed_asset_account': '_Test Fixed Asset - _TC', 'accumulated_depreciation_account': '_Test Accumulated Depreciations - _TC', - 'depreciation_expense_account': '_Test Depreciation - _TC' + 'depreciation_expense_account': '_Test Depreciations - _TC' }] }).insert() @@ -568,6 +619,8 @@ class TestPurchaseReceipt(unittest.TestCase): location = frappe.db.get_value('Asset', assets[0].name, 'location') self.assertEquals(location, "Test Location") + pr.cancel() + def test_purchase_return_with_submitted_asset(self): from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_return @@ -594,6 +647,9 @@ class TestPurchaseReceipt(unittest.TestCase): pr_return.submit() + pr_return.cancel() + pr.cancel() + def test_purchase_receipt_cost_center(self): from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center cost_center = "_Test Cost Center for BS Account - TCP1" @@ -605,7 +661,8 @@ class TestPurchaseReceipt(unittest.TestCase): 'location_name': 'Test Location' }).insert() - pr = make_purchase_receipt(cost_center=cost_center, company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1") + pr = make_purchase_receipt(cost_center=cost_center, company="_Test Company with perpetual inventory", + warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1") stock_in_hand_account = get_inventory_account(pr.company, pr.get("items")[0].warehouse) gl_entries = get_gl_entries("Purchase Receipt", pr.name) @@ -623,6 +680,8 @@ class TestPurchaseReceipt(unittest.TestCase): for i, gle in enumerate(gl_entries): self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center) + pr.cancel() + def test_purchase_receipt_cost_center_with_balance_sheet_account(self): if not frappe.db.exists('Location', 'Test Location'): frappe.get_doc({ @@ -648,6 +707,8 @@ class TestPurchaseReceipt(unittest.TestCase): for i, gle in enumerate(gl_entries): self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center) + pr.cancel() + def test_make_purchase_invoice_from_pr_for_returned_qty(self): from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order, create_pr_against_po @@ -663,6 +724,12 @@ class TestPurchaseReceipt(unittest.TestCase): pi = make_purchase_invoice(pr.name) self.assertEquals(pi.items[0].qty, 3) + pr1.cancel() + pr.reload() + pr.cancel() + po.reload() + po.cancel() + def test_make_purchase_invoice_from_pr_with_returned_qty_duplicate_items(self): pr1 = make_purchase_receipt(qty=8, do_not_submit=True) pr1.append("items", { @@ -689,8 +756,14 @@ class TestPurchaseReceipt(unittest.TestCase): self.assertEquals(pi2.items[0].qty, 2) self.assertEquals(pi2.items[1].qty, 1) + pr2.cancel() + pi1.cancel() + pr1.reload() + pr1.cancel() + def test_stock_transfer_from_purchase_receipt(self): - pr1 = make_purchase_receipt(warehouse = 'Work In Progress - TCP1', company="_Test Company with perpetual inventory") + pr1 = make_purchase_receipt(warehouse = 'Work In Progress - TCP1', + company="_Test Company with perpetual inventory") pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", do_not_save=1) @@ -713,18 +786,20 @@ class TestPurchaseReceipt(unittest.TestCase): for sle in sl_entries: self.assertEqual(expected_sle[sle.warehouse], sle.actual_qty) - def test_stock_transfer_from_purchase_receipt_with_valuation(self): - warehouse = frappe.get_doc('Warehouse', 'Work In Progress - TCP1') - warehouse.account = '_Test Account Stock In Hand - TCP1' - warehouse.save() + pr.cancel() + pr1.cancel() - pr1 = make_purchase_receipt(warehouse = 'Work In Progress - TCP1', + def test_stock_transfer_from_purchase_receipt_with_valuation(self): + create_warehouse("_Test Warehouse for Valuation", company="_Test Company with perpetual inventory", + properties={"account": '_Test Account Stock In Hand - TCP1'}) + + pr1 = make_purchase_receipt(warehouse = '_Test Warehouse for Valuation - TCP1', company="_Test Company with perpetual inventory") pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", do_not_save=1) - pr.items[0].from_warehouse = 'Work In Progress - TCP1' + pr.items[0].from_warehouse = '_Test Warehouse for Valuation - TCP1' pr.supplier_warehouse = '' @@ -749,7 +824,7 @@ class TestPurchaseReceipt(unittest.TestCase): ] expected_sle = { - 'Work In Progress - TCP1': -5, + '_Test Warehouse for Valuation - TCP1': -5, 'Stores - TCP1': 5 } @@ -761,60 +836,9 @@ class TestPurchaseReceipt(unittest.TestCase): self.assertEqual(gle.debit, expected_gle[i][1]) self.assertEqual(gle.credit, expected_gle[i][2]) - warehouse.account = '' - warehouse.save() + pr.cancel() + pr1.cancel() - def test_backdated_purchase_receipt(self): - # make purchase receipt for default company - make_purchase_receipt(company="_Test Company 4", warehouse="Stores - _TC4") - - # try to make another backdated PR - posting_date = add_days(today(), -1) - pr = make_purchase_receipt(company="_Test Company 4", warehouse="Stores - _TC4", - do_not_submit=True) - - pr.set_posting_time = 1 - pr.posting_date = posting_date - pr.save() - - self.assertRaises(frappe.ValidationError, pr.submit) - - # make purchase receipt for other company backdated - pr = make_purchase_receipt(company="_Test Company 5", warehouse="Stores - _TC5", - do_not_submit=True) - - pr.set_posting_time = 1 - pr.posting_date = posting_date - pr.submit() - - # Allowed to submit for other company's PR - self.assertEqual(pr.docstatus, 1) - - def test_backdated_purchase_receipt_for_same_company_different_warehouse(self): - # make purchase receipt for default company - make_purchase_receipt(company="_Test Company 4", warehouse="Stores - _TC4") - - # try to make another backdated PR - posting_date = add_days(today(), -1) - pr = make_purchase_receipt(company="_Test Company 4", warehouse="Stores - _TC4", - do_not_submit=True) - - pr.set_posting_time = 1 - pr.posting_date = posting_date - pr.save() - - self.assertRaises(frappe.ValidationError, pr.submit) - - # make purchase receipt for other company backdated - pr = make_purchase_receipt(company="_Test Company 4", warehouse="Finished Goods - _TC4", - do_not_submit=True) - - pr.set_posting_time = 1 - pr.posting_date = posting_date - pr.submit() - - # Allowed to submit for other company's PR - self.assertEqual(pr.docstatus, 1) def test_subcontracted_pr_for_multi_transfer_batches(self): from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry @@ -877,6 +901,12 @@ class TestPurchaseReceipt(unittest.TestCase): update_backflush_based_on("BOM") + pr.delete() + se.cancel() + ste2.cancel() + ste1.cancel() + po.cancel() + def get_sl_entries(voucher_type, voucher_no): return frappe.db.sql(""" select actual_qty, warehouse, stock_value_difference from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s @@ -972,6 +1002,8 @@ def make_purchase_receipt(**args): pr.posting_date = args.posting_date or today() if args.posting_time: pr.posting_time = args.posting_time + if args.posting_date or args.posting_time: + pr.set_posting_time = 1 pr.company = args.company or "_Test Company" pr.supplier = args.supplier or "_Test Supplier" pr.is_subcontracted = args.is_subcontracted or "No" diff --git a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json index 84c64aa8f8..871b255b06 100644 --- a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json +++ b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json @@ -866,7 +866,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2020-11-02 10:00:38.204294", + "modified": "2020-12-07 10:00:38.204294", "modified_by": "Administrator", "module": "Stock", "name": "Purchase Receipt Item", diff --git a/erpnext/stock/doctype/repost_item_valuation/__init__.py b/erpnext/stock/doctype/repost_item_valuation/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js new file mode 100644 index 0000000000..e429cd5e30 --- /dev/null +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js @@ -0,0 +1,52 @@ +// Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Repost Item Valuation', { + setup: function(frm) { + frm.set_query("warehouse", () => { + let filters = { + 'is_group': 0 + }; + if (frm.doc.company) filters['company'] = frm.doc.company; + return {filters: filters}; + }); + + frm.set_query("voucher_type", () => { + return { + filters: { + name: ['in', ['Purchase Receipt', 'Purchase Invoice', 'Delivery Note', + 'Sales Invoice', 'Stock Entry', 'Stock Reconciliation']] + } + }; + }); + + if (frm.doc.company) { + frm.set_query("voucher_no", () => { + return { + filters: { + company: frm.doc.company + } + }; + }); + } + }, + refresh: function(frm) { + if (frm.doc.status == "Failed") { + frm.add_custom_button(__('Restart'), function () { + frm.trigger("restart_reposting"); + }).addClass("btn-primary"); + } + }, + + restart_reposting: function(frm) { + frappe.call({ + method: "restart_reposting", + doc: frm.doc, + callback: function(r) { + if (!r.exc) { + frm.refresh(); + } + } + }); + } +}); diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json new file mode 100644 index 0000000000..071fc86d9b --- /dev/null +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json @@ -0,0 +1,215 @@ +{ + "actions": [], + "autoname": "REPOST-ITEM-VAL-.######", + "creation": "2020-10-22 22:27:07.742161", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "based_on", + "voucher_type", + "voucher_no", + "item_code", + "warehouse", + "posting_date", + "posting_time", + "column_break_5", + "status", + "company", + "allow_negative_stock", + "via_landed_cost_voucher", + "allow_zero_rate", + "amended_from", + "error_section", + "error_log" + ], + "fields": [ + { + "depends_on": "eval:doc.based_on=='Item and Warehouse'", + "fieldname": "item_code", + "fieldtype": "Link", + "label": "Item Code", + "mandatory_depends_on": "eval:doc.based_on=='Item and Warehouse'", + "options": "Item" + }, + { + "depends_on": "eval:doc.based_on=='Item and Warehouse'", + "fieldname": "warehouse", + "fieldtype": "Link", + "label": "Warehouse", + "mandatory_depends_on": "eval:doc.based_on=='Item and Warehouse'", + "options": "Warehouse" + }, + { + "fetch_from": "voucher_no.posting_date", + "fieldname": "posting_date", + "fieldtype": "Date", + "label": "Posting Date", + "reqd": 1 + }, + { + "fetch_from": "voucher_no.posting_time", + "fieldname": "posting_time", + "fieldtype": "Time", + "label": "Posting Time" + }, + { + "default": "Queued", + "fieldname": "status", + "fieldtype": "Select", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Status", + "no_copy": 1, + "options": "Queued\nIn Progress\nCompleted\nFailed", + "read_only": 1 + }, + { + "fieldname": "amended_from", + "fieldtype": "Link", + "label": "Amended From", + "no_copy": 1, + "options": "Repost Item Valuation", + "print_hide": 1, + "read_only": 1 + }, + { + "fieldname": "column_break_5", + "fieldtype": "Column Break" + }, + { + "depends_on": "eval:doc.status=='Failed'", + "fieldname": "error_section", + "fieldtype": "Section Break", + "label": "Error" + }, + { + "fieldname": "error_log", + "fieldtype": "Long Text", + "label": "Error Log", + "no_copy": 1, + "read_only": 1 + }, + { + "fetch_from": "warehouse.company", + "fieldname": "company", + "fieldtype": "Link", + "label": "Company", + "options": "Company" + }, + { + "depends_on": "eval:doc.based_on=='Transaction'", + "fieldname": "voucher_type", + "fieldtype": "Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Voucher Type", + "mandatory_depends_on": "eval:doc.based_on=='Transaction'", + "options": "DocType" + }, + { + "depends_on": "eval:doc.based_on=='Transaction'", + "fieldname": "voucher_no", + "fieldtype": "Dynamic Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Voucher No", + "mandatory_depends_on": "eval:doc.based_on=='Transaction'", + "options": "voucher_type" + }, + { + "default": "Transaction", + "fieldname": "based_on", + "fieldtype": "Select", + "label": "Based On", + "options": "Transaction\nItem and Warehouse", + "reqd": 1 + }, + { + "default": "0", + "fieldname": "allow_negative_stock", + "fieldtype": "Check", + "label": "Allow Negative Stock" + }, + { + "default": "0", + "fieldname": "via_landed_cost_voucher", + "fieldtype": "Check", + "label": "Via Landed Cost Voucher" + }, + { + "default": "0", + "fieldname": "allow_zero_rate", + "fieldtype": "Check", + "label": "Allow Zero Rate" + } + ], + "index_web_pages_for_search": 1, + "is_submittable": 1, + "links": [], + "modified": "2020-12-10 07:52:12.476589", + "modified_by": "Administrator", + "module": "Stock", + "name": "Repost Item Valuation", + "owner": "Administrator", + "permissions": [ + { + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "submit": 1, + "write": 1 + }, + { + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Stock User", + "share": 1, + "submit": 1, + "write": 1 + }, + { + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Stock Manager", + "share": 1, + "submit": 1, + "write": 1 + }, + { + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts User", + "share": 1, + "submit": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py new file mode 100644 index 0000000000..a942f2edda --- /dev/null +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -0,0 +1,89 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe, erpnext +from frappe.model.document import Document +from frappe.utils import cint +from erpnext.stock.stock_ledger import repost_future_sle +from erpnext.accounts.utils import update_gl_entries_after + + +class RepostItemValuation(Document): + def validate(self): + self.set_status() + self.reset_field_values() + self.set_company() + + def reset_field_values(self): + if self.based_on == 'Transaction': + self.item_code = None + self.warehouse = None + else: + self.voucher_type = None + self.voucher_no = None + + def set_company(self): + if self.voucher_type and self.voucher_no: + self.company = frappe.get_cached_value(self.voucher_type, self.voucher_no, "company") + elif self.warehouse: + self.company = frappe.get_cached_value("Warehouse", self.warehouse, "company") + + def set_status(self, status=None): + if not status: + status = 'Queued' + self.db_set('status', status) + + def on_submit(self): + frappe.enqueue(repost, timeout=1800, queue='long', + job_name='repost_sle', now=frappe.flags.in_test, doc=self) + + def restart_reposting(self): + self.set_status('Queued') + frappe.enqueue(repost, timeout=1800, queue='long', + job_name='repost_sle', now=True, doc=self) + +def repost(doc): + try: + doc.set_status('In Progress') + frappe.db.commit() + + repost_sl_entries(doc) + repost_gl_entries(doc) + doc.set_status('Completed') + except Exception: + frappe.db.rollback() + traceback = frappe.get_traceback() + frappe.log_error(traceback) + frappe.db.set_value(doc.doctype, doc.name, 'error_log', traceback) + doc.set_status('Failed') + raise + finally: + frappe.db.commit() + +def repost_sl_entries(doc): + if doc.based_on == 'Transaction': + repost_future_sle(voucher_type=doc.voucher_type, voucher_no=doc.voucher_no, + allow_negative_stock=doc.allow_negative_stock, via_landed_cost_voucher=doc.via_landed_cost_voucher) + else: + repost_future_sle(args=[frappe._dict({ + "item_code": doc.item_code, + "warehouse": doc.warehouse, + "posting_date": doc.posting_date, + "posting_time": doc.posting_time + })], allow_negative_stock=doc.allow_negative_stock, via_landed_cost_voucher=doc.via_landed_cost_voucher) + +def repost_gl_entries(doc): + if not cint(erpnext.is_perpetual_inventory_enabled(doc.company)): + return + + if doc.based_on == 'Transaction': + ref_doc = frappe.get_doc(doc.voucher_type, doc.voucher_no) + items, warehouses = ref_doc.get_items_and_warehouses() + else: + items = [doc.item_code] + warehouses = [doc.warehouse] + + update_gl_entries_after(doc.posting_date, doc.posting_time, + warehouses, items, company=doc.company) \ No newline at end of file diff --git a/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py new file mode 100644 index 0000000000..13ceb68669 --- /dev/null +++ b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +# import frappe +import unittest + +class TestRepostItemValuation(unittest.TestCase): + pass diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py index 64bdf3b171..2d89996f2a 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.py +++ b/erpnext/stock/doctype/serial_no/serial_no.py @@ -134,17 +134,13 @@ class SerialNo(StockController): sle_dict = self.get_stock_ledger_entries(serial_no) if sle_dict: if sle_dict.get("incoming", []): - sle_list = [sle for sle in sle_dict["incoming"] if sle.is_cancelled == 0] - if sle_list: - entries["purchase_sle"] = sle_list[0] + entries["purchase_sle"] = sle_dict["incoming"][0] if len(sle_dict.get("incoming", [])) - len(sle_dict.get("outgoing", [])) > 0: entries["last_sle"] = sle_dict["incoming"][0] else: entries["last_sle"] = sle_dict["outgoing"][0] - sle_list = [sle for sle in sle_dict["outgoing"] if sle.is_cancelled == 0] - if sle_list: - entries["delivery_sle"] = sle_list[0] + entries["delivery_sle"] = sle_dict["outgoing"][0] return entries @@ -155,11 +151,12 @@ class SerialNo(StockController): for sle in frappe.db.sql(""" SELECT voucher_type, voucher_no, - posting_date, posting_time, incoming_rate, actual_qty, serial_no, is_cancelled + posting_date, posting_time, incoming_rate, actual_qty, serial_no FROM `tabStock Ledger Entry` WHERE item_code=%s AND company = %s + AND is_cancelled = 0 AND (serial_no = %s OR serial_no like %s OR serial_no like %s @@ -179,7 +176,7 @@ class SerialNo(StockController): def on_trash(self): sl_entries = frappe.db.sql("""select serial_no from `tabStock Ledger Entry` - where serial_no like %s and item_code=%s""", + where serial_no like %s and item_code=%s and is_cancelled=0""", ("%%%s%%" % self.name, self.item_code), as_dict=True) # Find the exact match @@ -229,7 +226,7 @@ def validate_serial_no(sle, item_det): if serial_nos: frappe.throw(_("Item {0} is not setup for Serial Nos. Column must be blank").format(sle.item_code), SerialNoNotRequiredError) - else: + elif not sle.is_cancelled: if serial_nos: if cint(sle.actual_qty) != flt(sle.actual_qty): frappe.throw(_("Serial No {0} quantity {1} cannot be a fraction").format(sle.item_code, sle.actual_qty)) @@ -247,10 +244,6 @@ def validate_serial_no(sle, item_det): "delivery_document_no", "delivery_document_type", "warehouse", "purchase_document_no", "company"], as_dict=1) - if sr and cint(sle.actual_qty) < 0 and sr.warehouse != sle.warehouse: - frappe.throw(_("Cannot cancel {0} {1} because Serial No {2} does not belong to the warehouse {3}") - .format(sle.voucher_type, sle.voucher_no, serial_no, sle.warehouse), SerialNoWarehouseError) - if sr.item_code!=sle.item_code: if not allow_serial_nos_with_different_item(serial_no, sle): frappe.throw(_("Serial No {0} does not belong to Item {1}").format(serial_no, @@ -277,7 +270,7 @@ def validate_serial_no(sle, item_det): frappe.throw(_("Serial No {0} does not belong to Batch {1}").format(serial_no, sle.batch_no), SerialNoBatchError) - if not sr.warehouse: + if not sle.is_cancelled and not sr.warehouse: frappe.throw(_("Serial No {0} does not belong to any Warehouse") .format(serial_no), SerialNoWarehouseError) @@ -327,6 +320,12 @@ def validate_serial_no(sle, item_det): elif cint(sle.actual_qty) < 0 or not item_det.serial_no_series: frappe.throw(_("Serial Nos Required for Serialized Item {0}").format(sle.item_code), SerialNoRequiredError) + elif serial_nos: + for serial_no in serial_nos: + sr = frappe.db.get_value("Serial No", serial_no, ["name", "warehouse"], as_dict=1) + if sr and cint(sle.actual_qty) < 0 and sr.warehouse != sle.warehouse: + frappe.throw(_("Cannot cancel {0} {1} because Serial No {2} does not belong to the warehouse {3}") + .format(sle.voucher_type, sle.voucher_no, serial_no, sle.warehouse)) def validate_material_transfer_entry(sle_doc): sle_doc.update({ @@ -334,7 +333,7 @@ def validate_material_transfer_entry(sle_doc): "skip_serial_no_validaiton": False }) - if (sle_doc.voucher_type == "Stock Entry" and + if (sle_doc.voucher_type == "Stock Entry" and not sle_doc.is_cancelled and frappe.get_cached_value("Stock Entry", sle_doc.voucher_no, "purpose") == "Material Transfer"): if sle_doc.actual_qty < 0: sle_doc.skip_update_serial_no = True @@ -379,7 +378,7 @@ def allow_serial_nos_with_different_item(sle_serial_no, sle): stock_entry = frappe.get_cached_doc("Stock Entry", sle.voucher_no) if stock_entry.purpose in ("Repack", "Manufacture"): for d in stock_entry.get("items"): - if d.serial_no and (d.s_warehouse or d.t_warehouse): + if d.serial_no and (d.s_warehouse if not sle.is_cancelled else d.t_warehouse): serial_nos = get_serial_nos(d.serial_no) if sle_serial_no in serial_nos: allow_serial_nos = True @@ -388,7 +387,7 @@ def allow_serial_nos_with_different_item(sle_serial_no, sle): def update_serial_nos(sle, item_det): if sle.skip_update_serial_no: return - if not sle.serial_no and cint(sle.actual_qty) > 0 \ + if not sle.is_cancelled and not sle.serial_no and cint(sle.actual_qty) > 0 \ and item_det.has_serial_no == 1 and item_det.serial_no_series: serial_nos = get_auto_serial_nos(item_det.serial_no_series, sle.actual_qty) frappe.db.set(sle, "serial_no", serial_nos) diff --git a/erpnext/stock/doctype/serial_no/test_serial_no.py b/erpnext/stock/doctype/serial_no/test_serial_no.py index ab061076e5..ed70790b2c 100644 --- a/erpnext/stock/doctype/serial_no/test_serial_no.py +++ b/erpnext/stock/doctype/serial_no/test_serial_no.py @@ -12,7 +12,6 @@ from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_pu from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse -from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory test_dependencies = ["Item"] test_records = frappe.get_test_records('Serial No') @@ -38,8 +37,6 @@ class TestSerialNo(unittest.TestCase): self.assertTrue(SerialNoCannotCannotChangeError, sr.save) def test_inter_company_transfer(self): - set_perpetual_inventory(0, "_Test Company 1") - set_perpetual_inventory(0) se = make_serialized_item(target_warehouse="_Test Warehouse - _TC") serial_nos = get_serial_nos(se.get("items")[0].serial_no) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 27fcbb7e2a..98116ec183 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -510,22 +510,31 @@ frappe.ui.form.on('Stock Entry', { calculate_amount: function(frm) { frm.events.calculate_total_additional_costs(frm); - - const total_basic_amount = frappe.utils.sum( - (frm.doc.items || []).map(function(i) { return i.t_warehouse ? flt(i.basic_amount) : 0; }) - ); - + let total_basic_amount = 0; + if (in_list(["Repack", "Manufacture"], frm.doc.purpose)) { + total_basic_amount = frappe.utils.sum( + (frm.doc.items || []).map(function(i) { + return i.is_finished_item ? flt(i.basic_amount) : 0; + }) + ); + } else { + total_basic_amount = frappe.utils.sum( + (frm.doc.items || []).map(function(i) { + return i.t_warehouse ? flt(i.basic_amount) : 0; + }) + ); + } + for (let i in frm.doc.items) { let item = frm.doc.items[i]; - if (item.t_warehouse && total_basic_amount) { + if (((in_list(["Repack", "Manufacture"], frm.doc.purpose) && item.is_finished_item) || item.t_warehouse) && total_basic_amount) { item.additional_cost = (flt(item.basic_amount) / total_basic_amount) * frm.doc.total_additional_costs; } else { item.additional_cost = 0; } - item.amount = flt(item.basic_amount + flt(item.additional_cost), - precision("amount", item)); + item.amount = flt(item.basic_amount + flt(item.additional_cost), precision("amount", item)); if (flt(item.transfer_qty)) { item.valuation_rate = flt(flt(item.basic_rate) + (flt(item.additional_cost) / flt(item.transfer_qty)), diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.json b/erpnext/stock/doctype/stock_entry/stock_entry.json index 61e0df6723..5aed08102c 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.json +++ b/erpnext/stock/doctype/stock_entry/stock_entry.json @@ -644,9 +644,10 @@ ], "icon": "fa fa-file-text", "idx": 1, + "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2020-08-11 19:10:07.954981", + "modified": "2020-09-09 12:59:02.508943", "modified_by": "Administrator", "module": "Stock", "name": "Stock Entry", diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 32d7e6eb34..afdb54ceaa 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -18,7 +18,7 @@ from erpnext.stock.utils import get_bin from frappe.model.mapper import get_mapped_doc from erpnext.stock.doctype.serial_no.serial_no import update_serial_nos_after_submit, get_serial_nos from erpnext.stock.doctype.stock_reconciliation.stock_reconciliation import OpeningEntryAccountError - +from erpnext.accounts.general_ledger import process_gl_map import json from six import string_types, itervalues, iteritems @@ -58,6 +58,7 @@ class StockEntry(StockController): self.validate_warehouse() self.validate_work_order() self.validate_bom() + self.mark_finished_and_scrap_items() self.validate_finished_goods() self.validate_with_material_request() self.validate_batch() @@ -75,13 +76,11 @@ class StockEntry(StockController): else: set_batch_nos(self, 's_warehouse') - self.set_incoming_rate() self.validate_serialized_batch() self.set_actual_qty() - self.calculate_rate_and_amount(update_finished_item_rate=False) + self.calculate_rate_and_amount() def on_submit(self): - self.update_stock_ledger() update_serial_nos_after_submit(self, "items") @@ -89,11 +88,15 @@ class StockEntry(StockController): self.validate_purchase_order() if self.purchase_order and self.purpose == "Send to Subcontractor": self.update_purchase_order_supplied_items() + self.make_gl_entries() + + self.repost_future_sle_and_gle() self.update_cost_in_project() self.validate_reserved_serial_no_consumption() self.update_transferred_qty() self.update_quality_inspection() + if self.work_order and self.purpose == "Manufacture": self.update_so_in_serial_number() @@ -113,9 +116,10 @@ class StockEntry(StockController): self.update_work_order() self.update_stock_ledger() - self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry') + self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry', 'Repost Item Valuation') self.make_gl_entries_on_cancel() + self.repost_future_sle_and_gle() self.update_cost_in_project() self.update_transferred_qty() self.update_quality_inspection() @@ -256,11 +260,10 @@ class StockEntry(StockController): def validate_fg_completed_qty(self): if self.purpose == "Manufacture" and self.work_order: - production_item = frappe.get_value('Work Order', self.work_order, 'production_item') - for item in self.items: - if item.item_code == production_item and item.t_warehouse and item.qty != self.fg_completed_qty: + for d in self.items: + if d.is_finished_item and d.qty != self.fg_completed_qty: frappe.throw(_("Finished product quantity {0} and For Quantity {1} cannot be different") - .format(item.qty, self.fg_completed_qty)) + .format(d.qty, self.fg_completed_qty)) def validate_difference_account(self): if not cint(erpnext.is_perpetual_inventory_enabled(self.company)): @@ -382,21 +385,6 @@ class StockEntry(StockController): frappe.throw(_("Stock Entries already created for Work Order ") + self.work_order + ":" + ", ".join(other_ste), DuplicateEntryForWorkOrderError) - def set_incoming_rate(self): - if self.purpose == "Repack": - self.set_basic_rate_for_finished_goods() - - for d in self.items: - if d.s_warehouse: - args = self.get_args_for_incoming_rate(d) - d.basic_rate = get_incoming_rate(args) - elif d.allow_zero_valuation_rate and not d.s_warehouse: - d.basic_rate = 0.0 - elif d.t_warehouse and not d.basic_rate: - d.basic_rate = get_valuation_rate(d.item_code, d.t_warehouse, - self.doctype, self.name, d.allow_zero_valuation_rate, - currency=erpnext.get_company_currency(self.company), company=self.company) - def set_actual_qty(self): allow_negative_stock = cint(frappe.db.get_value("Stock Settings", None, "allow_negative_stock")) @@ -432,57 +420,64 @@ class StockEntry(StockController): d.serial_no = transferred_serial_no def get_stock_and_rate(self): + """ + Updates rate and availability of all the items. + Called from Update Rate and Availability button. + """ self.set_work_order_details() self.set_transfer_qty() self.set_actual_qty() self.calculate_rate_and_amount() - def calculate_rate_and_amount(self, force=False, - update_finished_item_rate=True, raise_error_if_no_rate=True): - self.set_basic_rate(force, update_finished_item_rate, raise_error_if_no_rate) + def calculate_rate_and_amount(self, reset_outgoing_rate=True, raise_error_if_no_rate=True): + self.set_basic_rate(reset_outgoing_rate, raise_error_if_no_rate) self.distribute_additional_costs() self.update_valuation_rate() self.set_total_incoming_outgoing_value() self.set_total_amount() - def set_basic_rate(self, force=False, update_finished_item_rate=True, raise_error_if_no_rate=True): - """get stock and incoming rate on posting date""" - raw_material_cost = 0.0 - scrap_material_cost = 0.0 - fg_basic_rate = 0.0 + def set_basic_rate(self, reset_outgoing_rate=True, raise_error_if_no_rate=True): + """ + Set rate for outgoing, scrapped and finished items + """ + # Set rate for outgoing items + outgoing_items_cost = self.set_rate_for_outgoing_items(reset_outgoing_rate) + # Set basic rate for incoming items for d in self.get('items'): - if d.t_warehouse: fg_basic_rate = flt(d.basic_rate) - args = self.get_args_for_incoming_rate(d) + if d.s_warehouse or d.set_basic_rate_manually: continue - # get basic rate - if not d.bom_no: - if (not flt(d.basic_rate) and not d.allow_zero_valuation_rate) or d.s_warehouse or force: - basic_rate = flt(get_incoming_rate(args, raise_error_if_no_rate), self.precision("basic_rate", d)) - if basic_rate > 0: - d.basic_rate = basic_rate + if d.allow_zero_valuation_rate: + d.basic_rate = 0.0 + elif d.is_finished_item: + if self.purpose == "Manufacture": + d.basic_rate = self.get_basic_rate_for_manufactured_item(d.transfer_qty, outgoing_items_cost) + elif self.purpose == "Repack": + d.basic_rate = self.get_basic_rate_for_repacked_items(d.transfer_qty, outgoing_items_cost) + + if not d.basic_rate and not d.allow_zero_valuation_rate: + d.basic_rate = get_valuation_rate(d.item_code, d.t_warehouse, + self.doctype, self.name, d.allow_zero_valuation_rate, + currency=erpnext.get_company_currency(self.company), company=self.company, + raise_error_if_no_rate=raise_error_if_no_rate) + + d.basic_rate = flt(d.basic_rate, d.precision("basic_rate")) + d.basic_amount = flt(flt(d.transfer_qty) * flt(d.basic_rate), d.precision("basic_amount")) + + def set_rate_for_outgoing_items(self, reset_outgoing_rate=True): + outgoing_items_cost = 0.0 + for d in self.get('items'): + if d.s_warehouse: + if reset_outgoing_rate: + args = self.get_args_for_incoming_rate(d) + rate = get_incoming_rate(args) + if rate > 0: + d.basic_rate = rate d.basic_amount = flt(flt(d.transfer_qty) * flt(d.basic_rate), d.precision("basic_amount")) if not d.t_warehouse: - raw_material_cost += flt(d.basic_amount) - - # get scrap items basic rate - if d.bom_no: - if not flt(d.basic_rate) and not d.allow_zero_valuation_rate and \ - getattr(self, "pro_doc", frappe._dict()).scrap_warehouse == d.t_warehouse: - basic_rate = flt(get_incoming_rate(args, raise_error_if_no_rate), - self.precision("basic_rate", d)) - if basic_rate > 0: - d.basic_rate = basic_rate - d.basic_amount = flt(flt(d.transfer_qty) * flt(d.basic_rate), d.precision("basic_amount")) - - if getattr(self, "pro_doc", frappe._dict()).scrap_warehouse == d.t_warehouse: - - scrap_material_cost += flt(d.basic_amount) - - number_of_fg_items = len([t.t_warehouse for t in self.get("items") if t.t_warehouse]) - if (fg_basic_rate == 0.0 and number_of_fg_items == 1) or update_finished_item_rate: - self.set_basic_rate_for_finished_goods(raw_material_cost, scrap_material_cost) + outgoing_items_cost += flt(d.basic_amount) + return outgoing_items_cost def get_args_for_incoming_rate(self, item): return frappe._dict({ @@ -498,44 +493,44 @@ class StockEntry(StockController): "allow_zero_valuation": item.allow_zero_valuation_rate, }) - def set_basic_rate_for_finished_goods(self, raw_material_cost=0, scrap_material_cost=0): - total_fg_qty = 0 - if not raw_material_cost and self.get("items"): - raw_material_cost = sum([flt(row.basic_amount) for row in self.items - if row.s_warehouse and not row.t_warehouse]) + def get_basic_rate_for_repacked_items(self, finished_item_qty, outgoing_items_cost): + finished_items = [d.item_code for d in self.get("items") if d.is_finished_item] + if len(finished_items) == 1: + return flt(outgoing_items_cost / finished_item_qty) + else: + unique_finished_items = set(finished_items) + if len(unique_finished_items) == 1: + total_fg_qty = sum([flt(d.transfer_qty) for d in self.items if d.is_finished_item]) + return flt(outgoing_items_cost / total_fg_qty) - total_fg_qty = sum([flt(row.qty) for row in self.items - if row.t_warehouse and not row.s_warehouse]) + def get_basic_rate_for_manufactured_item(self, finished_item_qty, outgoing_items_cost=0): + scrap_items_cost = sum([flt(d.basic_amount) for d in self.get("items") if d.is_scrap_item]) - if self.purpose in ["Manufacture", "Repack"]: - for d in self.get("items"): - if (d.transfer_qty and (d.bom_no or d.t_warehouse) - and (getattr(self, "pro_doc", frappe._dict()).scrap_warehouse != d.t_warehouse)): + # Get raw materials cost from BOM if multiple material consumption entries + if frappe.db.get_single_value("Manufacturing Settings", "material_consumption"): + bom_items = self.get_bom_raw_materials(finished_item_qty) + outgoing_items_cost = sum([flt(row.qty)*flt(row.rate) for row in bom_items.values()]) - if (self.work_order and self.purpose == "Manufacture" - and frappe.db.get_single_value("Manufacturing Settings", "material_consumption")): - bom_items = self.get_bom_raw_materials(d.transfer_qty) - raw_material_cost = sum([flt(row.qty)*flt(row.rate) for row in bom_items.values()]) - - if raw_material_cost and self.purpose == "Manufacture": - d.basic_rate = flt((raw_material_cost - scrap_material_cost) / flt(d.transfer_qty), d.precision("basic_rate")) - d.basic_amount = flt((raw_material_cost - scrap_material_cost), d.precision("basic_amount")) - elif self.purpose == "Repack" and total_fg_qty and not d.set_basic_rate_manually: - d.basic_rate = flt(raw_material_cost) / flt(total_fg_qty) - d.basic_amount = d.basic_rate * flt(d.qty) + return flt(outgoing_items_cost - scrap_items_cost) def distribute_additional_costs(self): - if self.purpose == "Material Issue": + # If no incoming items, set additional costs blank + if not any([d.item_code for d in self.items if d.t_warehouse]): self.additional_costs = [] self.total_additional_costs = sum([flt(t.amount) for t in self.get("additional_costs")]) - total_basic_amount = sum([flt(t.basic_amount) for t in self.get("items") if t.t_warehouse]) - for d in self.get("items"): - if d.t_warehouse and total_basic_amount: - d.additional_cost = (flt(d.basic_amount) / total_basic_amount) * self.total_additional_costs - else: - d.additional_cost = 0 + if self.purpose in ("Repack", "Manufacture"): + incoming_items_cost = sum([flt(t.basic_amount) for t in self.get("items") if t.is_finished_item]) + else: + incoming_items_cost = sum([flt(t.basic_amount) for t in self.get("items") if t.t_warehouse]) + + if incoming_items_cost: + for d in self.get("items"): + if (self.purpose in ("Repack", "Manufacture") and d.is_finished_item) or d.t_warehouse: + d.additional_cost = (flt(d.basic_amount) / incoming_items_cost) * self.total_additional_costs + else: + d.additional_cost = 0 def update_valuation_rate(self): for d in self.get("items"): @@ -638,71 +633,115 @@ class StockEntry(StockController): item_code = d.original_item or d.item_code validate_bom_no(item_code, d.bom_no) + def mark_finished_and_scrap_items(self): + if self.purpose in ("Repack", "Manufacture"): + if any([d.item_code for d in self.items if (d.is_finished_item and d.t_warehouse)]): + return + + finished_item = self.get_finished_item() + + for d in self.items: + if d.t_warehouse and not d.s_warehouse: + if self.purpose=="Repack" or d.item_code == finished_item: + d.is_finished_item = 1 + else: + d.is_scrap_item = 1 + else: + d.is_finished_item = 0 + d.is_scrap_item = 0 + + def get_finished_item(self): + finished_item = None + if self.work_order: + finished_item = frappe.db.get_value("Work Order", self.work_order, "production_item") + elif self.bom_no: + finished_item = frappe.db.get_value("BOM", self.bom_no, "item") + + return finished_item + def validate_finished_goods(self): """validation: finished good quantity should be same as manufacturing quantity""" if not self.work_order: return - items_with_target_warehouse = [] - allowance_percentage = flt(frappe.db.get_single_value("Manufacturing Settings", - "overproduction_percentage_for_work_order")) - production_item, wo_qty = frappe.db.get_value("Work Order", self.work_order, ["production_item", "qty"]) + number_of_finished_items = 0 for d in self.get('items'): - if (self.purpose != "Send to Subcontractor" and d.bom_no - and flt(d.transfer_qty) > flt(self.fg_completed_qty) and d.item_code == production_item): - frappe.throw(_("Quantity in row {0} ({1}) must be same as manufactured quantity {2}"). \ - format(d.idx, d.transfer_qty, self.fg_completed_qty)) + if d.is_finished_item: + if d.item_code != production_item: + frappe.throw(_("Finished Item {0} does not match with Work Order {1}") + .format(d.item_code, self.work_order)) + elif flt(d.transfer_qty) > flt(self.fg_completed_qty): + frappe.throw(_("Quantity in row {0} ({1}) must be same as manufactured quantity {2}"). \ + format(d.idx, d.transfer_qty, self.fg_completed_qty)) + number_of_finished_items += 1 - if self.work_order and self.purpose == "Manufacture" and d.t_warehouse: - items_with_target_warehouse.append(d.item_code) + if number_of_finished_items > 1: + frappe.throw(_("Multiple items cannot be marked as finished item")) + + if self.purpose == "Manufacture": + allowance_percentage = flt(frappe.db.get_single_value("Manufacturing Settings", + "overproduction_percentage_for_work_order")) - if self.work_order and self.purpose == "Manufacture": allowed_qty = wo_qty + (allowance_percentage/100 * wo_qty) if self.fg_completed_qty > allowed_qty: frappe.throw(_("For quantity {0} should not be greater than work order quantity {1}") .format(flt(self.fg_completed_qty), wo_qty)) - if production_item not in items_with_target_warehouse: - frappe.throw(_("Finished Item {0} must be entered for Manufacture type entry") - .format(production_item)) - def update_stock_ledger(self): sl_entries = [] + finished_item_row = self.get_finished_item_row() - # make sl entries for source warehouse first, then do for target warehouse - for d in self.get('items'): - if cstr(d.s_warehouse): - sl_entries.append(self.get_sl_entries(d, { - "warehouse": cstr(d.s_warehouse), - "actual_qty": -flt(d.transfer_qty), - "incoming_rate": 0 - })) - - for d in self.get('items'): - if cstr(d.t_warehouse): - sl_entries.append(self.get_sl_entries(d, { - "warehouse": cstr(d.t_warehouse), - "actual_qty": flt(d.transfer_qty), - "incoming_rate": flt(d.valuation_rate) - })) - - # On cancellation, make stock ledger entry for - # target warehouse first, to update serial no values properly - - # if cstr(d.s_warehouse) and self.docstatus == 2: - # sl_entries.append(self.get_sl_entries(d, { - # "warehouse": cstr(d.s_warehouse), - # "actual_qty": -flt(d.transfer_qty), - # "incoming_rate": 0 - # })) + # make sl entries for source warehouse first + self.get_sle_for_source_warehouse(sl_entries, finished_item_row) + # SLE for target warehouse + self.get_sle_for_target_warehouse(sl_entries, finished_item_row) + + # reverse sl entries if cancel if self.docstatus == 2: sl_entries.reverse() self.make_sl_entries(sl_entries) + def get_finished_item_row(self): + finished_item_row = None + if self.purpose in ("Manufacture", "Repack"): + for d in self.get('items'): + if d.is_finished_item: + finished_item_row = d + + return finished_item_row + + def get_sle_for_source_warehouse(self, sl_entries, finished_item_row): + for d in self.get('items'): + if cstr(d.s_warehouse): + sle = self.get_sl_entries(d, { + "warehouse": cstr(d.s_warehouse), + "actual_qty": -flt(d.transfer_qty), + "incoming_rate": 0 + }) + if cstr(d.t_warehouse): + sle.dependant_sle_voucher_detail_no = d.name + elif finished_item_row and (finished_item_row.item_code != d.item_code or finished_item_row.t_warehouse != d.s_warehouse): + sle.dependant_sle_voucher_detail_no = finished_item_row.name + + sl_entries.append(sle) + + def get_sle_for_target_warehouse(self, sl_entries, finished_item_row): + for d in self.get('items'): + if cstr(d.t_warehouse): + sle = self.get_sl_entries(d, { + "warehouse": cstr(d.t_warehouse), + "actual_qty": flt(d.transfer_qty), + "incoming_rate": flt(d.valuation_rate) + }) + if cstr(d.s_warehouse) or (finished_item_row and d.name == finished_item_row.name): + sle.recalculate_rate = 1 + + sl_entries.append(sle) + def get_gl_entries(self, warehouse_account): gl_entries = super(StockEntry, self).get_gl_entries(warehouse_account) @@ -747,7 +786,7 @@ class StockEntry(StockController): "credit": -1 * amount # put it as negative credit instead of debit purposefully }, item=d)) - return gl_entries + return process_gl_map(gl_entries) def update_work_order(self): def _validate_work_order(pro_doc): @@ -996,6 +1035,7 @@ class StockEntry(StockController): "stock_uom": item.stock_uom, "expense_account": item.get("expense_account"), "cost_center": item.get("buying_cost_center"), + "is_finished_item": 1 } }, bom_no = self.bom_no) @@ -1034,6 +1074,7 @@ class StockEntry(StockController): for item in itervalues(item_dict): item.from_warehouse = "" + item.is_scrap_item = 1 return item_dict def get_unconsumed_raw_materials(self): @@ -1246,6 +1287,8 @@ class StockEntry(StockController): se_child.subcontracted_item = item_dict[d].get("main_item_code") se_child.cost_center = (item_dict[d].get("cost_center") or get_default_cost_center(item_dict[d], company = self.company)) + se_child.is_finished_item = item_dict[d].get("is_finished_item", 0) + se_child.is_scrap_item = item_dict[d].get("is_scrap_item", 0) for field in ["idx", "po_detail", "original_item", "expense_account", "description", "item_name"]: diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index 9b6744ca3c..1a641855aa 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -6,7 +6,6 @@ import frappe, unittest import frappe.defaults from frappe.utils import flt, nowdate, nowtime from erpnext.stock.doctype.serial_no.serial_no import * -from erpnext import set_perpetual_inventory from erpnext.stock.doctype.stock_ledger_entry.stock_ledger_entry import StockFreezeError from erpnext.stock.stock_ledger import get_previous_sle from frappe.permissions import add_user_permission, remove_user_permission @@ -32,7 +31,6 @@ def get_sle(**args): class TestStockEntry(unittest.TestCase): def tearDown(self): frappe.set_user("Administrator") - set_perpetual_inventory(0) def test_fifo(self): frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) @@ -213,7 +211,6 @@ class TestStockEntry(unittest.TestCase): def test_repack_no_change_in_valuation(self): company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC', 'company') - set_perpetual_inventory(0, company) make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=50, basic_rate=100) make_stock_entry(item_code="_Test Item Home Desktop 100", target="_Test Warehouse - _TC", @@ -235,8 +232,6 @@ class TestStockEntry(unittest.TestCase): order by account desc""", repack.name, as_dict=1) self.assertFalse(gl_entries) - set_perpetual_inventory(0, repack.company) - def test_repack_with_additional_costs(self): company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company') @@ -474,7 +469,6 @@ class TestStockEntry(unittest.TestCase): def test_warehouse_company_validation(self): company = frappe.db.get_value('Warehouse', '_Test Warehouse 2 - _TC1', 'company') - set_perpetual_inventory(0, company) frappe.get_doc("User", "test2@example.com")\ .add_roles("Sales User", "Sales Manager", "Stock User", "Stock Manager") frappe.set_user("test2@example.com") @@ -500,7 +494,7 @@ class TestStockEntry(unittest.TestCase): st1 = frappe.copy_doc(test_records[0]) st1.company = "_Test Company 1" - set_perpetual_inventory(0, st1.company) + frappe.set_user("test@example.com") st1.get("items")[0].t_warehouse="_Test Warehouse 2 - _TC1" self.assertRaises(frappe.PermissionError, st1.insert) @@ -698,47 +692,54 @@ class TestStockEntry(unittest.TestCase): repack.insert() self.assertRaises(frappe.ValidationError, repack.submit) - def test_material_consumption(self): - from erpnext.manufacturing.doctype.work_order.work_order \ - import make_stock_entry as _make_stock_entry - bom_no = frappe.db.get_value("BOM", {"item": "_Test FG Item 2", - "is_default": 1, "docstatus": 1}) + # def test_material_consumption(self): + # frappe.db.set_value("Manufacturing Settings", None, "backflush_raw_materials_based_on", "BOM") + # frappe.db.set_value("Manufacturing Settings", None, "material_consumption", "0") - work_order = frappe.new_doc("Work Order") - work_order.update({ - "company": "_Test Company", - "fg_warehouse": "_Test Warehouse 1 - _TC", - "production_item": "_Test FG Item 2", - "bom_no": bom_no, - "qty": 4.0, - "stock_uom": "_Test UOM", - "wip_warehouse": "_Test Warehouse - _TC", - "additional_operating_cost": 1000 - }) - work_order.insert() - work_order.submit() + # from erpnext.manufacturing.doctype.work_order.work_order \ + # import make_stock_entry as _make_stock_entry + # bom_no = frappe.db.get_value("BOM", {"item": "_Test FG Item 2", + # "is_default": 1, "docstatus": 1}) - make_stock_entry(item_code="_Test Serialized Item With Series", target="_Test Warehouse - _TC", qty=50, basic_rate=100) - make_stock_entry(item_code="_Test Item 2", target="_Test Warehouse - _TC", qty=50, basic_rate=20) + # work_order = frappe.new_doc("Work Order") + # work_order.update({ + # "company": "_Test Company", + # "fg_warehouse": "_Test Warehouse 1 - _TC", + # "production_item": "_Test FG Item 2", + # "bom_no": bom_no, + # "qty": 4.0, + # "stock_uom": "_Test UOM", + # "wip_warehouse": "_Test Warehouse - _TC", + # "additional_operating_cost": 1000, + # "use_multi_level_bom": 1 + # }) + # work_order.insert() + # work_order.submit() - item_quantity = { - '_Test Item': 10.0, - '_Test Item 2': 12.0, - '_Test Serialized Item With Series': 6.0 - } + # make_stock_entry(item_code="_Test Serialized Item With Series", target="_Test Warehouse - _TC", qty=50, basic_rate=100) + # make_stock_entry(item_code="_Test Item 2", target="_Test Warehouse - _TC", qty=50, basic_rate=20) - stock_entry = frappe.get_doc(_make_stock_entry(work_order.name, "Material Consumption for Manufacture", 2)) - for d in stock_entry.get('items'): - self.assertEqual(item_quantity.get(d.item_code), d.qty) + # item_quantity = { + # '_Test Item': 2.0, + # '_Test Item 2': 12.0, + # '_Test Serialized Item With Series': 6.0 + # } + + # stock_entry = frappe.get_doc(_make_stock_entry(work_order.name, "Material Consumption for Manufacture", 2)) + # for d in stock_entry.get('items'): + # self.assertEqual(item_quantity.get(d.item_code), d.qty) def test_customer_provided_parts_se(self): create_item('CUST-0987', is_customer_provided_item = 1, customer = '_Test Customer', is_purchase_item = 0) - se = make_stock_entry(item_code='CUST-0987', purpose = 'Material Receipt', qty=4, to_warehouse = "_Test Warehouse - _TC") + se = make_stock_entry(item_code='CUST-0987', purpose = 'Material Receipt', + qty=4, to_warehouse = "_Test Warehouse - _TC") self.assertEqual(se.get("items")[0].allow_zero_valuation_rate, 1) self.assertEqual(se.get("items")[0].amount, 0) def test_gle_for_opening_stock_entry(self): - mr = make_stock_entry(item_code="_Test Item", target="Stores - TCP1", company="_Test Company with perpetual inventory",qty=50, basic_rate=100, expense_account="Stock Adjustment - TCP1", is_opening="Yes", do_not_save=True) + mr = make_stock_entry(item_code="_Test Item", target="Stores - TCP1", + company="_Test Company with perpetual inventory", qty=50, basic_rate=100, + expense_account="Stock Adjustment - TCP1", is_opening="Yes", do_not_save=True) self.assertRaises(OpeningEntryAccountError, mr.save) @@ -759,8 +760,8 @@ class TestStockEntry(unittest.TestCase): "company":"_Test Company with perpetual inventory", "items":[ { - "item_code":"Basil Leaves", - "description":"Basil Leaves", + "item_code":"_Test Item", + "description":"_Test Item", "qty": 1, "basic_rate": 0, "uom":"Nos", @@ -769,8 +770,8 @@ class TestStockEntry(unittest.TestCase): "cost_center": "Main - TCP1" }, { - "item_code":"Basil Leaves", - "description":"Basil Leaves", + "item_code":"_Test Item", + "description":"_Test Item", "qty": 2, "basic_rate": 0, "uom":"Nos", diff --git a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json index 79e8f9af8f..6fe60298ee 100644 --- a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json +++ b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json @@ -13,8 +13,10 @@ "t_warehouse", "sec_break1", "item_code", - "col_break2", "item_name", + "col_break2", + "is_finished_item", + "is_scrap_item", "subcontracted_item", "section_break_8", "description", @@ -22,35 +24,37 @@ "item_group", "image", "image_view", - "quantity_and_rate", - "set_basic_rate_manually", + "quantity_section", "qty", - "basic_rate", - "basic_amount", - "additional_cost", - "amount", - "valuation_rate", - "col_break3", - "uom", - "conversion_factor", - "stock_uom", "transfer_qty", "retain_sample", + "column_break_20", + "uom", + "stock_uom", + "conversion_factor", "sample_quantity", + "rates_section", + "basic_rate", + "additional_cost", + "valuation_rate", + "allow_zero_valuation_rate", + "col_break3", + "set_basic_rate_manually", + "basic_amount", + "amount", "serial_no_batch", "serial_no", "col_break4", "batch_no", - "quality_inspection", "accounting", "expense_account", - "col_break5", "accounting_dimensions_section", "cost_center", + "project", "dimension_col_break", "more_info", - "allow_zero_valuation_rate", "actual_qty", + "transferred_qty", "bom_no", "allow_alternative_item", "col_break6", @@ -62,9 +66,8 @@ "ste_detail", "po_detail", "column_break_51", - "transferred_qty", "reference_purchase_receipt", - "project" + "quality_inspection" ], "fields": [ { @@ -159,11 +162,6 @@ "options": "image", "print_hide": 1 }, - { - "fieldname": "quantity_and_rate", - "fieldtype": "Section Break", - "label": "Quantity and Rate" - }, { "bold": 1, "fieldname": "qty", @@ -321,10 +319,6 @@ "options": "Account", "print_hide": 1 }, - { - "fieldname": "col_break5", - "fieldtype": "Column Break" - }, { "default": ":Company", "depends_on": "eval:cint(erpnext.is_perpetual_inventory_enabled(parent.company))", @@ -335,6 +329,7 @@ "print_hide": 1 }, { + "collapsible": 1, "fieldname": "more_info", "fieldtype": "Section Break", "label": "More Information" @@ -456,6 +451,7 @@ "read_only": 1 }, { + "collapsible": 1, "fieldname": "accounting_dimensions_section", "fieldtype": "Section Break", "label": "Accounting Dimensions" @@ -498,6 +494,32 @@ "fieldname": "set_basic_rate_manually", "fieldtype": "Check", "label": "Set Basic Rate Manually" + }, + { + "fieldname": "quantity_section", + "fieldtype": "Section Break", + "label": "Quantity" + }, + { + "fieldname": "column_break_20", + "fieldtype": "Column Break" + }, + { + "fieldname": "rates_section", + "fieldtype": "Section Break", + "label": "Rates" + }, + { + "default": "0", + "fieldname": "is_scrap_item", + "fieldtype": "Check", + "label": "Is Scrap Item" + }, + { + "default": "0", + "fieldname": "is_finished_item", + "fieldtype": "Check", + "label": "Is Finished Item" } ], "idx": 1, diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json index fda17e08ab..2463a21ed6 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json +++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json @@ -8,26 +8,33 @@ "engine": "InnoDB", "field_order": [ "item_code", - "serial_no", - "batch_no", "warehouse", "posting_date", "posting_time", + "column_break_6", "voucher_type", "voucher_no", "voucher_detail_no", + "dependant_sle_voucher_detail_no", + "recalculate_rate", + "section_break_11", "actual_qty", + "qty_after_transaction", "incoming_rate", "outgoing_rate", - "stock_uom", - "qty_after_transaction", + "column_break_17", "valuation_rate", "stock_value", "stock_value_difference", "stock_queue", - "project", + "section_break_21", "company", + "stock_uom", + "project", + "batch_no", + "column_break_26", "fiscal_year", + "serial_no", "is_cancelled", "to_rename" ], @@ -50,7 +57,6 @@ { "fieldname": "serial_no", "fieldtype": "Long Text", - "in_list_view": 1, "label": "Serial No", "print_width": "100px", "read_only": 1, @@ -59,7 +65,6 @@ { "fieldname": "batch_no", "fieldtype": "Data", - "in_list_view": 1, "label": "Batch No", "oldfieldname": "batch_no", "oldfieldtype": "Data", @@ -119,6 +124,7 @@ "fieldname": "voucher_no", "fieldtype": "Dynamic Link", "in_filter": 1, + "in_list_view": 1, "in_standard_filter": 1, "label": "Voucher No", "oldfieldname": "voucher_no", @@ -142,6 +148,7 @@ "fieldname": "actual_qty", "fieldtype": "Float", "in_filter": 1, + "in_list_view": 1, "label": "Actual Quantity", "oldfieldname": "actual_qty", "oldfieldtype": "Currency", @@ -152,6 +159,7 @@ { "fieldname": "incoming_rate", "fieldtype": "Currency", + "in_list_view": 1, "label": "Incoming Rate", "oldfieldname": "incoming_rate", "oldfieldtype": "Currency", @@ -217,13 +225,11 @@ { "fieldname": "stock_queue", "fieldtype": "Text", - "hidden": 1, "label": "Stock Queue (FIFO)", "oldfieldname": "fcfs_stack", "oldfieldtype": "Text", "print_hide": 1, - "read_only": 1, - "report_hide": 1 + "read_only": 1 }, { "fieldname": "project", @@ -269,14 +275,48 @@ "hidden": 1, "label": "To Rename", "search_index": 1 + }, + { + "fieldname": "dependant_sle_voucher_detail_no", + "fieldtype": "Data", + "label": "Dependant SLE Voucher Detail No" + }, + { + "fieldname": "column_break_6", + "fieldtype": "Column Break" + }, + { + "fieldname": "section_break_11", + "fieldtype": "Section Break" + }, + { + "fieldname": "column_break_17", + "fieldtype": "Column Break" + }, + { + "fieldname": "section_break_21", + "fieldtype": "Section Break" + }, + { + "fieldname": "column_break_26", + "fieldtype": "Column Break" + }, + { + "default": "0", + "fieldname": "recalculate_rate", + "fieldtype": "Check", + "label": "Recalculate Incoming/Outgoing Rate", + "no_copy": 1, + "read_only": 1 } ], "hide_toolbar": 1, "icon": "fa fa-list", "idx": 1, "in_create": 1, + "index_web_pages_for_search": 1, "links": [], - "modified": "2020-04-23 05:57:03.985520", + "modified": "2020-09-07 11:10:35.318872", "modified_by": "Administrator", "module": "Stock", "name": "Stock Ledger Entry", diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py index bb356f694a..a5c303ccb4 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py @@ -10,8 +10,10 @@ from frappe.model.document import Document from datetime import date from erpnext.controllers.item_variant import ItemTemplateCannotHaveStock from erpnext.accounts.utils import get_fiscal_year +from frappe.core.doctype.role.role import get_users class StockFreezeError(frappe.ValidationError): pass +class BackDatedStockTransaction(frappe.ValidationError): pass exclude_from_linked_with = True @@ -34,7 +36,6 @@ class StockLedgerEntry(Document): self.validate_and_set_fiscal_year() self.block_transactions_against_group_warehouse() self.validate_with_last_transaction_posting_time() - self.validate_future_posting() def on_submit(self): self.check_stock_frozen_date() @@ -48,7 +49,7 @@ class StockLedgerEntry(Document): def calculate_batch_qty(self): if self.batch_no: batch_qty = frappe.db.get_value("Stock Ledger Entry", - {"docstatus": 1, "batch_no": self.batch_no}, + {"docstatus": 1, "batch_no": self.batch_no, "is_cancelled": 0}, "sum(actual_qty)") or 0 frappe.db.set_value("Batch", self.batch_no, "batch_qty", batch_qty) @@ -88,14 +89,14 @@ class StockLedgerEntry(Document): # check if batch number is required if self.voucher_type != 'Stock Reconciliation': - if item_det.has_batch_no ==1: + if item_det.has_batch_no == 1: batch_item = self.item_code if self.item_code == item_det.item_name else self.item_code + ":" + item_det.item_name if not self.batch_no: frappe.throw(_("Batch number is mandatory for Item {0}").format(batch_item)) elif not frappe.db.get_value("Batch",{"item": self.item_code, "name": self.batch_no}): frappe.throw(_("{0} is not a valid Batch Number for Item {1}").format(self.batch_no, batch_item)) - elif item_det.has_batch_no ==0 and self.batch_no: + elif item_det.has_batch_no == 0 and self.batch_no and self.is_cancelled == 0: frappe.throw(_("The Item {0} cannot have Batch").format(self.item_code)) if item_det.has_variants: @@ -142,28 +143,28 @@ class StockLedgerEntry(Document): is_group_warehouse(self.warehouse) def validate_with_last_transaction_posting_time(self): - last_transaction_time = frappe.db.sql(""" - select MAX(timestamp(posting_date, posting_time)) as posting_time - from `tabStock Ledger Entry` - where docstatus = 1 and item_code = %s - and warehouse = %s""", (self.item_code, self.warehouse))[0][0] + authorized_role = frappe.db.get_single_value("Stock Settings", "role_allowed_to_create_edit_back_dated_transactions") + if authorized_role: + authorized_users = get_users(authorized_role) + if authorized_users and frappe.session.user not in authorized_users: + last_transaction_time = frappe.db.sql(""" + select MAX(timestamp(posting_date, posting_time)) as posting_time + from `tabStock Ledger Entry` + where docstatus = 1 and item_code = %s + and warehouse = %s""", (self.item_code, self.warehouse))[0][0] - cur_doc_posting_datetime = "%s %s" % (self.posting_date, self.get("posting_time") or "00:00:00") + cur_doc_posting_datetime = "%s %s" % (self.posting_date, self.get("posting_time") or "00:00:00") - if last_transaction_time and get_datetime(cur_doc_posting_datetime) < get_datetime(last_transaction_time): - msg = _("Last Stock Transaction for item {0} under warehouse {1} was on {2}.").format(frappe.bold(self.item_code), - frappe.bold(self.warehouse), frappe.bold(last_transaction_time)) + if last_transaction_time and get_datetime(cur_doc_posting_datetime) < get_datetime(last_transaction_time): + msg = _("Last Stock Transaction for item {0} under warehouse {1} was on {2}.").format(frappe.bold(self.item_code), + frappe.bold(self.warehouse), frappe.bold(last_transaction_time)) - msg += "

" + _("Stock Transactions for Item {0} under warehouse {1} cannot be posted before this time.").format( - frappe.bold(self.item_code), frappe.bold(self.warehouse)) + msg += "

" + _("You are not authorized to make/edit Stock Transactions for Item {0} under warehouse {1} before this time.").format( + frappe.bold(self.item_code), frappe.bold(self.warehouse)) - msg += "

" + _("Please remove this item and try to submit again or update the posting time.") - frappe.throw(msg, title=_("Backdated Stock Entry")) - - def validate_future_posting(self): - if date_diff(self.posting_date, getdate()) > 0: - msg = _("Posting future stock transactions are not allowed due to Immutable Ledger") - frappe.throw(msg, title=_("Future Posting Not Allowed")) + msg += "

" + _("Please contact any of the following users to {} this transaction.") + msg += "
" + "
".join(authorized_users) + frappe.throw(msg, BackDatedStockTransaction, title=_("Backdated Stock Entry")) def on_doctype_update(): if not frappe.db.has_index('tabStock Ledger Entry', 'posting_sort_index'): diff --git a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py index 04dae83447..59f1f3961b 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py @@ -5,8 +5,397 @@ from __future__ import unicode_literals import frappe import unittest - -# test_records = frappe.get_test_records('Stock Ledger Entry') +from frappe.utils import today, add_days +from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation \ + import create_stock_reconciliation +from erpnext.stock.doctype.item.test_item import make_item +from erpnext.stock.stock_ledger import get_previous_sle +from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt +from erpnext.stock.doctype.landed_cost_voucher.test_landed_cost_voucher import create_landed_cost_voucher +from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note +from erpnext.stock.doctype.stock_ledger_entry.stock_ledger_entry import BackDatedStockTransaction class TestStockLedgerEntry(unittest.TestCase): - pass + def setUp(self): + items = create_items() + + # delete SLE and BINs for all items + frappe.db.sql("delete from `tabStock Ledger Entry` where item_code in (%s)" % (', '.join(['%s']*len(items))), items) + frappe.db.sql("delete from `tabBin` where item_code in (%s)" % (', '.join(['%s']*len(items))), items) + + def test_item_cost_reposting(self): + company = "_Test Company" + + # _Test Item for Reposting at Stores warehouse on 10-04-2020: Qty = 50, Rate = 100 + create_stock_reconciliation( + item_code="_Test Item for Reposting", + warehouse="Stores - _TC", + qty=50, + rate=100, + company=company, + expense_account = "Stock Adjustment - _TC", + posting_date='2020-04-10', + posting_time='14:00' + ) + + # _Test Item for Reposting at FG warehouse on 20-04-2020: Qty = 10, Rate = 200 + create_stock_reconciliation( + item_code="_Test Item for Reposting", + warehouse="Finished Goods - _TC", + qty=10, + rate=200, + company=company, + expense_account = "Stock Adjustment - _TC", + posting_date='2020-04-20', + posting_time='14:00' + ) + + # _Test Item for Reposting transferred from Stores to FG warehouse on 30-04-2020 + make_stock_entry( + item_code="_Test Item for Reposting", + source="Stores - _TC", + target="Finished Goods - _TC", + company=company, + qty=10, + expense_account="Stock Adjustment - _TC", + posting_date='2020-04-30', + posting_time='14:00' + ) + target_wh_sle = get_previous_sle({ + "item_code": "_Test Item for Reposting", + "warehouse": "Finished Goods - _TC", + "posting_date": '2020-04-30', + "posting_time": '14:00' + }) + + self.assertEqual(target_wh_sle.get("valuation_rate"), 150) + + # Repack entry on 5-5-2020 + repack = create_repack_entry(company=company, posting_date='2020-05-05', posting_time='14:00') + + finished_item_sle = get_previous_sle({ + "item_code": "_Test Finished Item for Reposting", + "warehouse": "Finished Goods - _TC", + "posting_date": '2020-05-05', + "posting_time": '14:00' + }) + self.assertEqual(finished_item_sle.get("incoming_rate"), 540) + self.assertEqual(finished_item_sle.get("valuation_rate"), 540) + + # Reconciliation for _Test Item for Reposting at Stores on 12-04-2020: Qty = 50, Rate = 150 + create_stock_reconciliation( + item_code="_Test Item for Reposting", + warehouse="Stores - _TC", + qty=50, + rate=150, + company=company, + expense_account = "Stock Adjustment - _TC", + posting_date='2020-04-12', + posting_time='14:00' + ) + + + # Check valuation rate of finished goods warehouse after back-dated entry at Stores + target_wh_sle = get_previous_sle({ + "item_code": "_Test Item for Reposting", + "warehouse": "Finished Goods - _TC", + "posting_date": '2020-04-30', + "posting_time": '14:00' + }) + self.assertEqual(target_wh_sle.get("incoming_rate"), 150) + self.assertEqual(target_wh_sle.get("valuation_rate"), 175) + + # Check valuation rate of repacked item after back-dated entry at Stores + finished_item_sle = get_previous_sle({ + "item_code": "_Test Finished Item for Reposting", + "warehouse": "Finished Goods - _TC", + "posting_date": '2020-05-05', + "posting_time": '14:00' + }) + self.assertEqual(finished_item_sle.get("incoming_rate"), 790) + self.assertEqual(finished_item_sle.get("valuation_rate"), 790) + + # Check updated rate in Repack entry + repack.reload() + self.assertEqual(repack.items[0].get("basic_rate"), 150) + self.assertEqual(repack.items[1].get("basic_rate"), 750) + + def test_purchase_return_valuation_reposting(self): + pr = make_purchase_receipt(company="_Test Company", posting_date='2020-04-10', + warehouse="Stores - _TC", item_code="_Test Item for Reposting", qty=5, rate=100) + + return_pr = make_purchase_receipt(company="_Test Company", posting_date='2020-04-15', + warehouse="Stores - _TC", item_code="_Test Item for Reposting", is_return=1, return_against=pr.name, qty=-2) + + # check sle + outgoing_rate, stock_value_difference = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt", + "voucher_no": return_pr.name}, ["outgoing_rate", "stock_value_difference"]) + + self.assertEqual(outgoing_rate, 100) + self.assertEqual(stock_value_difference, -200) + + create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company) + + outgoing_rate, stock_value_difference = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt", + "voucher_no": return_pr.name}, ["outgoing_rate", "stock_value_difference"]) + + self.assertEqual(outgoing_rate, 110) + self.assertEqual(stock_value_difference, -220) + + def test_sales_return_valuation_reposting(self): + company = "_Test Company" + item_code="_Test Item for Reposting" + + # Purchase Return: Qty = 5, Rate = 100 + pr = make_purchase_receipt(company=company, posting_date='2020-04-10', + warehouse="Stores - _TC", item_code=item_code, qty=5, rate=100) + + #Delivery Note: Qty = 5, Rate = 150 + dn = create_delivery_note(item_code=item_code, qty=5, rate=150, warehouse="Stores - _TC", + company=company, expense_account="Cost of Goods Sold - _TC", cost_center="Main - _TC") + + # check outgoing_rate for DN + outgoing_rate = abs(frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note", + "voucher_no": dn.name}, "stock_value_difference") / 5) + + self.assertEqual(dn.items[0].incoming_rate, 100) + self.assertEqual(outgoing_rate, 100) + + # Return Entry: Qty = -2, Rate = 150 + return_dn = create_delivery_note(is_return=1, return_against=dn.name, item_code=item_code, qty=-2, rate=150, + company=company, warehouse="Stores - _TC", expense_account="Cost of Goods Sold - _TC", cost_center="Main - _TC") + + # check incoming rate for Return entry + incoming_rate, stock_value_difference = frappe.db.get_value("Stock Ledger Entry", + {"voucher_type": "Delivery Note", "voucher_no": return_dn.name}, + ["incoming_rate", "stock_value_difference"]) + + self.assertEqual(return_dn.items[0].incoming_rate, 100) + self.assertEqual(incoming_rate, 100) + self.assertEqual(stock_value_difference, 200) + + #------------------------------- + + # Landed Cost Voucher to update the rate of incoming Purchase Return: Additional cost = 50 + lcv = create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company) + + # check outgoing_rate for DN after reposting + outgoing_rate = abs(frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note", + "voucher_no": dn.name}, "stock_value_difference") / 5) + self.assertEqual(outgoing_rate, 110) + + dn.reload() + self.assertEqual(dn.items[0].incoming_rate, 110) + + # check incoming rate for Return entry after reposting + incoming_rate, stock_value_difference = frappe.db.get_value("Stock Ledger Entry", + {"voucher_type": "Delivery Note", "voucher_no": return_dn.name}, + ["incoming_rate", "stock_value_difference"]) + + self.assertEqual(incoming_rate, 110) + self.assertEqual(stock_value_difference, 220) + + return_dn.reload() + self.assertEqual(return_dn.items[0].incoming_rate, 110) + + # Cleanup data + return_dn.cancel() + dn.cancel() + lcv.cancel() + pr.cancel() + + def test_reposting_of_sales_return_for_packed_item(self): + company = "_Test Company" + packed_item_code="_Test Item for Reposting" + bundled_item = "_Test Bundled Item for Reposting" + create_product_bundle_item(bundled_item, [[packed_item_code, 4]]) + + # Purchase Return: Qty = 50, Rate = 100 + pr = make_purchase_receipt(company=company, posting_date='2020-04-10', + warehouse="Stores - _TC", item_code=packed_item_code, qty=50, rate=100) + + #Delivery Note: Qty = 5, Rate = 150 + dn = create_delivery_note(item_code=bundled_item, qty=5, rate=150, warehouse="Stores - _TC", + company=company, expense_account="Cost of Goods Sold - _TC", cost_center="Main - _TC") + + # check outgoing_rate for DN + outgoing_rate = abs(frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note", + "voucher_no": dn.name}, "stock_value_difference") / 20) + + self.assertEqual(dn.packed_items[0].incoming_rate, 100) + self.assertEqual(outgoing_rate, 100) + + # Return Entry: Qty = -2, Rate = 150 + return_dn = create_delivery_note(is_return=1, return_against=dn.name, item_code=bundled_item, qty=-2, rate=150, + company=company, warehouse="Stores - _TC", expense_account="Cost of Goods Sold - _TC", cost_center="Main - _TC") + + # check incoming rate for Return entry + incoming_rate, stock_value_difference = frappe.db.get_value("Stock Ledger Entry", + {"voucher_type": "Delivery Note", "voucher_no": return_dn.name}, + ["incoming_rate", "stock_value_difference"]) + + self.assertEqual(return_dn.packed_items[0].incoming_rate, 100) + self.assertEqual(incoming_rate, 100) + self.assertEqual(stock_value_difference, 800) + + #------------------------------- + + # Landed Cost Voucher to update the rate of incoming Purchase Return: Additional cost = 50 + lcv = create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company) + + # check outgoing_rate for DN after reposting + outgoing_rate = abs(frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note", + "voucher_no": dn.name}, "stock_value_difference") / 20) + self.assertEqual(outgoing_rate, 101) + + dn.reload() + self.assertEqual(dn.packed_items[0].incoming_rate, 101) + + # check incoming rate for Return entry after reposting + incoming_rate, stock_value_difference = frappe.db.get_value("Stock Ledger Entry", + {"voucher_type": "Delivery Note", "voucher_no": return_dn.name}, + ["incoming_rate", "stock_value_difference"]) + + self.assertEqual(incoming_rate, 101) + self.assertEqual(stock_value_difference, 808) + + return_dn.reload() + self.assertEqual(return_dn.packed_items[0].incoming_rate, 101) + + # Cleanup data + return_dn.cancel() + dn.cancel() + lcv.cancel() + pr.cancel() + + def test_sub_contracted_item_costing(self): + from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom + + company = "_Test Company" + rm_item_code="_Test Item for Reposting" + subcontracted_item = "_Test Subcontracted Item for Reposting" + + frappe.db.set_value("Buying Settings", None, "backflush_raw_materials_of_subcontract_based_on", "BOM") + make_bom(item = subcontracted_item, raw_materials =[rm_item_code], currency="INR") + + # Purchase raw materials on supplier warehouse: Qty = 50, Rate = 100 + pr = make_purchase_receipt(company=company, posting_date='2020-04-10', + warehouse="Stores - _TC", item_code=rm_item_code, qty=10, rate=100) + + # Purchase Receipt for subcontracted item + pr1 = make_purchase_receipt(company=company, posting_date='2020-04-20', + warehouse="Finished Goods - _TC", supplier_warehouse="Stores - _TC", + item_code=subcontracted_item, qty=10, rate=20, is_subcontracted="Yes") + + self.assertEqual(pr1.items[0].valuation_rate, 120) + + # Update raw material's valuation via LCV, Additional cost = 50 + lcv = create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company) + + pr1.reload() + self.assertEqual(pr1.items[0].valuation_rate, 125) + + # check outgoing_rate for DN after reposting + incoming_rate = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt", + "voucher_no": pr1.name, "item_code": subcontracted_item}, "incoming_rate") + self.assertEqual(incoming_rate, 125) + + # cleanup data + pr1.cancel() + lcv.cancel() + pr.cancel() + + def test_back_dated_entry_not_allowed(self): + # Back dated stock transactions are only allowed to stock managers + frappe.db.set_value("Stock Settings", None, + "role_allowed_to_create_edit_back_dated_transactions", "Stock Manager") + + # Set User with Stock User role but not Stock Manager + frappe.set_user("test@example.com") + user = frappe.get_doc("User", "test@example.com") + user.add_roles("Stock User") + user.remove_roles("Stock Manager") + + stock_entry_on_today = make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100) + back_dated_se_1 = make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100, + posting_date=add_days(today(), -1), do_not_submit=True) + + # Block back-dated entry + self.assertRaises(BackDatedStockTransaction, back_dated_se_1.submit) + + user.add_roles("Stock Manager") + + # Back dated entry allowed to Stock Manager + back_dated_se_2 = make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100, + posting_date=add_days(today(), -1)) + + back_dated_se_2.cancel() + stock_entry_on_today.cancel() + + frappe.db.set_value("Stock Settings", None, "role_allowed_to_create_edit_back_dated_transactions", None) + frappe.set_user("Administrator") + + +def create_repack_entry(**args): + args = frappe._dict(args) + repack = frappe.new_doc("Stock Entry") + repack.stock_entry_type = "Repack" + repack.company = args.company or "_Test Company" + repack.posting_date = args.posting_date + repack.set_posting_time = 1 + repack.append("items", { + "item_code": "_Test Item for Reposting", + "s_warehouse": "Stores - _TC", + "qty": 5, + "conversion_factor": 1, + "expense_account": "Stock Adjustment - _TC", + "cost_center": "Main - _TC" + }) + + repack.append("items", { + "item_code": "_Test Finished Item for Reposting", + "t_warehouse": "Finished Goods - _TC", + "qty": 1, + "conversion_factor": 1, + "expense_account": "Stock Adjustment - _TC", + "cost_center": "Main - _TC" + }) + + repack.append("additional_costs", { + "expense_account": "Freight and Forwarding Charges - _TC", + "description": "transport cost", + "amount": 40 + }) + + repack.save() + repack.submit() + + return repack + +def create_product_bundle_item(new_item_code, packed_items): + if not frappe.db.exists("Product Bundle", new_item_code): + item = frappe.new_doc("Product Bundle") + item.new_item_code = new_item_code + + for d in packed_items: + item.append("items", { + "item_code": d[0], + "qty": d[1] + }) + + item.save() + +def create_items(): + items = ["_Test Item for Reposting", "_Test Finished Item for Reposting", + "_Test Subcontracted Item for Reposting", "_Test Bundled Item for Reposting"] + for d in items: + properties = {"valuation_method": "FIFO"} + if d == "_Test Bundled Item for Reposting": + properties.update({"is_stock_item": 0}) + elif d == "_Test Subcontracted Item for Reposting": + properties.update({"is_sub_contracted_item": 1}) + + make_item(d, properties=properties) + + return items \ No newline at end of file diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index 00b8f69c08..5b40292ea8 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -37,14 +37,16 @@ class StockReconciliation(StockController): def on_submit(self): self.update_stock_ledger() self.make_gl_entries() + self.repost_future_sle_and_gle() from erpnext.stock.doctype.serial_no.serial_no import update_serial_nos_after_submit update_serial_nos_after_submit(self, "items") def on_cancel(self): - self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry') + self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry', 'Repost Item Valuation') self.make_sle_on_cancel() self.make_gl_entries_on_cancel() + self.repost_future_sle_and_gle() def remove_items_with_no_change(self): """Remove items if qty or rate is not changed""" diff --git a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index 23d48d4ac7..088456f865 100644 --- a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -8,12 +8,11 @@ from __future__ import unicode_literals import frappe, unittest from frappe.utils import flt, nowdate, nowtime from erpnext.accounts.utils import get_stock_and_account_balance -from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory from erpnext.stock.stock_ledger import get_previous_sle, update_entries_after from erpnext.stock.doctype.stock_reconciliation.stock_reconciliation import EmptyStockReconciliationItemsError, get_items from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse from erpnext.stock.doctype.item.test_item import create_item -from erpnext.stock.utils import get_stock_balance, get_incoming_rate, get_available_serial_nos, get_stock_value_on +from erpnext.stock.utils import get_incoming_rate, get_stock_value_on, get_valuation_method from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos class TestStockReconciliation(unittest.TestCase): @@ -29,16 +28,17 @@ class TestStockReconciliation(unittest.TestCase): self._test_reco_sle_gle("Moving Average") def _test_reco_sle_gle(self, valuation_method): - insert_existing_sle(warehouse='Stores - TCP1') + se1, se2, se3 = insert_existing_sle(warehouse='Stores - TCP1') company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company') # [[qty, valuation_rate, posting_date, # posting_time, expected_stock_value, bin_qty, bin_valuation]] + input_data = [ - [50, 1000], - [25, 900], - ["", 1000], - [20, ""], - [0, ""] + [50, 1000, "2012-12-26", "12:00"], + [25, 900, "2012-12-26", "12:00"], + ["", 1000, "2012-12-20", "12:05"], + [20, "", "2012-12-26", "12:05"], + [0, "", "2012-12-31", "12:10"] ] for d in input_data: @@ -47,13 +47,13 @@ class TestStockReconciliation(unittest.TestCase): last_sle = get_previous_sle({ "item_code": "_Test Item", "warehouse": "Stores - TCP1", - "posting_date": nowdate(), - "posting_time": nowtime() + "posting_date": d[2], + "posting_time": d[3] }) # submit stock reconciliation stock_reco = create_stock_reconciliation(qty=d[0], rate=d[1], - posting_date=nowdate(), posting_time=nowtime(), warehouse="Stores - TCP1", + posting_date=d[2], posting_time=d[3], warehouse="Stores - TCP1", company=company, expense_account = "Stock Adjustment - TCP1") # check stock value @@ -81,10 +81,15 @@ class TestStockReconciliation(unittest.TestCase): stock_reco.cancel() + se3.cancel() + se2.cancel() + se1.cancel() + def test_get_items(self): - create_warehouse("_Test Warehouse Group 1", {"is_group": 1}) + create_warehouse("_Test Warehouse Group 1", + {"is_group": 1, "company": "_Test Company", "parent_warehouse": "All Warehouses - _TC"}) create_warehouse("_Test Warehouse Ledger 1", - {"is_group": 0, "parent_warehouse": "_Test Warehouse Group 1 - _TC"}) + {"is_group": 0, "parent_warehouse": "_Test Warehouse Group 1 - _TC", "company": "_Test Company"}) create_item("_Test Stock Reco Item", is_stock_item=1, valuation_rate=100, warehouse="_Test Warehouse Ledger 1 - _TC", opening_stock=100) @@ -95,8 +100,6 @@ class TestStockReconciliation(unittest.TestCase): [items[0]["item_code"], items[0]["warehouse"], items[0]["qty"]]) def test_stock_reco_for_serialized_item(self): - set_perpetual_inventory() - to_delete_records = [] to_delete_serial_nos = [] @@ -148,8 +151,6 @@ class TestStockReconciliation(unittest.TestCase): stock_doc.cancel() def test_stock_reco_for_batch_item(self): - set_perpetual_inventory() - to_delete_records = [] to_delete_serial_nos = [] @@ -196,15 +197,17 @@ class TestStockReconciliation(unittest.TestCase): def insert_existing_sle(warehouse): from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry - make_stock_entry(posting_date=nowdate(), posting_time=nowtime(), item_code="_Test Item", + se1 = make_stock_entry(posting_date="2012-12-15", posting_time="02:00", item_code="_Test Item", target=warehouse, qty=10, basic_rate=700) - make_stock_entry(posting_date=nowdate(), posting_time=nowtime(), item_code="_Test Item", + se2 = make_stock_entry(posting_date="2012-12-25", posting_time="03:00", item_code="_Test Item", source=warehouse, qty=15) - make_stock_entry(posting_date=nowdate(), posting_time=nowtime(), item_code="_Test Item", + se3 = make_stock_entry(posting_date="2013-01-05", posting_time="07:00", item_code="_Test Item", target=warehouse, qty=15, basic_rate=1200) + return se1, se2, se3 + def create_batch_or_serial_no_items(): create_warehouse("_Test Warehouse for Stock Reco1", {"is_group": 0, "parent_warehouse": "_Test Warehouse Group - _TC"}) @@ -256,6 +259,10 @@ def create_stock_reconciliation(**args): return sr def set_valuation_method(item_code, valuation_method): + existing_valuation_method = get_valuation_method(item_code) + if valuation_method == existing_valuation_method: + return + frappe.db.set_value("Item", item_code, "valuation_method", valuation_method) for warehouse in frappe.get_all("Warehouse", filters={"company": "_Test Company"}, fields=["name", "is_group"]): diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.json b/erpnext/stock/doctype/stock_settings/stock_settings.json index a1666579d1..859aea2eb6 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.json +++ b/erpnext/stock/doctype/stock_settings/stock_settings.json @@ -28,7 +28,9 @@ "inter_warehouse_transfer_settings_section", "allow_from_dn", "allow_from_pr", - "freeze_stock_entries", + "control_historical_stock_transactions_section", + "role_allowed_to_create_edit_back_dated_transactions", + "column_break_26", "stock_frozen_upto", "stock_frozen_upto_days", "stock_auth_role", @@ -156,21 +158,20 @@ "label": "Notify by Email on Creation of Automatic Material Request" }, { - "fieldname": "freeze_stock_entries", - "fieldtype": "Section Break", - "label": "Freeze Stock Entries" - }, - { + "description": "No stock transactions can be created or modified before this date.", "fieldname": "stock_frozen_upto", "fieldtype": "Date", "label": "Stock Frozen Upto" }, { + "description": "Stock transactions that are older than the mentioned days cannot be modified.", "fieldname": "stock_frozen_upto_days", "fieldtype": "Int", "label": "Freeze Stocks Older Than (Days)" }, { + "depends_on": "eval:(doc.stock_frozen_upto || doc.stock_frozen_upto_days)", + "description": "The users with this Role are allowed to create/modify a stock transaction, even though the transaction is frozen.", "fieldname": "stock_auth_role", "fieldtype": "Link", "label": "Role Allowed to Edit Frozen Stock", @@ -210,6 +211,22 @@ "fieldname": "allow_from_pr", "fieldtype": "Check", "label": "Allow Material Transfer from Purchase Receipt to Purchase Invoice" + }, + { + "description": "If mentioned, the system will allow only the users with this Role to create or modify any stock transaction earlier than the latest stock transaction for a specific item and warehouse. If set as blank, it allows all users to create/edit back-dated transactions.", + "fieldname": "role_allowed_to_create_edit_back_dated_transactions", + "fieldtype": "Link", + "label": "Role Allowed to Create/Edit Back-dated Transactions", + "options": "User" + }, + { + "fieldname": "column_break_26", + "fieldtype": "Column Break" + }, + { + "fieldname": "control_historical_stock_transactions_section", + "fieldtype": "Section Break", + "label": "Control Historical Stock Transactions" } ], "icon": "icon-cog", @@ -217,7 +234,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2020-11-23 15:26:54.225608", + "modified": "2020-11-23 22:26:54.225608", "modified_by": "Administrator", "module": "Stock", "name": "Stock Settings", diff --git a/erpnext/stock/doctype/warehouse/test_warehouse.py b/erpnext/stock/doctype/warehouse/test_warehouse.py index 3101e8af4c..95478f61f0 100644 --- a/erpnext/stock/doctype/warehouse/test_warehouse.py +++ b/erpnext/stock/doctype/warehouse/test_warehouse.py @@ -10,13 +10,10 @@ from frappe.test_runner import make_test_records import erpnext from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry -from erpnext import set_perpetual_inventory from erpnext.accounts.doctype.account.test_account import get_inventory_account, create_account - test_records = frappe.get_test_records('Warehouse') - class TestWarehouse(unittest.TestCase): def setUp(self): if not frappe.get_value('Item', '_Test Item'): @@ -37,63 +34,63 @@ class TestWarehouse(unittest.TestCase): self.assertEqual(child_warehouse.is_group, 0) def test_warehouse_renaming(self): - set_perpetual_inventory(1) - create_warehouse("Test Warehouse for Renaming 1") - account = get_inventory_account("_Test Company", "Test Warehouse for Renaming 1 - _TC") + create_warehouse("Test Warehouse for Renaming 1", company="_Test Company with perpetual inventory") + account = get_inventory_account("_Test Company with perpetual inventory", "Test Warehouse for Renaming 1 - TCP1") self.assertTrue(frappe.db.get_value("Warehouse", filters={"account": account})) # Rename with abbr - if frappe.db.exists("Warehouse", "Test Warehouse for Renaming 2 - _TC"): - frappe.delete_doc("Warehouse", "Test Warehouse for Renaming 2 - _TC") - frappe.rename_doc("Warehouse", "Test Warehouse for Renaming 1 - _TC", "Test Warehouse for Renaming 2 - _TC") + if frappe.db.exists("Warehouse", "Test Warehouse for Renaming 2 - TCP1"): + frappe.delete_doc("Warehouse", "Test Warehouse for Renaming 2 - TCP1") + frappe.rename_doc("Warehouse", "Test Warehouse for Renaming 1 - TCP1", "Test Warehouse for Renaming 2 - TCP1") self.assertTrue(frappe.db.get_value("Warehouse", - filters={"account": "Test Warehouse for Renaming 1 - _TC"})) + filters={"account": "Test Warehouse for Renaming 1 - TCP1"})) # Rename without abbr - if frappe.db.exists("Warehouse", "Test Warehouse for Renaming 3 - _TC"): - frappe.delete_doc("Warehouse", "Test Warehouse for Renaming 3 - _TC") + if frappe.db.exists("Warehouse", "Test Warehouse for Renaming 3 - TCP1"): + frappe.delete_doc("Warehouse", "Test Warehouse for Renaming 3 - TCP1") - frappe.rename_doc("Warehouse", "Test Warehouse for Renaming 2 - _TC", "Test Warehouse for Renaming 3") + frappe.rename_doc("Warehouse", "Test Warehouse for Renaming 2 - TCP1", "Test Warehouse for Renaming 3") self.assertTrue(frappe.db.get_value("Warehouse", - filters={"account": "Test Warehouse for Renaming 1 - _TC"})) + filters={"account": "Test Warehouse for Renaming 1 - TCP1"})) # Another rename with multiple dashes - if frappe.db.exists("Warehouse", "Test - Warehouse - Company - _TC"): - frappe.delete_doc("Warehouse", "Test - Warehouse - Company - _TC") - frappe.rename_doc("Warehouse", "Test Warehouse for Renaming 3 - _TC", "Test - Warehouse - Company") + if frappe.db.exists("Warehouse", "Test - Warehouse - Company - TCP1"): + frappe.delete_doc("Warehouse", "Test - Warehouse - Company - TCP1") + frappe.rename_doc("Warehouse", "Test Warehouse for Renaming 3 - TCP1", "Test - Warehouse - Company") def test_warehouse_merging(self): - set_perpetual_inventory(1) + company = "_Test Company with perpetual inventory" + create_warehouse("Test Warehouse for Merging 1", company=company, + properties={"parent_warehouse": "All Warehouses - TCP1"}) + create_warehouse("Test Warehouse for Merging 2", company=company, + properties={"parent_warehouse": "All Warehouses - TCP1"}) - create_warehouse("Test Warehouse for Merging 1") - create_warehouse("Test Warehouse for Merging 2") - - make_stock_entry(item_code="_Test Item", target="Test Warehouse for Merging 1 - _TC", - qty=1, rate=100) - make_stock_entry(item_code="_Test Item", target="Test Warehouse for Merging 2 - _TC", - qty=1, rate=100) + make_stock_entry(item_code="_Test Item", target="Test Warehouse for Merging 1 - TCP1", + qty=1, rate=100, company=company) + make_stock_entry(item_code="_Test Item", target="Test Warehouse for Merging 2 - TCP1", + qty=1, rate=100, company=company) existing_bin_qty = ( cint(frappe.db.get_value("Bin", - {"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 1 - _TC"}, "actual_qty")) + {"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 1 - TCP1"}, "actual_qty")) + cint(frappe.db.get_value("Bin", - {"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 2 - _TC"}, "actual_qty")) + {"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 2 - TCP1"}, "actual_qty")) ) - frappe.rename_doc("Warehouse", "Test Warehouse for Merging 1 - _TC", - "Test Warehouse for Merging 2 - _TC", merge=True) + frappe.rename_doc("Warehouse", "Test Warehouse for Merging 1 - TCP1", + "Test Warehouse for Merging 2 - TCP1", merge=True) - self.assertFalse(frappe.db.exists("Warehouse", "Test Warehouse for Merging 1 - _TC")) + self.assertFalse(frappe.db.exists("Warehouse", "Test Warehouse for Merging 1 - TCP1")) bin_qty = frappe.db.get_value("Bin", - {"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 2 - _TC"}, "actual_qty") + {"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 2 - TCP1"}, "actual_qty") self.assertEqual(bin_qty, existing_bin_qty) self.assertTrue(frappe.db.get_value("Warehouse", - filters={"account": "Test Warehouse for Merging 2 - _TC"})) + filters={"account": "Test Warehouse for Merging 2 - TCP1"})) def create_warehouse(warehouse_name, properties=None, company=None): if not company: diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py index cd86be3115..6c84f168fd 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.py +++ b/erpnext/stock/doctype/warehouse/warehouse.py @@ -29,7 +29,6 @@ class Warehouse(NestedSet): self.set_onload('account', account) load_address_and_contact(self) - def on_update(self): self.update_nsm_model() diff --git a/erpnext/stock/report/stock_analytics/stock_analytics.py b/erpnext/stock/report/stock_analytics/stock_analytics.py index 54eefdfaaa..0cc8ca48aa 100644 --- a/erpnext/stock/report/stock_analytics/stock_analytics.py +++ b/erpnext/stock/report/stock_analytics/stock_analytics.py @@ -7,9 +7,11 @@ from frappe import _, scrub from frappe.utils import getdate, flt from erpnext.stock.report.stock_balance.stock_balance import (get_items, get_stock_ledger_entries, get_item_details) from erpnext.accounts.utils import get_fiscal_year +from erpnext.stock.utils import is_reposting_item_valuation_in_progress from six import iteritems def execute(filters=None): + is_reposting_item_valuation_in_progress() filters = frappe._dict(filters or {}) columns = get_columns(filters) data = get_data(filters) diff --git a/erpnext/stock/report/stock_balance/stock_balance.py b/erpnext/stock/report/stock_balance/stock_balance.py index ccd01001bb..e5d4d626c4 100644 --- a/erpnext/stock/report/stock_balance/stock_balance.py +++ b/erpnext/stock/report/stock_balance/stock_balance.py @@ -7,12 +7,13 @@ from frappe import _ from frappe.utils import flt, cint, getdate, now, date_diff from erpnext.stock.utils import add_additional_uom_columns from erpnext.stock.report.stock_ledger.stock_ledger import get_item_group_condition - +from erpnext.stock.utils import is_reposting_item_valuation_in_progress from erpnext.stock.report.stock_ageing.stock_ageing import get_fifo_queue, get_average_age from six import iteritems def execute(filters=None): + is_reposting_item_valuation_in_progress() if not filters: filters = {} validate_filters(filters) diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.py b/erpnext/stock/report/stock_ledger/stock_ledger.py index 86af5e0c86..7b5701a993 100644 --- a/erpnext/stock/report/stock_ledger/stock_ledger.py +++ b/erpnext/stock/report/stock_ledger/stock_ledger.py @@ -5,11 +5,12 @@ from __future__ import unicode_literals import frappe from frappe.utils import cint, flt -from erpnext.stock.utils import update_included_uom_in_report +from erpnext.stock.utils import update_included_uom_in_report, is_reposting_item_valuation_in_progress from frappe import _ from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos def execute(filters=None): + is_reposting_item_valuation_in_progress() include_uom = filters.get("include_uom") columns = get_columns() items = get_items(filters) diff --git a/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py b/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py index c8efb1637f..1183e41d04 100644 --- a/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py +++ b/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py @@ -5,9 +5,10 @@ from __future__ import unicode_literals import frappe from frappe import _ from frappe.utils import flt, today -from erpnext.stock.utils import update_included_uom_in_report +from erpnext.stock.utils import update_included_uom_in_report, is_reposting_item_valuation_in_progress def execute(filters=None): + is_reposting_item_valuation_in_progress() filters = frappe._dict(filters or {}) include_uom = filters.get("include_uom") columns = get_columns() 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 ebcb106b02..04f7d347ba 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 @@ -11,9 +11,11 @@ from frappe.utils import flt, cint, getdate from erpnext.stock.report.stock_balance.stock_balance import (get_item_details, get_item_reorder_details, get_item_warehouse_map, get_items, get_stock_ledger_entries) from erpnext.stock.report.stock_ageing.stock_ageing import get_fifo_queue, get_average_age +from erpnext.stock.utils import is_reposting_item_valuation_in_progress from six import iteritems def execute(filters=None): + is_reposting_item_valuation_in_progress() if not filters: filters = {} validate_filters(filters) diff --git a/erpnext/stock/stock_balance.py b/erpnext/stock/stock_balance.py index b5ae1b78eb..8ba1f1ca5c 100644 --- a/erpnext/stock/stock_balance.py +++ b/erpnext/stock/stock_balance.py @@ -6,6 +6,7 @@ import frappe from frappe.utils import flt, cstr, nowdate, nowtime from erpnext.stock.utils import update_bin from erpnext.stock.stock_ledger import update_entries_after +from erpnext.controllers.stock_controller import create_repost_item_valuation_entry def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False, only_bin=False): """ @@ -56,12 +57,18 @@ def repost_stock(item_code, warehouse, allow_zero_rate=False, update_bin_qty(item_code, warehouse, qty_dict) def repost_actual_qty(item_code, warehouse, allow_zero_rate=False, allow_negative_stock=False): - update_entries_after({ "item_code": item_code, "warehouse": warehouse }, - allow_zero_rate=allow_zero_rate, allow_negative_stock=allow_negative_stock) + create_repost_item_valuation_entry({ + "item_code": item_code, + "warehouse": warehouse, + "posting_date": "1900-01-01", + "posting_time": "00:01", + "allow_negative_stock": allow_negative_stock, + "allow_zero_rate": allow_zero_rate + }) def get_balance_qty_from_sle(item_code, warehouse): balance_qty = frappe.db.sql("""select qty_after_transaction from `tabStock Ledger Entry` - where item_code=%s and warehouse=%s + where item_code=%s and warehouse=%s and is_cancelled=0 order by posting_date desc, posting_time desc, creation desc limit 1""", (item_code, warehouse)) @@ -191,7 +198,7 @@ def set_stock_balance_as_per_serial_no(item_code=None, posting_date=None, postin print(d[0], d[1], d[2], serial_nos[0][0]) sle = frappe.db.sql("""select valuation_rate, company from `tabStock Ledger Entry` - where item_code = %s and warehouse = %s + where item_code = %s and warehouse = %s and is_cancelled = 0 order by posting_date desc limit 1""", (d[0], d[1])) sle_dict = { @@ -223,7 +230,8 @@ def set_stock_balance_as_per_serial_no(item_code=None, posting_date=None, postin }) update_bin(args) - update_entries_after({ + + create_repost_item_valuation_entry({ "item_code": d[0], "warehouse": d[1], "posting_date": posting_date, diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index f4490f1b01..5b9ada0ee5 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -5,9 +5,10 @@ from __future__ import unicode_literals import frappe, erpnext from frappe import _ from frappe.utils import cint, flt, cstr, now, now_datetime +from frappe.model.meta import get_field_precision from erpnext.stock.utils import get_valuation_method, get_incoming_outgoing_rate_for_cancel +from erpnext.stock.utils import get_bin import json - from six import iteritems # future reposting @@ -25,32 +26,23 @@ def make_sl_entries(sl_entries, allow_negative_stock=False, via_landed_cost_vouc set_as_cancel(sl_entries[0].get('voucher_type'), sl_entries[0].get('voucher_no')) for sle in sl_entries: - sle_id = None - if via_landed_cost_voucher or cancel: - sle['posting_date'] = now_datetime().strftime('%Y-%m-%d') - sle['posting_time'] = now_datetime().strftime('%H:%M:%S.%f') + if cancel: + sle['actual_qty'] = -flt(sle.get('actual_qty')) - if cancel: - sle['actual_qty'] = -flt(sle.get('actual_qty')) - - if sle['actual_qty'] < 0 and not sle.get('outgoing_rate'): - sle['outgoing_rate'] = get_incoming_outgoing_rate_for_cancel(sle.item_code, - sle.voucher_type, sle.voucher_no, sle.voucher_detail_no) - sle['incoming_rate'] = 0.0 - - if sle['actual_qty'] > 0 and not sle.get('incoming_rate'): - sle['incoming_rate'] = get_incoming_outgoing_rate_for_cancel(sle.item_code, - sle.voucher_type, sle.voucher_no, sle.voucher_detail_no) - sle['outgoing_rate'] = 0.0 + if sle['actual_qty'] < 0 and not sle.get('outgoing_rate'): + sle['outgoing_rate'] = get_incoming_outgoing_rate_for_cancel(sle.item_code, + sle.voucher_type, sle.voucher_no, sle.voucher_detail_no) + sle['incoming_rate'] = 0.0 + if sle['actual_qty'] > 0 and not sle.get('incoming_rate'): + sle['incoming_rate'] = get_incoming_outgoing_rate_for_cancel(sle.item_code, + sle.voucher_type, sle.voucher_no, sle.voucher_detail_no) + sle['outgoing_rate'] = 0.0 if sle.get("actual_qty") or sle.get("voucher_type")=="Stock Reconciliation": - sle_id = make_entry(sle, allow_negative_stock, via_landed_cost_voucher) - - args = sle.copy() - args.update({ - "sle_id": sle_id - }) + sle_doc = make_entry(sle, allow_negative_stock, via_landed_cost_voucher) + + args = sle_doc.as_dict() update_bin(args, allow_negative_stock, via_landed_cost_voucher) @@ -68,8 +60,36 @@ def make_entry(args, allow_negative_stock=False, via_landed_cost_voucher=False): sle.via_landed_cost_voucher = via_landed_cost_voucher sle.insert() sle.submit() - return sle.name + return sle +def repost_future_sle(args=None, voucher_type=None, voucher_no=None, allow_negative_stock=False, via_landed_cost_voucher=False): + if not args and voucher_type and voucher_no: + args = get_args_for_voucher(voucher_type, voucher_no) + + distinct_item_warehouses = [(d.item_code, d.warehouse) for d in args] + + i = 0 + while i < len(args): + obj = update_entries_after({ + "item_code": args[i].item_code, + "warehouse": args[i].warehouse, + "posting_date": args[i].posting_date, + "posting_time": args[i].posting_time + }, allow_negative_stock=allow_negative_stock, via_landed_cost_voucher=via_landed_cost_voucher) + + for item_wh, new_sle in iteritems(obj.new_items): + if item_wh not in distinct_item_warehouses: + args.append(new_sle) + + i += 1 + +def get_args_for_voucher(voucher_type, voucher_no): + return frappe.db.get_all("Stock Ledger Entry", + filters={"voucher_type": voucher_type, "voucher_no": voucher_no}, + fields=["item_code", "warehouse", "posting_date", "posting_time"], + order_by="creation asc", + group_by="item_code, warehouse" + ) class update_entries_after(object): """ @@ -86,141 +106,299 @@ class update_entries_after(object): } """ def __init__(self, args, allow_zero_rate=False, allow_negative_stock=None, via_landed_cost_voucher=False, verbose=1): - from frappe.model.meta import get_field_precision - - self.exceptions = [] + self.exceptions = {} self.verbose = verbose self.allow_zero_rate = allow_zero_rate - self.allow_negative_stock = allow_negative_stock self.via_landed_cost_voucher = via_landed_cost_voucher - if not self.allow_negative_stock: - self.allow_negative_stock = cint(frappe.db.get_single_value("Stock Settings", - "allow_negative_stock")) + self.allow_negative_stock = allow_negative_stock \ + or cint(frappe.db.get_single_value("Stock Settings", "allow_negative_stock")) - self.args = args - for key, value in iteritems(args): - setattr(self, key, value) + self.args = frappe._dict(args) + self.item_code = args.get("item_code") + if self.args.sle_id: + self.args['name'] = self.args.sle_id - self.previous_sle = self.get_sle_before_datetime() - self.previous_sle = self.previous_sle[0] if self.previous_sle else frappe._dict() + self.company = frappe.get_cached_value("Warehouse", self.args.warehouse, "company") + self.get_precision() + self.valuation_method = get_valuation_method(self.item_code) + self.new_items = {} + + self.data = frappe._dict() + self.initialize_previous_data(self.args) + + self.build() + + def get_precision(self): + company_base_currency = frappe.get_cached_value('Company', self.company, "default_currency") + self.precision = get_field_precision(frappe.get_meta("Stock Ledger Entry").get_field("stock_value"), + currency=company_base_currency) + + def initialize_previous_data(self, args): + """ + Get previous sl entries for current item for each related warehouse + and assigns into self.data dict + + :Data Structure: + + self.data = { + warehouse1: { + 'previus_sle': {}, + 'qty_after_transaction': 10, + 'valuation_rate': 100, + 'stock_value': 1000, + 'prev_stock_value': 1000, + 'stock_queue': '[[10, 100]]', + 'stock_value_difference': 1000 + } + } + + """ + self.data.setdefault(args.warehouse, frappe._dict()) + warehouse_dict = self.data[args.warehouse] + previous_sle = self.get_sle_before_datetime(args) + warehouse_dict.previous_sle = previous_sle for key in ("qty_after_transaction", "valuation_rate", "stock_value"): - setattr(self, key, flt(self.previous_sle.get(key))) + setattr(warehouse_dict, key, flt(previous_sle.get(key))) - self.company = frappe.db.get_value("Warehouse", self.warehouse, "company") - self.precision = get_field_precision(frappe.get_meta("Stock Ledger Entry").get_field("stock_value"), - currency=frappe.get_cached_value('Company', self.company, "default_currency")) + warehouse_dict.update({ + "prev_stock_value": previous_sle.stock_value or 0.0, + "stock_queue": json.loads(previous_sle.stock_queue or "[]"), + "stock_value_difference": 0.0 + }) - self.prev_stock_value = self.previous_sle.stock_value or 0.0 - self.stock_queue = json.loads(self.previous_sle.stock_queue or "[]") - self.valuation_method = get_valuation_method(self.item_code) - self.stock_value_difference = 0.0 - self.build(args.get('sle_id')) - - def build(self, sle_id): - if sle_id: - sle = get_sle_by_id(sle_id) - self.process_sle(sle) + def build(self): + if self.args.get("sle_id"): + self.process_sle_against_current_voucher() else: - # includes current entry! - entries_to_fix = self.get_sle_after_datetime() - for sle in entries_to_fix: + entries_to_fix = self.get_future_entries_to_fix() + + i = 0 + while i < len(entries_to_fix): + sle = entries_to_fix[i] + i += 1 + self.process_sle(sle) + if sle.dependant_sle_voucher_detail_no: + self.get_dependent_entries_to_fix(entries_to_fix, sle) + if self.exceptions: self.raise_exceptions() self.update_bin() - def update_bin(self): - # update bin - bin_name = frappe.db.get_value("Bin", { - "item_code": self.item_code, - "warehouse": self.warehouse - }) + def process_sle_against_current_voucher(self): + sl_entries = self.get_sle_against_current_voucher() + for sle in sl_entries: + self.process_sle(sle) - if not bin_name: - bin_doc = frappe.get_doc({ - "doctype": "Bin", - "item_code": self.item_code, - "warehouse": self.warehouse - }) - bin_doc.insert(ignore_permissions=True) - else: - bin_doc = frappe.get_doc("Bin", bin_name) + def get_sle_against_current_voucher(self): + return frappe.db.sql(""" + select + *, timestamp(posting_date, posting_time) as "timestamp" + from + `tabStock Ledger Entry` + where + item_code = %(item_code)s + and warehouse = %(warehouse)s + and voucher_type = %(voucher_type)s + and voucher_no = %(voucher_no)s + order by + creation ASC + for update + """, self.args, as_dict=1) - bin_doc.update({ - "valuation_rate": self.valuation_rate, - "actual_qty": self.qty_after_transaction, - "stock_value": self.stock_value - }) - bin_doc.flags.via_stock_ledger_entry = True + def get_future_entries_to_fix(self): + # includes current entry! + args = self.data[self.args.warehouse].previous_sle \ + or frappe._dict({"item_code": self.item_code, "warehouse": self.args.warehouse}) + + return list(self.get_sle_after_datetime(args)) - bin_doc.save(ignore_permissions=True) + def get_dependent_entries_to_fix(self, entries_to_fix, sle): + dependant_sle = get_sle_by_voucher_detail_no(sle.dependant_sle_voucher_detail_no, + excluded_sle=sle.name) + + if not dependant_sle: + return + elif dependant_sle.item_code == self.item_code and dependant_sle.warehouse == self.args.warehouse: + return + elif dependant_sle.item_code != self.item_code \ + and (dependant_sle.item_code, dependant_sle.warehouse) not in self.new_items: + self.new_items[(dependant_sle.item_code, dependant_sle.warehouse)] = dependant_sle + return + + self.initialize_previous_data(dependant_sle) + + args = self.data[dependant_sle.warehouse].previous_sle \ + or frappe._dict({"item_code": self.item_code, "warehouse": dependant_sle.warehouse}) + future_sle_for_dependant = list(self.get_sle_after_datetime(args)) + + entries_to_fix.extend(future_sle_for_dependant) + entries_to_fix = sorted(entries_to_fix, key=lambda k: k['timestamp']) def process_sle(self, sle): + # previous sle data for this warehouse + self.wh_data = self.data[sle.warehouse] + if (sle.serial_no and not self.via_landed_cost_voucher) or not cint(self.allow_negative_stock): # validate negative stock for serialized items, fifo valuation # or when negative stock is not allowed for moving average if not self.validate_negative_stock(sle): - self.qty_after_transaction += flt(sle.actual_qty) + self.wh_data.qty_after_transaction += flt(sle.actual_qty) return + # Get dynamic incoming/outgoing rate + self.get_dynamic_incoming_outgoing_rate(sle) + if sle.serial_no: self.get_serialized_values(sle) - self.qty_after_transaction += flt(sle.actual_qty) + self.wh_data.qty_after_transaction += flt(sle.actual_qty) if sle.voucher_type == "Stock Reconciliation": - self.qty_after_transaction = sle.qty_after_transaction + self.wh_data.qty_after_transaction = sle.qty_after_transaction - self.stock_value = flt(self.qty_after_transaction) * flt(self.valuation_rate) + self.wh_data.stock_value = flt(self.wh_data.qty_after_transaction) * flt(self.wh_data.valuation_rate) else: if sle.voucher_type=="Stock Reconciliation" and not sle.batch_no: # assert - self.valuation_rate = sle.valuation_rate - self.qty_after_transaction = sle.qty_after_transaction - self.stock_queue = [[self.qty_after_transaction, self.valuation_rate]] - self.stock_value = flt(self.qty_after_transaction) * flt(self.valuation_rate) + self.wh_data.valuation_rate = sle.valuation_rate + self.wh_data.qty_after_transaction = sle.qty_after_transaction + self.wh_data.stock_queue = [[self.wh_data.qty_after_transaction, self.wh_data.valuation_rate]] + self.wh_data.stock_value = flt(self.wh_data.qty_after_transaction) * flt(self.wh_data.valuation_rate) else: if self.valuation_method == "Moving Average": self.get_moving_average_values(sle) - self.qty_after_transaction += flt(sle.actual_qty) - self.stock_value = flt(self.qty_after_transaction) * flt(self.valuation_rate) + self.wh_data.qty_after_transaction += flt(sle.actual_qty) + self.wh_data.stock_value = flt(self.wh_data.qty_after_transaction) * flt(self.wh_data.valuation_rate) else: self.get_fifo_values(sle) - self.qty_after_transaction += flt(sle.actual_qty) - self.stock_value = sum((flt(batch[0]) * flt(batch[1]) for batch in self.stock_queue)) + self.wh_data.qty_after_transaction += flt(sle.actual_qty) + self.wh_data.stock_value = sum((flt(batch[0]) * flt(batch[1]) for batch in self.wh_data.stock_queue)) # rounding as per precision - self.stock_value = flt(self.stock_value, self.precision) - - stock_value_difference = self.stock_value - self.prev_stock_value - - self.prev_stock_value = self.stock_value + self.wh_data.stock_value = flt(self.wh_data.stock_value, self.precision) + stock_value_difference = self.wh_data.stock_value - self.wh_data.prev_stock_value + self.wh_data.prev_stock_value = self.wh_data.stock_value # update current sle - sle.qty_after_transaction = self.qty_after_transaction - sle.valuation_rate = self.valuation_rate - sle.stock_value = self.stock_value - sle.stock_queue = json.dumps(self.stock_queue) + sle.qty_after_transaction = self.wh_data.qty_after_transaction + sle.valuation_rate = self.wh_data.valuation_rate + sle.stock_value = self.wh_data.stock_value + sle.stock_queue = json.dumps(self.wh_data.stock_queue) sle.stock_value_difference = stock_value_difference sle.doctype="Stock Ledger Entry" frappe.get_doc(sle).db_update() + self.update_outgoing_rate_on_transaction(sle) + def validate_negative_stock(self, sle): """ validate negative stock for entries current datetime onwards will not consider cancelled entries """ - diff = self.qty_after_transaction + flt(sle.actual_qty) + diff = self.wh_data.qty_after_transaction + flt(sle.actual_qty) if diff < 0 and abs(diff) > 0.0001: # negative stock! exc = sle.copy().update({"diff": diff}) - self.exceptions.append(exc) + self.exceptions.setdefault(sle.warehouse, []).append(exc) return False else: return True + def get_dynamic_incoming_outgoing_rate(self, sle): + # Get updated incoming/outgoing rate from transaction + if sle.recalculate_rate: + rate = self.get_incoming_outgoing_rate_from_transaction(sle) + + if flt(sle.actual_qty) >= 0: + sle.incoming_rate = rate + else: + sle.outgoing_rate = rate + + def get_incoming_outgoing_rate_from_transaction(self, sle): + rate = 0 + # Material Transfer, Repack, Manufacturing + if sle.voucher_type == "Stock Entry": + rate = frappe.db.get_value("Stock Entry Detail", sle.voucher_detail_no, "valuation_rate") + # Sales and Purchase Return + elif sle.voucher_type in ("Purchase Receipt", "Purchase Invoice", "Delivery Note", "Sales Invoice"): + if frappe.get_cached_value(sle.voucher_type, sle.voucher_no, "is_return"): + from erpnext.controllers.sales_and_purchase_return import get_rate_for_return # don't move this import to top + rate = get_rate_for_return(sle.voucher_type, sle.voucher_no, sle.item_code, voucher_detail_no=sle.voucher_detail_no) + else: + if sle.voucher_type in ("Purchase Receipt", "Purchase Invoice"): + rate_field = "valuation_rate" + else: + rate_field = "incoming_rate" + + # check in item table + item_code, incoming_rate = frappe.db.get_value(sle.voucher_type + " Item", + sle.voucher_detail_no, ["item_code", rate_field]) + + if item_code == sle.item_code: + rate = incoming_rate + else: + if sle.voucher_type in ("Delivery Note", "Sales Invoice"): + ref_doctype = "Packed Item" + else: + ref_doctype = "Purchase Receipt Item Supplied" + + rate = frappe.db.get_value(ref_doctype, {"parent_detail_docname": sle.voucher_detail_no, + "item_code": sle.item_code}, rate_field) + + return rate + + def update_outgoing_rate_on_transaction(self, sle): + """ + Update outgoing rate in Stock Entry, Delivery Note, Sales Invoice and Sales Return + In case of Stock Entry, also calculate FG Item rate and total incoming/outgoing amount + """ + if sle.actual_qty and sle.voucher_detail_no: + outgoing_rate = abs(flt(sle.stock_value_difference)) / abs(sle.actual_qty) + + if flt(sle.actual_qty) < 0 and sle.voucher_type == "Stock Entry": + self.update_rate_on_stock_entry(sle, outgoing_rate) + elif sle.voucher_type in ("Delivery Note", "Sales Invoice"): + self.update_rate_on_delivery_and_sales_return(sle, outgoing_rate) + elif flt(sle.actual_qty) < 0 and sle.voucher_type in ("Purchase Receipt", "Purchase Invoice"): + self.update_rate_on_purchase_receipt(sle, outgoing_rate) + + def update_rate_on_stock_entry(self, sle, outgoing_rate): + frappe.db.set_value("Stock Entry Detail", sle.voucher_detail_no, "basic_rate", outgoing_rate) + + # Update outgoing item's rate, recalculate FG Item's rate and total incoming/outgoing amount + stock_entry = frappe.get_doc("Stock Entry", sle.voucher_no) + stock_entry.calculate_rate_and_amount(reset_outgoing_rate=False, raise_error_if_no_rate=False) + stock_entry.db_update() + for d in stock_entry.items: + d.db_update() + + def update_rate_on_delivery_and_sales_return(self, sle, outgoing_rate): + # Update item's incoming rate on transaction + item_code = frappe.db.get_value(sle.voucher_type + " Item", sle.voucher_detail_no, "item_code") + if item_code == sle.item_code: + frappe.db.set_value(sle.voucher_type + " Item", sle.voucher_detail_no, "incoming_rate", outgoing_rate) + else: + # packed item + frappe.db.set_value("Packed Item", + {"parent_detail_docname": sle.voucher_detail_no, "item_code": sle.item_code}, + "incoming_rate", outgoing_rate) + + def update_rate_on_purchase_receipt(self, sle, outgoing_rate): + if frappe.db.exists(sle.voucher_type + " Item", sle.voucher_detail_no): + frappe.db.set_value(sle.voucher_type + " Item", sle.voucher_detail_no, "base_net_rate", outgoing_rate) + else: + frappe.db.set_value("Purchase Receipt Item Supplied", sle.voucher_detail_no, "rate", outgoing_rate) + + # Recalculate subcontracted item's rate in case of subcontracted purchase receipt/invoice + if frappe.db.get_value(sle.voucher_type, sle.voucher_no, "is_subcontracted"): + doc = frappe.get_cached_doc(sle.voucher_type, sle.voucher_no) + doc.update_valuation_rate(reset_outgoing_rate=False) + for d in (doc.items + doc.supplied_items): + d.db_update() + def get_serialized_values(self, sle): incoming_rate = flt(sle.incoming_rate) actual_qty = flt(sle.actual_qty) @@ -228,7 +406,7 @@ class update_entries_after(object): if incoming_rate < 0: # wrong incoming rate - incoming_rate = self.valuation_rate + incoming_rate = self.wh_data.valuation_rate stock_value_change = 0 if incoming_rate: @@ -236,22 +414,25 @@ class update_entries_after(object): elif actual_qty < 0: # In case of delivery/stock issue, get average purchase rate # of serial nos of current entry - outgoing_value = self.get_incoming_value_for_serial_nos(sle, serial_nos) - stock_value_change = -1 * outgoing_value + if not sle.is_cancelled: + outgoing_value = self.get_incoming_value_for_serial_nos(sle, serial_nos) + stock_value_change = -1 * outgoing_value + else: + stock_value_change = actual_qty * sle.outgoing_rate - new_stock_qty = self.qty_after_transaction + actual_qty + new_stock_qty = self.wh_data.qty_after_transaction + actual_qty if new_stock_qty > 0: - new_stock_value = (self.qty_after_transaction * self.valuation_rate) + stock_value_change + new_stock_value = (self.wh_data.qty_after_transaction * self.wh_data.valuation_rate) + stock_value_change if new_stock_value >= 0: # calculate new valuation rate only if stock value is positive # else it remains the same as that of previous entry - self.valuation_rate = new_stock_value / new_stock_qty + self.wh_data.valuation_rate = new_stock_value / new_stock_qty - if not self.valuation_rate and sle.voucher_detail_no: + if not self.wh_data.valuation_rate and sle.voucher_detail_no: allow_zero_rate = self.check_if_allow_zero_valuation_rate(sle.voucher_type, sle.voucher_detail_no) if not allow_zero_rate: - self.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, + self.wh_data.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, sle.voucher_type, sle.voucher_no, self.allow_zero_rate, currency=erpnext.get_company_currency(sle.company)) @@ -287,39 +468,39 @@ class update_entries_after(object): def get_moving_average_values(self, sle): actual_qty = flt(sle.actual_qty) - new_stock_qty = flt(self.qty_after_transaction) + actual_qty + new_stock_qty = flt(self.wh_data.qty_after_transaction) + actual_qty if new_stock_qty >= 0: if actual_qty > 0: - if flt(self.qty_after_transaction) <= 0: - self.valuation_rate = sle.incoming_rate + if flt(self.wh_data.qty_after_transaction) <= 0: + self.wh_data.valuation_rate = sle.incoming_rate else: - new_stock_value = (self.qty_after_transaction * self.valuation_rate) + \ + new_stock_value = (self.wh_data.qty_after_transaction * self.wh_data.valuation_rate) + \ (actual_qty * sle.incoming_rate) - self.valuation_rate = new_stock_value / new_stock_qty + self.wh_data.valuation_rate = new_stock_value / new_stock_qty elif sle.outgoing_rate: if new_stock_qty: - new_stock_value = (self.qty_after_transaction * self.valuation_rate) + \ + new_stock_value = (self.wh_data.qty_after_transaction * self.wh_data.valuation_rate) + \ (actual_qty * sle.outgoing_rate) - self.valuation_rate = new_stock_value / new_stock_qty + self.wh_data.valuation_rate = new_stock_value / new_stock_qty else: - self.valuation_rate = sle.outgoing_rate + self.wh_data.valuation_rate = sle.outgoing_rate else: - if flt(self.qty_after_transaction) >= 0 and sle.outgoing_rate: - self.valuation_rate = sle.outgoing_rate + if flt(self.wh_data.qty_after_transaction) >= 0 and sle.outgoing_rate: + self.wh_data.valuation_rate = sle.outgoing_rate - if not self.valuation_rate and actual_qty > 0: - self.valuation_rate = sle.incoming_rate + if not self.wh_data.valuation_rate and actual_qty > 0: + self.wh_data.valuation_rate = sle.incoming_rate # Get valuation rate from previous SLE or Item master, if item does not have the # allow zero valuration rate flag set - if not self.valuation_rate and sle.voucher_detail_no: + if not self.wh_data.valuation_rate and sle.voucher_detail_no: allow_zero_valuation_rate = self.check_if_allow_zero_valuation_rate(sle.voucher_type, sle.voucher_detail_no) if not allow_zero_valuation_rate: - self.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, + self.wh_data.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, sle.voucher_type, sle.voucher_no, self.allow_zero_rate, currency=erpnext.get_company_currency(sle.company)) @@ -329,22 +510,22 @@ class update_entries_after(object): outgoing_rate = flt(sle.outgoing_rate) if actual_qty > 0: - if not self.stock_queue: - self.stock_queue.append([0, 0]) + if not self.wh_data.stock_queue: + self.wh_data.stock_queue.append([0, 0]) # last row has the same rate, just updated the qty - if self.stock_queue[-1][1]==incoming_rate: - self.stock_queue[-1][0] += actual_qty + if self.wh_data.stock_queue[-1][1]==incoming_rate: + self.wh_data.stock_queue[-1][0] += actual_qty else: - if self.stock_queue[-1][0] > 0: - self.stock_queue.append([actual_qty, incoming_rate]) + if self.wh_data.stock_queue[-1][0] > 0: + self.wh_data.stock_queue.append([actual_qty, incoming_rate]) else: - qty = self.stock_queue[-1][0] + actual_qty - self.stock_queue[-1] = [qty, incoming_rate] + qty = self.wh_data.stock_queue[-1][0] + actual_qty + self.wh_data.stock_queue[-1] = [qty, incoming_rate] else: qty_to_pop = abs(actual_qty) while qty_to_pop: - if not self.stock_queue: + if not self.wh_data.stock_queue: # Get valuation rate from last sle if exists or from valuation rate field in item master allow_zero_valuation_rate = self.check_if_allow_zero_valuation_rate(sle.voucher_type, sle.voucher_detail_no) if not allow_zero_valuation_rate: @@ -354,35 +535,35 @@ class update_entries_after(object): else: _rate = 0 - self.stock_queue.append([0, _rate]) + self.wh_data.stock_queue.append([0, _rate]) index = None if outgoing_rate > 0: # Find the entry where rate matched with outgoing rate - for i, v in enumerate(self.stock_queue): + for i, v in enumerate(self.wh_data.stock_queue): if v[1] == outgoing_rate: index = i break # If no entry found with outgoing rate, collapse stack if index == None: - new_stock_value = sum((d[0]*d[1] for d in self.stock_queue)) - qty_to_pop*outgoing_rate - new_stock_qty = sum((d[0] for d in self.stock_queue)) - qty_to_pop - self.stock_queue = [[new_stock_qty, new_stock_value/new_stock_qty if new_stock_qty > 0 else outgoing_rate]] + new_stock_value = sum((d[0]*d[1] for d in self.wh_data.stock_queue)) - qty_to_pop*outgoing_rate + new_stock_qty = sum((d[0] for d in self.wh_data.stock_queue)) - qty_to_pop + self.wh_data.stock_queue = [[new_stock_qty, new_stock_value/new_stock_qty if new_stock_qty > 0 else outgoing_rate]] break else: index = 0 # select first batch or the batch with same rate - batch = self.stock_queue[index] + batch = self.wh_data.stock_queue[index] if qty_to_pop >= batch[0]: # consume current batch qty_to_pop = qty_to_pop - batch[0] - self.stock_queue.pop(index) - if not self.stock_queue and qty_to_pop: + self.wh_data.stock_queue.pop(index) + if not self.wh_data.stock_queue and qty_to_pop: # stock finished, qty still remains to be withdrawn # negative stock, keep in as a negative batch - self.stock_queue.append([-qty_to_pop, outgoing_rate or batch[1]]) + self.wh_data.stock_queue.append([-qty_to_pop, outgoing_rate or batch[1]]) break else: @@ -391,14 +572,14 @@ class update_entries_after(object): batch[0] = batch[0] - qty_to_pop qty_to_pop = 0 - stock_value = sum((flt(batch[0]) * flt(batch[1]) for batch in self.stock_queue)) - stock_qty = sum((flt(batch[0]) for batch in self.stock_queue)) + stock_value = sum((flt(batch[0]) * flt(batch[1]) for batch in self.wh_data.stock_queue)) + stock_qty = sum((flt(batch[0]) for batch in self.wh_data.stock_queue)) if stock_qty: - self.valuation_rate = stock_value / flt(stock_qty) + self.wh_data.valuation_rate = stock_value / flt(stock_qty) - if not self.stock_queue: - self.stock_queue.append([0, sle.incoming_rate or sle.outgoing_rate or self.valuation_rate]) + if not self.wh_data.stock_queue: + self.wh_data.stock_queue.append([0, sle.incoming_rate or sle.outgoing_rate or self.wh_data.valuation_rate]) def check_if_allow_zero_valuation_rate(self, voucher_type, voucher_detail_no): ref_item_dt = "" @@ -413,39 +594,56 @@ class update_entries_after(object): else: return 0 - def get_sle_before_datetime(self): + def get_sle_before_datetime(self, args): """get previous stock ledger entry before current time-bucket""" - if self.args.get('sle_id'): - self.args['name'] = self.args.get('sle_id') + sle = get_stock_ledger_entries(args, "<", "desc", "limit 1", for_update=False) + sle = sle[0] if sle else frappe._dict() + return sle - return get_stock_ledger_entries(self.args, "<=", "desc", "limit 1", for_update=False) - - def get_sle_after_datetime(self): + def get_sle_after_datetime(self, args): """get Stock Ledger Entries after a particular datetime, for reposting""" - return get_stock_ledger_entries(self.previous_sle or frappe._dict({ - "item_code": self.args.get("item_code"), "warehouse": self.args.get("warehouse") }), - ">", "asc", for_update=True, check_serial_no=False) + return get_stock_ledger_entries(args, ">", "asc", for_update=True, check_serial_no=False) def raise_exceptions(self): - deficiency = min(e["diff"] for e in self.exceptions) + msg_list = [] + for warehouse, exceptions in iteritems(self.exceptions): + deficiency = min(e["diff"] for e in exceptions) - if ((self.exceptions[0]["voucher_type"], self.exceptions[0]["voucher_no"]) in - frappe.local.flags.currently_saving): + if ((exceptions[0]["voucher_type"], exceptions[0]["voucher_no"]) in + frappe.local.flags.currently_saving): - msg = _("{0} units of {1} needed in {2} to complete this transaction.").format( - abs(deficiency), frappe.get_desk_link('Item', self.item_code), - frappe.get_desk_link('Warehouse', self.warehouse)) - else: - msg = _("{0} units of {1} needed in {2} on {3} {4} for {5} to complete this transaction.").format( - abs(deficiency), frappe.get_desk_link('Item', self.item_code), - frappe.get_desk_link('Warehouse', self.warehouse), - self.exceptions[0]["posting_date"], self.exceptions[0]["posting_time"], - frappe.get_desk_link(self.exceptions[0]["voucher_type"], self.exceptions[0]["voucher_no"])) + msg = _("{0} units of {1} needed in {2} to complete this transaction.").format( + abs(deficiency), frappe.get_desk_link('Item', self.item_code), + frappe.get_desk_link('Warehouse', warehouse)) + else: + msg = _("{0} units of {1} needed in {2} on {3} {4} for {5} to complete this transaction.").format( + abs(deficiency), frappe.get_desk_link('Item', self.item_code), + frappe.get_desk_link('Warehouse', warehouse), + exceptions[0]["posting_date"], exceptions[0]["posting_time"], + frappe.get_desk_link(exceptions[0]["voucher_type"], exceptions[0]["voucher_no"])) - if self.verbose: - frappe.throw(msg, NegativeStockError, title='Insufficient Stock') - else: - raise NegativeStockError(msg) + if msg: + msg_list.append(msg) + + if msg_list: + message = "\n\n".join(msg_list) + if self.verbose: + frappe.throw(message, NegativeStockError, title='Insufficient Stock') + else: + raise NegativeStockError(message) + + def update_bin(self): + # update bin for each warehouse + for warehouse, data in iteritems(self.data): + bin_doc = get_bin(self.item_code, warehouse) + + bin_doc.update({ + "valuation_rate": data.valuation_rate, + "actual_qty": data.qty_after_transaction, + "stock_value": data.stock_value + }) + bin_doc.flags.via_stock_ledger_entry = True + bin_doc.save(ignore_permissions=True) def get_previous_sle(args, for_update=False): """ @@ -489,6 +687,7 @@ def get_stock_ledger_entries(previous_sle, operator=None, select *, timestamp(posting_date, posting_time) as "timestamp" from `tabStock Ledger Entry` where item_code = %%(item_code)s + and is_cancelled = 0 %(conditions)s order by timestamp(posting_date, posting_time) %(order)s, creation %(order)s %(limit)s %(for_update)s""" % { @@ -498,10 +697,11 @@ def get_stock_ledger_entries(previous_sle, operator=None, "order": order }, previous_sle, as_dict=1, debug=debug) -def get_sle_by_id(sle_id): - return frappe.db.get_all('Stock Ledger Entry', - fields=['*', 'timestamp(posting_date, posting_time) as timestamp'], - filters={'name': sle_id})[0] +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]}, + ['item_code', 'warehouse', 'posting_date', 'posting_time', 'timestamp(posting_date, posting_time) as timestamp'], + as_dict=1) def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, allow_zero_rate=False, currency=None, company=None, raise_error_if_no_rate=True): @@ -529,7 +729,7 @@ def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, order by posting_date desc, posting_time desc, name desc limit 1""", (item_code, voucher_no, voucher_type)) if last_valuation_rate: - return flt(last_valuation_rate[0][0]) # as there is previous records, it might come with zero rate + return flt(last_valuation_rate[0][0]) # If negative stock allowed, and item delivered without any incoming entry, # system does not found any SLE, then take valuation rate from Item @@ -561,3 +761,54 @@ def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, frappe.throw(msg=msg, title=_("Valuation Rate Missing")) return valuation_rate + +def update_qty_in_future_sle(args, allow_negative_stock=None): + frappe.db.sql(""" + update `tabStock Ledger Entry` + set qty_after_transaction = qty_after_transaction + {qty} + where + item_code = %(item_code)s + and warehouse = %(warehouse)s + and voucher_no != %(voucher_no)s + and is_cancelled = 0 + and (timestamp(posting_date, posting_time) > timestamp(%(posting_date)s, %(posting_time)s) + or ( + timestamp(posting_date, posting_time) = timestamp(%(posting_date)s, %(posting_time)s) + and creation > %(creation)s + ) + ) + """.format(qty=args.actual_qty), args) + + validate_negative_qty_in_future_sle(args, allow_negative_stock) + +def validate_negative_qty_in_future_sle(args, allow_negative_stock=None): + allow_negative_stock = allow_negative_stock \ + or cint(frappe.db.get_single_value("Stock Settings", "allow_negative_stock")) + + if args.actual_qty < 0 and not allow_negative_stock: + sle = get_future_sle_with_negative_qty(args) + if sle: + message = _("{0} units of {1} needed in {2} on {3} {4} for {5} to complete this transaction.").format( + abs(sle[0]["qty_after_transaction"]), + frappe.get_desk_link('Item', args.item_code), + frappe.get_desk_link('Warehouse', args.warehouse), + sle[0]["posting_date"], sle[0]["posting_time"], + frappe.get_desk_link(sle[0]["voucher_type"], sle[0]["voucher_no"])) + + frappe.throw(message, NegativeStockError, title='Insufficient Stock') + +def get_future_sle_with_negative_qty(args): + return frappe.db.sql(""" + select + qty_after_transaction, posting_date, posting_time, + voucher_type, voucher_no + from `tabStock Ledger Entry` + where + item_code = %(item_code)s + and warehouse = %(warehouse)s + and voucher_no != %(voucher_no)s + and timestamp(posting_date, posting_time) >= timestamp(%(posting_date)s, %(posting_time)s) + and is_cancelled = 0 + and qty_after_transaction < 0 + limit 1 + """, args, as_dict=1) \ No newline at end of file diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index f9ac25443e..4ea7e4fcd6 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -63,6 +63,7 @@ def get_stock_value_on(warehouse=None, posting_date=None, item_code=None): SELECT item_code, stock_value, name, warehouse FROM `tabStock Ledger Entry` sle WHERE posting_date <= %s {0} + and is_cancelled = 0 ORDER BY timestamp(posting_date, posting_time) DESC, creation DESC """.format(condition), values, as_dict=1) @@ -211,7 +212,7 @@ def get_incoming_rate(args, raise_error_if_no_rate=True): currency=erpnext.get_company_currency(args.get('company')), company=args.get('company'), raise_error_if_no_rate=raise_error_if_no_rate) - return in_rate + return flt(in_rate) def get_avg_purchase_rate(serial_nos): """get average value of serial numbers""" @@ -375,4 +376,10 @@ def get_incoming_outgoing_rate_for_cancel(item_code, voucher_type, voucher_no, v outgoing_rate = outgoing_rate[0][0] if outgoing_rate else 0.0 - return outgoing_rate \ No newline at end of file + return outgoing_rate + +def is_reposting_item_valuation_in_progress(): + reposting_in_progress = frappe.db.exists("Repost Item Valuation", + {'docstatus': 1, 'status': ['in', ['Queued','In Progress']]}) + if reposting_in_progress: + frappe.msgprint(_("Item valuation reposting in progress. Report might show incorrect item valuation."), alert=1) \ No newline at end of file From 0a1390a7ca2c67f53c33119bb429e2f8efaaf943 Mon Sep 17 00:00:00 2001 From: Anurag Mishra <32095923+Anurag810@users.noreply.github.com> Date: Tue, 22 Dec 2020 11:16:36 +0530 Subject: [PATCH 218/449] fix: leave policy dashboard fix and roles (#24170) --- .../doctype/leave_policy/leave_policy_dashboard.py | 14 +------------- .../leave_policy_assignment.json | 5 ++++- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/erpnext/hr/doctype/leave_policy/leave_policy_dashboard.py b/erpnext/hr/doctype/leave_policy/leave_policy_dashboard.py index ff5dc2ff3e..e0ec4be2dc 100644 --- a/erpnext/hr/doctype/leave_policy/leave_policy_dashboard.py +++ b/erpnext/hr/doctype/leave_policy/leave_policy_dashboard.py @@ -4,22 +4,10 @@ from frappe import _ def get_data(): return { 'fieldname': 'leave_policy', - 'non_standard_fieldnames': { - 'Employee Grade': 'default_leave_policy' - }, 'transactions': [ - { - 'label': _('Employees'), - 'items': ['Employee', 'Employee Grade'] - }, { 'label': _('Leaves'), 'items': ['Leave Allocation'] }, ] - } - - - - - \ No newline at end of file + } \ No newline at end of file diff --git a/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json b/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json index ecebb3b7d6..bbb4222715 100644 --- a/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json +++ b/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json @@ -111,7 +111,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-10-15 15:18:15.227848", + "modified": "2020-12-17 16:27:20.311060", "modified_by": "Administrator", "module": "HR", "name": "Leave Policy Assignment", @@ -127,6 +127,7 @@ "report": 1, "role": "HR Manager", "share": 1, + "submit": 1, "write": 1 }, { @@ -139,6 +140,7 @@ "report": 1, "role": "HR User", "share": 1, + "submit": 1, "write": 1 }, { @@ -151,6 +153,7 @@ "report": 1, "role": "System Manager", "share": 1, + "submit": 1, "write": 1 } ], From adf9b49e1462862a7743026def8bb7e1a3c48311 Mon Sep 17 00:00:00 2001 From: Afshan Date: Wed, 23 Dec 2020 11:39:38 +0530 Subject: [PATCH 219/449] fix: sal slip popup error --- .../payroll/doctype/salary_slip/salary_slip.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.js b/erpnext/payroll/doctype/salary_slip/salary_slip.js index f7e22c6387..abe873d839 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.js +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.js @@ -214,14 +214,16 @@ frappe.ui.form.on('Salary Slip Timesheet', { }); var calculate_totals = function(frm) { - if (frm.doc.earnings || frm.doc.deductions) { - frappe.call({ - method: "set_totals", - doc: frm.doc, - callback: function() { - frm.refresh_fields(); - } - }); + if (frm.doc.docstatus === 0) { + if (frm.doc.earnings || frm.doc.deductions) { + frappe.call({ + method: "set_totals", + doc: frm.doc, + callback: function() { + frm.refresh_fields(); + } + }); + } } }; From 9fe7f235d0c2d40b4c0bd6cf40102b6d367eb73a Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 24 Dec 2020 11:03:48 +0530 Subject: [PATCH 220/449] fix: Do not cancel reference document on Quality Inspection cancellation (#24198) --- .../stock/doctype/quality_inspection/quality_inspection.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.js b/erpnext/stock/doctype/quality_inspection/quality_inspection.js index 376848afaa..03e3de115b 100644 --- a/erpnext/stock/doctype/quality_inspection/quality_inspection.js +++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.js @@ -4,6 +4,11 @@ cur_frm.cscript.refresh = cur_frm.cscript.inspection_type; frappe.ui.form.on("Quality Inspection", { + refresh: function(frm) { + // Ignore cancellation of reference doctype on cancel all. + frm.ignore_doctypes_on_cancel_all = [frm.doc.reference_type]; + }, + item_code: function(frm) { if (frm.doc.item_code) { return frm.call({ From ba5b603a0bb73bf2a03e5efd0c61286e58114067 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 24 Dec 2020 22:44:31 +0530 Subject: [PATCH 221/449] fix: multiple pricing rule with margin type not working --- erpnext/accounts/doctype/pricing_rule/pricing_rule.py | 6 +++++- erpnext/accounts/doctype/pricing_rule/utils.py | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index 55a5b0e513..05652642eb 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -345,9 +345,13 @@ def apply_price_discount_rule(pricing_rule, item_details, args): if ((pricing_rule.margin_type in ['Amount', 'Percentage'] and pricing_rule.currency == args.currency) or (pricing_rule.margin_type == 'Percentage')): item_details.margin_type = pricing_rule.margin_type - item_details.margin_rate_or_amount = pricing_rule.margin_rate_or_amount item_details.has_margin = True + if pricing_rule.apply_multiple_pricing_rules and item_details.margin_rate_or_amount is not None: + item_details.margin_rate_or_amount += pricing_rule.margin_rate_or_amount + else: + item_details.margin_rate_or_amount = pricing_rule.margin_rate_or_amount + if pricing_rule.rate_or_discount == 'Rate': pricing_rule_rate = 0.0 if pricing_rule.currency == args.currency: diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index 2c7cd14451..fb1fbe484e 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -164,7 +164,15 @@ def _get_tree_conditions(args, parenttype, table, allow_blank=True): frappe.throw(_("Invalid {0}").format(args.get(field))) parent_groups = frappe.db.sql_list("""select name from `tab%s` - where lft<=%s and rgt>=%s""" % (parenttype, '%s', '%s'), (lft, rgt)) + where lft>=%s and rgt<=%s""" % (parenttype, '%s', '%s'), (lft, rgt)) + + if parenttype in ["Customer Group", "Item Group", "Territory"]: + parent_field = "parent_{0}".format(frappe.scrub(parenttype)) + root_name = frappe.db.get_list(parenttype, + {"is_group": 1, parent_field: ("is", "not set")}, "name", as_list=1) + + if root_name and root_name[0][0]: + parent_groups.append(root_name[0][0]) if parent_groups: if allow_blank: parent_groups.append('') From adc369f7269096dd907d9ca8edbe5cc1fb1aa257 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 25 Dec 2020 13:23:12 +0530 Subject: [PATCH 222/449] fix: partial serial no return issue --- .../controllers/sales_and_purchase_return.py | 51 +++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index 8f65c31f3d..7b03705f7f 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -205,20 +205,22 @@ def get_already_returned_items(doc): def get_returned_qty_map_for_row(row_name, doctype): child_doctype = doctype + " Item" - reference_field = frappe.scrub(child_doctype) if doctype == "Purchase Receipt" else "dn_detail" + reference_field = "dn_detail" if doctype == "Delivery Note" else frappe.scrub(child_doctype) fields = [ "sum(abs(`tab{0}`.qty)) as qty".format(child_doctype), "sum(abs(`tab{0}`.stock_qty)) as stock_qty".format(child_doctype) ] - if doctype == "Purchase Receipt": + if doctype in ("Purchase Receipt", "Purchase Invoice"): fields += [ "sum(abs(`tab{0}`.rejected_qty)) as rejected_qty".format(child_doctype), - "sum(abs(`tab{0}`.received_qty)) as received_qty".format(child_doctype), - "sum(abs(`tab{0}`.received_stock_qty)) as received_stock_qty".format(child_doctype) + "sum(abs(`tab{0}`.received_qty)) as received_qty".format(child_doctype) ] + if doctype == "Purchase Receipt": + fields += ["sum(abs(`tab{0}`.received_stock_qty)) as received_stock_qty".format(child_doctype)] + data = frappe.db.get_list(doctype, fields = fields, filters = [ @@ -231,6 +233,7 @@ def get_returned_qty_map_for_row(row_name, doctype): def make_return_doc(doctype, source_name, target_doc=None): from frappe.model.mapper import get_mapped_doc + from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos company = frappe.db.get_value("Delivery Note", source_name, "company") default_warehouse_for_sales_return = frappe.db.get_value("Company", company, "default_warehouse_for_sales_return") @@ -290,6 +293,12 @@ def make_return_doc(doctype, source_name, target_doc=None): def update_item(source_doc, target_doc, source_parent): target_doc.qty = -1 * source_doc.qty + if source_doc.serial_no: + returned_serial_nos = get_returned_serial_nos(source_doc, source_parent) + serial_nos = list(set(get_serial_nos(source_doc.serial_no)) - set(returned_serial_nos)) + if serial_nos: + target_doc.serial_no = '\n'.join(serial_nos) + if doctype == "Purchase Receipt": returned_qty_map = get_returned_qty_map_for_row(source_doc.name, doctype) target_doc.received_qty = -1 * flt(source_doc.received_qty - (returned_qty_map.get('received_qty') or 0)) @@ -305,10 +314,12 @@ def make_return_doc(doctype, source_name, target_doc=None): target_doc.purchase_receipt_item = source_doc.name elif doctype == "Purchase Invoice": - target_doc.received_qty = -1 * source_doc.received_qty - target_doc.rejected_qty = -1 * source_doc.rejected_qty - target_doc.qty = -1* source_doc.qty - target_doc.stock_qty = -1 * source_doc.stock_qty + returned_qty_map = get_returned_qty_map_for_row(source_doc.name, doctype) + target_doc.received_qty = -1 * flt(source_doc.received_qty - (returned_qty_map.get('received_qty') or 0)) + target_doc.rejected_qty = -1 * flt(source_doc.rejected_qty - (returned_qty_map.get('rejected_qty') or 0)) + target_doc.qty = -1 * flt(source_doc.qty - (returned_qty_map.get('qty') or 0)) + + target_doc.stock_qty = -1 * flt(source_doc.stock_qty - (returned_qty_map.get('stock_qty') or 0)) target_doc.purchase_order = source_doc.purchase_order target_doc.purchase_receipt = source_doc.purchase_receipt target_doc.rejected_warehouse = source_doc.rejected_warehouse @@ -330,6 +341,10 @@ def make_return_doc(doctype, source_name, target_doc=None): if default_warehouse_for_sales_return: target_doc.warehouse = default_warehouse_for_sales_return elif doctype == "Sales Invoice" or doctype == "POS Invoice": + returned_qty_map = get_returned_qty_map_for_row(source_doc.name, doctype) + target_doc.qty = -1 * flt(source_doc.qty - (returned_qty_map.get('qty') or 0)) + target_doc.stock_qty = -1 * flt(source_doc.stock_qty - (returned_qty_map.get('stock_qty') or 0)) + target_doc.sales_order = source_doc.sales_order target_doc.delivery_note = source_doc.delivery_note target_doc.so_detail = source_doc.so_detail @@ -406,4 +421,22 @@ def get_filters(voucher_type, voucher_no, voucher_detail_no, return_against, ite if reference_voucher_detail_no: filters["voucher_detail_no"] = reference_voucher_detail_no - return filters \ No newline at end of file + return filters + +def get_returned_serial_nos(child_doc, parent_doc): + from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos + return_ref_field = frappe.scrub(child_doc.doctype) + if child_doc.doctype == "Delivery Note Item": + return_ref_field = "dn_detail" + + serial_nos = [] + + fields = ["`{0}`.`serial_no`".format("tab" + child_doc.doctype)] + + filters = [[parent_doc.doctype, "return_against", "=", parent_doc.name], [parent_doc.doctype, "is_return", "=", 1], + [child_doc.doctype, return_ref_field, "=", child_doc.name], [parent_doc.doctype, "docstatus", "=", 1]] + + for row in frappe.get_all(parent_doc.doctype, fields = fields, filters=filters): + serial_nos.extend(get_serial_nos(row.serial_no)) + + return serial_nos \ No newline at end of file From 327f03566ac8dec8f311aea0a243549cb163c66a Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 25 Dec 2020 18:11:54 +0530 Subject: [PATCH 223/449] Reposting fixes pre release (#24203) * fix: finished item validation and rate * fix: Check if stock and account balance in sync after reposting * fix: validate stock accounts in journal entry * fix: validate expense against budget --- .../doctype/journal_entry/journal_entry.py | 21 +++- .../journal_entry/test_journal_entry.py | 18 ++- erpnext/accounts/general_ledger.py | 62 ---------- erpnext/accounts/utils.py | 115 ++++++++++++++---- erpnext/controllers/buying_controller.py | 2 +- erpnext/controllers/stock_controller.py | 10 +- .../purchase_receipt/purchase_receipt.py | 2 +- .../repost_item_valuation.py | 35 +++++- .../stock/doctype/stock_entry/stock_entry.py | 9 +- .../doctype/stock_entry/test_stock_entry.py | 78 ++++++------ .../stock_entry_detail.json | 2 +- .../stock_and_account_value_comparison.py | 3 +- 12 files changed, 205 insertions(+), 152 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index cd712738aa..cb90f8036e 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -6,14 +6,18 @@ import frappe, erpnext, json from frappe.utils import cstr, flt, fmt_money, formatdate, getdate, nowdate, cint, get_link_to_form from frappe import msgprint, _, scrub from erpnext.controllers.accounts_controller import AccountsController -from erpnext.accounts.utils import get_balance_on, get_account_currency +from erpnext.accounts.utils import get_balance_on, get_stock_accounts, get_stock_and_account_balance, \ + get_account_currency, check_if_stock_and_account_balance_synced from erpnext.accounts.party import get_party_account from erpnext.hr.doctype.expense_claim.expense_claim import update_reimbursed_amount -from erpnext.accounts.doctype.invoice_discounting.invoice_discounting import get_party_account_based_on_invoice_discounting +from erpnext.accounts.doctype.invoice_discounting.invoice_discounting \ + import get_party_account_based_on_invoice_discounting from erpnext.accounts.deferred_revenue import get_deferred_booking_accounts from six import string_types, iteritems +class StockAccountInvalidTransaction(frappe.ValidationError): pass + class JournalEntry(AccountsController): def __init__(self, *args, **kwargs): super(JournalEntry, self).__init__(*args, **kwargs) @@ -46,6 +50,7 @@ class JournalEntry(AccountsController): self.validate_empty_accounts_table() self.set_account_and_party_balance() self.validate_inter_company_accounts() + self.validate_stock_accounts() if not self.title: self.title = self.get_title() @@ -57,6 +62,8 @@ class JournalEntry(AccountsController): self.update_expense_claim() self.update_inter_company_jv() self.update_invoice_discounting() + check_if_stock_and_account_balance_synced(self.posting_date, + self.company, self.doctype, self.name) def on_cancel(self): from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries @@ -95,6 +102,16 @@ class JournalEntry(AccountsController): if account_currency == previous_account_currency: if self.total_credit != doc.total_debit or self.total_debit != doc.total_credit: frappe.throw(_("Total Credit/ Debit Amount should be same as linked Journal Entry")) + + def validate_stock_accounts(self): + stock_accounts = get_stock_accounts(self.company, self.doctype, self.name) + for account in stock_accounts: + account_bal, stock_bal, warehouse_list = get_stock_and_account_balance(account, + self.posting_date, self.company) + + if account_bal == stock_bal: + frappe.throw(_("Account: {0} can only be updated via Stock Transactions") + .format(account), StockAccountInvalidTransaction) def update_inter_company_jv(self): if self.voucher_type == "Inter Company Journal Entry" and self.inter_company_journal_entry_reference: diff --git a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py index 1d2eacdb80..b56f8e5fe2 100644 --- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py @@ -6,7 +6,7 @@ import unittest, frappe from frappe.utils import flt, nowdate from erpnext.accounts.doctype.account.test_account import get_inventory_account from erpnext.exceptions import InvalidAccountCurrency -from erpnext.accounts.general_ledger import StockAccountInvalidTransaction +from erpnext.accounts.doctype.journal_entry.journal_entry import StockAccountInvalidTransaction class TestJournalEntry(unittest.TestCase): def test_journal_entry_with_against_jv(self): @@ -84,25 +84,31 @@ class TestJournalEntry(unittest.TestCase): company = "_Test Company with perpetual inventory" stock_account = get_inventory_account(company) + from erpnext.accounts.utils import get_stock_and_account_balance + account_bal, stock_bal, warehouse_list = get_stock_and_account_balance(stock_account, nowdate(), company) + diff = flt(account_bal) - flt(stock_bal) + + if not diff: + diff = 100 + jv = frappe.new_doc("Journal Entry") jv.company = company jv.posting_date = nowdate() jv.append("accounts", { "account": stock_account, "cost_center": "Main - TCP1", - "debit_in_account_currency": 100 + "debit_in_account_currency": 0 if diff > 0 else abs(diff), + "credit_in_account_currency": diff if diff > 0 else 0 }) jv.append("accounts", { "account": "Stock Adjustment - TCP1", - "credit_in_account_currency": 100, "cost_center": "Main - TCP1", + "debit_in_account_currency": diff if diff > 0 else 0, + "credit_in_account_currency": 0 if diff > 0 else abs(diff) }) jv.insert() - from erpnext.accounts.utils import get_stock_and_account_balance - account_bal, stock_bal, warehouse_list = get_stock_and_account_balance(stock_account, nowdate(), company) - if account_bal == stock_bal: self.assertRaises(StockAccountInvalidTransaction, jv.submit) frappe.db.rollback() diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index c7f0c8781c..287c79f13f 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -5,15 +5,11 @@ from __future__ import unicode_literals import frappe, erpnext from frappe.utils import flt, cstr, cint, comma_and, today, getdate, formatdate, now from frappe import _ -from erpnext.accounts.utils import get_stock_and_account_balance from frappe.model.meta import get_field_precision from erpnext.accounts.doctype.budget.budget import validate_expense_against_budget from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions - class ClosedAccountingPeriod(frappe.ValidationError): pass -class StockAccountInvalidTransaction(frappe.ValidationError): pass -class StockValueAndAccountBalanceOutOfSync(frappe.ValidationError): pass def make_gl_entries(gl_map, cancel=False, adv_adj=False, merge_entries=True, update_outstanding='Yes', from_repost=False): if gl_map: @@ -131,10 +127,6 @@ def save_entries(gl_map, adv_adj, update_outstanding, from_repost=False): for entry in gl_map: make_entry(entry, adv_adj, update_outstanding, from_repost) - if not from_repost: - validate_account_for_perpetual_inventory(gl_map) - - def make_entry(args, adv_adj, update_outstanding, from_repost=False): gle = frappe.new_doc("GL Entry") gle.update(args) @@ -144,63 +136,9 @@ def make_entry(args, adv_adj, update_outstanding, from_repost=False): gle.run_method("on_update_with_args", adv_adj, update_outstanding, from_repost) gle.submit() - # check against budget if not from_repost: validate_expense_against_budget(args) -def validate_account_for_perpetual_inventory(gl_map): - if cint(erpnext.is_perpetual_inventory_enabled(gl_map[0].company)): - account_list = [gl_entries.account for gl_entries in gl_map] - - aii_accounts = [d.name for d in frappe.get_all("Account", - filters={'account_type': 'Stock', 'is_group': 0, 'company': gl_map[0].company})] - - for account in account_list: - if account not in aii_accounts: - continue - - # Always use current date to get stock and account balance as there can future entries for - # other items - account_bal, stock_bal, warehouse_list = get_stock_and_account_balance(account, - gl_map[0].posting_date, gl_map[0].company) - - if gl_map[0].voucher_type=="Journal Entry": - # In case of Journal Entry, there are no corresponding SL entries, - # hence deducting currency amount - account_bal -= flt(gl_map[0].debit) - flt(gl_map[0].credit) - if account_bal == stock_bal: - frappe.throw(_("Account: {0} can only be updated via Stock Transactions") - .format(account), StockAccountInvalidTransaction) - - elif abs(account_bal - stock_bal) > 0.1: - precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"), - currency=frappe.get_cached_value('Company', gl_map[0].company, "default_currency")) - - diff = flt(stock_bal - account_bal, precision) - error_reason = _("Stock Value ({0}) and Account Balance ({1}) are out of sync for account {2} and it's linked warehouses on {3}.").format( - stock_bal, account_bal, frappe.bold(account), gl_map[0].posting_date) - error_resolution = _("Please create adjustment Journal Entry for amount {0} ").format(frappe.bold(diff)) - stock_adjustment_account = frappe.db.get_value("Company",gl_map[0].company,"stock_adjustment_account") - - db_or_cr_warehouse_account =('credit_in_account_currency' if diff < 0 else 'debit_in_account_currency') - db_or_cr_stock_adjustment_account = ('debit_in_account_currency' if diff < 0 else 'credit_in_account_currency') - - journal_entry_args = { - 'accounts':[ - {'account': account, db_or_cr_warehouse_account : abs(diff)}, - {'account': stock_adjustment_account, db_or_cr_stock_adjustment_account : abs(diff)} - ] - } - - frappe.msgprint(msg="""{0}

{1}

""".format(error_reason, error_resolution), - raise_exception=StockValueAndAccountBalanceOutOfSync, - title=_('Values Out Of Sync'), - primary_action={ - 'label': _('Make Journal Entry'), - 'client_action': 'erpnext.route_to_adjustment_jv', - 'args': journal_entry_args - }) - def validate_cwip_accounts(gl_map): cwip_enabled = any([cint(ac.enable_cwip_accounting) for ac in frappe.db.get_all("Asset Category","enable_cwip_accounting")]) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 540ac84182..67c7fd2d22 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -12,11 +12,12 @@ from frappe.utils import formatdate, get_number_format_info from six import iteritems # imported to enable erpnext.accounts.utils.get_account_currency from erpnext.accounts.doctype.account.account import get_account_currency +from frappe.model.meta import get_field_precision from erpnext.stock.utils import get_stock_value_on from erpnext.stock import get_warehouse_account_map - +class StockValueAndAccountBalanceOutOfSync(frappe.ValidationError): pass class FiscalYearError(frappe.ValidationError): pass @frappe.whitelist() @@ -585,24 +586,6 @@ def fix_total_debit_credit(): (dr_or_cr, dr_or_cr, '%s', '%s', '%s', dr_or_cr), (d.diff, d.voucher_type, d.voucher_no)) -def get_stock_and_account_balance(account=None, posting_date=None, company=None): - if not posting_date: posting_date = nowdate() - - warehouse_account = get_warehouse_account_map(company) - - account_balance = get_balance_on(account, posting_date, in_account_currency=False, ignore_account_permission=True) - - related_warehouses = [wh for wh, wh_details in warehouse_account.items() - if wh_details.account == account and not wh_details.is_group] - - total_stock_value = 0.0 - for warehouse in related_warehouses: - value = get_stock_value_on(warehouse, posting_date) - total_stock_value += value - - precision = frappe.get_precision("Journal Entry Account", "debit_in_account_currency") - return flt(account_balance, precision), flt(total_stock_value, precision), related_warehouses - def get_currency_precision(): precision = cint(frappe.db.get_default("currency_precision")) if not precision: @@ -903,12 +886,6 @@ def get_coa(doctype, parent, is_root, chart=None): return accounts -def get_stock_accounts(company): - return frappe.get_all("Account", filters = { - "account_type": "Stock", - "company": company - }) - def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for_items=None, warehouse_account=None, company=None): def _delete_gl_entries(voucher_type, voucher_no): @@ -983,4 +960,90 @@ def compare_existing_and_expected_gle(existing_gle, expected_gle): if not account_existed: matched = False break - return matched \ No newline at end of file + return matched + +def check_if_stock_and_account_balance_synced(posting_date, company, voucher_type=None, voucher_no=None): + if not cint(erpnext.is_perpetual_inventory_enabled(company)): + return + + accounts = get_stock_accounts(company, voucher_type, voucher_no) + stock_adjustment_account = frappe.db.get_value("Company", company, "stock_adjustment_account") + + for account in accounts: + account_bal, stock_bal, warehouse_list = get_stock_and_account_balance(account, + posting_date, company) + + if abs(account_bal - stock_bal) > 0.1: + precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"), + currency=frappe.get_cached_value('Company', company, "default_currency")) + + diff = flt(stock_bal - account_bal, precision) + + error_reason = _("Stock Value ({0}) and Account Balance ({1}) are out of sync for account {2} and it's linked warehouses as on {3}.").format( + stock_bal, account_bal, frappe.bold(account), posting_date) + error_resolution = _("Please create an adjustment Journal Entry for amount {0} on {1}")\ + .format(frappe.bold(diff), frappe.bold(posting_date)) + + frappe.msgprint( + msg="""{0}

{1}

""".format(error_reason, error_resolution), + raise_exception=StockValueAndAccountBalanceOutOfSync, + title=_('Values Out Of Sync'), + primary_action={ + 'label': _('Make Journal Entry'), + 'client_action': 'erpnext.route_to_adjustment_jv', + 'args': get_journal_entry(account, stock_adjustment_account, diff) + }) + +def get_stock_accounts(company, voucher_type=None, voucher_no=None): + stock_accounts = [d.name for d in frappe.db.get_all("Account", { + "account_type": "Stock", + "company": company, + "is_group": 0 + })] + if voucher_type and voucher_no: + if voucher_type == "Journal Entry": + stock_accounts = [d.account for d in frappe.db.get_all("Journal Entry Account", { + "parent": voucher_no, + "account": ["in", stock_accounts] + }, "account")] + + else: + stock_accounts = [d.account for d in frappe.db.get_all("GL Entry", { + "voucher_type": voucher_type, + "voucher_no": voucher_no, + "account": ["in", stock_accounts] + }, "account")] + + return stock_accounts + +def get_stock_and_account_balance(account=None, posting_date=None, company=None): + if not posting_date: posting_date = nowdate() + + warehouse_account = get_warehouse_account_map(company) + + account_balance = get_balance_on(account, posting_date, in_account_currency=False, ignore_account_permission=True) + + related_warehouses = [wh for wh, wh_details in warehouse_account.items() + if wh_details.account == account and not wh_details.is_group] + + total_stock_value = 0.0 + for warehouse in related_warehouses: + value = get_stock_value_on(warehouse, posting_date) + total_stock_value += value + + precision = frappe.get_precision("Journal Entry Account", "debit_in_account_currency") + return flt(account_balance, precision), flt(total_stock_value, precision), related_warehouses + +def get_journal_entry(account, stock_adjustment_account, amount): + db_or_cr_warehouse_account =('credit_in_account_currency' if amount < 0 else 'debit_in_account_currency') + db_or_cr_stock_adjustment_account = ('debit_in_account_currency' if amount < 0 else 'credit_in_account_currency') + + return { + 'accounts':[{ + 'account': account, + db_or_cr_warehouse_account: abs(amount) + }, { + 'account': stock_adjustment_account, + db_or_cr_stock_adjustment_account : abs(amount) + }] + } diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index dc61870df3..6edc020701 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -241,7 +241,7 @@ class BuyingController(StockController): if rate > 0: d.rate = rate - d.amount = flt(d.consumed_qty) * flt(d.rate) + d.amount = flt(flt(d.consumed_qty) * flt(d.rate), d.precision("amount")) supplied_items_cost += flt(d.amount) return supplied_items_cost diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 51c063c2c0..439997616c 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -6,7 +6,7 @@ import frappe, erpnext from frappe.utils import cint, flt, cstr, get_link_to_form, today, getdate from frappe import _ import frappe.defaults -from erpnext.accounts.utils import get_fiscal_year +from erpnext.accounts.utils import get_fiscal_year, check_if_stock_and_account_balance_synced from erpnext.accounts.general_ledger import make_gl_entries, make_reverse_gl_entries, process_gl_map from erpnext.controllers.accounts_controller import AccountsController from erpnext.stock.stock_ledger import get_valuation_rate @@ -402,6 +402,14 @@ class StockController(AccountsController): if check_if_future_sle_exists(args): create_repost_item_valuation_entry(args) + elif not is_reposting_pending(): + check_if_stock_and_account_balance_synced(self.posting_date, + self.company, self.doctype, self.name) + +def is_reposting_pending(): + return frappe.db.exists("Repost Item Valuation", + {'docstatus': 1, 'status': ['in', ['Queued','In Progress']]}) + def check_if_future_sle_exists(args): sl_entries = frappe.db.get_all("Stock Ledger Entry", diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 226064bae7..159a6085ff 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -408,7 +408,7 @@ class PurchaseReceipt(BuyingController): if warehouse_with_no_account: frappe.msgprint(_("No accounting entries for the following warehouses") + ": \n" + "\n".join(warehouse_with_no_account)) - + return process_gl_map(gl_entries) def get_asset_gl_entry(self, gl_entries): diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py index a942f2edda..ba2c2c6f44 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -5,11 +5,11 @@ from __future__ import unicode_literals import frappe, erpnext from frappe.model.document import Document -from frappe.utils import cint +from frappe.utils import cint, get_link_to_form from erpnext.stock.stock_ledger import repost_future_sle -from erpnext.accounts.utils import update_gl_entries_after - - +from erpnext.accounts.utils import update_gl_entries_after, check_if_stock_and_account_balance_synced +from frappe.utils.user import get_users_with_role +from frappe import _ class RepostItemValuation(Document): def validate(self): self.set_status() @@ -51,12 +51,20 @@ def repost(doc): repost_sl_entries(doc) repost_gl_entries(doc) + check_if_stock_and_account_balance_synced(doc.posting_date, doc.company) + doc.set_status('Completed') except Exception: frappe.db.rollback() traceback = frappe.get_traceback() frappe.log_error(traceback) - frappe.db.set_value(doc.doctype, doc.name, 'error_log', traceback) + + message = frappe.message_log.pop() + if traceback: + message += "
" + "Traceback:
" + traceback + frappe.db.set_value(doc.doctype, doc.name, 'error_log', message) + + notify_error_to_stock_managers(doc) doc.set_status('Failed') raise finally: @@ -86,4 +94,19 @@ def repost_gl_entries(doc): warehouses = [doc.warehouse] update_gl_entries_after(doc.posting_date, doc.posting_time, - warehouses, items, company=doc.company) \ No newline at end of file + warehouses, items, company=doc.company) + +def notify_error_to_stock_managers(doc, traceback): + recipients = get_users_with_role("Stock Manager") + if not recipients: + get_users_with_role("System Manager") + + subject = _("Error while reposting item valuation") + message = (_("Hi,") + "
" + + _("An error has been appeared while reposting item valuation via {0}") + .format(get_link_to_form(doc.doctype, doc.name)) + "
" + + _("Please check the error message and take necessary actions to fix the error and then restart the reposting again.") + ) + frappe.sendmail(recipients=recipients, subject=subject, message=message) + + diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index afdb54ceaa..60758b4f8a 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -442,6 +442,7 @@ class StockEntry(StockController): """ # Set rate for outgoing items outgoing_items_cost = self.set_rate_for_outgoing_items(reset_outgoing_rate) + finished_item_qty = sum([d.transfer_qty for d in self.items if d.is_finished_item]) # Set basic rate for incoming items for d in self.get('items'): @@ -451,7 +452,7 @@ class StockEntry(StockController): d.basic_rate = 0.0 elif d.is_finished_item: if self.purpose == "Manufacture": - d.basic_rate = self.get_basic_rate_for_manufactured_item(d.transfer_qty, outgoing_items_cost) + d.basic_rate = self.get_basic_rate_for_manufactured_item(finished_item_qty, outgoing_items_cost) elif self.purpose == "Repack": d.basic_rate = self.get_basic_rate_for_repacked_items(d.transfer_qty, outgoing_items_cost) @@ -666,7 +667,7 @@ class StockEntry(StockController): production_item, wo_qty = frappe.db.get_value("Work Order", self.work_order, ["production_item", "qty"]) - number_of_finished_items = 0 + finished_items = [] for d in self.get('items'): if d.is_finished_item: if d.item_code != production_item: @@ -675,9 +676,9 @@ class StockEntry(StockController): elif flt(d.transfer_qty) > flt(self.fg_completed_qty): frappe.throw(_("Quantity in row {0} ({1}) must be same as manufactured quantity {2}"). \ format(d.idx, d.transfer_qty, self.fg_completed_qty)) - number_of_finished_items += 1 + finished_items.append(d.item_code) - if number_of_finished_items > 1: + if len(set(finished_items)) > 1: frappe.throw(_("Multiple items cannot be marked as finished item")) if self.purpose == "Manufacture": diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index 1a641855aa..123f0c8647 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -179,22 +179,20 @@ class TestStockEntry(unittest.TestCase): def test_material_transfer_gl_entry(self): company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company') - create_stock_reconciliation(qty=100, rate=100) - mtn = make_stock_entry(item_code="_Test Item", source="Stores - TCP1", - target="Finished Goods - TCP1", qty=45) + target="Finished Goods - TCP1", qty=45, company=company) self.check_stock_ledger_entries("Stock Entry", mtn.name, [["_Test Item", "Stores - TCP1", -45.0], ["_Test Item", "Finished Goods - TCP1", 45.0]]) - stock_in_hand_account = get_inventory_account(mtn.company, mtn.get("items")[0].s_warehouse) + source_warehouse_account = get_inventory_account(mtn.company, mtn.get("items")[0].s_warehouse) - fixed_asset_account = get_inventory_account(mtn.company, mtn.get("items")[0].t_warehouse) + target_warehouse_account = get_inventory_account(mtn.company, mtn.get("items")[0].t_warehouse) - if stock_in_hand_account == fixed_asset_account: + if source_warehouse_account == target_warehouse_account: # no gl entry as both source and target warehouse has linked to same account. self.assertFalse(frappe.db.sql("""select * from `tabGL Entry` - where voucher_type='Stock Entry' and voucher_no=%s""", mtn.name)) + where voucher_type='Stock Entry' and voucher_no=%s""", mtn.name, as_dict=1)) else: stock_value_diff = abs(frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Stock Entry", @@ -202,8 +200,8 @@ class TestStockEntry(unittest.TestCase): self.check_gl_entries("Stock Entry", mtn.name, sorted([ - [stock_in_hand_account, 0.0, stock_value_diff], - [fixed_asset_account, stock_value_diff, 0.0], + [source_warehouse_account, 0.0, stock_value_diff], + [target_warehouse_account, stock_value_diff, 0.0], ]) ) @@ -754,37 +752,37 @@ class TestStockEntry(unittest.TestCase): def test_total_basic_amount_zero(self): se = frappe.get_doc({"doctype":"Stock Entry", - "purpose":"Material Receipt", - "stock_entry_type":"Material Receipt", - "posting_date": nowdate(), - "company":"_Test Company with perpetual inventory", - "items":[ - { - "item_code":"_Test Item", - "description":"_Test Item", - "qty": 1, - "basic_rate": 0, - "uom":"Nos", - "t_warehouse": "Stores - TCP1", - "allow_zero_valuation_rate": 1, - "cost_center": "Main - TCP1" - }, - { - "item_code":"_Test Item", - "description":"_Test Item", - "qty": 2, - "basic_rate": 0, - "uom":"Nos", - "t_warehouse": "Stores - TCP1", - "allow_zero_valuation_rate": 1, - "cost_center": "Main - TCP1" - }, - ], - "additional_costs":[ - {"expense_account":"Miscellaneous Expenses - TCP1", - "amount":100, - "description": "miscellanous"} - ] + "purpose":"Material Receipt", + "stock_entry_type":"Material Receipt", + "posting_date": nowdate(), + "company":"_Test Company with perpetual inventory", + "items":[ + { + "item_code":"_Test Item", + "description":"_Test Item", + "qty": 1, + "basic_rate": 0, + "uom":"Nos", + "t_warehouse": "Stores - TCP1", + "allow_zero_valuation_rate": 1, + "cost_center": "Main - TCP1" + }, + { + "item_code":"_Test Item", + "description":"_Test Item", + "qty": 2, + "basic_rate": 0, + "uom":"Nos", + "t_warehouse": "Stores - TCP1", + "allow_zero_valuation_rate": 1, + "cost_center": "Main - TCP1" + }, + ], + "additional_costs":[ + {"expense_account":"Miscellaneous Expenses - TCP1", + "amount":100, + "description": "miscellanous" + }] }) se.insert() se.submit() diff --git a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json index 6fe60298ee..b78ae6d79b 100644 --- a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json +++ b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json @@ -526,7 +526,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2020-09-23 17:55:03.384138", + "modified": "2020-12-23 17:55:03.384138", "modified_by": "Administrator", "module": "Stock", "name": "Stock Entry Detail", diff --git a/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py b/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py index 1af68dd7f2..14d543b174 100644 --- a/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py +++ b/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py @@ -57,8 +57,7 @@ def get_gl_data(report_filters, filters): if report_filters.account: stock_accounts = [report_filters.account] else: - stock_accounts = [k.name - for k in get_stock_accounts(report_filters.company)] + stock_accounts = get_stock_accounts(report_filters.company) filters.update({ "account": ("in", stock_accounts) From 0917c1ec7c21dcb31d88c1befd5199c1dc54b0a8 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Fri, 25 Dec 2020 18:13:12 +0530 Subject: [PATCH 224/449] fix: travis failing (#24211) --- erpnext/controllers/sales_and_purchase_return.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index 7b03705f7f..79792262c0 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -204,6 +204,8 @@ def get_already_returned_items(doc): return items def get_returned_qty_map_for_row(row_name, doctype): + if doctype == "POS Invoice": return {} + child_doctype = doctype + " Item" reference_field = "dn_detail" if doctype == "Delivery Note" else frappe.scrub(child_doctype) From 49d7499990ab881fcca6a2cde029443bda819abb Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Fri, 25 Dec 2020 18:15:35 +0530 Subject: [PATCH 225/449] fix: added shipment link in delivery note dashboard (#24210) * fix: added shipment link in delivery note dashboard * Update shipment.py --- .../stock/doctype/delivery_note/delivery_note.js | 1 + .../stock/doctype/delivery_note/delivery_note.py | 14 +++++++++++--- .../delivery_note/delivery_note_dashboard.py | 2 +- erpnext/stock/doctype/shipment/shipment.json | 5 +++-- erpnext/stock/doctype/shipment/shipment.py | 7 ++++++- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js index 03921c554e..5f2658c102 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.js +++ b/erpnext/stock/doctype/delivery_note/delivery_note.js @@ -15,6 +15,7 @@ frappe.ui.form.on("Delivery Note", { 'Installation Note': 'Installation Note', 'Sales Invoice': 'Invoice', 'Stock Entry': 'Return', + 'Shipment': 'Shipment' }, frm.set_indicator_formatter('item_code', function(doc) { diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index 1a6a555092..a30cadf0a0 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -598,6 +598,9 @@ def make_shipment(source_name, target_doc=None): pickup_contact_display += '
' + user.mobile_no target.pickup_contact = pickup_contact_display + # As we are using session user details in the pickup_contact then pickup_contact_person will be session user + target.pickup_contact_person = frappe.session.user + contact = frappe.db.get_value("Contact", source.contact_person, ['email_id', 'phone', 'mobile_no'], as_dict=1) delivery_contact_display = '{}'.format(source.contact_display) if contact: @@ -609,6 +612,13 @@ def make_shipment(source_name, target_doc=None): delivery_contact_display += '
' + contact.mobile_no target.delivery_contact = delivery_contact_display + if source.shipping_address_name: + target.delivery_address_name = source.shipping_address_name + target.delivery_address = source.shipping_address + elif source.customer_address: + target.delivery_address_name = source.customer_address + target.delivery_address = source.address_display + doclist = get_mapped_doc("Delivery Note", source_name, { "Delivery Note": { "doctype": "Shipment", @@ -617,9 +627,7 @@ def make_shipment(source_name, target_doc=None): "company": "pickup_company", "company_address": "pickup_address_name", "company_address_display": "pickup_address", - "address_display": "delivery_address", "customer": "delivery_customer", - "shipping_address_name": "delivery_address_name", "contact_person": "delivery_contact_name", "contact_email": "delivery_contact_email" }, @@ -637,7 +645,7 @@ def make_shipment(source_name, target_doc=None): } } }, target_doc, postprocess) - + return doclist @frappe.whitelist() diff --git a/erpnext/stock/doctype/delivery_note/delivery_note_dashboard.py b/erpnext/stock/doctype/delivery_note/delivery_note_dashboard.py index beeb9ebb05..47684d5c6e 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note_dashboard.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note_dashboard.py @@ -19,7 +19,7 @@ def get_data(): }, { 'label': _('Reference'), - 'items': ['Sales Order', 'Quality Inspection'] + 'items': ['Sales Order', 'Shipment', 'Quality Inspection'] }, { 'label': _('Returns'), diff --git a/erpnext/stock/doctype/shipment/shipment.json b/erpnext/stock/doctype/shipment/shipment.json index 37a9cc6c02..76c331c5c2 100644 --- a/erpnext/stock/doctype/shipment/shipment.json +++ b/erpnext/stock/doctype/shipment/shipment.json @@ -345,7 +345,8 @@ "label": "Status", "no_copy": 1, "options": "Draft\nSubmitted\nBooked\nCancelled\nCompleted", - "print_hide": 1 + "print_hide": 1, + "read_only": 1 }, { "fieldname": "tracking_url", @@ -430,7 +431,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-12-02 15:43:44.607039", + "modified": "2020-12-25 15:02:34.891976", "modified_by": "Administrator", "module": "Stock", "name": "Shipment", diff --git a/erpnext/stock/doctype/shipment/shipment.py b/erpnext/stock/doctype/shipment/shipment.py index de0c243b05..4697a7b323 100644 --- a/erpnext/stock/doctype/shipment/shipment.py +++ b/erpnext/stock/doctype/shipment/shipment.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe from frappe import _ -from frappe.utils import flt +from frappe.utils import flt, get_time from frappe.model.document import Document from erpnext.accounts.party import get_party_shipping_address from frappe.contacts.doctype.contact.contact import get_default_contact @@ -13,6 +13,7 @@ from frappe.contacts.doctype.contact.contact import get_default_contact class Shipment(Document): def validate(self): self.validate_weight() + self.validate_pickup_time() self.set_value_of_goods() if self.docstatus == 0: self.status = 'Draft' @@ -32,6 +33,10 @@ class Shipment(Document): if flt(parcel.weight) <= 0: frappe.throw(_('Parcel weight cannot be 0')) + def validate_pickup_time(self): + if self.pickup_from and self.pickup_to and get_time(self.pickup_to) < get_time(self.pickup_from): + frappe.throw(_("Pickup To time should be greater than Pickup From time")) + def set_value_of_goods(self): value_of_goods = 0 for entry in self.get("shipment_delivery_note"): From f8c1cb5dc3017a34c7a056d893c79b91afcfadf0 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 25 Dec 2020 20:52:59 +0530 Subject: [PATCH 226/449] fix: Removed permissions from UAE VAT Settings --- .../uae_vat_settings/uae_vat_settings.json | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/erpnext/regional/doctype/uae_vat_settings/uae_vat_settings.json b/erpnext/regional/doctype/uae_vat_settings/uae_vat_settings.json index ce2c1d4e14..1ff5680bfe 100644 --- a/erpnext/regional/doctype/uae_vat_settings/uae_vat_settings.json +++ b/erpnext/regional/doctype/uae_vat_settings/uae_vat_settings.json @@ -29,25 +29,12 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2020-09-30 20:08:18.764798", + "modified": "2020-12-25 20:20:22.342426", "modified_by": "Administrator", "module": "Regional", "name": "UAE VAT Settings", "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "System Manager", - "share": 1, - "write": 1 - } - ], + "permissions": [], "quick_entry": 1, "sort_field": "modified", "sort_order": "DESC", From 17e96901db5755b1c349796ff9369b69e279a1eb Mon Sep 17 00:00:00 2001 From: Saqib Date: Fri, 25 Dec 2020 10:26:43 +0530 Subject: [PATCH 227/449] feat: GST E Invoicing (#23455) * feat: init e-invoice settings * feat: read public key file * feat: rsa encryption with public key * feat: save token and sek from auth request * chore: handle error response * feat: AES decryption of SEK with appkey * feat: decrypt json data with SEK * feat: make e invoice from erpnext sales invoice * feat: generate IRN * feat: decode signed json and QR code * chore: validations * feat: cancel IRN * feat: complete e-invoice schema * chore: move e-invoice settings to regional * chore: split einvoice settings and operations * chore: rename schema to template & js cleanup * feat: make IRN field on regional setup * feat: Generate & Cancel IRN from Sales Invoice * chore: minor fixes * fix: item discount * chore: show irn cancelled check after cancellation * fix: hide cancel irn dialog on error * fix: public key is required on validate * fix: cannot find attached key file * fix: validation if e invoicing is disabled * fix: do not show generate irn for invalid supply type * fix: update irn_cancelled after cancelling irn * chore: show irn field for proper gst_category * feat: e-way bill details in e-invoice * fix: save e-way bill no on irn generation * chore: no copy on e invoice custom fields * feat: cancel e-way bill before cancelling IRN * feat: manual download / upload json * chore: group e-invoicing actions * fix: fn name * chore: save signed invoice and qrcode after uplaoding irn * fix: fetch token if not valid * chore: move einvoicing stuff to seperate folder * feat: QRCode Image and E-Invoice Print Format * fix: bug * fix: invalid syntax * chore: code cleanup * chore: clean up e invoice actions * fix: download & upload e-invoice * fix: print format * fix: validations * fix: add permissions on regional setup * feat: add patch * fix: validate document name * fix: return date * fix: credit note einvoice * fix: validations * fix: error logging * fix: e_invoice module not found * fix: add missing package * fix: rename e_invoice_utils.py * fix: einvoice field validation * fix: patch * fix: invoice totals calculation * fix: other charges calculation * chore: improve document name validation message * fix: qr code image string * feat: initialize GSP connector * chore: remove unwanted fields * fix: qr code generation * feat: fetch and cache GSTIN details * feat: generate & cancel IRN * feat: cancel eway bill * chore: remove unwanted fuctions * chore: clean up einvoice actions * fix: attach qrcode on irn generation * fix: generate & cancel IRN * fix: show/hide eway bill fields * fix: valiations * feat: generate eway bill from IRN * chore: remove unwanted imports * chore: error logging * feat: header & footer in GST E Invoice * chore: remove test pincode * fix: invalid syntax * feat: cess non advolem on einvoice item * chore: remove fetch token from e invocie settings * fix: imports * fix: error handling * feat: update timeline on einvoice actions * fix: qrcode image size * fix: exclude intra company transactions * fix: eway bill test * fix: ewaybill mandatory conditions * chore: add tests * fix: returning condition * feat: log e-invocing requests * chore: add ack date and ack no field for print formats * fix: sider issues * feat: show e-invoice preview before IRN generation * fix: use as_list for error message * fix: minor ux issues * fix: dialog is undefined * fix: error handling * feat: add docs link to e invoice settings * feat: multiple gstins for e invoicing * fix: uncomment test condition * fix: remove test pincode * fix: cannot cancel irn without submitting sales invoice * chore: code cleanup * fix: sider issues * fix: e invoice request log permissions Co-authored-by: Nabin Hait --- .../doctype/sales_invoice/regional/india.js | 2 + .../doctype/sales_invoice/sales_invoice.py | 2 +- .../sales_invoice/test_sales_invoice.py | 269 +++-- .../print_format/gst_e_invoice/__init__.py | 0 .../gst_e_invoice/gst_e_invoice.html | 162 +++ .../gst_e_invoice/gst_e_invoice.json | 24 + erpnext/controllers/accounts_controller.py | 10 + erpnext/hooks.py | 3 +- erpnext/patches.txt | 1 + .../patches/v12_0/setup_einvoice_fields.py | 55 + .../doctype/e_invoice_request_log/__init__.py | 0 .../e_invoice_request_log.js | 8 + .../e_invoice_request_log.json | 103 ++ .../e_invoice_request_log.py | 10 + .../test_e_invoice_request_log.py | 10 + .../doctype/e_invoice_settings/__init__.py | 0 .../e_invoice_settings/e_invoice_settings.js | 11 + .../e_invoice_settings.json | 58 ++ .../e_invoice_settings/e_invoice_settings.py | 14 + .../test_e_invoice_settings.py | 10 + .../doctype/e_invoice_user/__init__.py | 0 .../e_invoice_user/e_invoice_user.json | 48 + .../doctype/e_invoice_user/e_invoice_user.py | 10 + erpnext/regional/india/e_invoice/__init__.py | 0 .../india/e_invoice/einv_item_template.json | 31 + .../india/e_invoice/einv_template.json | 110 ++ .../india/e_invoice/einv_validation.json | 956 ++++++++++++++++++ erpnext/regional/india/e_invoice/einvoice.js | 305 ++++++ erpnext/regional/india/e_invoice/utils.py | 772 ++++++++++++++ erpnext/regional/india/setup.py | 31 +- requirements.txt | 1 + 31 files changed, 2922 insertions(+), 94 deletions(-) create mode 100644 erpnext/accounts/print_format/gst_e_invoice/__init__.py create mode 100644 erpnext/accounts/print_format/gst_e_invoice/gst_e_invoice.html create mode 100644 erpnext/accounts/print_format/gst_e_invoice/gst_e_invoice.json create mode 100644 erpnext/patches/v12_0/setup_einvoice_fields.py create mode 100644 erpnext/regional/doctype/e_invoice_request_log/__init__.py create mode 100644 erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.js create mode 100644 erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.json create mode 100644 erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.py create mode 100644 erpnext/regional/doctype/e_invoice_request_log/test_e_invoice_request_log.py create mode 100644 erpnext/regional/doctype/e_invoice_settings/__init__.py create mode 100644 erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.js create mode 100644 erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.json create mode 100644 erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.py create mode 100644 erpnext/regional/doctype/e_invoice_settings/test_e_invoice_settings.py create mode 100644 erpnext/regional/doctype/e_invoice_user/__init__.py create mode 100644 erpnext/regional/doctype/e_invoice_user/e_invoice_user.json create mode 100644 erpnext/regional/doctype/e_invoice_user/e_invoice_user.py create mode 100644 erpnext/regional/india/e_invoice/__init__.py create mode 100644 erpnext/regional/india/e_invoice/einv_item_template.json create mode 100644 erpnext/regional/india/e_invoice/einv_template.json create mode 100644 erpnext/regional/india/e_invoice/einv_validation.json create mode 100644 erpnext/regional/india/e_invoice/einvoice.js create mode 100644 erpnext/regional/india/e_invoice/utils.py diff --git a/erpnext/accounts/doctype/sales_invoice/regional/india.js b/erpnext/accounts/doctype/sales_invoice/regional/india.js index 6336db16eb..f54bce8aac 100644 --- a/erpnext/accounts/doctype/sales_invoice/regional/india.js +++ b/erpnext/accounts/doctype/sales_invoice/regional/india.js @@ -1,6 +1,8 @@ {% include "erpnext/regional/india/taxes.js" %} +{% include "erpnext/regional/india/e_invoice/einvoice.js" %} erpnext.setup_auto_gst_taxation('Sales Invoice'); +erpnext.setup_einvoice_actions('Sales Invoice') frappe.ui.form.on("Sales Invoice", { setup: function(frm) { diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 50734c865c..40009ac69d 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -232,9 +232,9 @@ class SalesInvoice(SellingController): frappe.throw(_("At least one mode of payment is required for POS invoice.")) def before_cancel(self): + super(SalesInvoice, self).before_cancel() self.update_time_sheet(None) - def on_cancel(self): super(SalesInvoice, self).on_cancel() diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index ceb7907989..3c681eeecf 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -1825,93 +1825,7 @@ class TestSalesInvoice(unittest.TestCase): # check_gl_entries(self, target_doc.name, pi_gl_entries, add_days(nowdate(), -1)) def test_eway_bill_json(self): - if not frappe.db.exists('Address', '_Test Address for Eway bill-Billing'): - address = frappe.get_doc({ - "address_line1": "_Test Address Line 1", - "address_title": "_Test Address for Eway bill", - "address_type": "Billing", - "city": "_Test City", - "state": "Test State", - "country": "India", - "doctype": "Address", - "is_primary_address": 1, - "phone": "+91 0000000000", - "gstin": "27AAECE4835E1ZR", - "gst_state": "Maharashtra", - "gst_state_number": "27", - "pincode": "401108" - }).insert() - - address.append("links", { - "link_doctype": "Company", - "link_name": "_Test Company" - }) - - address.save() - - if not frappe.db.exists('Address', '_Test Customer-Address for Eway bill-Shipping'): - address = frappe.get_doc({ - "address_line1": "_Test Address Line 1", - "address_title": "_Test Customer-Address for Eway bill", - "address_type": "Shipping", - "city": "_Test City", - "state": "Test State", - "country": "India", - "doctype": "Address", - "is_primary_address": 1, - "phone": "+91 0000000000", - "gst_state": "Maharashtra", - "gst_state_number": "27", - "pincode": "410038" - }).insert() - - address.append("links", { - "link_doctype": "Customer", - "link_name": "_Test Customer" - }) - - address.save() - - gst_settings = frappe.get_doc("GST Settings") - - gst_account = frappe.get_all( - "GST Account", - fields=["cgst_account", "sgst_account", "igst_account"], - filters = {"company": "_Test Company"}) - - if not gst_account: - gst_settings.append("gst_accounts", { - "company": "_Test Company", - "cgst_account": "CGST - _TC", - "sgst_account": "SGST - _TC", - "igst_account": "IGST - _TC", - }) - - gst_settings.save() - - si = create_sales_invoice(do_not_save =1, rate = '60000') - - si.distance = 2000 - si.company_address = "_Test Address for Eway bill-Billing" - si.customer_address = "_Test Customer-Address for Eway bill-Shipping" - si.vehicle_no = "KA12KA1234" - si.gst_category = "Registered Regular" - - si.append("taxes", { - "charge_type": "On Net Total", - "account_head": "CGST - _TC", - "cost_center": "Main - _TC", - "description": "CGST @ 9.0", - "rate": 9 - }) - - si.append("taxes", { - "charge_type": "On Net Total", - "account_head": "SGST - _TC", - "cost_center": "Main - _TC", - "description": "SGST @ 9.0", - "rate": 9 - }) + si = make_sales_invoice_for_ewaybill() si.submit() @@ -1927,6 +1841,187 @@ class TestSalesInvoice(unittest.TestCase): self.assertEqual(data['billLists'][0]['sgstValue'], 5400) self.assertEqual(data['billLists'][0]['vehicleNo'], 'KA12KA1234') self.assertEqual(data['billLists'][0]['itemList'][0]['taxableAmount'], 60000) + + def test_einvoice_submission_without_irn(self): + # init + frappe.db.set_value('E Invoice Settings', 'E Invoice Settings', 'enable', 1) + country = frappe.flags.country + frappe.flags.country = 'India' + + si = make_sales_invoice_for_ewaybill() + self.assertRaises(frappe.ValidationError, si.submit) + + si.irn = 'test_irn' + si.submit() + + # reset + frappe.db.set_value('E Invoice Settings', 'E Invoice Settings', 'enable', 0) + frappe.flags.country = country + + def test_einvoice_json(self): + from erpnext.regional.india.e_invoice.utils import make_einvoice + + customer_gstin = '27AACCM7806M1Z3' + customer_gstin_dtls = { + 'LegalName': '_Test Customer', 'TradeName': '_Test Customer', 'AddrLoc': '_Test City', + 'StateCode': '27', 'AddrPncd': '410038', 'AddrBno': '_Test Bldg', + 'AddrBnm': '100', 'AddrFlno': '200', 'AddrSt': '_Test Street' + } + company_gstin = '27AAECE4835E1ZR' + company_gstin_dtls = { + 'LegalName': '_Test Company', 'TradeName': '_Test Company', 'AddrLoc': '_Test City', + 'StateCode': '27', 'AddrPncd': '401108', 'AddrBno': '_Test Bldg', + 'AddrBnm': '100', 'AddrFlno': '200', 'AddrSt': '_Test Street' + } + # set cache gstin details to avoid fetching details which will require connection to GSP servers + frappe.local.gstin_cache = {} + frappe.local.gstin_cache[customer_gstin] = customer_gstin_dtls + frappe.local.gstin_cache[company_gstin] = company_gstin_dtls + + si = make_sales_invoice_for_ewaybill() + si.naming_series = 'INV-2020-.#####' + si.items = [] + si.append("items", { + "item_code": "_Test Item", + "uom": "Nos", + "warehouse": "_Test Warehouse - _TC", + "qty": 2, + "rate": 100, + "income_account": "Sales - _TC", + "expense_account": "Cost of Goods Sold - _TC", + "cost_center": "_Test Cost Center - _TC", + }) + si.append("items", { + "item_code": "_Test Item 2", + "uom": "Nos", + "warehouse": "_Test Warehouse - _TC", + "qty": 4, + "rate": 150, + "income_account": "Sales - _TC", + "expense_account": "Cost of Goods Sold - _TC", + "cost_center": "_Test Cost Center - _TC", + }) + si.save() + + einvoice = make_einvoice(si) + + total_item_ass_value = sum([d['AssAmt'] for d in einvoice['ItemList']]) + total_item_cgst_value = sum([d['CgstAmt'] for d in einvoice['ItemList']]) + total_item_sgst_value = sum([d['SgstAmt'] for d in einvoice['ItemList']]) + total_item_igst_value = sum([d['IgstAmt'] for d in einvoice['ItemList']]) + total_item_value = sum([d['TotItemVal'] for d in einvoice['ItemList']]) + + self.assertEqual(einvoice['Version'], '1.1') + self.assertEqual(einvoice['ValDtls']['AssVal'], total_item_ass_value) + self.assertEqual(einvoice['ValDtls']['CgstVal'], total_item_cgst_value) + self.assertEqual(einvoice['ValDtls']['SgstVal'], total_item_sgst_value) + self.assertEqual(einvoice['ValDtls']['IgstVal'], total_item_igst_value) + self.assertEqual(einvoice['ValDtls']['TotInvVal'], total_item_value) + self.assertTrue(einvoice['EwbDtls']) + +def make_sales_invoice_for_ewaybill(): + if not frappe.db.exists('Address', '_Test Address for Eway bill-Billing'): + address = frappe.get_doc({ + "address_line1": "_Test Address Line 1", + "address_title": "_Test Address for Eway bill", + "address_type": "Billing", + "city": "_Test City", + "state": "Test State", + "country": "India", + "doctype": "Address", + "is_primary_address": 1, + "phone": "+910000000000", + "gstin": "27AAECE4835E1ZR", + "gst_state": "Maharashtra", + "gst_state_number": "27", + "pincode": "401108" + }).insert() + + address.append("links", { + "link_doctype": "Company", + "link_name": "_Test Company" + }) + + address.save() + + if not frappe.db.exists('Address', '_Test Customer-Address for Eway bill-Shipping'): + address = frappe.get_doc({ + "address_line1": "_Test Address Line 1", + "address_title": "_Test Customer-Address for Eway bill", + "address_type": "Shipping", + "city": "_Test City", + "state": "Test State", + "country": "India", + "doctype": "Address", + "is_primary_address": 1, + "phone": "+910000000000", + "gstin": "27AACCM7806M1Z3", + "gst_state": "Maharashtra", + "gst_state_number": "27", + "pincode": "410038" + }).insert() + + address.append("links", { + "link_doctype": "Customer", + "link_name": "_Test Customer" + }) + + address.save() + + if not frappe.db.exists('Supplier', '_Test Transporter'): + frappe.get_doc({ + "doctype": "Supplier", + "supplier_name": "_Test Transporter", + "country": "India", + "supplier_group": "_Test Supplier Group", + "supplier_type": "Company", + "is_transporter": 1 + }).insert() + + gst_settings = frappe.get_doc("GST Settings") + + gst_account = frappe.get_all( + "GST Account", + fields=["cgst_account", "sgst_account", "igst_account"], + filters = {"company": "_Test Company"}) + + if not gst_account: + gst_settings.append("gst_accounts", { + "company": "_Test Company", + "cgst_account": "CGST - _TC", + "sgst_account": "SGST - _TC", + "igst_account": "IGST - _TC", + }) + + gst_settings.save() + + si = create_sales_invoice(do_not_save =1, rate = '60000') + + si.distance = 2000 + si.company_address = "_Test Address for Eway bill-Billing" + si.customer_address = "_Test Customer-Address for Eway bill-Shipping" + si.vehicle_no = "KA12KA1234" + si.gst_category = "Registered Regular" + si.mode_of_transport = 'Road' + si.transporter = '_Test Transporter' + + si.append("taxes", { + "charge_type": "On Net Total", + "account_head": "CGST - _TC", + "cost_center": "Main - _TC", + "description": "CGST @ 9.0", + "rate": 9 + }) + + si.append("taxes", { + "charge_type": "On Net Total", + "account_head": "SGST - _TC", + "cost_center": "Main - _TC", + "description": "SGST @ 9.0", + "rate": 9 + }) + + return si def check_gl_entries(doc, voucher_no, expected_gle, posting_date): gl_entries = frappe.db.sql("""select account, debit, credit, posting_date diff --git a/erpnext/accounts/print_format/gst_e_invoice/__init__.py b/erpnext/accounts/print_format/gst_e_invoice/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/accounts/print_format/gst_e_invoice/gst_e_invoice.html b/erpnext/accounts/print_format/gst_e_invoice/gst_e_invoice.html new file mode 100644 index 0000000000..9827e00b71 --- /dev/null +++ b/erpnext/accounts/print_format/gst_e_invoice/gst_e_invoice.html @@ -0,0 +1,162 @@ +{%- from "templates/print_formats/standard_macros.html" import add_header, render_field, print_value -%} +{%- set einvoice = json.loads(doc.signed_einvoice) -%} + +
+
+ {% if letter_head and not no_letterhead %} +
{{ letter_head }}
+ {% endif %} + +
+ {% if print_settings.repeat_header_footer %} + + {% endif %} +
+
1. Transaction Details
+
+
+
+
{{ einvoice.Irn }}
+
+
+
+
{{ einvoice.AckNo }}
+
+
+
+
{{ frappe.utils.format_datetime(einvoice.AckDt, "dd/MM/yyyy hh:mm:ss") }}
+
+
+
+
{{ einvoice.TranDtls.SupTyp }}
+
+
+
+
{{ einvoice.DocDtls.Typ }}
+
+
+
+
{{ einvoice.DocDtls.No }}
+
+
+
+ +
+
+
+
2. Party Details
+ {%- set seller = einvoice.SellerDtls -%} +
+
Seller
+

{{ seller.Gstin }}

+

{{ seller.LglNm }}

+

{{ seller.Addr1 }}

+ {%- if seller.Addr2 -%}

{{ seller.Addr2 }}

{% endif %} +

{{ seller.Loc }}

+

{{ frappe.db.get_value("Address", doc.company_address, "gst_state") }} - {{ seller.Pin }}

+ + {%- if einvoice.ShipDtls -%} + {%- set shipping = einvoice.ShipDtls -%} +
Shipping
+

{{ shipping.Gstin }}

+

{{ shipping.LglNm }}

+

{{ shipping.Addr1 }}

+ {%- if shipping.Addr2 -%}

{{ shipping.Addr2 }}

{% endif %} +

{{ shipping.Loc }}

+

{{ frappe.db.get_value("Address", doc.shipping_address_name, "gst_state") }} - {{ shipping.Pin }}

+ {% endif %} +
+ {%- set buyer = einvoice.BuyerDtls -%} +
+
Buyer
+

{{ buyer.Gstin }}

+

{{ buyer.LglNm }}

+

{{ buyer.Addr1 }}

+ {%- if buyer.Addr2 -%}

{{ buyer.Addr2 }}

{% endif %} +

{{ buyer.Loc }}

+

{{ frappe.db.get_value("Address", doc.customer_address, "gst_state") }} - {{ buyer.Pin }}

+
+
+
+
3. Item Details
+ + + + + + + + + + + + + + + + + + {% for item in einvoice.ItemList %} + + + + + + + + + + + + + + {% endfor %} + +
Sr. No.ItemHSN CodeQtyUOMRateDiscountTaxable AmountTax RateOther ChargesTotal
{{ item.SlNo }}{{ item.PrdDesc }}{{ item.HsnCd }}{{ item.Qty }}{{ item.Unit }}{{ frappe.utils.fmt_money(item.UnitPrice, None, "INR") }}{{ frappe.utils.fmt_money(item.Discount, None, "INR") }}{{ frappe.utils.fmt_money(item.AssAmt, None, "INR") }}{{ item.GstRt + item.CesRt }} %{{ frappe.utils.fmt_money(0, None, "INR") }}{{ frappe.utils.fmt_money(item.TotItemVal, None, "INR") }}
+
+
+
4. Value Details
+ + + + + + + + + + + + + + + + + {%- set value_details = einvoice.ValDtls -%} + + + + + + + + + + + + + +
Taxable AmountCGSTSGSTIGSTCESSState CESSDiscountOther ChargesRound OffTotal Value
{{ frappe.utils.fmt_money(value_details.AssVal, None, "INR") }}{{ frappe.utils.fmt_money(value_details.CgstVal, None, "INR") }}{{ frappe.utils.fmt_money(value_details.SgstVal, None, "INR") }}{{ frappe.utils.fmt_money(value_details.IgstVal, None, "INR") }}{{ frappe.utils.fmt_money(value_details.CesVal, None, "INR") }}{{ frappe.utils.fmt_money(0, None, "INR") }}{{ frappe.utils.fmt_money(value_details.Discount, None, "INR") }}{{ frappe.utils.fmt_money(0, None, "INR") }}{{ frappe.utils.fmt_money(value_details.RndOffAmt, None, "INR") }}{{ frappe.utils.fmt_money(value_details.TotInvVal, None, "INR") }}
+
+
\ No newline at end of file diff --git a/erpnext/accounts/print_format/gst_e_invoice/gst_e_invoice.json b/erpnext/accounts/print_format/gst_e_invoice/gst_e_invoice.json new file mode 100644 index 0000000000..1001199a09 --- /dev/null +++ b/erpnext/accounts/print_format/gst_e_invoice/gst_e_invoice.json @@ -0,0 +1,24 @@ +{ + "align_labels_right": 1, + "creation": "2020-10-10 18:01:21.032914", + "custom_format": 0, + "default_print_language": "en-US", + "disabled": 1, + "doc_type": "Sales Invoice", + "docstatus": 0, + "doctype": "Print Format", + "font": "Default", + "html": "", + "idx": 0, + "line_breaks": 1, + "modified": "2020-10-23 19:54:40.634936", + "modified_by": "Administrator", + "module": "Accounts", + "name": "GST E-Invoice", + "owner": "Administrator", + "print_format_builder": 0, + "print_format_type": "Jinja", + "raw_printing": 0, + "show_section_headings": 1, + "standard": "Yes" +} \ No newline at end of file diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 32c5d3a3b1..0f1aa23064 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -110,8 +110,14 @@ class AccountsController(TransactionBase): self.set_inter_company_account() validate_regional(self) + + validate_einvoice_fields(self) + if self.doctype != 'Material Request': apply_pricing_rule_on_transaction(self) + + def before_cancel(self): + validate_einvoice_fields(self) def validate_deferred_start_and_end_date(self): for d in self.items: @@ -1518,3 +1524,7 @@ def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name, chil @erpnext.allow_regional def validate_regional(doc): pass + +@erpnext.allow_regional +def validate_einvoice_fields(doc): + pass diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 1e3bb6a5cf..a2d9d861bb 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -397,7 +397,8 @@ regional_overrides = { 'erpnext.accounts.party.get_regional_address_details': 'erpnext.regional.india.utils.get_regional_address_details', 'erpnext.hr.utils.calculate_annual_eligible_hra_exemption': 'erpnext.regional.india.utils.calculate_annual_eligible_hra_exemption', 'erpnext.hr.utils.calculate_hra_exemption_for_period': 'erpnext.regional.india.utils.calculate_hra_exemption_for_period', - 'erpnext.accounts.doctype.purchase_invoice.purchase_invoice.make_regional_gl_entries': 'erpnext.regional.india.utils.make_regional_gl_entries' + 'erpnext.accounts.doctype.purchase_invoice.purchase_invoice.make_regional_gl_entries': 'erpnext.regional.india.utils.make_regional_gl_entries', + 'erpnext.controllers.accounts_controller.validate_einvoice_fields': 'erpnext.regional.india.e_invoice.utils.validate_einvoice_fields' }, 'United Arab Emirates': { 'erpnext.controllers.taxes_and_totals.update_itemised_tax_data': 'erpnext.regional.united_arab_emirates.utils.update_itemised_tax_data', diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 86ac613ae5..5b37b38e68 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -733,6 +733,7 @@ erpnext.patches.v13_0.set_youtube_video_id erpnext.patches.v13_0.print_uom_after_quantity_patch erpnext.patches.v13_0.set_payment_channel_in_payment_gateway_account erpnext.patches.v13_0.create_healthcare_custom_fields_in_stock_entry_detail +erpnext.patches.v12_0.setup_einvoice_fields #2020-12-02 erpnext.patches.v13_0.updates_for_multi_currency_payroll erpnext.patches.v13_0.update_reason_for_resignation_in_employee erpnext.patches.v13_0.update_custom_fields_for_shopify diff --git a/erpnext/patches/v12_0/setup_einvoice_fields.py b/erpnext/patches/v12_0/setup_einvoice_fields.py new file mode 100644 index 0000000000..d0782765de --- /dev/null +++ b/erpnext/patches/v12_0/setup_einvoice_fields.py @@ -0,0 +1,55 @@ +from __future__ import unicode_literals +import frappe +from frappe.custom.doctype.custom_field.custom_field import create_custom_fields +from erpnext.regional.india.setup import add_permissions, add_print_formats + +def execute(): + company = frappe.get_all('Company', filters = {'country': 'India'}) + if not company: + return + + frappe.reload_doc("regional", "doctype", "e_invoice_settings") + custom_fields = { + 'Sales Invoice': [ + dict(fieldname='irn', label='IRN', fieldtype='Data', read_only=1, insert_after='customer', no_copy=1, print_hide=1, + depends_on='eval:in_list(["Registered Regular", "SEZ", "Overseas", "Deemed Export"], doc.gst_category) && doc.irn_cancelled === 0'), + + dict(fieldname='ack_no', label='Ack. No.', fieldtype='Data', read_only=1, hidden=1, insert_after='irn', no_copy=1, print_hide=1), + + dict(fieldname='ack_date', label='Ack. Date', fieldtype='Data', read_only=1, hidden=1, insert_after='ack_no', no_copy=1, print_hide=1), + + dict(fieldname='irn_cancelled', label='IRN Cancelled', fieldtype='Check', no_copy=1, print_hide=1, + depends_on='eval:(doc.irn_cancelled === 1)', read_only=1, allow_on_submit=1, insert_after='customer'), + + dict(fieldname='eway_bill_cancelled', label='E-Way Bill Cancelled', fieldtype='Check', no_copy=1, print_hide=1, + depends_on='eval:(doc.eway_bill_cancelled === 1)', read_only=1, allow_on_submit=1, insert_after='customer'), + + dict(fieldname='signed_einvoice', fieldtype='Code', options='JSON', hidden=1, no_copy=1, print_hide=1, read_only=1), + + dict(fieldname='signed_qr_code', fieldtype='Code', options='JSON', hidden=1, no_copy=1, print_hide=1, read_only=1), + + dict(fieldname='qrcode_image', label='QRCode', fieldtype='Attach Image', hidden=1, no_copy=1, print_hide=1, read_only=1) + ] + } + create_custom_fields(custom_fields, update=True) + add_permissions() + add_print_formats() + + einvoice_cond = 'in_list(["Registered Regular", "SEZ", "Overseas", "Deemed Export"], doc.gst_category)' + t = { + 'mode_of_transport': [{'default': None}], + 'distance': [{'mandatory_depends_on': f'eval:{einvoice_cond} && doc.transporter'}], + 'gst_vehicle_type': [{'mandatory_depends_on': f'eval:{einvoice_cond} && doc.mode_of_transport == "Road"'}], + 'lr_date': [{'mandatory_depends_on': f'eval:{einvoice_cond} && in_list(["Air", "Ship", "Rail"], doc.mode_of_transport)'}], + 'lr_no': [{'mandatory_depends_on': f'eval:{einvoice_cond} && in_list(["Air", "Ship", "Rail"], doc.mode_of_transport)'}], + 'vehicle_no': [{'mandatory_depends_on': f'eval:{einvoice_cond} && doc.mode_of_transport == "Road"'}], + 'ewaybill': [ + {'read_only_depends_on': 'eval:doc.irn && doc.ewaybill'}, + {'depends_on': 'eval:((doc.docstatus === 1 || doc.ewaybill) && doc.eway_bill_cancelled === 0)'} + ] + } + + for field, conditions in t.items(): + for c in conditions: + [(prop, value)] = c.items() + frappe.db.set_value('Custom Field', { 'fieldname': field }, prop, value) diff --git a/erpnext/regional/doctype/e_invoice_request_log/__init__.py b/erpnext/regional/doctype/e_invoice_request_log/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.js b/erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.js new file mode 100644 index 0000000000..7b7ba964e5 --- /dev/null +++ b/erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.js @@ -0,0 +1,8 @@ +// Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('E Invoice Request Log', { + // refresh: function(frm) { + + // } +}); diff --git a/erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.json b/erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.json new file mode 100644 index 0000000000..5c1c79dc04 --- /dev/null +++ b/erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.json @@ -0,0 +1,103 @@ +{ + "actions": [], + "autoname": "EINV-REQ-.#####", + "creation": "2020-12-08 12:54:08.175992", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "user", + "url", + "headers", + "response", + "column_break_7", + "timestamp", + "reference_invoice", + "data" + ], + "fields": [ + { + "fieldname": "user", + "fieldtype": "Link", + "label": "User", + "options": "User" + }, + { + "fieldname": "reference_invoice", + "fieldtype": "Link", + "label": "Reference Invoice", + "options": "Sales Invoice" + }, + { + "fieldname": "headers", + "fieldtype": "Code", + "label": "Headers", + "options": "JSON" + }, + { + "fieldname": "data", + "fieldtype": "Code", + "label": "Data", + "options": "JSON" + }, + { + "default": "Now", + "fieldname": "timestamp", + "fieldtype": "Datetime", + "label": "Timestamp" + }, + { + "fieldname": "response", + "fieldtype": "Code", + "label": "Response", + "options": "JSON" + }, + { + "fieldname": "url", + "fieldtype": "Data", + "label": "URL" + }, + { + "fieldname": "column_break_7", + "fieldtype": "Column Break" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2020-12-24 21:09:38.882866", + "modified_by": "Administrator", + "module": "Regional", + "name": "E Invoice Request Log", + "owner": "Administrator", + "permissions": [ + { + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1 + }, + { + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts User", + "share": 1 + }, + { + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts Manager", + "share": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.py b/erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.py new file mode 100644 index 0000000000..9150bdd926 --- /dev/null +++ b/erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +# import frappe +from frappe.model.document import Document + +class EInvoiceRequestLog(Document): + pass diff --git a/erpnext/regional/doctype/e_invoice_request_log/test_e_invoice_request_log.py b/erpnext/regional/doctype/e_invoice_request_log/test_e_invoice_request_log.py new file mode 100644 index 0000000000..c84e9a249b --- /dev/null +++ b/erpnext/regional/doctype/e_invoice_request_log/test_e_invoice_request_log.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +# import frappe +import unittest + +class TestEInvoiceRequestLog(unittest.TestCase): + pass diff --git a/erpnext/regional/doctype/e_invoice_settings/__init__.py b/erpnext/regional/doctype/e_invoice_settings/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.js b/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.js new file mode 100644 index 0000000000..cc2d9f06d2 --- /dev/null +++ b/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.js @@ -0,0 +1,11 @@ +// Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('E Invoice Settings', { + refresh(frm) { + const docs_link = 'https://docs.erpnext.com/docs/user/manual/en/regional/india/setup-e-invoicing'; + frm.dashboard.set_headline( + __("Read {0} for more information on E Invoicing features.", [`documentation`]) + ); + } +}); diff --git a/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.json b/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.json new file mode 100644 index 0000000000..4dcb22a54c --- /dev/null +++ b/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.json @@ -0,0 +1,58 @@ +{ + "actions": [], + "creation": "2020-09-24 16:23:16.235722", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "enable", + "section_break_2", + "credentials", + "auth_token", + "token_expiry" + ], + "fields": [ + { + "default": "0", + "fieldname": "enable", + "fieldtype": "Check", + "label": "Enable" + }, + { + "depends_on": "enable", + "fieldname": "section_break_2", + "fieldtype": "Section Break" + }, + { + "fieldname": "auth_token", + "fieldtype": "Data", + "hidden": 1, + "read_only": 1 + }, + { + "fieldname": "token_expiry", + "fieldtype": "Datetime", + "hidden": 1, + "read_only": 1 + }, + { + "fieldname": "credentials", + "fieldtype": "Table", + "label": "Credentials", + "mandatory_depends_on": "enable", + "options": "E Invoice User" + } + ], + "index_web_pages_for_search": 1, + "issingle": 1, + "links": [], + "modified": "2020-12-22 15:34:57.280044", + "modified_by": "Administrator", + "module": "Regional", + "name": "E Invoice Settings", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.py b/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.py new file mode 100644 index 0000000000..c24ad886ea --- /dev/null +++ b/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt +from __future__ import unicode_literals + +import frappe +from frappe import _ +from frappe.model.document import Document + +class EInvoiceSettings(Document): + def validate(self): + if self.enable and not self.credentials: + frappe.throw(_('You must add atleast one credentials to be able to use E Invoicing.')) + diff --git a/erpnext/regional/doctype/e_invoice_settings/test_e_invoice_settings.py b/erpnext/regional/doctype/e_invoice_settings/test_e_invoice_settings.py new file mode 100644 index 0000000000..a11ce63ee6 --- /dev/null +++ b/erpnext/regional/doctype/e_invoice_settings/test_e_invoice_settings.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +# import frappe +import unittest + +class TestEInvoiceSettings(unittest.TestCase): + pass diff --git a/erpnext/regional/doctype/e_invoice_user/__init__.py b/erpnext/regional/doctype/e_invoice_user/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/regional/doctype/e_invoice_user/e_invoice_user.json b/erpnext/regional/doctype/e_invoice_user/e_invoice_user.json new file mode 100644 index 0000000000..dd9d99773a --- /dev/null +++ b/erpnext/regional/doctype/e_invoice_user/e_invoice_user.json @@ -0,0 +1,48 @@ +{ + "actions": [], + "creation": "2020-12-22 15:02:46.229474", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "gstin", + "username", + "password" + ], + "fields": [ + { + "fieldname": "gstin", + "fieldtype": "Data", + "in_list_view": 1, + "label": "GSTIN", + "reqd": 1 + }, + { + "fieldname": "username", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Username", + "reqd": 1 + }, + { + "fieldname": "password", + "fieldtype": "Password", + "in_list_view": 1, + "label": "Password", + "reqd": 1 + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2020-12-22 15:10:53.466205", + "modified_by": "Administrator", + "module": "Regional", + "name": "E Invoice User", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/regional/doctype/e_invoice_user/e_invoice_user.py b/erpnext/regional/doctype/e_invoice_user/e_invoice_user.py new file mode 100644 index 0000000000..056c54f069 --- /dev/null +++ b/erpnext/regional/doctype/e_invoice_user/e_invoice_user.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +# import frappe +from frappe.model.document import Document + +class EInvoiceUser(Document): + pass diff --git a/erpnext/regional/india/e_invoice/__init__.py b/erpnext/regional/india/e_invoice/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/regional/india/e_invoice/einv_item_template.json b/erpnext/regional/india/e_invoice/einv_item_template.json new file mode 100644 index 0000000000..78e56518df --- /dev/null +++ b/erpnext/regional/india/e_invoice/einv_item_template.json @@ -0,0 +1,31 @@ +{{ + "SlNo": "{item.sr_no}", + "PrdDesc": "{item.description}", + "IsServc": "{item.is_service_item}", + "HsnCd": "{item.gst_hsn_code}", + "Barcde": "{item.barcode}", + "Unit": "{item.uom}", + "Qty": "{item.qty}", + "FreeQty": "{item.free_qty}", + "UnitPrice": "{item.unit_rate}", + "TotAmt": "{item.gross_amount}", + "Discount": "{item.discount_amount}", + "AssAmt": "{item.taxable_value}", + "PrdSlNo": "{item.serial_no}", + "GstRt": "{item.tax_rate}", + "IgstAmt": "{item.igst_amount}", + "CgstAmt": "{item.cgst_amount}", + "SgstAmt": "{item.sgst_amount}", + "CesRt": "{item.cess_rate}", + "CesAmt": "{item.cess_amount}", + "CesNonAdvlAmt": "{item.cess_nadv_amount}", + "StateCesRt": "{item.state_cess_rate}", + "StateCesAmt": "{item.state_cess_amount}", + "StateCesNonAdvlAmt": "{item.state_cess_nadv_amount}", + "OthChrg": "{item.other_charges}", + "TotItemVal": "{item.total_value}", + "BchDtls": {{ + "Nm": "{item.batch_no}", + "ExpDt": "{item.batch_expiry_date}" + }} +}} \ No newline at end of file diff --git a/erpnext/regional/india/e_invoice/einv_template.json b/erpnext/regional/india/e_invoice/einv_template.json new file mode 100644 index 0000000000..e5751da561 --- /dev/null +++ b/erpnext/regional/india/e_invoice/einv_template.json @@ -0,0 +1,110 @@ +{{ + "Version": "1.1", + "TranDtls": {{ + "TaxSch": "{transaction_details.tax_scheme}", + "SupTyp": "{transaction_details.supply_type}", + "RegRev": "{transaction_details.reverse_charge}", + "EcmGstin": "{transaction_details.ecom_gstin}", + "IgstOnIntra": "{transaction_details.igst_on_intra}" + }}, + "DocDtls": {{ + "Typ": "{doc_details.invoice_type}", + "No": "{doc_details.invoice_name}", + "Dt": "{doc_details.invoice_date}" + }}, + "SellerDtls": {{ + "Gstin": "{seller_details.gstin}", + "LglNm": "{seller_details.legal_name}", + "TrdNm": "{seller_details.trade_name}", + "Loc": "{seller_details.location}", + "Pin": "{seller_details.pincode}", + "Stcd": "{seller_details.state_code}", + "Addr1": "{seller_details.address_line1}", + "Addr2": "{seller_details.address_line2}", + "Ph": "{seller_details.phone}", + "Em": "{seller_details.email}" + }}, + "BuyerDtls": {{ + "Gstin": "{buyer_details.gstin}", + "LglNm": "{buyer_details.legal_name}", + "TrdNm": "{buyer_details.trade_name}", + "Addr1": "{buyer_details.address_line1}", + "Addr2": "{buyer_details.address_line2}", + "Loc": "{buyer_details.location}", + "Pin": "{buyer_details.pincode}", + "Stcd": "{buyer_details.state_code}", + "Ph": "{buyer_details.phone}", + "Em": "{buyer_details.email}", + "Pos": "{buyer_details.place_of_supply}" + }}, + "DispDtls": {{ + "Nm": "{dispatch_details.company_name}", + "Addr1": "{dispatch_details.address_line1}", + "Addr2": "{dispatch_details.address_line2}", + "Loc": "{dispatch_details.location}", + "Pin": "{dispatch_details.pincode}", + "Stcd": "{dispatch_details.state_code}" + }}, + "ShipDtls": {{ + "Gstin": "{shipping_details.gstin}", + "LglNm": "{shipping_details.legal_name}", + "TrdNm": "{shipping_details.trader_name}", + "Addr1": "{shipping_details.address_line1}", + "Addr2": "{shipping_details.address_line2}", + "Loc": "{shipping_details.location}", + "Pin": "{shipping_details.pincode}", + "Stcd": "{shipping_details.state_code}" + }}, + "ItemList": [ + {item_list} + ], + "ValDtls": {{ + "AssVal": "{invoice_value_details.base_net_total}", + "CgstVal": "{invoice_value_details.total_cgst_amt}", + "SgstVal": "{invoice_value_details.total_sgst_amt}", + "IgstVal": "{invoice_value_details.total_igst_amt}", + "CesVal": "{invoice_value_details.total_cess_amt}", + "Discount": "{invoice_value_details.invoice_discount_amt}", + "RndOffAmt": "{invoice_value_details.round_off}", + "OthChrg": "{invoice_value_details.total_other_charges}", + "TotInvVal": "{invoice_value_details.base_grand_total}", + "TotInvValFc": "{invoice_value_details.grand_total}" + }}, + "PayDtls": {{ + "Nm": "{payment_details.payee_name}", + "AccDet": "{payment_details.account_no}", + "Mode": "{payment_details.mode_of_payment}", + "FinInsBr": "{payment_details.ifsc_code}", + "PayTerm": "{payment_details.terms}", + "PaidAmt": "{payment_details.paid_amount}", + "PaymtDue": "{payment_details.outstanding_amount}" + }}, + "RefDtls": {{ + "DocPerdDtls": {{ + "InvStDt": "{period_details.start_date}", + "InvEndDt": "{period_details.end_date}" + }}, + "PrecDocDtls": [{{ + "InvNo": "{prev_doc_details.invoice_name}", + "InvDt": "{prev_doc_details.invoice_date}" + }}] + }}, + "ExpDtls": {{ + "ShipBNo": "{export_details.bill_no}", + "ShipBDt": "{export_details.bill_date}", + "Port": "{export_details.port}", + "ForCur": "{export_details.foreign_curr_code}", + "CntCode": "{export_details.country_code}", + "ExpDuty": "{export_details.export_duty}" + }}, + "EwbDtls": {{ + "TransId": "{eway_bill_details.gstin}", + "TransName": "{eway_bill_details.name}", + "TransMode": "{eway_bill_details.mode_of_transport}", + "Distance": "{eway_bill_details.distance}", + "TransDocNo": "{eway_bill_details.document_name}", + "TransDocDt": "{eway_bill_details.document_date}", + "VehNo": "{eway_bill_details.vehicle_no}", + "VehType": "{eway_bill_details.vehicle_type}" + }} +}} \ No newline at end of file diff --git a/erpnext/regional/india/e_invoice/einv_validation.json b/erpnext/regional/india/e_invoice/einv_validation.json new file mode 100644 index 0000000000..86290cfe52 --- /dev/null +++ b/erpnext/regional/india/e_invoice/einv_validation.json @@ -0,0 +1,956 @@ +{ + "Version": { + "type": "string", + "minLength": 1, + "maxLength": 6, + "description": "Version of the schema" + }, + "Irn": { + "type": "string", + "minLength": 64, + "maxLength": 64, + "description": "Invoice Reference Number" + }, + "TranDtls": { + "type": "object", + "properties": { + "TaxSch": { + "type": "string", + "minLength": 3, + "maxLength": 10, + "enum": ["GST"], + "description": "GST- Goods and Services Tax Scheme" + }, + "SupTyp": { + "type": "string", + "minLength": 3, + "maxLength": 10, + "enum": ["B2B", "SEZWP", "SEZWOP", "EXPWP", "EXPWOP", "DEXP"], + "description": "Type of Supply: B2B-Business to Business, SEZWP - SEZ with payment, SEZWOP - SEZ without payment, EXPWP - Export with Payment, EXPWOP - Export without payment,DEXP - Deemed Export" + }, + "RegRev": { + "type": "string", + "minLength": 1, + "maxLength": 1, + "enum": ["Y", "N"], + "description": "Y- whether the tax liability is payable under reverse charge" + }, + "EcmGstin": { + "type": "string", + "minLength": 15, + "maxLength": 15, + "pattern": "([0-9]{2}[0-9A-Z]{13})", + "description": "E-Commerce GSTIN", + "validationMsg": "E-Commerce GSTIN is invalid" + }, + "IgstOnIntra": { + "type": "string", + "minLength": 1, + "maxLength": 1, + "enum": ["Y", "N"], + "description": "Y- indicates the supply is intra state but chargeable to IGST" + } + }, + "required": ["TaxSch", "SupTyp"] + }, + "DocDtls": { + "type": "object", + "properties": { + "Typ": { + "type": "string", + "minLength": 3, + "maxLength": 3, + "enum": ["INV", "CRN", "DBN"], + "description": "Document Type" + }, + "No": { + "type": "string", + "minLength": 1, + "maxLength": 16, + "pattern": "^([A-Z1-9]{1}[A-Z0-9/-]{0,15})$", + "description": "Document Number", + "validationMsg": "Document Number should not be starting with 0, / and -" + }, + "Dt": { + "type": "string", + "minLength": 10, + "maxLength": 10, + "pattern": "[0-3][0-9]/[0-1][0-9]/[2][0][1-2][0-9]", + "description": "Document Date" + } + }, + "required": ["Typ", "No", "Dt"] + }, + "SellerDtls": { + "type": "object", + "properties": { + "Gstin": { + "type": "string", + "minLength": 15, + "maxLength": 15, + "pattern": "([0-9]{2}[0-9A-Z]{13})", + "description": "Supplier GSTIN", + "validationMsg": "Company GSTIN is invalid" + }, + "LglNm": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Legal Name" + }, + "TrdNm": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Tradename" + }, + "Addr1": { + "type": "string", + "minLength": 1, + "maxLength": 100, + "description": "Address Line 1" + }, + "Addr2": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Address Line 2" + }, + "Loc": { + "type": "string", + "minLength": 3, + "maxLength": 50, + "description": "Location" + }, + "Pin": { + "type": "number", + "minimum": 100000, + "maximum": 999999, + "description": "Pincode" + }, + "Stcd": { + "type": "string", + "minLength": 1, + "maxLength": 2, + "description": "Supplier State Code" + }, + "Ph": { + "type": "string", + "minLength": 6, + "maxLength": 12, + "description": "Phone" + }, + "Em": { + "type": "string", + "minLength": 6, + "maxLength": 100, + "description": "Email-Id" + } + }, + "required": ["Gstin", "LglNm", "Addr1", "Loc", "Pin", "Stcd"] + }, + "BuyerDtls": { + "type": "object", + "properties": { + "Gstin": { + "type": "string", + "minLength": 3, + "maxLength": 15, + "pattern": "^(([0-9]{2}[0-9A-Z]{13})|URP)$", + "description": "Buyer GSTIN", + "validationMsg": "Customer GSTIN is invalid" + }, + "LglNm": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Legal Name" + }, + "TrdNm": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Trade Name" + }, + "Pos": { + "type": "string", + "minLength": 1, + "maxLength": 2, + "description": "Place of Supply State code" + }, + "Addr1": { + "type": "string", + "minLength": 1, + "maxLength": 100, + "description": "Address Line 1" + }, + "Addr2": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Address Line 2" + }, + "Loc": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Location" + }, + "Pin": { + "type": "number", + "minimum": 100000, + "maximum": 999999, + "description": "Pincode" + }, + "Stcd": { + "type": "string", + "minLength": 1, + "maxLength": 2, + "description": "Buyer State Code" + }, + "Ph": { + "type": "string", + "minLength": 6, + "maxLength": 12, + "description": "Phone" + }, + "Em": { + "type": "string", + "minLength": 6, + "maxLength": 100, + "description": "Email-Id" + } + }, + "required": ["Gstin", "LglNm", "Pos", "Addr1", "Loc", "Stcd"] + }, + "DispDtls": { + "type": "object", + "properties": { + "Nm": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Dispatch Address Name" + }, + "Addr1": { + "type": "string", + "minLength": 1, + "maxLength": 100, + "description": "Address Line 1" + }, + "Addr2": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Address Line 2" + }, + "Loc": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Location" + }, + "Pin": { + "type": "number", + "minimum": 100000, + "maximum": 999999, + "description": "Pincode" + }, + "Stcd": { + "type": "string", + "minLength": 1, + "maxLength": 2, + "description": "State Code" + } + }, + "required": ["Nm", "Addr1", "Loc", "Pin", "Stcd"] + }, + "ShipDtls": { + "type": "object", + "properties": { + "Gstin": { + "type": "string", + "maxLength": 15, + "minLength": 3, + "pattern": "^(([0-9]{2}[0-9A-Z]{13})|URP)$", + "description": "Shipping Address GSTIN", + "validationMsg": "Shipping Address GSTIN is invalid" + }, + "LglNm": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Legal Name" + }, + "TrdNm": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Trade Name" + }, + "Addr1": { + "type": "string", + "minLength": 1, + "maxLength": 100, + "description": "Address Line 1" + }, + "Addr2": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Address Line 2" + }, + "Loc": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Location" + }, + "Pin": { + "type": "number", + "minimum": 100000, + "maximum": 999999, + "description": "Pincode" + }, + "Stcd": { + "type": "string", + "minLength": 1, + "maxLength": 2, + "description": "State Code" + } + }, + "required": ["LglNm", "Addr1", "Loc", "Pin", "Stcd"] + }, + "ItemList": { + "type": "Array", + "properties": { + "SlNo": { + "type": "string", + "minLength": 1, + "maxLength": 6, + "description": "Serial No. of Item" + }, + "PrdDesc": { + "type": "string", + "minLength": 3, + "maxLength": 300, + "description": "Item Name" + }, + "IsServc": { + "type": "string", + "minLength": 1, + "maxLength": 1, + "enum": ["Y", "N"], + "description": "Is Service Item" + }, + "HsnCd": { + "type": "string", + "minLength": 4, + "maxLength": 8, + "description": "HSN Code" + }, + "Barcde": { + "type": "string", + "minLength": 3, + "maxLength": 30, + "description": "Barcode" + }, + "Qty": { + "type": "number", + "minimum": 0, + "maximum": 9999999999.999, + "description": "Quantity" + }, + "FreeQty": { + "type": "number", + "minimum": 0, + "maximum": 9999999999.999, + "description": "Free Quantity" + }, + "Unit": { + "type": "string", + "minLength": 3, + "maxLength": 8, + "description": "UOM" + }, + "UnitPrice": { + "type": "number", + "minimum": 0, + "maximum": 999999999999.999, + "description": "Rate" + }, + "TotAmt": { + "type": "number", + "minimum": 0, + "maximum": 999999999999.99, + "description": "Gross Amount" + }, + "Discount": { + "type": "number", + "minimum": 0, + "maximum": 999999999999.99, + "description": "Discount" + }, + "PreTaxVal": { + "type": "number", + "minimum": 0, + "maximum": 999999999999.99, + "description": "Pre tax value" + }, + "AssAmt": { + "type": "number", + "minimum": 0, + "maximum": 999999999999.99, + "description": "Taxable Value" + }, + "GstRt": { + "type": "number", + "minimum": 0, + "maximum": 999.999, + "description": "GST Rate" + }, + "IgstAmt": { + "type": "number", + "minimum": 0, + "maximum": 999999999999.99, + "description": "IGST Amount" + }, + "CgstAmt": { + "type": "number", + "minimum": 0, + "maximum": 999999999999.99, + "description": "CGST Amount" + }, + "SgstAmt": { + "type": "number", + "minimum": 0, + "maximum": 999999999999.99, + "description": "SGST Amount" + }, + "CesRt": { + "type": "number", + "minimum": 0, + "maximum": 999.999, + "description": "Cess Rate" + }, + "CesAmt": { + "type": "number", + "minimum": 0, + "maximum": 999999999999.99, + "description": "Cess Amount (Advalorem)" + }, + "CesNonAdvlAmt": { + "type": "number", + "minimum": 0, + "maximum": 999999999999.99, + "description": "Cess Amount (Non-Advalorem)" + }, + "StateCesRt": { + "type": "number", + "minimum": 0, + "maximum": 999.999, + "description": "State CESS Rate" + }, + "StateCesAmt": { + "type": "number", + "minimum": 0, + "maximum": 999999999999.99, + "description": "State CESS Amount" + }, + "StateCesNonAdvlAmt": { + "type": "number", + "minimum": 0, + "maximum": 999999999999.99, + "description": "State CESS Amount (Non Advalorem)" + }, + "OthChrg": { + "type": "number", + "minimum": 0, + "maximum": 999999999999.99, + "description": "Other Charges" + }, + "TotItemVal": { + "type": "number", + "minimum": 0, + "maximum": 999999999999.99, + "description": "Total Item Value" + }, + "OrdLineRef": { + "type": "string", + "minLength": 1, + "maxLength": 50, + "description": "Order line reference" + }, + "OrgCntry": { + "type": "string", + "minLength": 2, + "maxLength": 2, + "description": "Origin Country" + }, + "PrdSlNo": { + "type": "string", + "minLength": 1, + "maxLength": 20, + "description": "Serial number" + }, + "BchDtls": { + "type": "object", + "properties": { + "Nm": { + "type": "string", + "minLength": 3, + "maxLength": 20, + "description": "Batch number" + }, + "ExpDt": { + "type": "string", + "maxLength": 10, + "minLength": 10, + "pattern": "[0-3][0-9]/[0-1][0-9]/[2][0][1-2][0-9]", + "description": "Batch Expiry Date" + }, + "WrDt": { + "type": "string", + "maxLength": 10, + "minLength": 10, + "pattern": "[0-3][0-9]/[0-1][0-9]/[2][0][1-2][0-9]", + "description": "Warranty Date" + } + }, + "required": ["Nm"] + }, + "AttribDtls": { + "type": "Array", + "Attribute": { + "type": "object", + "properties": { + "Nm": { + "type": "string", + "minLength": 1, + "maxLength": 100, + "description": "Attribute name of the item" + }, + "Val": { + "type": "string", + "minLength": 1, + "maxLength": 100, + "description": "Attribute value of the item" + } + } + } + } + }, + "required": [ + "SlNo", + "IsServc", + "HsnCd", + "UnitPrice", + "TotAmt", + "AssAmt", + "GstRt", + "TotItemVal" + ] + }, + "ValDtls": { + "type": "object", + "properties": { + "AssVal": { + "type": "number", + "minimum": 0, + "maximum": 99999999999999.99, + "description": "Total Assessable value of all items" + }, + "CgstVal": { + "type": "number", + "maximum": 99999999999999.99, + "minimum": 0, + "description": "Total CGST value of all items" + }, + "SgstVal": { + "type": "number", + "minimum": 0, + "maximum": 99999999999999.99, + "description": "Total SGST value of all items" + }, + "IgstVal": { + "type": "number", + "minimum": 0, + "maximum": 99999999999999.99, + "description": "Total IGST value of all items" + }, + "CesVal": { + "type": "number", + "minimum": 0, + "maximum": 99999999999999.99, + "description": "Total CESS value of all items" + }, + "StCesVal": { + "type": "number", + "minimum": 0, + "maximum": 99999999999999.99, + "description": "Total State CESS value of all items" + }, + "Discount": { + "type": "number", + "minimum": 0, + "maximum": 99999999999999.99, + "description": "Invoice Discount" + }, + "OthChrg": { + "type": "number", + "minimum": 0, + "maximum": 99999999999999.99, + "description": "Other Charges" + }, + "RndOffAmt": { + "type": "number", + "minimum": -99.99, + "maximum": 99.99, + "description": "Rounded off Amount" + }, + "TotInvVal": { + "type": "number", + "minimum": 0, + "maximum": 99999999999999.99, + "description": "Final Invoice Value " + }, + "TotInvValFc": { + "type": "number", + "minimum": 0, + "maximum": 99999999999999.99, + "description": "Final Invoice value in Foreign Currency" + } + }, + "required": ["AssVal", "TotInvVal"] + }, + "PayDtls": { + "type": "object", + "properties": { + "Nm": { + "type": "string", + "minLength": 1, + "maxLength": 100, + "description": "Payee Name" + }, + "AccDet": { + "type": "string", + "minLength": 1, + "maxLength": 18, + "description": "Bank Account Number of Payee" + }, + "Mode": { + "type": "string", + "minLength": 1, + "maxLength": 18, + "description": "Mode of Payment" + }, + "FinInsBr": { + "type": "string", + "minLength": 1, + "maxLength": 11, + "description": "Branch or IFSC code" + }, + "PayTerm": { + "type": "string", + "minLength": 1, + "maxLength": 100, + "description": "Terms of Payment" + }, + "PayInstr": { + "type": "string", + "minLength": 1, + "maxLength": 100, + "description": "Payment Instruction" + }, + "CrTrn": { + "type": "string", + "minLength": 1, + "maxLength": 100, + "description": "Credit Transfer" + }, + "DirDr": { + "type": "string", + "minLength": 1, + "maxLength": 100, + "description": "Direct Debit" + }, + "CrDay": { + "type": "number", + "minimum": 0, + "maximum": 9999, + "description": "Credit Days" + }, + "PaidAmt": { + "type": "number", + "minimum": 0, + "maximum": 99999999999999.99, + "description": "Advance Amount" + }, + "PaymtDue": { + "type": "number", + "minimum": 0, + "maximum": 99999999999999.99, + "description": "Outstanding Amount" + } + } + }, + "RefDtls": { + "type": "object", + "properties": { + "InvRm": { + "type": "string", + "maxLength": 100, + "minLength": 3, + "pattern": "^[0-9A-Za-z/-]{3,100}$", + "description": "Remarks/Note" + }, + "DocPerdDtls": { + "type": "object", + "properties": { + "InvStDt": { + "type": "string", + "maxLength": 10, + "minLength": 10, + "pattern": "[0-3][0-9]/[0-1][0-9]/[2][0][1-2][0-9]", + "description": "Invoice Period Start Date" + }, + "InvEndDt": { + "type": "string", + "maxLength": 10, + "minLength": 10, + "pattern": "[0-3][0-9]/[0-1][0-9]/[2][0][1-2][0-9]", + "description": "Invoice Period End Date" + } + }, + "required": ["InvStDt ", "InvEndDt "] + }, + "PrecDocDtls": { + "type": "object", + "properties": { + "InvNo": { + "type": "string", + "minLength": 1, + "maxLength": 16, + "pattern": "^[1-9A-Z]{1}[0-9A-Z/-]{1,15}$", + "description": "Reference of Original Invoice" + }, + "InvDt": { + "type": "string", + "maxLength": 10, + "minLength": 10, + "pattern": "[0-3][0-9]/[0-1][0-9]/[2][0][1-2][0-9]", + "description": "Date of Orginal Invoice" + }, + "OthRefNo": { + "type": "string", + "minLength": 1, + "maxLength": 20, + "description": "Other Reference" + } + } + }, + "required": ["InvNo", "InvDt"], + "ContrDtls": { + "type": "object", + "properties": { + "RecAdvRefr": { + "type": "string", + "minLength": 1, + "maxLength": 20, + "pattern": "^([0-9A-Za-z/-]){1,20}$", + "description": "Receipt Advice No." + }, + "RecAdvDt": { + "type": "string", + "minLength": 10, + "maxLength": 10, + "pattern": "[0-3][0-9]/[0-1][0-9]/[2][0][1-2][0-9]", + "description": "Date of receipt advice" + }, + "TendRefr": { + "type": "string", + "minLength": 1, + "maxLength": 20, + "pattern": "^([0-9A-Za-z/-]){1,20}$", + "description": "Lot/Batch Reference No." + }, + "ContrRefr": { + "type": "string", + "minLength": 1, + "maxLength": 20, + "pattern": "^([0-9A-Za-z/-]){1,20}$", + "description": "Contract Reference Number" + }, + "ExtRefr": { + "type": "string", + "minLength": 1, + "maxLength": 20, + "pattern": "^([0-9A-Za-z/-]){1,20}$", + "description": "Any other reference" + }, + "ProjRefr": { + "type": "string", + "minLength": 1, + "maxLength": 20, + "pattern": "^([0-9A-Za-z/-]){1,20}$", + "description": "Project Reference Number" + }, + "PORefr": { + "type": "string", + "minLength": 1, + "maxLength": 16, + "pattern": "^([0-9A-Za-z/-]){1,16}$", + "description": "PO Reference Number" + }, + "PORefDt": { + "type": "string", + "minLength": 10, + "maxLength": 10, + "pattern": "[0-3][0-9]/[0-1][0-9]/[2][0][1-2][0-9]", + "description": "PO Reference date" + } + } + } + } + }, + "AddlDocDtls": { + "type": "Array", + "properties": { + "Url": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Supporting document URL" + }, + "Docs": { + "type": "string", + "minLength": 3, + "maxLength": 1000, + "description": "Supporting document in Base64 Format" + }, + "Info": { + "type": "string", + "minLength": 3, + "maxLength": 1000, + "description": "Any additional information" + } + } + }, + + "ExpDtls": { + "type": "object", + "properties": { + "ShipBNo": { + "type": "string", + "minLength": 1, + "maxLength": 20, + "description": "Shipping Bill No." + }, + "ShipBDt": { + "type": "string", + "minLength": 10, + "maxLength": 10, + "pattern": "[0-3][0-9]/[0-1][0-9]/[2][0][1-2][0-9]", + "description": "Shipping Bill Date" + }, + "Port": { + "type": "string", + "minLength": 2, + "maxLength": 10, + "pattern": "^[0-9A-Za-z]{2,10}$", + "description": "Port Code. Refer the master" + }, + "RefClm": { + "type": "string", + "minLength": 1, + "maxLength": 1, + "description": "Claiming Refund. Y/N" + }, + "ForCur": { + "type": "string", + "minLength": 3, + "maxLength": 16, + "description": "Additional Currency Code. Refer the master" + }, + "CntCode": { + "type": "string", + "minLength": 2, + "maxLength": 2, + "description": "Country Code. Refer the master" + }, + "ExpDuty": { + "type": "number", + "minimum": 0, + "maximum": 999999999999.99, + "description": "Export Duty" + } + } + }, + "EwbDtls": { + "type": "object", + "properties": { + "TransId": { + "type": "string", + "minLength": 15, + "maxLength": 15, + "description": "Transporter GSTIN" + }, + "TransName": { + "type": "string", + "minLength": 3, + "maxLength": 100, + "description": "Transporter Name" + }, + "TransMode": { + "type": "string", + "maxLength": 1, + "minLength": 1, + "enum": ["1", "2", "3", "4"], + "description": "Mode of Transport" + }, + "Distance": { + "type": "number", + "minimum": 1, + "maximum": 9999, + "description": "Distance" + }, + "TransDocNo": { + "type": "string", + "minLength": 1, + "maxLength": 15, + "pattern": "^([0-9A-Z/-]){1,15}$", + "description": "Tranport Document Number" + }, + "TransDocDt": { + "type": "string", + "minLength": 10, + "maxLength": 10, + "pattern": "[0-3][0-9]/[0-1][0-9]/[2][0][1-2][0-9]", + "description": "Transport Document Date" + }, + "VehNo": { + "type": "string", + "minLength": 4, + "maxLength": 20, + "description": "Vehicle Number" + }, + "VehType": { + "type": "string", + "minLength": 1, + "maxLength": 1, + "enum": ["O", "R"], + "description": "Vehicle Type" + } + }, + "required": ["Distance"] + }, + "required": [ + "Version", + "TranDtls", + "DocDtls", + "SellerDtls", + "BuyerDtls", + "ItemList", + "ValDtls" + ] +} diff --git a/erpnext/regional/india/e_invoice/einvoice.js b/erpnext/regional/india/e_invoice/einvoice.js new file mode 100644 index 0000000000..9c86cc89f5 --- /dev/null +++ b/erpnext/regional/india/e_invoice/einvoice.js @@ -0,0 +1,305 @@ +erpnext.setup_einvoice_actions = (doctype) => { + frappe.ui.form.on(doctype, { + refresh(frm) { + const einvoicing_enabled = frappe.db.get_value("E Invoice Settings", "E Invoice Settings", "enable"); + const supply_type = frm.doc.gst_category; + const valid_supply_type = ['Registered Regular', 'SEZ', 'Overseas', 'Deemed Export'].includes(supply_type); + const company_transaction = frm.doc.billing_address_gstin == frm.doc.company_gstin; + + if (!einvoicing_enabled || !valid_supply_type || company_transaction) return; + + const { doctype, irn, irn_cancelled, ewaybill, eway_bill_cancelled, name, __unsaved } = frm.doc; + + const add_custom_button = (label, action) => { + if (!frm.custom_buttons[label]) { + frm.add_custom_button(label, action, __('E Invoicing')); + } + }; + + if (!irn && !__unsaved) { + const action = () => { + frappe.call({ + method: 'erpnext.regional.india.e_invoice.utils.get_einvoice', + args: { doctype, docname: name }, + freeze: true, + callback: (res) => { + const einvoice = res.message; + show_einvoice_preview(frm, einvoice); + } + }); + }; + + add_custom_button(__("Generate IRN"), action); + } + + if (irn && !irn_cancelled && !ewaybill) { + const fields = [ + { + "label": "Reason", + "fieldname": "reason", + "fieldtype": "Select", + "reqd": 1, + "default": "1-Duplicate", + "options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"] + }, + { + "label": "Remark", + "fieldname": "remark", + "fieldtype": "Data", + "reqd": 1 + } + ]; + const action = () => { + const d = new frappe.ui.Dialog({ + title: __("Cancel IRN"), + fields: fields, + primary_action: function() { + const data = d.get_values(); + frappe.call({ + method: 'erpnext.regional.india.e_invoice.utils.cancel_irn', + args: { + doctype, + docname: name, + irn: irn, + reason: data.reason.split('-')[0], + remark: data.remark + }, + freeze: true, + callback: () => frm.reload_doc() || d.hide(), + error: () => d.hide() + }); + }, + primary_action_label: __('Submit') + }); + d.show(); + }; + add_custom_button(__("Cancel IRN"), action); + } + + if (irn && !irn_cancelled && !ewaybill) { + const action = () => { + const d = new frappe.ui.Dialog({ + title: __('Generate E-Way Bill'), + wide: 1, + fields: get_ewaybill_fields(frm), + primary_action: function() { + const data = d.get_values(); + frappe.call({ + method: 'erpnext.regional.india.e_invoice.utils.generate_eway_bill', + args: { + doctype, + docname: name, + irn, + ...data + }, + freeze: true, + callback: () => frm.reload_doc() || d.hide(), + error: () => d.hide() + }); + }, + primary_action_label: __('Submit') + }); + d.show(); + }; + + add_custom_button(__("Generate E-Way Bill"), action); + } + + if (irn && ewaybill && !irn_cancelled && !eway_bill_cancelled) { + const fields = [ + { + "label": "Reason", + "fieldname": "reason", + "fieldtype": "Select", + "reqd": 1, + "default": "1-Duplicate", + "options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"] + }, + { + "label": "Remark", + "fieldname": "remark", + "fieldtype": "Data", + "reqd": 1 + } + ]; + const action = () => { + const d = new frappe.ui.Dialog({ + title: __('Cancel E-Way Bill'), + fields: fields, + primary_action: function() { + const data = d.get_values(); + frappe.call({ + method: 'erpnext.regional.india.e_invoice.utils.cancel_eway_bill', + args: { + doctype, + docname: name, + eway_bill: ewaybill, + reason: data.reason.split('-')[0], + remark: data.remark + }, + freeze: true, + callback: () => frm.reload_doc() || d.hide(), + error: () => d.hide() + }); + }, + primary_action_label: __('Submit') + }); + d.show(); + }; + add_custom_button(__("Cancel E-Way Bill"), action); + } + } + }); +}; + +const get_ewaybill_fields = (frm) => { + return [ + { + 'fieldname': 'transporter', + 'label': 'Transporter', + 'fieldtype': 'Link', + 'options': 'Supplier', + 'default': frm.doc.transporter + }, + { + 'fieldname': 'gst_transporter_id', + 'label': 'GST Transporter ID', + 'fieldtype': 'Data', + 'fetch_from': 'transporter.gst_transporter_id', + 'default': frm.doc.gst_transporter_id + }, + { + 'fieldname': 'driver', + 'label': 'Driver', + 'fieldtype': 'Link', + 'options': 'Driver', + 'default': frm.doc.driver + }, + { + 'fieldname': 'lr_no', + 'label': 'Transport Receipt No', + 'fieldtype': 'Data', + 'default': frm.doc.lr_no + }, + { + 'fieldname': 'vehicle_no', + 'label': 'Vehicle No', + 'fieldtype': 'Data', + 'depends_on': 'eval:(doc.mode_of_transport === "Road")', + 'default': frm.doc.vehicle_no + }, + { + 'fieldname': 'distance', + 'label': 'Distance (in km)', + 'fieldtype': 'Float', + 'default': frm.doc.distance + }, + { + 'fieldname': 'transporter_col_break', + 'fieldtype': 'Column Break', + }, + { + 'fieldname': 'transporter_name', + 'label': 'Transporter Name', + 'fieldtype': 'Data', + 'fetch_from': 'transporter.name', + 'read_only': 1, + 'default': frm.doc.transporter_name + }, + { + 'fieldname': 'mode_of_transport', + 'label': 'Mode of Transport', + 'fieldtype': 'Select', + 'options': `\nRoad\nAir\nRail\nShip`, + 'default': frm.doc.mode_of_transport + }, + { + 'fieldname': 'driver_name', + 'label': 'Driver Name', + 'fieldtype': 'Data', + 'fetch_from': 'driver.full_name', + 'read_only': 1, + 'default': frm.doc.driver_name + }, + { + 'fieldname': 'lr_date', + 'label': 'Transport Receipt Date', + 'fieldtype': 'Date', + 'default': frm.doc.lr_date + }, + { + 'fieldname': 'gst_vehicle_type', + 'label': 'GST Vehicle Type', + 'fieldtype': 'Select', + 'options': `Regular\nOver Dimensional Cargo (ODC)`, + 'depends_on': 'eval:(doc.mode_of_transport === "Road")', + 'default': frm.doc.gst_vehicle_type + } + ]; +}; + +const request_irn_generation = (frm) => { + frappe.call({ + method: 'erpnext.regional.india.e_invoice.utils.generate_irn', + args: { doctype: frm.doc.doctype, docname: frm.doc.name }, + freeze: true, + callback: () => frm.reload_doc() + }); +}; + +const get_preview_dialog = (frm, action) => { + const dialog = new frappe.ui.Dialog({ + title: __("Preview"), + wide: 1, + fields: [ + { + "label": "Preview", + "fieldname": "preview_html", + "fieldtype": "HTML" + } + ], + primary_action: () => action(frm) || dialog.hide(), + primary_action_label: __('Generate IRN') + }); + return dialog; +}; + +const show_einvoice_preview = (frm, einvoice) => { + const preview_dialog = get_preview_dialog(frm, request_irn_generation); + + // initialize e-invoice fields + einvoice["Irn"] = einvoice["AckNo"] = ''; einvoice["AckDt"] = frappe.datetime.nowdate(); + frm.doc.signed_einvoice = JSON.stringify(einvoice); + + // initialize preview wrapper + const $preview_wrapper = preview_dialog.get_field("preview_html").$wrapper; + $preview_wrapper.html( + `
+ +
+
` + ); + + frappe.call({ + method: "frappe.www.printview.get_html_and_style", + args: { + doc: frm.doc, + print_format: "GST E-Invoice", + no_letterhead: 1 + }, + callback: function (r) { + if (!r.exc) { + $preview_wrapper.find(".print-format").html(r.message.html); + const style = ` + .print-format { box-shadow: 0px 0px 5px rgba(0,0,0,0.2); padding: 0.30in; min-height: 80vh; } + .print-preview { min-height: 0px; } + .modal-dialog { width: 720px; }`; + + frappe.dom.set_style(style, "custom-print-style"); + preview_dialog.show(); + } + } + }); +}; \ No newline at end of file diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py new file mode 100644 index 0000000000..cb92c42464 --- /dev/null +++ b/erpnext/regional/india/e_invoice/utils.py @@ -0,0 +1,772 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import os +import re +import jwt +import sys +import json +import base64 +import frappe +import traceback +from frappe import _, bold +from pyqrcode import create as qrcreate +from frappe.integrations.utils import make_post_request, make_get_request +from erpnext.regional.india.utils import get_gst_accounts, get_place_of_supply +from frappe.utils.data import cstr, cint, format_date, flt, time_diff_in_seconds, now_datetime, add_to_date + +def validate_einvoice_fields(doc): + einvoicing_enabled = cint(frappe.db.get_value('E Invoice Settings', 'E Invoice Settings', 'enable')) + invalid_doctype = doc.doctype not in ['Sales Invoice'] + invalid_supply_type = doc.get('gst_category') not in ['Registered Regular', 'SEZ', 'Overseas', 'Deemed Export'] + company_transaction = doc.get('billing_address_gstin') == doc.get('company_gstin') + + if not einvoicing_enabled or invalid_doctype or invalid_supply_type or company_transaction: return + + if doc.docstatus == 0 and doc._action == 'save': + if doc.irn: + frappe.throw(_('You cannot edit the invoice after generating IRN'), title=_('Edit Not Allowed')) + if len(doc.name) > 16: + raise_document_name_too_long_error() + + elif doc.docstatus == 1 and doc._action == 'submit' and not doc.irn: + frappe.throw(_('You must generate IRN before submitting the document.'), title=_('Missing IRN')) + + elif doc.docstatus == 2 and doc._action == 'cancel' and not doc.irn_cancelled: + frappe.throw(_('You must cancel IRN before cancelling the document.'), title=_('Cancel Not Allowed')) + +def raise_document_name_too_long_error(): + title = _('Document ID Too Long') + msg = _('As you have E-Invoicing enabled, to be able to generate IRN for this invoice, ') + msg += _('document id {} exceed 16 letters. ').format(bold(_('should not'))) + msg += '

' + msg += _('You must {} your {} in order to have document id of {} length 16. ').format( + bold(_('modify')), bold(_('naming series')), bold(_('maximum')) + ) + msg += _('Please account for ammended documents too. ') + frappe.throw(msg, title=title) + +def read_json(name): + file_path = os.path.join(os.path.dirname(__file__), '{name}.json'.format(name=name)) + with open(file_path, 'r') as f: + return cstr(f.read()) + +def get_transaction_details(invoice): + supply_type = '' + if invoice.gst_category == 'Registered Regular': supply_type = 'B2B' + elif invoice.gst_category == 'SEZ': supply_type = 'SEZWOP' + elif invoice.gst_category == 'Overseas': supply_type = 'EXPWOP' + elif invoice.gst_category == 'Deemed Export': supply_type = 'DEXP' + + if not supply_type: + rr, sez, overseas, export = bold('Registered Regular'), bold('SEZ'), bold('Overseas'), bold('Deemed Export') + frappe.throw(_('GST category should be one of {}, {}, {}, {}').format(rr, sez, overseas, export), + title=_('Invalid Supply Type')) + + return frappe._dict(dict( + tax_scheme='GST', + supply_type=supply_type, + reverse_charge=invoice.reverse_charge + )) + +def get_doc_details(invoice): + invoice_type = 'CRN' if invoice.is_return else 'INV' + + invoice_name = invoice.name + invoice_date = format_date(invoice.posting_date, 'dd/mm/yyyy') + + return frappe._dict(dict( + invoice_type=invoice_type, + invoice_name=invoice_name, + invoice_date=invoice_date + )) + +def get_party_details(address_name): + address = frappe.get_all('Address', filters={'name': address_name}, fields=['*'])[0] + gstin = address.get('gstin') + + gstin_details = get_gstin_details(gstin) + legal_name = gstin_details.get('LegalName') + location = gstin_details.get('AddrLoc') or address.get('city') + state_code = gstin_details.get('StateCode') + pincode = gstin_details.get('AddrPncd') + address_line1 = '{} {}'.format(gstin_details.get('AddrBno'), gstin_details.get('AddrFlno')) + address_line2 = '{} {}'.format(gstin_details.get('AddrBnm'), gstin_details.get('AddrSt')) + email_id = address.get('email_id') + phone = address.get('phone') + # get last 10 digit + phone = phone.replace(" ", "")[-10:] if phone else '' + + if state_code == 97: + # according to einvoice standard + pincode = 999999 + + return frappe._dict(dict( + gstin=gstin, legal_name=legal_name, location=location, + pincode=pincode, state_code=state_code, address_line1=address_line1, + address_line2=address_line2, email=email_id, phone=phone + )) + +def get_gstin_details(gstin): + if not hasattr(frappe.local, 'gstin_cache'): + frappe.local.gstin_cache = {} + + key = gstin + details = frappe.local.gstin_cache.get(key) + if details: + return details + + details = frappe.cache().hget('gstin_cache', key) + if details: + frappe.local.gstin_cache[key] = details + return details + + if not details: + return GSPConnector.get_gstin_details(gstin) + +def get_overseas_address_details(address_name): + address_title, address_line1, address_line2, city, phone, email_id = frappe.db.get_value( + 'Address', address_name, ['address_title', 'address_line1', 'address_line2', 'city', 'phone', 'email_id'] + ) + + return frappe._dict(dict( + gstin='URP', legal_name=address_title, address_line1=address_line1, + address_line2=address_line2, email=email_id, phone=phone, + pincode=999999, state_code=96, place_of_supply=96, location=city + )) + +def get_item_list(invoice): + item_list = [] + + for d in invoice.items: + einvoice_item_schema = read_json('einv_item_template') + item = frappe._dict({}) + item.update(d.as_dict()) + + item.sr_no = d.idx + item.qty = abs(item.qty) + item.description = d.item_name + item.taxable_value = abs(item.base_net_amount) + item.discount_amount = abs(item.discount_amount * item.qty) + item.unit_rate = abs(item.base_price_list_rate) if item.discount_amount else abs(item.base_net_rate) + item.gross_amount = abs(item.unit_rate * item.qty) + + item.batch_expiry_date = frappe.db.get_value('Batch', d.batch_no, 'expiry_date') if d.batch_no else None + item.batch_expiry_date = format_date(item.batch_expiry_date, 'dd/mm/yyyy') if item.batch_expiry_date else None + item.is_service_item = 'N' if frappe.db.get_value('Item', d.item_code, 'is_stock_item') else 'Y' + + item = update_item_taxes(invoice, item) + + item.total_value = abs( + item.taxable_value + item.igst_amount + item.sgst_amount + + item.cgst_amount + item.cess_amount + item.cess_nadv_amount + item.other_charges + ) + einv_item = einvoice_item_schema.format(item=item) + item_list.append(einv_item) + + return ', '.join(item_list) + +def update_item_taxes(invoice, item): + gst_accounts = get_gst_accounts(invoice.company) + gst_accounts_list = [d for accounts in gst_accounts.values() for d in accounts if d] + + for attr in [ + 'tax_rate', 'cess_rate', 'cess_nadv_amount', + 'cgst_amount', 'sgst_amount', 'igst_amount', + 'cess_amount', 'cess_nadv_amount', 'other_charges' + ]: + item[attr] = 0 + + for t in invoice.taxes: + item_tax_detail = json.loads(t.item_wise_tax_detail).get(item.item_code) + if t.account_head in gst_accounts_list: + if t.account_head in gst_accounts.cess_account: + if t.charge_type == 'On Item Quantity': + item.cess_nadv_amount += abs(item_tax_detail[1]) + else: + item.cess_rate += item_tax_detail[0] + item.cess_amount += abs(item_tax_detail[1]) + elif t.account_head in gst_accounts.igst_account: + item.tax_rate += item_tax_detail[0] + item.igst_amount += abs(item_tax_detail[1]) + elif t.account_head in gst_accounts.sgst_account: + item.tax_rate += item_tax_detail[0] + item.sgst_amount += abs(item_tax_detail[1]) + elif t.account_head in gst_accounts.cgst_account: + item.tax_rate += item_tax_detail[0] + item.cgst_amount += abs(item_tax_detail[1]) + + return item + +def get_invoice_value_details(invoice): + invoice_value_details = frappe._dict(dict()) + invoice_value_details.base_net_total = abs(invoice.base_net_total) + invoice_value_details.invoice_discount_amt = invoice.discount_amount if invoice.discount_amount and invoice.discount_amount > 0 else 0 + # discount amount cannnot be -ve in an e-invoice, so if -ve include discount in round_off + invoice_value_details.round_off = invoice.rounding_adjustment - (invoice.discount_amount if invoice.discount_amount and invoice.discount_amount < 0 else 0) + disable_rounded = frappe.db.get_single_value('Global Defaults', 'disable_rounded_total') + invoice_value_details.base_grand_total = abs(invoice.base_grand_total) if disable_rounded else abs(invoice.base_rounded_total) + invoice_value_details.grand_total = abs(invoice.grand_total) if disable_rounded else abs(invoice.rounded_total) + + invoice_value_details = update_invoice_taxes(invoice, invoice_value_details) + + return invoice_value_details + +def update_invoice_taxes(invoice, invoice_value_details): + gst_accounts = get_gst_accounts(invoice.company) + gst_accounts_list = [d for accounts in gst_accounts.values() for d in accounts if d] + + invoice_value_details.total_cgst_amt = 0 + invoice_value_details.total_sgst_amt = 0 + invoice_value_details.total_igst_amt = 0 + invoice_value_details.total_cess_amt = 0 + invoice_value_details.total_other_charges = 0 + for t in invoice.taxes: + if t.account_head in gst_accounts_list: + if t.account_head in gst_accounts.cess_account: + invoice_value_details.total_cess_amt += abs(t.base_tax_amount_after_discount_amount) + elif t.account_head in gst_accounts.igst_account: + invoice_value_details.total_igst_amt += abs(t.base_tax_amount_after_discount_amount) + elif t.account_head in gst_accounts.sgst_account: + invoice_value_details.total_sgst_amt += abs(t.base_tax_amount_after_discount_amount) + elif t.account_head in gst_accounts.cgst_account: + invoice_value_details.total_cgst_amt += abs(t.base_tax_amount_after_discount_amount) + else: + invoice_value_details.total_other_charges += abs(t.base_tax_amount_after_discount_amount) + + return invoice_value_details + +def get_payment_details(invoice): + payee_name = invoice.company + mode_of_payment = ', '.join([d.mode_of_payment for d in invoice.payments]) + paid_amount = invoice.base_paid_amount + outstanding_amount = invoice.outstanding_amount + + return frappe._dict(dict( + payee_name=payee_name, mode_of_payment=mode_of_payment, + paid_amount=paid_amount, outstanding_amount=outstanding_amount + )) + +def get_return_doc_reference(invoice): + invoice_date = frappe.db.get_value('Sales Invoice', invoice.return_against, 'posting_date') + return frappe._dict(dict( + invoice_name=invoice.return_against, invoice_date=format_date(invoice_date, 'dd/mm/yyyy') + )) + +def get_eway_bill_details(invoice): + if invoice.is_return: + frappe.throw(_('E-Way Bill cannot be generated for Credit Notes & Debit Notes'), title=_('E Invoice Validation Failed')) + + mode_of_transport = { '': '', 'Road': '1', 'Air': '2', 'Rail': '3', 'Ship': '4' } + vehicle_type = { 'Regular': 'R', 'Over Dimensional Cargo (ODC)': 'O' } + + return frappe._dict(dict( + gstin=invoice.gst_transporter_id, + name=invoice.transporter_name, + mode_of_transport=mode_of_transport[invoice.mode_of_transport], + distance=invoice.distance or 0, + document_name=invoice.lr_no, + document_date=format_date(invoice.lr_date, 'dd/mm/yyyy'), + vehicle_no=invoice.vehicle_no, + vehicle_type=vehicle_type[invoice.gst_vehicle_type] + )) + +def make_einvoice(invoice): + schema = read_json('einv_template') + + transaction_details = get_transaction_details(invoice) + item_list = get_item_list(invoice) + doc_details = get_doc_details(invoice) + invoice_value_details = get_invoice_value_details(invoice) + seller_details = get_party_details(invoice.company_address) + + if invoice.gst_category == 'Overseas': + buyer_details = get_overseas_address_details(invoice.customer_address) + else: + buyer_details = get_party_details(invoice.customer_address) + place_of_supply = get_place_of_supply(invoice, invoice.doctype) or invoice.billing_address_gstin + place_of_supply = place_of_supply[:2] + buyer_details.update(dict(place_of_supply=place_of_supply)) + + shipping_details = payment_details = prev_doc_details = eway_bill_details = frappe._dict({}) + if invoice.shipping_address_name and invoice.customer_address != invoice.shipping_address_name: + shipping_details = get_party_details(invoice.shipping_address_name) + + if invoice.is_pos and invoice.base_paid_amount: + payment_details = get_payment_details(invoice) + + if invoice.is_return and invoice.return_against: + prev_doc_details = get_return_doc_reference(invoice) + + if invoice.transporter: + eway_bill_details = get_eway_bill_details(invoice) + + # not yet implemented + dispatch_details = period_details = export_details = frappe._dict({}) + + einvoice = schema.format( + transaction_details=transaction_details, doc_details=doc_details, dispatch_details=dispatch_details, + seller_details=seller_details, buyer_details=buyer_details, shipping_details=shipping_details, + item_list=item_list, invoice_value_details=invoice_value_details, payment_details=payment_details, + period_details=period_details, prev_doc_details=prev_doc_details, + export_details=export_details, eway_bill_details=eway_bill_details + ) + einvoice = json.loads(einvoice) + + validations = json.loads(read_json('einv_validation')) + errors = validate_einvoice(validations, einvoice) + if errors: + message = "\n".join([ + "E Invoice: ", json.dumps(einvoice, indent=4), + "-" * 50, + "Errors: ", json.dumps(errors, indent=4) + ]) + frappe.log_error(title="E Invoice Validation Failed", message=message) + frappe.throw(errors, title=_('E Invoice Validation Failed'), as_list=1) + + return einvoice + +def validate_einvoice(validations, einvoice, errors=[]): + for fieldname, field_validation in validations.items(): + value = einvoice.get(fieldname, None) + if not value or value == "None": + # remove keys with empty values + einvoice.pop(fieldname, None) + continue + + value_type = field_validation.get("type").lower() + if value_type in ['object', 'array']: + child_validations = field_validation.get('properties') + + if isinstance(value, list): + for d in value: + validate_einvoice(child_validations, d, errors) + if not d: + # remove empty dicts + einvoice.pop(fieldname, None) + else: + validate_einvoice(child_validations, value, errors) + if not value: + # remove empty dicts + einvoice.pop(fieldname, None) + continue + + # convert to int or str + if value_type == 'string': + einvoice[fieldname] = str(value) + elif value_type == 'number': + is_integer = '.' not in str(field_validation.get('maximum')) + einvoice[fieldname] = flt(value, 2) if not is_integer else cint(value) + value = einvoice[fieldname] + + max_length = field_validation.get('maxLength') + minimum = flt(field_validation.get('minimum')) + maximum = flt(field_validation.get('maximum')) + pattern_str = field_validation.get('pattern') + pattern = re.compile(pattern_str or '') + + label = field_validation.get('description') or fieldname + + if value_type == 'string' and len(value) > max_length: + errors.append(_('{} should not exceed {} characters').format(label, max_length)) + if value_type == 'number' and (value > maximum or value < minimum): + errors.append(_('{} {} should be between {} and {}').format(label, value, minimum, maximum)) + if pattern_str and not pattern.match(value): + errors.append(field_validation.get('validationMsg')) + + return errors + +class RequestFailed(Exception): pass + +class GSPConnector(): + def __init__(self, doctype=None, docname=None): + self.e_invoice_settings = frappe.get_cached_doc('E Invoice Settings') + self.invoice = frappe.get_cached_doc(doctype, docname) if doctype and docname else None + self.credentials = self.get_credentials() + + self.base_url = 'https://gsp.adaequare.com/' + self.authenticate_url = self.base_url + 'gsp/authenticate?grant_type=token' + self.gstin_details_url = self.base_url + 'test/enriched/ei/api/master/gstin' + self.generate_irn_url = self.base_url + 'test/enriched/ei/api/invoice' + self.irn_details_url = self.base_url + 'test/enriched/ei/api/invoice/irn' + self.cancel_irn_url = self.base_url + 'test/enriched/ei/api/invoice/cancel' + self.cancel_ewaybill_url = self.base_url + '/test/enriched/ei/api/ewayapi' + self.generate_ewaybill_url = self.base_url + 'test/enriched/ei/api/ewaybill' + + def get_credentials(self): + if self.invoice: + gstin = self.get_seller_gstin() + credentials = next(d for d in self.e_invoice_settings.credentials if d.gstin == gstin) + else: + credentials = self.e_invoice_settings.credentials[0] if self.e_invoice_settings.credentials else None + return credentials + + def get_seller_gstin(self): + gstin = self.invoice.company_gstin or frappe.db.get_value('Address', self.invoice.company_address, 'gstin') + if not gstin: + frappe.throw(_('Cannot retrieve Company GSTIN. Please select company address with valid GSTIN.')) + return gstin + + def get_auth_token(self): + if time_diff_in_seconds(self.e_invoice_settings.token_expiry, now_datetime()) < 150.0: + self.fetch_auth_token() + + return self.e_invoice_settings.auth_token + + def make_request(self, request_type, url, headers=None, data=None): + if request_type == 'post': + res = make_post_request(url, headers=headers, data=data) + else: + res = make_get_request(url, headers=headers, data=data) + + self.log_request(url, headers, data, res) + return res + + def log_request(self, url, headers, data, res): + headers.update({ 'password': self.credentials.password }) + request_log = frappe.get_doc({ + "doctype": "E Invoice Request Log", + "user": frappe.session.user, + "reference_invoice": self.invoice.name if self.invoice else None, + "url": url, + "headers": json.dumps(headers, indent=4) if headers else None, + "data": json.dumps(data, indent=4) if isinstance(data, dict) else data, + "response": json.dumps(res, indent=4) if res else None + }) + request_log.insert(ignore_permissions=True) + frappe.db.commit() + + def fetch_auth_token(self): + headers = { + 'gspappid': frappe.conf.einvoice_client_id, + 'gspappsecret': frappe.conf.einvoice_client_secret + } + res = {} + try: + res = self.make_request('post', self.authenticate_url, headers) + self.e_invoice_settings.auth_token = "{} {}".format(res.get('token_type'), res.get('access_token')) + self.e_invoice_settings.token_expiry = add_to_date(None, seconds=res.get('expires_in')) + self.e_invoice_settings.save() + + except Exception: + self.log_error(res) + self.raise_error(True) + + def get_headers(self): + return { + 'content-type': 'application/json', + 'user_name': self.credentials.username, + 'password': self.credentials.get_password(), + 'gstin': self.credentials.gstin, + 'authorization': self.get_auth_token(), + 'requestid': str(base64.b64encode(os.urandom(18))), + } + + def fetch_gstin_details(self, gstin): + headers = self.get_headers() + + try: + params = '?gstin={gstin}'.format(gstin=gstin) + res = self.make_request('get', self.gstin_details_url + params, headers) + if res.get('success'): + return res.get('result') + else: + self.log_error(res) + raise RequestFailed + + except RequestFailed: + self.raise_error() + + except Exception: + self.log_error() + self.raise_error(True) + + @staticmethod + def get_gstin_details(gstin): + '''fetch and cache GSTIN details''' + if not hasattr(frappe.local, 'gstin_cache'): + frappe.local.gstin_cache = {} + + key = gstin + gsp_connector = GSPConnector() + details = gsp_connector.fetch_gstin_details(gstin) + + frappe.local.gstin_cache[key] = details + frappe.cache().hset('gstin_cache', key, details) + return details + + def generate_irn(self): + headers = self.get_headers() + einvoice = make_einvoice(self.invoice) + data = json.dumps(einvoice, indent=4) + + try: + res = self.make_request('post', self.generate_irn_url, headers, data) + if res.get('success'): + self.set_einvoice_data(res.get('result')) + + elif '2150' in res.get('message'): + # IRN already generated but not updated in invoice + # Extract the IRN from the response description and fetch irn details + irn = res.get('result')[0].get('Desc').get('Irn') + irn_details = self.get_irn_details(irn) + if irn_details: + self.set_einvoice_data(irn_details) + else: + raise RequestFailed('IRN has already been generated for the invoice but cannot fetch details for the it. \ + Contact ERPNext support to resolve the issue.') + + else: + raise RequestFailed + + except RequestFailed: + errors = self.sanitize_error_message(res.get('message')) + self.raise_error(errors=errors) + + except Exception: + self.log_error(data) + self.raise_error(True) + + def get_irn_details(self, irn): + headers = self.get_headers() + + try: + params = '?irn={irn}'.format(irn=irn) + res = self.make_request('get', self.irn_details_url + params, headers) + if res.get('success'): + return res.get('result') + else: + raise RequestFailed + + except RequestFailed: + errors = self.sanitize_error_message(res.get('message')) + self.raise_error(errors=errors) + + except Exception: + self.log_error() + self.raise_error(True) + + def cancel_irn(self, irn, reason, remark): + headers = self.get_headers() + data = json.dumps({ + 'Irn': irn, + 'Cnlrsn': reason, + 'Cnlrem': remark + }, indent=4) + + try: + res = self.make_request('post', self.cancel_irn_url, headers, data) + if res.get('success'): + self.invoice.irn_cancelled = 1 + self.invoice.flags.updater_reference = { + 'doctype': self.invoice.doctype, + 'docname': self.invoice.name, + 'label': _('IRN Cancelled - {}').format(remark) + } + self.update_invoice() + + else: + raise RequestFailed + + except RequestFailed: + errors = self.sanitize_error_message(res.get('message')) + self.raise_error(errors=errors) + + except Exception: + self.log_error(data) + self.raise_error(True) + + def generate_eway_bill(self, **kwargs): + args = frappe._dict(kwargs) + + headers = self.get_headers() + eway_bill_details = get_eway_bill_details(args) + data = json.dumps({ + 'Irn': args.irn, + 'Distance': cint(eway_bill_details.distance), + 'TransMode': eway_bill_details.mode_of_transport, + 'TransId': eway_bill_details.gstin, + 'TransName': eway_bill_details.transporter, + 'TrnDocDt': eway_bill_details.document_date, + 'TrnDocNo': eway_bill_details.document_name, + 'VehNo': eway_bill_details.vehicle_no, + 'VehType': eway_bill_details.vehicle_type + }, indent=4) + + try: + res = self.make_request('post', self.generate_ewaybill_url, headers, data) + if res.get('success'): + self.invoice.ewaybill = res.get('result').get('EwbNo') + self.invoice.eway_bill_cancelled = 0 + self.invoice.update(args) + self.invoice.flags.updater_reference = { + 'doctype': self.invoice.doctype, + 'docname': self.invoice.name, + 'label': _('E-Way Bill Generated') + } + self.update_invoice() + + else: + raise RequestFailed + + except RequestFailed: + errors = self.sanitize_error_message(res.get('message')) + self.raise_error(errors=errors) + + except Exception: + self.log_error(data) + self.raise_error(True) + + def cancel_eway_bill(self, eway_bill, reason, remark): + headers = self.get_headers() + data = json.dumps({ + 'ewbNo': eway_bill, + 'cancelRsnCode': reason, + 'cancelRmrk': remark + }, indent=4) + + try: + res = self.make_request('post', self.cancel_ewaybill_url, headers, data) + if res.get('success'): + self.invoice.ewaybill = '' + self.invoice.eway_bill_cancelled = 1 + self.invoice.flags.updater_reference = { + 'doctype': self.invoice.doctype, + 'docname': self.invoice.name, + 'label': _('E-Way Bill Cancelled - {}').format(remark) + } + self.update_invoice() + + else: + raise RequestFailed + + except RequestFailed: + errors = self.sanitize_error_message(res.get('message')) + self.raise_error(errors=errors) + + except Exception: + self.log_error(data) + self.raise_error(True) + + def sanitize_error_message(self, message): + ''' + On validation errors, response message looks something like this: + message = '2174 : For inter-state transaction, CGST and SGST amounts are not applicable; only IGST amount is applicable, + 3095 : Supplier GSTIN is inactive' + we search for string between ':' to extract the error messages + errors = [ + ': For inter-state transaction, CGST and SGST amounts are not applicable; only IGST amount is applicable, 3095 ', + ': Test' + ] + then we trim down the message by looping over errors + ''' + errors = re.findall(': [^:]+', message) + for idx, e in enumerate(errors): + # remove colons + errors[idx] = errors[idx].replace(':', '').strip() + # if not last + if idx != len(errors) - 1: + # remove last 7 chars eg: ', 3095 ' + errors[idx] = errors[idx][:-6] + + return errors + + def log_error(self, data={}): + if not isinstance(data, dict): + data = json.loads(data) + + seperator = "--" * 50 + err_tb = traceback.format_exc() + err_msg = str(sys.exc_info()[1]) + data = json.dumps(data, indent=4) + + message = "\n".join([ + "Error", err_msg, seperator, + "Data:", data, seperator, + "Exception:", err_tb + ]) + frappe.log_error(title=_('E Invoice Request Failed'), message=message) + + def raise_error(self, raise_exception=False, errors=[]): + title = _('E Invoice Request Failed') + if errors: + frappe.throw(errors, title=title, as_list=1) + else: + link_to_error_list = 'Error Log' + frappe.msgprint( + _('An error occurred while making e-invoicing request. Please check {} for more information.').format(link_to_error_list), + title=title, + raise_exception=raise_exception, + indicator='red' + ) + + def set_einvoice_data(self, res): + enc_signed_invoice = res.get('SignedInvoice') + dec_signed_invoice = jwt.decode(enc_signed_invoice, verify=False)['data'] + + self.invoice.irn = res.get('Irn') + self.invoice.ewaybill = res.get('EwbNo') + self.invoice.signed_einvoice = dec_signed_invoice + self.invoice.signed_qr_code = res.get('SignedQRCode') + + self.attach_qrcode_image() + + self.invoice.flags.updater_reference = { + 'doctype': self.invoice.doctype, + 'docname': self.invoice.name, + 'label': _('IRN Generated') + } + self.update_invoice() + + def attach_qrcode_image(self): + qrcode = self.invoice.signed_qr_code + doctype = self.invoice.doctype + docname = self.invoice.name + + _file = frappe.new_doc('File') + _file.update({ + 'file_name': f'QRCode_{docname}.png', + 'attached_to_doctype': doctype, + 'attached_to_name': docname, + 'content': 'qrcode', + 'is_private': 1 + }) + _file.insert() + frappe.db.commit() + url = qrcreate(qrcode, error='L') + abs_file_path = os.path.abspath(_file.get_full_path()) + url.png(abs_file_path, scale=2, quiet_zone=1) + + self.invoice.qrcode_image = _file.file_url + + def update_invoice(self): + self.invoice.flags.ignore_validate_update_after_submit = True + self.invoice.flags.ignore_validate = True + self.invoice.save() + +@frappe.whitelist() +def get_einvoice(doctype, docname): + invoice = frappe.get_doc(doctype, docname) + return make_einvoice(invoice) + +@frappe.whitelist() +def generate_irn(doctype, docname): + gsp_connector = GSPConnector(doctype, docname) + gsp_connector.generate_irn() + +@frappe.whitelist() +def cancel_irn(doctype, docname, irn, reason, remark): + gsp_connector = GSPConnector(doctype, docname) + gsp_connector.cancel_irn(irn, reason, remark) + +@frappe.whitelist() +def generate_eway_bill(doctype, docname, **kwargs): + gsp_connector = GSPConnector(doctype, docname) + gsp_connector.generate_eway_bill(**kwargs) + +@frappe.whitelist() +def cancel_eway_bill(doctype, docname, eway_bill, reason, remark): + gsp_connector = GSPConnector(doctype, docname) + gsp_connector.cancel_eway_bill(eway_bill, reason, remark) \ No newline at end of file diff --git a/erpnext/regional/india/setup.py b/erpnext/regional/india/setup.py index cbcd6e3203..5321a9a3b5 100644 --- a/erpnext/regional/india/setup.py +++ b/erpnext/regional/india/setup.py @@ -87,7 +87,7 @@ def add_custom_roles_for_reports(): )).insert() def add_permissions(): - for doctype in ('GST HSN Code', 'GST Settings', 'GSTR 3B Report', 'Lower Deduction Certificate'): + for doctype in ('GST HSN Code', 'GST Settings', 'GSTR 3B Report', 'Lower Deduction Certificate', 'E Invoice Settings'): add_permission(doctype, 'All', 0) for role in ('Accounts Manager', 'Accounts User', 'System Manager'): add_permission(doctype, role, 0) @@ -103,9 +103,10 @@ def add_permissions(): def add_print_formats(): frappe.reload_doc("regional", "print_format", "gst_tax_invoice") frappe.reload_doc("accounts", "print_format", "gst_pos_invoice") + frappe.reload_doc("accounts", "print_format", "GST E-Invoice") frappe.db.sql(""" update `tabPrint Format` set disabled = 0 where - name in('GST POS Invoice', 'GST Tax Invoice') """) + name in('GST POS Invoice', 'GST Tax Invoice', 'GST E-Invoice') """) def make_custom_fields(update=True): hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC', @@ -351,7 +352,6 @@ def make_custom_fields(update=True): 'label': 'Mode of Transport', 'fieldtype': 'Select', 'options': '\nRoad\nAir\nRail\nShip', - 'default': 'Road', 'insert_after': 'transporter_name', 'print_hide': 1, 'translatable': 0 @@ -388,13 +388,34 @@ def make_custom_fields(update=True): 'fieldname': 'ewaybill', 'label': 'E-Way Bill No.', 'fieldtype': 'Data', - 'depends_on': 'eval:(doc.docstatus === 1)', + 'depends_on': 'eval:((doc.docstatus === 1 || doc.ewaybill) && doc.eway_bill_cancelled === 0)', 'allow_on_submit': 1, 'insert_after': 'tax_id', 'translatable': 0 } ] + si_einvoice_fields = [ + dict(fieldname='irn', label='IRN', fieldtype='Data', read_only=1, insert_after='customer', no_copy=1, print_hide=1, + depends_on='eval:in_list(["Registered Regular", "SEZ", "Overseas", "Deemed Export"], doc.gst_category) && doc.irn_cancelled === 0'), + + dict(fieldname='ack_no', label='Ack. No.', fieldtype='Data', read_only=1, hidden=1, insert_after='irn', no_copy=1, print_hide=1), + + dict(fieldname='ack_date', label='Ack. Date', fieldtype='Data', read_only=1, hidden=1, insert_after='ack_no', no_copy=1, print_hide=1), + + dict(fieldname='irn_cancelled', label='IRN Cancelled', fieldtype='Check', no_copy=1, print_hide=1, + depends_on='eval:(doc.irn_cancelled === 1)', read_only=1, allow_on_submit=1, insert_after='customer'), + + dict(fieldname='eway_bill_cancelled', label='E-Way Bill Cancelled', fieldtype='Check', no_copy=1, print_hide=1, + depends_on='eval:(doc.eway_bill_cancelled === 1)', read_only=1, allow_on_submit=1, insert_after='customer'), + + dict(fieldname='signed_einvoice', fieldtype='Code', options='JSON', hidden=1, no_copy=1, print_hide=1, read_only=1), + + dict(fieldname='signed_qr_code', fieldtype='Code', options='JSON', hidden=1, no_copy=1, print_hide=1, read_only=1), + + dict(fieldname='qrcode_image', label='QRCode', fieldtype='Attach Image', hidden=1, no_copy=1, print_hide=1, read_only=1) + ] + custom_fields = { 'Address': [ dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data', @@ -407,7 +428,7 @@ def make_custom_fields(update=True): 'Purchase Invoice': purchase_invoice_gst_category + invoice_gst_fields + purchase_invoice_itc_fields + purchase_invoice_gst_fields, 'Purchase Order': purchase_invoice_gst_fields, 'Purchase Receipt': purchase_invoice_gst_fields, - 'Sales Invoice': sales_invoice_gst_category + invoice_gst_fields + sales_invoice_shipping_fields + sales_invoice_gst_fields + si_ewaybill_fields, + 'Sales Invoice': sales_invoice_gst_category + invoice_gst_fields + sales_invoice_shipping_fields + sales_invoice_gst_fields + si_ewaybill_fields + si_einvoice_fields, 'Delivery Note': sales_invoice_gst_fields + ewaybill_fields + sales_invoice_shipping_fields, 'Sales Order': sales_invoice_gst_fields, 'Tax Category': inter_state_gst_field, diff --git a/requirements.txt b/requirements.txt index c4f9171fca..c448ebca2d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,3 +12,4 @@ taxjar==1.9.0 tweepy==3.8.0 Unidecode==1.1.1 WooCommerce==2.1.1 +pycryptodome==3.9.8 \ No newline at end of file From af1af925ac9e0997553c784f7d5dc5f3485d115b Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Sat, 26 Dec 2020 11:09:46 +0530 Subject: [PATCH 228/449] chore: Added change log (#24213) --- erpnext/change_log/v13/v13_0_0-beta_6.md | 151 +++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 erpnext/change_log/v13/v13_0_0-beta_6.md diff --git a/erpnext/change_log/v13/v13_0_0-beta_6.md b/erpnext/change_log/v13/v13_0_0-beta_6.md new file mode 100644 index 0000000000..4c6d9c28cf --- /dev/null +++ b/erpnext/change_log/v13/v13_0_0-beta_6.md @@ -0,0 +1,151 @@ +### Version 13.0.0 Beta 6 Release Notes + +#### Features and Enhancements + +- GST E-invoicing for India ([#23455](https://github.com/frappe/erpnext/pull/23455)) +- Multi-currency payroll ([#23519](https://github.com/frappe/erpnext/pull/23519)) +- Allow back-dated stock transactions and repost item costing via background job ([#24183](https://github.com/frappe/erpnext/pull/24183)) +- Introduced telephony feature using Twillio ([#24032](https://github.com/frappe/erpnext/pull/24032)) +- Shipment Doctype ([#22914](https://github.com/frappe/erpnext/pull/22914)) +- Leave policy assignment ([#23112](https://github.com/frappe/erpnext/pull/23112)) +- UAE VAT 201 Report ([#23447](https://github.com/frappe/erpnext/pull/23447)) +- Return tracking in PR/DN ([#22859](https://github.com/frappe/erpnext/pull/22859)) +- Close Production Plan ([#23728](https://github.com/frappe/erpnext/pull/23728)) +- Quality Inspection on Job Card ([#23964](https://github.com/frappe/erpnext/pull/23964)) +- Inpatient Medication Orders Script Report ([#23984](https://github.com/frappe/erpnext/pull/23984)) +- Leave type with partial payment ([#23173](https://github.com/frappe/erpnext/pull/23173)) +- Formula based Quality Inspection ([#23916](https://github.com/frappe/erpnext/pull/23916)) +- Link to Material Requests in Tools section for RFQ and Supplier Quotation ([#23429](https://github.com/frappe/erpnext/pull/23429)) +- Hide images & auto add item checkbox ([#24102](https://github.com/frappe/erpnext/pull/24102)) +- In reports get item details from Item instead of the transactions ([#24082](https://github.com/frappe/erpnext/pull/24082)) +- sales order status filter added for production plan ([#23805](https://github.com/frappe/erpnext/pull/23805)) +- Button to create Stock Entry for Drug Shortage ([#24012](https://github.com/frappe/erpnext/pull/24012)) +- Sync old shopify orders ([#23841](https://github.com/frappe/erpnext/pull/23841)) +- Added column cost center in Accounts Receivable report ([#23835](https://github.com/frappe/erpnext/pull/23835)) +- Added jinja templating in Contract Template ([#24046](https://github.com/frappe/erpnext/pull/24046)) +- Consider Holiday List in Student Leave Application and Attendance ([#23388](https://github.com/frappe/erpnext/pull/23388)) +- Make account number length configurable ([#23845](https://github.com/frappe/erpnext/pull/23845)) +- Add communication channel to communication medium ([#23793](https://github.com/frappe/erpnext/pull/23793)) + +#### Fixes + +- Loan disbursement amount validation ([#24000](https://github.com/frappe/erpnext/pull/24000)) +- Making company address read-only in delivery note ([#23890](https://github.com/frappe/erpnext/pull/23890)) +- BOM stock report color showing always red ([#23994](https://github.com/frappe/erpnext/pull/23994)) +- Added filter for customer field in Issue ([#24051](https://github.com/frappe/erpnext/pull/24051)) +- Added project link in timesheet form ([#23764](https://github.com/frappe/erpnext/pull/23764)) +- Update integrations desk page ([#23767](https://github.com/frappe/erpnext/pull/23767)) +- Place of supply change on address change ([#23941](https://github.com/frappe/erpnext/pull/23941)) +- TDS calculation, skip invoices with "Apply Tax Withholding Amount" has disabled ([#23672](https://github.com/frappe/erpnext/pull/23672)) +- Auto fetch serial nos with modified conversion factor ([#23854](https://github.com/frappe/erpnext/pull/23854)) +- Default cost center in item master not set in stock entry ([#23877](https://github.com/frappe/erpnext/pull/23877)) +- Incorrect de-link serial no and batch ([#23947](https://github.com/frappe/erpnext/pull/23947)) +- Accounting for internal transfer invoices within same company ([#24021](https://github.com/frappe/erpnext/pull/24021)) +- Multiple pricing rule with margin type as Percentage is not working ([#24205](https://github.com/frappe/erpnext/pull/24205)) +- Added Purchase Order to Global Search ([#24055](https://github.com/frappe/erpnext/pull/24055)) +- Cannot expand row in update items dialog ([#23839](https://github.com/frappe/erpnext/pull/23839)) +- Maintain stock can't be changed it there is product bundle ([#23989](https://github.com/frappe/erpnext/pull/23989)) +- SO to PO Mapping Issue ([#23820](https://github.com/frappe/erpnext/pull/23820)) +- Asset with value zero doesn't show up in fixed asset register ([#24091](https://github.com/frappe/erpnext/pull/24091)) +- Cannot save customer email & phone ([#23797](https://github.com/frappe/erpnext/pull/23797)) +- Incorrect balance value in stock balance report ([#24048](https://github.com/frappe/erpnext/pull/24048)) +- Payment Terms not fetched in Purchase Invoice from Purchase Receipt ([#23735](https://github.com/frappe/erpnext/pull/23735)) +- Fix for LMS Sign Up link ([#23743](https://github.com/frappe/erpnext/pull/23743)) +- Incorrect stock quantity if 'Allow Multiple Material Consumption… ([#24116](https://github.com/frappe/erpnext/pull/24116)) +- Added wrong absent days calculation in salary slip ([#23897](https://github.com/frappe/erpnext/pull/23897)) +- Purchase receipt to purchase invoice bill date mapping ([#23967](https://github.com/frappe/erpnext/pull/23967)) +- Overriding po ([#24022](https://github.com/frappe/erpnext/pull/24022)) +- Do not cancel reference document on Quality Inspection cancellation ([#24198](https://github.com/frappe/erpnext/pull/24198)) +- Get formatted value in 'taxes' print template ([#24035](https://github.com/frappe/erpnext/pull/24035)) +- Don't overrule Item Price via Pricing Rule Rate if 0 ([#23636](https://github.com/frappe/erpnext/pull/23636)) +- Job card error handling for operations field ([#23991](https://github.com/frappe/erpnext/pull/23991)) +- Validation for journal entry with 0 debit and credit values ([#23975](https://github.com/frappe/erpnext/pull/23975)) +- Check if customer exists in product listing ([#24030](https://github.com/frappe/erpnext/pull/24030)) +- Asset finance book posting date fix ([#23778](https://github.com/frappe/erpnext/pull/23778)) +- Same source and target tables in Status Updater's update query ([#24110](https://github.com/frappe/erpnext/pull/24110)) +- Asset finance book depreciation posting date fix ([#23833](https://github.com/frappe/erpnext/pull/23833)) +- Ignore exception during leave ledger creation from patch ([#24005](https://github.com/frappe/erpnext/pull/24005)) +- Added link of bank reconciliation and clearance in accounting desk page ([#23850](https://github.com/frappe/erpnext/pull/23850)) +- Sales invoice add button from sales order dashboard ([#24077](https://github.com/frappe/erpnext/pull/24077)) +- Incorrect calculation for consumed qty for subcontract item ([#23257](https://github.com/frappe/erpnext/pull/23257)) +- Incorrect required_qty in Production Planning Report ([#24074](https://github.com/frappe/erpnext/pull/24074)) +- Email digest user not found ([#23949](https://github.com/frappe/erpnext/pull/23949)) +- Delete Receive at Warehouse entry on cancellation of Send to War… ([#24115](https://github.com/frappe/erpnext/pull/24115)) +- Added TDS Payable account number and an error message ([#24065](https://github.com/frappe/erpnext/pull/24065)) +- Override field_map for job card gantt ([#24155](https://github.com/frappe/erpnext/pull/24155)) +- Old shopify order syncing date ([#23990](https://github.com/frappe/erpnext/pull/23990)) +- Shipping chanrges not sync in erpnext from shopify ([#24114](https://github.com/frappe/erpnext/pull/24114)) +- GSTR B2C report ([#24039](https://github.com/frappe/erpnext/pull/24039)) +- Ignore cancelled entries in stock balance report ([#23757](https://github.com/frappe/erpnext/pull/23757)) +- Stock ageing report not working ([#23923](https://github.com/frappe/erpnext/pull/23923)) +- Incorrect assign to in Maintenance Schedule ([#23831](https://github.com/frappe/erpnext/pull/23831)) +- Improve UX of DATEV report ([#23892](https://github.com/frappe/erpnext/pull/23892)) +- Set SLA variance in seconds for Duration fieldtype ([#23765](https://github.com/frappe/erpnext/pull/23765)) +- dDouble exception in payroll ([#24078](https://github.com/frappe/erpnext/pull/24078)) +- Make asset dashboard charts public ([#23751](https://github.com/frappe/erpnext/pull/23751)) +- Don't copy terms and discount from SO to PO ([#23903](https://github.com/frappe/erpnext/pull/23903)) +- Ignore doctypes on company transaction delete ([#23864](https://github.com/frappe/erpnext/pull/23864)) +- Error handling in Upload Attendance ([#23907](https://github.com/frappe/erpnext/pull/23907)) +- Tax template update on customer address change ([#24160](https://github.com/frappe/erpnext/pull/24160)) +- Not able to save bom ([#23910](https://github.com/frappe/erpnext/pull/23910)) +- Enable Allow Auto Repeat for standard doctypes having auto_repeat field ([#23776](https://github.com/frappe/erpnext/pull/23776)) +- Place of Supply fix in Sales Invoices ([#23785](https://github.com/frappe/erpnext/pull/23785)) +- Opening invoices in GSTR-1 report ([#24117](https://github.com/frappe/erpnext/pull/24117)) +- Add check for allowing access to european region ([#23770](https://github.com/frappe/erpnext/pull/23770)) +- Partial serial no return issue ([#24208](https://github.com/frappe/erpnext/pull/24208)) +- Multiple pos issues ([#23347](https://github.com/frappe/erpnext/pull/23347)) +- Import taxjar globally in the taxjar_integration module ([#24027](https://github.com/frappe/erpnext/pull/24027)) +- Payroll attendance error ([#23887](https://github.com/frappe/erpnext/pull/23887)) +- Cannot add items to cart ([#23796](https://github.com/frappe/erpnext/pull/23796)) +- Show tax amount in base currencies ([#24069](https://github.com/frappe/erpnext/pull/24069)) +- Loan application link on creating loan ([#23937](https://github.com/frappe/erpnext/pull/23937)) +- Added shipment link in delivery note dashboard ([#24210](https://github.com/frappe/erpnext/pull/24210)) +- POS item search includes non stock items ([#23914](https://github.com/frappe/erpnext/pull/23914)) +- Paid amount in Sales Invoice POS return resets to 0 ([#24057](https://github.com/frappe/erpnext/pull/24057)) +- Remove check for exempt_from_sales_tax ([#23870](https://github.com/frappe/erpnext/pull/23870)) +- Fiscal year can be shorter than 12 months ([#23838](https://github.com/frappe/erpnext/pull/23838)) +- Loan repayment type option remove ([#23582](https://github.com/frappe/erpnext/pull/23582)) +- Make contract template editable ([#23891](https://github.com/frappe/erpnext/pull/23891)) +- Item wise tax calculation ([#23744](https://github.com/frappe/erpnext/pull/23744)) +- Enabling track changes for stock settings ([#23982](https://github.com/frappe/erpnext/pull/23982)) +- Added link of bank reconciliation and clearance in accounting desk page ([#23809](https://github.com/frappe/erpnext/pull/23809)) +- Location data on Asset to use command(make_demo) ([#23825](https://github.com/frappe/erpnext/pull/23825)) +- Handle Account and Item None not found in Opening Invoice Creation Tool ([#23559](https://github.com/frappe/erpnext/pull/23559)) +- List index out of range on including UOM ([#23814](https://github.com/frappe/erpnext/pull/23814)) +- Showing error for wrong filters. ([#23726](https://github.com/frappe/erpnext/pull/23726)) +- Multiple subcontracting issues ([#23662](https://github.com/frappe/erpnext/pull/23662)) +- Sequence id override with workstation column ([#23810](https://github.com/frappe/erpnext/pull/23810)) +- Replaced formatdate -> format_date ([#23849](https://github.com/frappe/erpnext/pull/23849)) +- Test Payment Based on Leave Application (Travis) ([#24044](https://github.com/frappe/erpnext/pull/24044)) +- Leave policy dashboard fix and roles ([#24170](https://github.com/frappe/erpnext/pull/24170)) +- Budget test cases ([#23801](https://github.com/frappe/erpnext/pull/23801)) +- Handle for custom field IFSC code in Bank remittance report. ([#23905](https://github.com/frappe/erpnext/pull/23905)) +- Scan barcode does not update barcode item field in sales order ([#24090](https://github.com/frappe/erpnext/pull/24090)) +- Item price duplicate checking ([#23408](https://github.com/frappe/erpnext/pull/23408)) +- Tax template update on supplier change for India ([#24060](https://github.com/frappe/erpnext/pull/24060)) +- Consumed qty logic for subcontracted raw materials ([#23314](https://github.com/frappe/erpnext/pull/23314)) +- Finance book not getting added in journal Entry of asset value adjustment ([#24100](https://github.com/frappe/erpnext/pull/24100)) +- Fixed home desk page ([#24075](https://github.com/frappe/erpnext/pull/24075)) +- po_detail field has no value for subcontracted stock entry ([#23777](https://github.com/frappe/erpnext/pull/23777)) +- Set proper state code in ewaybill JSON when GST category is SEZ ([#23953](https://github.com/frappe/erpnext/pull/23953)) +- Copying po no when mapping doc ([#23729](https://github.com/frappe/erpnext/pull/23729)) +- Duplicate items validation for POS Invoice when allow multiple items is disabled ([#23896](https://github.com/frappe/erpnext/pull/23896)) +- POS register shows cancelled documents ([#23747](https://github.com/frappe/erpnext/pull/23747)) +- Subscription test case ([#23763](https://github.com/frappe/erpnext/pull/23763)) +- BOM stock report color issue ([#23980](https://github.com/frappe/erpnext/pull/23980)) +- Handle the "no leave_allocation found" case ([#23922](https://github.com/frappe/erpnext/pull/23922)) +- Filters for tax templates ([#23998](https://github.com/frappe/erpnext/pull/23998)) +- Do not allow Company as accounting dimension ([#23749](https://github.com/frappe/erpnext/pull/23749)) +- Validation for duplicate Tax Category ([#23978](https://github.com/frappe/erpnext/pull/23978)) +- Therapy plan and session fixes ([#23817](https://github.com/frappe/erpnext/pull/23817)) +- Correcting description field in taxes and charges for accounts with account number + account name ([#23836](https://github.com/frappe/erpnext/pull/23836)) +- Pricing rule with transaction not working for additional product ([#24053](https://github.com/frappe/erpnext/pull/24053)) +- Keyerror 'sourced_by_supplier' ([#24038](https://github.com/frappe/erpnext/pull/24038)) +- Validation for membership ([#23934](https://github.com/frappe/erpnext/pull/23934)) +- Inpatient Medication Order and Entry fixes ([#23799](https://github.com/frappe/erpnext/pull/23799)) +- Avoid using SQL query to get fiscal year dates ([#24050](https://github.com/frappe/erpnext/pull/24050)) +- Auto Statewise gst tax template ([#23832](https://github.com/frappe/erpnext/pull/23832)) +- POS profile has no attr 'show_only_available_items' ([#23758](https://github.com/frappe/erpnext/pull/23758)) +- On save sequence id column override with workstation ([#23812](https://github.com/frappe/erpnext/pull/23812)) +- Multiple pricing rules are not working on selling side ([#22711](https://github.com/frappe/erpnext/pull/22711)) +- Salary slip popup error ([#24192](https://github.com/frappe/erpnext/pull/24192)) \ No newline at end of file From d1d030b54a0375580b4139943aa9d61b576ef317 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Sat, 26 Dec 2020 15:15:51 +0550 Subject: [PATCH 229/449] bumped to version 13.0.0-beta.7 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 14d3563262..c108333e1a 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0-beta.6' +__version__ = '13.0.0-beta.7' def get_default_company(user=None): '''Get default company for user''' From a25cb9a563f468e6ea4072bae5ff03d54af6221a Mon Sep 17 00:00:00 2001 From: Karthikeyan S Date: Wed, 30 Dec 2020 19:41:00 +0530 Subject: [PATCH 230/449] fix(GST E Invoice): update live URLs for adaequare GSP (#24251) --- erpnext/regional/india/e_invoice/utils.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index cb92c42464..61fb88a21b 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -386,15 +386,15 @@ class GSPConnector(): self.invoice = frappe.get_cached_doc(doctype, docname) if doctype and docname else None self.credentials = self.get_credentials() - self.base_url = 'https://gsp.adaequare.com/' - self.authenticate_url = self.base_url + 'gsp/authenticate?grant_type=token' - self.gstin_details_url = self.base_url + 'test/enriched/ei/api/master/gstin' - self.generate_irn_url = self.base_url + 'test/enriched/ei/api/invoice' - self.irn_details_url = self.base_url + 'test/enriched/ei/api/invoice/irn' - self.cancel_irn_url = self.base_url + 'test/enriched/ei/api/invoice/cancel' - self.cancel_ewaybill_url = self.base_url + '/test/enriched/ei/api/ewayapi' - self.generate_ewaybill_url = self.base_url + 'test/enriched/ei/api/ewaybill' - + self.base_url = 'https://gsp.adaequare.com' + self.authenticate_url = self.base_url + '/gsp/authenticate?grant_type=token' + self.gstin_details_url = self.base_url + '/enriched/ei/api/master/gstin' + self.generate_irn_url = self.base_url + '/enriched/ei/api/invoice' + self.irn_details_url = self.base_url + '/enriched/ei/api/invoice/irn' + self.cancel_irn_url = self.base_url + '/enriched/ei/api/invoice/cancel' + self.cancel_ewaybill_url = self.base_url + '/enriched/ei/api/ewayapi' + self.generate_ewaybill_url = self.base_url + '/enriched/ei/api/ewaybill' + def get_credentials(self): if self.invoice: gstin = self.get_seller_gstin() From fc7a11e2aa4ba5d97354e3f6e2e4792e228b5705 Mon Sep 17 00:00:00 2001 From: Saqib Date: Thu, 31 Dec 2020 11:35:46 +0530 Subject: [PATCH 231/449] fix (e-invoicing): item & invoice value calculation (#24253) --- .../sales_invoice/test_sales_invoice.py | 63 +++++++++++++----- erpnext/patches.txt | 1 + .../patches/v12_0/setup_einvoice_fields.py | 1 + .../india/e_invoice/einv_template.json | 2 +- erpnext/regional/india/e_invoice/utils.py | 66 +++++++++---------- 5 files changed, 81 insertions(+), 52 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 3c681eeecf..eb223ee42c 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -1885,8 +1885,8 @@ class TestSalesInvoice(unittest.TestCase): "item_code": "_Test Item", "uom": "Nos", "warehouse": "_Test Warehouse - _TC", - "qty": 2, - "rate": 100, + "qty": 2000, + "rate": 12, "income_account": "Sales - _TC", "expense_account": "Cost of Goods Sold - _TC", "cost_center": "_Test Cost Center - _TC", @@ -1895,31 +1895,52 @@ class TestSalesInvoice(unittest.TestCase): "item_code": "_Test Item 2", "uom": "Nos", "warehouse": "_Test Warehouse - _TC", - "qty": 4, - "rate": 150, + "qty": 420, + "rate": 15, "income_account": "Sales - _TC", "expense_account": "Cost of Goods Sold - _TC", "cost_center": "_Test Cost Center - _TC", }) + si.discount_amount = 100 si.save() einvoice = make_einvoice(si) - total_item_ass_value = sum([d['AssAmt'] for d in einvoice['ItemList']]) - total_item_cgst_value = sum([d['CgstAmt'] for d in einvoice['ItemList']]) - total_item_sgst_value = sum([d['SgstAmt'] for d in einvoice['ItemList']]) - total_item_igst_value = sum([d['IgstAmt'] for d in einvoice['ItemList']]) - total_item_value = sum([d['TotItemVal'] for d in einvoice['ItemList']]) + total_item_ass_value = 0 + total_item_cgst_value = 0 + total_item_sgst_value = 0 + total_item_igst_value = 0 + total_item_value = 0 + + for item in einvoice['ItemList']: + total_item_ass_value += item['AssAmt'] + total_item_cgst_value += item['CgstAmt'] + total_item_sgst_value += item['SgstAmt'] + total_item_igst_value += item['IgstAmt'] + total_item_value += item['TotItemVal'] + + self.assertTrue(item['AssAmt'], item['TotAmt'] - item['Discount']) + self.assertTrue(item['TotItemVal'], item['AssAmt'] + item['CgstAmt'] + item['SgstAmt'] + item['IgstAmt']) + + value_details = einvoice['ValDtls'] self.assertEqual(einvoice['Version'], '1.1') - self.assertEqual(einvoice['ValDtls']['AssVal'], total_item_ass_value) - self.assertEqual(einvoice['ValDtls']['CgstVal'], total_item_cgst_value) - self.assertEqual(einvoice['ValDtls']['SgstVal'], total_item_sgst_value) - self.assertEqual(einvoice['ValDtls']['IgstVal'], total_item_igst_value) - self.assertEqual(einvoice['ValDtls']['TotInvVal'], total_item_value) + self.assertEqual(value_details['AssVal'], total_item_ass_value) + self.assertEqual(value_details['CgstVal'], total_item_cgst_value) + self.assertEqual(value_details['SgstVal'], total_item_sgst_value) + self.assertEqual(value_details['IgstVal'], total_item_igst_value) + + self.assertEqual( + value_details['TotInvVal'], + value_details['AssVal'] + value_details['CgstVal'] + + value_details['SgstVal'] + value_details['IgstVal'] + + value_details['OthChrg'] - value_details['Discount'] + ) + + self.assertEqual(value_details['TotInvVal'], si.base_grand_total) self.assertTrue(einvoice['EwbDtls']) -def make_sales_invoice_for_ewaybill(): +def make_test_address_for_ewaybill(): if not frappe.db.exists('Address', '_Test Address for Eway bill-Billing'): address = frappe.get_doc({ "address_line1": "_Test Address Line 1", @@ -1967,7 +1988,8 @@ def make_sales_invoice_for_ewaybill(): }) address.save() - + +def make_test_transporter_for_ewaybill(): if not frappe.db.exists('Supplier', '_Test Transporter'): frappe.get_doc({ "doctype": "Supplier", @@ -1978,12 +2000,17 @@ def make_sales_invoice_for_ewaybill(): "is_transporter": 1 }).insert() +def make_sales_invoice_for_ewaybill(): + make_test_address_for_ewaybill() + make_test_transporter_for_ewaybill() + gst_settings = frappe.get_doc("GST Settings") gst_account = frappe.get_all( "GST Account", fields=["cgst_account", "sgst_account", "igst_account"], - filters = {"company": "_Test Company"}) + filters = {"company": "_Test Company"} + ) if not gst_account: gst_settings.append("gst_accounts", { @@ -1995,7 +2022,7 @@ def make_sales_invoice_for_ewaybill(): gst_settings.save() - si = create_sales_invoice(do_not_save =1, rate = '60000') + si = create_sales_invoice(do_not_save=1, rate='60000') si.distance = 2000 si.company_address = "_Test Address for Eway bill-Billing" diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 5b37b38e68..894ee82b4c 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -712,6 +712,7 @@ erpnext.patches.v13_0.delete_old_sales_reports execute:frappe.delete_doc_if_exists("DocType", "Bank Reconciliation") erpnext.patches.v13_0.move_doctype_reports_and_notification_from_hr_to_payroll #22-06-2020 erpnext.patches.v13_0.move_payroll_setting_separately_from_hr_settings #22-06-2020 +execute:frappe.reload_doc("regional", "doctype", "e_invoice_settings") erpnext.patches.v13_0.check_is_income_tax_component #22-06-2020 erpnext.patches.v13_0.loyalty_points_entry_for_pos_invoice #22-07-2020 erpnext.patches.v12_0.add_taxjar_integration_field diff --git a/erpnext/patches/v12_0/setup_einvoice_fields.py b/erpnext/patches/v12_0/setup_einvoice_fields.py index d0782765de..2474bc3b82 100644 --- a/erpnext/patches/v12_0/setup_einvoice_fields.py +++ b/erpnext/patches/v12_0/setup_einvoice_fields.py @@ -8,6 +8,7 @@ def execute(): if not company: return + frappe.reload_doc("custom", "doctype", "custom_field") frappe.reload_doc("regional", "doctype", "e_invoice_settings") custom_fields = { 'Sales Invoice': [ diff --git a/erpnext/regional/india/e_invoice/einv_template.json b/erpnext/regional/india/e_invoice/einv_template.json index e5751da561..60f490d616 100644 --- a/erpnext/regional/india/e_invoice/einv_template.json +++ b/erpnext/regional/india/e_invoice/einv_template.json @@ -59,7 +59,7 @@ {item_list} ], "ValDtls": {{ - "AssVal": "{invoice_value_details.base_net_total}", + "AssVal": "{invoice_value_details.base_total}", "CgstVal": "{invoice_value_details.total_cgst_amt}", "SgstVal": "{invoice_value_details.total_sgst_amt}", "IgstVal": "{invoice_value_details.total_igst_amt}", diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 61fb88a21b..102a2f0f56 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -146,12 +146,12 @@ def get_item_list(invoice): item.update(d.as_dict()) item.sr_no = d.idx - item.qty = abs(item.qty) - item.description = d.item_name - item.taxable_value = abs(item.base_net_amount) item.discount_amount = abs(item.discount_amount * item.qty) - item.unit_rate = abs(item.base_price_list_rate) if item.discount_amount else abs(item.base_net_rate) - item.gross_amount = abs(item.unit_rate * item.qty) + item.description = d.item_name + item.qty = abs(item.qty) + item.unit_rate = abs(item.base_amount / item.qty) + item.gross_amount = abs(item.base_amount) + item.taxable_value = abs(item.base_amount) item.batch_expiry_date = frappe.db.get_value('Batch', d.batch_no, 'expiry_date') if d.batch_no else None item.batch_expiry_date = format_date(item.batch_expiry_date, 'dd/mm/yyyy') if item.batch_expiry_date else None @@ -180,35 +180,35 @@ def update_item_taxes(invoice, item): item[attr] = 0 for t in invoice.taxes: + # this contains item wise tax rate & tax amount (incl. discount) item_tax_detail = json.loads(t.item_wise_tax_detail).get(item.item_code) if t.account_head in gst_accounts_list: + item_tax_rate = item_tax_detail[0] + # item tax amount excluding discount amount + item_tax_amount = (item_tax_rate / 100) * item.base_amount + if t.account_head in gst_accounts.cess_account: + item_tax_amount_after_discount = item_tax_detail[1] if t.charge_type == 'On Item Quantity': - item.cess_nadv_amount += abs(item_tax_detail[1]) + item.cess_nadv_amount += abs(item_tax_amount_after_discount) else: - item.cess_rate += item_tax_detail[0] - item.cess_amount += abs(item_tax_detail[1]) - elif t.account_head in gst_accounts.igst_account: - item.tax_rate += item_tax_detail[0] - item.igst_amount += abs(item_tax_detail[1]) - elif t.account_head in gst_accounts.sgst_account: - item.tax_rate += item_tax_detail[0] - item.sgst_amount += abs(item_tax_detail[1]) - elif t.account_head in gst_accounts.cgst_account: - item.tax_rate += item_tax_detail[0] - item.cgst_amount += abs(item_tax_detail[1]) - + item.cess_rate += item_tax_rate + item.cess_amount += abs(item_tax_amount_after_discount) + + for tax_type in ['igst', 'cgst', 'sgst']: + if t.account_head in gst_accounts[f'{tax_type}_account']: + item.tax_rate += item_tax_rate + item[f'{tax_type}_amount'] += abs(item_tax_amount) + return item def get_invoice_value_details(invoice): invoice_value_details = frappe._dict(dict()) - invoice_value_details.base_net_total = abs(invoice.base_net_total) - invoice_value_details.invoice_discount_amt = invoice.discount_amount if invoice.discount_amount and invoice.discount_amount > 0 else 0 - # discount amount cannnot be -ve in an e-invoice, so if -ve include discount in round_off - invoice_value_details.round_off = invoice.rounding_adjustment - (invoice.discount_amount if invoice.discount_amount and invoice.discount_amount < 0 else 0) - disable_rounded = frappe.db.get_single_value('Global Defaults', 'disable_rounded_total') - invoice_value_details.base_grand_total = abs(invoice.base_grand_total) if disable_rounded else abs(invoice.base_rounded_total) - invoice_value_details.grand_total = abs(invoice.grand_total) if disable_rounded else abs(invoice.rounded_total) + invoice_value_details.base_total = abs(invoice.base_total) + invoice_value_details.invoice_discount_amt = invoice.discount_amount + invoice_value_details.round_off = invoice.rounding_adjustment + invoice_value_details.base_grand_total = abs(invoice.base_rounded_total) or abs(invoice.base_grand_total) + invoice_value_details.grand_total = abs(invoice.rounded_total) or abs(invoice.grand_total) invoice_value_details = update_invoice_taxes(invoice, invoice_value_details) @@ -226,15 +226,14 @@ def update_invoice_taxes(invoice, invoice_value_details): for t in invoice.taxes: if t.account_head in gst_accounts_list: if t.account_head in gst_accounts.cess_account: + # using after discount amt since item also uses after discount amt for cess calc invoice_value_details.total_cess_amt += abs(t.base_tax_amount_after_discount_amount) - elif t.account_head in gst_accounts.igst_account: - invoice_value_details.total_igst_amt += abs(t.base_tax_amount_after_discount_amount) - elif t.account_head in gst_accounts.sgst_account: - invoice_value_details.total_sgst_amt += abs(t.base_tax_amount_after_discount_amount) - elif t.account_head in gst_accounts.cgst_account: - invoice_value_details.total_cgst_amt += abs(t.base_tax_amount_after_discount_amount) + + for tax_type in ['igst', 'cgst', 'sgst']: + if t.account_head in gst_accounts[f'{tax_type}_account']: + invoice_value_details[f'total_{tax_type}_amt'] += abs(t.base_tax_amount) else: - invoice_value_details.total_other_charges += abs(t.base_tax_amount_after_discount_amount) + invoice_value_details.total_other_charges += abs(t.base_tax_amount) return invoice_value_details @@ -358,7 +357,8 @@ def validate_einvoice(validations, einvoice, errors=[]): einvoice[fieldname] = str(value) elif value_type == 'number': is_integer = '.' not in str(field_validation.get('maximum')) - einvoice[fieldname] = flt(value, 2) if not is_integer else cint(value) + precision = 3 if '.999' in str(field_validation.get('maximum')) else 2 + einvoice[fieldname] = flt(value, precision) if not is_integer else cint(value) value = einvoice[fieldname] max_length = field_validation.get('maxLength') From 08b89d1ce02894ce87d348eafd4d043740b384e3 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Thu, 31 Dec 2020 12:12:58 +0550 Subject: [PATCH 232/449] bumped to version 13.0.0-beta.8 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index c108333e1a..6599ee814f 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0-beta.7' +__version__ = '13.0.0-beta.8' def get_default_company(user=None): '''Get default company for user''' From f8f015c96152f7f3346847c2c7dc36e23cbb08ce Mon Sep 17 00:00:00 2001 From: Saqib Date: Thu, 31 Dec 2020 13:28:08 +0530 Subject: [PATCH 233/449] fix: cannot submit e-invoice if legal name not found --- erpnext/regional/india/e_invoice/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 102a2f0f56..02ce6c14c9 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -88,7 +88,7 @@ def get_party_details(address_name): gstin = address.get('gstin') gstin_details = get_gstin_details(gstin) - legal_name = gstin_details.get('LegalName') + legal_name = gstin_details.get('LegalName') or gstin_details.get('TradeName') location = gstin_details.get('AddrLoc') or address.get('city') state_code = gstin_details.get('StateCode') pincode = gstin_details.get('AddrPncd') From 16bce49f1856fae6e44650f53bde0c6c26561175 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 31 Dec 2020 17:39:52 +0530 Subject: [PATCH 234/449] fix: incorrect valuation rate for finished good --- erpnext/stock/doctype/stock_entry/stock_entry.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 60758b4f8a..6a0a363d2a 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -512,7 +512,7 @@ class StockEntry(StockController): bom_items = self.get_bom_raw_materials(finished_item_qty) outgoing_items_cost = sum([flt(row.qty)*flt(row.rate) for row in bom_items.values()]) - return flt(outgoing_items_cost - scrap_items_cost) + return flt((outgoing_items_cost - scrap_items_cost) / finished_item_qty) def distribute_additional_costs(self): # If no incoming items, set additional costs blank @@ -699,7 +699,7 @@ class StockEntry(StockController): # SLE for target warehouse self.get_sle_for_target_warehouse(sl_entries, finished_item_row) - + # reverse sl entries if cancel if self.docstatus == 2: sl_entries.reverse() @@ -727,9 +727,9 @@ class StockEntry(StockController): sle.dependant_sle_voucher_detail_no = d.name elif finished_item_row and (finished_item_row.item_code != d.item_code or finished_item_row.t_warehouse != d.s_warehouse): sle.dependant_sle_voucher_detail_no = finished_item_row.name - + sl_entries.append(sle) - + def get_sle_for_target_warehouse(self, sl_entries, finished_item_row): for d in self.get('items'): if cstr(d.t_warehouse): From 0feaab5261c9800454c03dbee50fe45c7533ef85 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Sat, 2 Jan 2021 20:19:56 +0550 Subject: [PATCH 235/449] bumped to version 13.0.0-beta.9 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 6599ee814f..5fbf06d0d8 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0-beta.8' +__version__ = '13.0.0-beta.9' def get_default_company(user=None): '''Get default company for user''' From 60460a6d23d8374315358f3eb40bb8597e415e73 Mon Sep 17 00:00:00 2001 From: Saqib Date: Tue, 5 Jan 2021 13:54:04 +0530 Subject: [PATCH 236/449] fix(e-invoicing): minor calculation fixes (#24282) --- .../controllers/sales_and_purchase_return.py | 2 + erpnext/public/js/controllers/transaction.js | 1 + erpnext/regional/india/e_invoice/utils.py | 41 +++++++++++++------ erpnext/stock/get_item_details.py | 4 +- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index 79792262c0..a048d6e2df 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -328,6 +328,7 @@ def make_return_doc(doctype, source_name, target_doc=None): target_doc.po_detail = source_doc.po_detail target_doc.pr_detail = source_doc.pr_detail target_doc.purchase_invoice_item = source_doc.name + target_doc.price_list_rate = 0 elif doctype == "Delivery Note": returned_qty_map = get_returned_qty_map_for_row(source_doc.name, doctype) @@ -353,6 +354,7 @@ def make_return_doc(doctype, source_name, target_doc=None): target_doc.dn_detail = source_doc.dn_detail target_doc.expense_account = source_doc.expense_account target_doc.sales_invoice_item = source_doc.name + target_doc.price_list_rate = 0 if default_warehouse_for_sales_return: target_doc.warehouse = default_warehouse_for_sales_return diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 3bc20f8733..bed9c14141 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -543,6 +543,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ company: me.frm.doc.company, order_type: me.frm.doc.order_type, is_pos: cint(me.frm.doc.is_pos), + is_return: cint(me.frm.doc.is_return), is_subcontracted: me.frm.doc.is_subcontracted, transaction_date: me.frm.doc.transaction_date || me.frm.doc.posting_date, ignore_pricing_rule: me.frm.doc.ignore_pricing_rule, diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 02ce6c14c9..e5f7d2d78c 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -92,21 +92,18 @@ def get_party_details(address_name): location = gstin_details.get('AddrLoc') or address.get('city') state_code = gstin_details.get('StateCode') pincode = gstin_details.get('AddrPncd') - address_line1 = '{} {}'.format(gstin_details.get('AddrBno'), gstin_details.get('AddrFlno')) - address_line2 = '{} {}'.format(gstin_details.get('AddrBnm'), gstin_details.get('AddrSt')) - email_id = address.get('email_id') - phone = address.get('phone') - # get last 10 digit - phone = phone.replace(" ", "")[-10:] if phone else '' + address_line1 = '{} {}'.format(gstin_details.get('AddrBno') or "", gstin_details.get('AddrFlno') or "") + address_line2 = '{} {}'.format(gstin_details.get('AddrBnm') or "", gstin_details.get('AddrSt') or "") if state_code == 97: # according to einvoice standard pincode = 999999 return frappe._dict(dict( - gstin=gstin, legal_name=legal_name, location=location, - pincode=pincode, state_code=state_code, address_line1=address_line1, - address_line2=address_line2, email=email_id, phone=phone + gstin=gstin, legal_name=legal_name, + location=location, pincode=pincode, + state_code=state_code, address_line1=address_line1, + address_line2=address_line2 )) def get_gstin_details(gstin): @@ -146,9 +143,10 @@ def get_item_list(invoice): item.update(d.as_dict()) item.sr_no = d.idx - item.discount_amount = abs(item.discount_amount * item.qty) - item.description = d.item_name + item.description = d.item_name.replace('"', '\\"') + item.qty = abs(item.qty) + item.discount_amount = abs(item.discount_amount * item.qty) item.unit_rate = abs(item.base_amount / item.qty) item.gross_amount = abs(item.base_amount) item.taxable_value = abs(item.base_amount) @@ -156,6 +154,7 @@ def get_item_list(invoice): item.batch_expiry_date = frappe.db.get_value('Batch', d.batch_no, 'expiry_date') if d.batch_no else None item.batch_expiry_date = format_date(item.batch_expiry_date, 'dd/mm/yyyy') if item.batch_expiry_date else None item.is_service_item = 'N' if frappe.db.get_value('Item', d.item_code, 'is_stock_item') else 'Y' + item.serial_no = "" item = update_item_taxes(invoice, item) @@ -272,7 +271,25 @@ def get_eway_bill_details(invoice): vehicle_type=vehicle_type[invoice.gst_vehicle_type] )) +def validate_mandatory_fields(invoice): + if not invoice.company_address: + frappe.throw(_('Company Address is mandatory to fetch company GSTIN details.'), title=_('Missing Fields')) + if not invoice.customer_address: + frappe.throw(_('Customer Address is mandatory to fetch customer GSTIN details.'), title=_('Missing Fields')) + if not frappe.db.get_value('Address', invoice.company_address, 'gstin'): + frappe.throw( + _('GSTIN is mandatory to fetch company GSTIN details. Please enter GSTIN in selected company address.'), + title=_('Missing Fields') + ) + if not frappe.db.get_value('Address', invoice.customer_address, 'gstin'): + frappe.throw( + _('GSTIN is mandatory to fetch customer GSTIN details. Please enter GSTIN in selected customer address.'), + title=_('Missing Fields') + ) + def make_einvoice(invoice): + validate_mandatory_fields(invoice) + schema = read_json('einv_template') transaction_details = get_transaction_details(invoice) @@ -351,7 +368,7 @@ def validate_einvoice(validations, einvoice, errors=[]): # remove empty dicts einvoice.pop(fieldname, None) continue - + # convert to int or str if value_type == 'string': einvoice[fieldname] = str(value) diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 08f7a83b89..bf45251c9d 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -74,7 +74,9 @@ def get_item_details(args, doc=None, for_validate=False, overwrite_warehouse=Tru update_party_blanket_order(args, out) - get_price_list_rate(args, item, out) + if not doc or cint(doc.get('is_return')) == 0: + # get price list rate only if the invoice is not a credit or debit note + get_price_list_rate(args, item, out) if args.customer and cint(args.is_pos): out.update(get_pos_profile_item_details(args.company, args)) From 80e0952ba73e3b31981e9917d86b8644cca14f10 Mon Sep 17 00:00:00 2001 From: Saqib Date: Tue, 5 Jan 2021 16:04:25 +0530 Subject: [PATCH 237/449] refactor: fetch & validate address from erpnext rather than gst portal --- erpnext/regional/india/e_invoice/utils.py | 54 ++++++++++++++--------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index e5f7d2d78c..abe15043af 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -15,7 +15,7 @@ from frappe import _, bold from pyqrcode import create as qrcreate from frappe.integrations.utils import make_post_request, make_get_request from erpnext.regional.india.utils import get_gst_accounts, get_place_of_supply -from frappe.utils.data import cstr, cint, format_date, flt, time_diff_in_seconds, now_datetime, add_to_date +from frappe.utils.data import cstr, cint, format_date, flt, time_diff_in_seconds, now_datetime, add_to_date, get_link_to_form def validate_einvoice_fields(doc): einvoicing_enabled = cint(frappe.db.get_value('E Invoice Settings', 'E Invoice Settings', 'enable')) @@ -84,26 +84,32 @@ def get_doc_details(invoice): )) def get_party_details(address_name): - address = frappe.get_all('Address', filters={'name': address_name}, fields=['*'])[0] - gstin = address.get('gstin') + d = frappe.get_all('Address', filters={'name': address_name}, fields=['*'])[0] - gstin_details = get_gstin_details(gstin) - legal_name = gstin_details.get('LegalName') or gstin_details.get('TradeName') - location = gstin_details.get('AddrLoc') or address.get('city') - state_code = gstin_details.get('StateCode') - pincode = gstin_details.get('AddrPncd') - address_line1 = '{} {}'.format(gstin_details.get('AddrBno') or "", gstin_details.get('AddrFlno') or "") - address_line2 = '{} {}'.format(gstin_details.get('AddrBnm') or "", gstin_details.get('AddrSt') or "") + if (not d.gstin + or not d.city + or not d.pincode + or not d.address_title + or not d.address_line1 + or not d.gst_state_number): - if state_code == 97: + frappe.throw( + msg=_('Address lines, city, pincode, gstin is mandatory for address {}. Please set them and try again.').format( + get_link_to_form('Address', address_name) + ), + title=_('Missing Address Fields') + ) + + if d.gst_state_number == 97: # according to einvoice standard pincode = 999999 return frappe._dict(dict( - gstin=gstin, legal_name=legal_name, - location=location, pincode=pincode, - state_code=state_code, address_line1=address_line1, - address_line2=address_line2 + gstin=d.gstin, legal_name=d.address_title, + location=d.city, pincode=d.pincode, + state_code=d.gst_state_number, + address_line1=d.address_line1, + address_line2=d.address_line2 )) def get_gstin_details(gstin): @@ -124,14 +130,22 @@ def get_gstin_details(gstin): return GSPConnector.get_gstin_details(gstin) def get_overseas_address_details(address_name): - address_title, address_line1, address_line2, city, phone, email_id = frappe.db.get_value( - 'Address', address_name, ['address_title', 'address_line1', 'address_line2', 'city', 'phone', 'email_id'] + address_title, address_line1, address_line2, city = frappe.db.get_value( + 'Address', address_name, ['address_title', 'address_line1', 'address_line2', 'city'] ) + if not address_title or not address_line1 or not city: + frappe.throw( + msg=_('Address lines and city is mandatory for address {}. Please set them and try again.').format( + get_link_to_form('Address', address_name) + ), + title=_('Missing Address Fields') + ) + return frappe._dict(dict( - gstin='URP', legal_name=address_title, address_line1=address_line1, - address_line2=address_line2, email=email_id, phone=phone, - pincode=999999, state_code=96, place_of_supply=96, location=city + gstin='URP', legal_name=address_title, location=city, + address_line1=address_line1, address_line2=address_line2, + pincode=999999, state_code=96, place_of_supply=96 )) def get_item_list(invoice): From df9144c198ef4f9ef9ade0d5bf5d5245300f6ff6 Mon Sep 17 00:00:00 2001 From: Leela vadlamudi Date: Tue, 15 Dec 2020 21:23:17 +0530 Subject: [PATCH 238/449] feat: Voice Call Settings doctype added (#24126) (cherry picked from commit 29778e2fba4b1f073fdfc048f784f755c57a1eeb) --- erpnext/public/js/telephony.js | 2 +- .../doctype/voice_call_settings/__init__.py | 0 .../test_voice_call_settings.py | 10 ++ .../voice_call_settings.js | 8 ++ .../voice_call_settings.json | 124 ++++++++++++++++++ .../voice_call_settings.py | 10 ++ 6 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 erpnext/telephony/doctype/voice_call_settings/__init__.py create mode 100644 erpnext/telephony/doctype/voice_call_settings/test_voice_call_settings.py create mode 100644 erpnext/telephony/doctype/voice_call_settings/voice_call_settings.js create mode 100644 erpnext/telephony/doctype/voice_call_settings/voice_call_settings.json create mode 100644 erpnext/telephony/doctype/voice_call_settings/voice_call_settings.py diff --git a/erpnext/public/js/telephony.js b/erpnext/public/js/telephony.js index bd7f890306..f9caadeed7 100644 --- a/erpnext/public/js/telephony.js +++ b/erpnext/public/js/telephony.js @@ -20,4 +20,4 @@ frappe.ui.form.ControlData = frappe.ui.form.ControlData.extend( { }); } } -}); \ No newline at end of file +}); diff --git a/erpnext/telephony/doctype/voice_call_settings/__init__.py b/erpnext/telephony/doctype/voice_call_settings/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/telephony/doctype/voice_call_settings/test_voice_call_settings.py b/erpnext/telephony/doctype/voice_call_settings/test_voice_call_settings.py new file mode 100644 index 0000000000..85d6adda09 --- /dev/null +++ b/erpnext/telephony/doctype/voice_call_settings/test_voice_call_settings.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +# import frappe +import unittest + +class TestVoiceCallSettings(unittest.TestCase): + pass diff --git a/erpnext/telephony/doctype/voice_call_settings/voice_call_settings.js b/erpnext/telephony/doctype/voice_call_settings/voice_call_settings.js new file mode 100644 index 0000000000..4a61b612d0 --- /dev/null +++ b/erpnext/telephony/doctype/voice_call_settings/voice_call_settings.js @@ -0,0 +1,8 @@ +// Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Voice Call Settings', { + // refresh: function(frm) { + + // } +}); diff --git a/erpnext/telephony/doctype/voice_call_settings/voice_call_settings.json b/erpnext/telephony/doctype/voice_call_settings/voice_call_settings.json new file mode 100644 index 0000000000..25e55a22dc --- /dev/null +++ b/erpnext/telephony/doctype/voice_call_settings/voice_call_settings.json @@ -0,0 +1,124 @@ +{ + "actions": [], + "autoname": "field:user", + "creation": "2020-12-08 16:52:40.590146", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "user", + "call_receiving_device", + "column_break_3", + "greeting_message", + "agent_busy_message", + "agent_unavailable_message" + ], + "fields": [ + { + "fieldname": "user", + "fieldtype": "Link", + "in_list_view": 1, + "label": "User", + "options": "User", + "permlevel": 1, + "reqd": 1, + "unique": 1 + }, + { + "fieldname": "greeting_message", + "fieldtype": "Data", + "label": "Greeting Message" + }, + { + "fieldname": "agent_busy_message", + "fieldtype": "Data", + "label": "Agent Busy Message" + }, + { + "fieldname": "agent_unavailable_message", + "fieldtype": "Data", + "label": "Agent Unavailable Message" + }, + { + "default": "Computer", + "fieldname": "call_receiving_device", + "fieldtype": "Select", + "label": "Call Receiving Device", + "options": "Computer\nPhone" + }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2020-12-14 18:49:34.600194", + "modified_by": "Administrator", + "module": "Telephony", + "name": "Voice Call Settings", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "All", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + }, + { + "delete": 1, + "email": 1, + "export": 1, + "permlevel": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + }, + { + "delete": 1, + "email": 1, + "export": 1, + "permlevel": 2, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + }, + { + "email": 1, + "export": 1, + "permlevel": 2, + "print": 1, + "read": 1, + "report": 1, + "role": "All", + "share": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/telephony/doctype/voice_call_settings/voice_call_settings.py b/erpnext/telephony/doctype/voice_call_settings/voice_call_settings.py new file mode 100644 index 0000000000..ad3bbf1784 --- /dev/null +++ b/erpnext/telephony/doctype/voice_call_settings/voice_call_settings.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +# import frappe +from frappe.model.document import Document + +class VoiceCallSettings(Document): + pass From d43bb4db41d556056b72d73b80f2ea4571a14721 Mon Sep 17 00:00:00 2001 From: Saqib Date: Mon, 11 Jan 2021 12:59:35 +0530 Subject: [PATCH 239/449] fix(pos): error while merging pos invoices into sales invoice (#24337) --- .../doctype/pos_closing_entry/pos_closing_entry.py | 6 +++++- .../pos_invoice_merge_log/pos_invoice_merge_log.py | 11 ++++++----- erpnext/controllers/sales_and_purchase_return.py | 1 + erpnext/patches.txt | 1 + .../patches/v13_0/create_uae_pos_invoice_fields.py | 14 ++++++++++++++ 5 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 erpnext/patches/v13_0/create_uae_pos_invoice_fields.py diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py index 2b91c74ce6..c26e14ff6f 100644 --- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py +++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py @@ -57,7 +57,11 @@ class POSClosingEntry(Document): if not invalid_rows: return - error_list = [_("Row #{}: {}").format(row.get('idx'), row.get('msg')) for row in invalid_rows] + error_list = [] + for row in invalid_rows: + for msg in row.get('msg'): + error_list.append(_("Row #{}: {}").format(row.get('idx'), msg)) + frappe.throw(error_list, title=_("Invalid POS Invoices"), as_list=True) def on_submit(self): diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py index add27e9dff..5e43cfe030 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py @@ -5,10 +5,10 @@ from __future__ import unicode_literals import frappe from frappe import _ -from frappe.utils import cint, flt, add_months, today, date_diff, getdate, add_days, cstr, nowdate -from frappe.model.document import Document -from frappe.model.mapper import map_doc from frappe.model import default_fields +from frappe.model.document import Document +from frappe.model.mapper import map_doc, map_child_doc +from frappe.utils import cint, flt, add_months, today, date_diff, getdate, add_days, cstr, nowdate from six import iteritems @@ -83,7 +83,7 @@ class POSInvoiceMergeLog(Document): credit_note.is_consolidated = 1 # TODO: return could be against multiple sales invoice which could also have been consolidated? - credit_note.return_against = self.consolidated_invoice + # credit_note.return_against = self.consolidated_invoice credit_note.save() credit_note.submit() self.consolidated_credit_note = credit_note.name @@ -111,7 +111,8 @@ class POSInvoiceMergeLog(Document): i.qty = i.qty + item.qty if not found: item.rate = item.net_rate - items.append(item) + si_item = map_child_doc(item, invoice, {"doctype": "Sales Invoice Item"}) + items.append(si_item) for tax in doc.get('taxes'): found = False diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index 79792262c0..85af0eaedf 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -262,6 +262,7 @@ def make_return_doc(doctype, source_name, target_doc=None): if doc.get("is_return"): if doc.doctype == 'Sales Invoice' or doc.doctype == 'POS Invoice': + doc.consolidated_invoice = "" doc.set('payments', []) for data in source.payments: paid_amount = 0.00 diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 894ee82b4c..ca8e01c515 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -743,3 +743,4 @@ erpnext.patches.v13_0.updates_for_multi_currency_payroll erpnext.patches.v13_0.create_leave_policy_assignment_based_on_employee_current_leave_policy erpnext.patches.v13_0.add_po_to_global_search erpnext.patches.v13_0.update_returned_qty_in_pr_dn +erpnext.patches.v13_0.create_uae_pos_invoice_fields \ No newline at end of file diff --git a/erpnext/patches/v13_0/create_uae_pos_invoice_fields.py b/erpnext/patches/v13_0/create_uae_pos_invoice_fields.py new file mode 100644 index 0000000000..48d5cb4cc8 --- /dev/null +++ b/erpnext/patches/v13_0/create_uae_pos_invoice_fields.py @@ -0,0 +1,14 @@ +# Copyright (c) 2019, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals + +import frappe +from erpnext.regional.united_arab_emirates.setup import make_custom_fields + +def execute(): + company = frappe.get_all('Company', filters = {'country': ['in', ['Saudi Arabia', 'United Arab Emirates']]}) + if not company: + return + + make_custom_fields() \ No newline at end of file From aeba3d311c6278dc62d46dc8dd44f3efd5c554f7 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 14 Jan 2021 11:47:57 +0530 Subject: [PATCH 240/449] fix: extra transferred qty has not consumed against work order --- .../doctype/work_order/test_work_order.py | 42 +++++++++++++++++++ .../stock/doctype/stock_entry/stock_entry.py | 8 +++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/doctype/work_order/test_work_order.py b/erpnext/manufacturing/doctype/work_order/test_work_order.py index a77bd159af..e562d6c4bd 100644 --- a/erpnext/manufacturing/doctype/work_order/test_work_order.py +++ b/erpnext/manufacturing/doctype/work_order/test_work_order.py @@ -550,6 +550,48 @@ class TestWorkOrder(unittest.TestCase): frappe.db.set_value("Manufacturing Settings", None, "material_consumption", 0) + def test_extra_material_transfer(self): + frappe.db.set_value("Manufacturing Settings", None, "material_consumption", 0) + frappe.db.set_value("Manufacturing Settings", None, "backflush_raw_materials_based_on", + "Material Transferred for Manufacture") + + wo_order = make_wo_order_test_record(planned_start_date=now(), qty=4) + + ste_cancel_list = [] + ste1 = test_stock_entry.make_stock_entry(item_code="_Test Item", + target="_Test Warehouse - _TC", qty=20, basic_rate=5000.0) + ste2 = test_stock_entry.make_stock_entry(item_code="_Test Item Home Desktop 100", + target="_Test Warehouse - _TC", qty=20, basic_rate=1000.0) + + ste_cancel_list.extend([ste1, ste2]) + + itemwise_qty = {} + s = frappe.get_doc(make_stock_entry(wo_order.name, "Material Transfer for Manufacture", 4)) + for row in s.items: + row.qty = row.qty + 2 + itemwise_qty.setdefault(row.item_code, row.qty) + + s.submit() + ste_cancel_list.append(s) + + ste3 = frappe.get_doc(make_stock_entry(wo_order.name, "Manufacture", 2)) + for ste_row in ste3.items: + if itemwise_qty.get(ste_row.item_code) and ste_row.s_warehouse: + self.assertEquals(ste_row.qty, itemwise_qty.get(ste_row.item_code) / 2) + + ste3.submit() + ste_cancel_list.append(ste3) + + ste2 = frappe.get_doc(make_stock_entry(wo_order.name, "Manufacture", 2)) + for ste_row in ste2.items: + if itemwise_qty.get(ste_row.item_code) and ste_row.s_warehouse: + self.assertEquals(ste_row.qty, itemwise_qty.get(ste_row.item_code) / 2) + + for ste_doc in ste_cancel_list: + ste_doc.cancel() + + frappe.db.set_value("Manufacturing Settings", None, "backflush_raw_materials_based_on", "BOM") + def get_scrap_item_details(bom_no): scrap_items = {} for item in frappe.db.sql("""select item_code, stock_qty from `tabBOM Scrap Item` diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index d623d5c758..d77b70ff14 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -1200,7 +1200,10 @@ class StockEntry(StockController): else: qty = (req_qty_each * flt(self.fg_completed_qty)) - remaining_qty else: - qty = req_qty_each * flt(self.fg_completed_qty) + if self.flags.backflush_based_on == "Material Transferred for Manufacture": + qty = (item.qty/trans_qty) * flt(self.fg_completed_qty) + else: + qty = req_qty_each * flt(self.fg_completed_qty) elif backflushed_materials.get(item.item_code): for d in backflushed_materials.get(item.item_code): @@ -1208,7 +1211,8 @@ class StockEntry(StockController): if (qty > req_qty): qty = (qty/trans_qty) * flt(self.fg_completed_qty) - if consumed_qty: + if consumed_qty and frappe.db.get_single_value("Manufacturing Settings", + "material_consumption"): qty -= consumed_qty if cint(frappe.get_cached_value('UOM', item.stock_uom, 'must_be_whole_number')): From fd91973ac1c8efd99c53a47750aa37193eb194a7 Mon Sep 17 00:00:00 2001 From: pateljannat Date: Fri, 29 Jan 2021 13:18:39 +0530 Subject: [PATCH 241/449] fix: template task parent child deadlock --- erpnext/projects/doctype/task/task.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py index a2095c95d5..a99603329b 100755 --- a/erpnext/projects/doctype/task/task.py +++ b/erpnext/projects/doctype/task/task.py @@ -77,14 +77,7 @@ class Task(NestedSet): def validate_dependencies_for_template_task(self): if self.is_template: - self.validate_parent_template_task() self.validate_depends_on_tasks() - - def validate_parent_template_task(self): - if self.parent_task: - if not frappe.db.get_value("Task", self.parent_task, "is_template"): - parent_task_format = """{0}""".format(self.parent_task) - frappe.throw(_("Parent Task {0} is not a Template Task").format(parent_task_format)) def validate_depends_on_tasks(self): if self.depends_on: From 2fa840e5d4bf298e38212301a5e84be5439db090 Mon Sep 17 00:00:00 2001 From: Marica Date: Mon, 1 Feb 2021 20:07:00 +0530 Subject: [PATCH 242/449] chore: Use sql to set naming series in older projects (#24513) * chore: Use sql to set naming series in older projects * fix: Remove unncessary db.commit() --- erpnext/patches.txt | 2 +- .../add_naming_series_to_old_projects.py | 23 ++++--------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index f3660b3c51..9e022da807 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -747,4 +747,4 @@ erpnext.patches.v13_0.update_project_template_tasks erpnext.patches.v13_0.set_company_in_leave_ledger_entry erpnext.patches.v13_0.convert_qi_parameter_to_link_field erpnext.patches.v13_0.setup_patient_history_settings_for_standard_doctypes -erpnext.patches.v13_0.add_naming_series_to_old_projects +erpnext.patches.v13_0.add_naming_series_to_old_projects # 1-02-2021 diff --git a/erpnext/patches/v13_0/add_naming_series_to_old_projects.py b/erpnext/patches/v13_0/add_naming_series_to_old_projects.py index 79b67533ed..5ed9040f1e 100644 --- a/erpnext/patches/v13_0/add_naming_series_to_old_projects.py +++ b/erpnext/patches/v13_0/add_naming_series_to_old_projects.py @@ -4,23 +4,10 @@ from frappe.custom.doctype.property_setter.property_setter import make_property_ def execute(): frappe.reload_doc("projects", "doctype", "project") - projects = frappe.db.get_all("Project", - fields=["name", "naming_series", "modified"], - filters={ - "naming_series": ["is", "not set"] - }, - order_by="timestamp(modified) asc") - # disable set only once as the old docs must be saved - # (to bypass 'Cant change naming series' validation on save) - make_property_setter("Project", "naming_series", "set_only_once", 0, "Check") + frappe.db.sql("""UPDATE `tabProject` + SET + naming_series = 'PROJ-.####' + WHERE + naming_series is NULL""") - for entry in projects: - # need to save the doc so that users can edit old projects - doc = frappe.get_doc("Project", entry.name) - if not doc.naming_series: - doc.naming_series = "PROJ-.####" - doc.save() - - delete_property_setter("Project", "set_only_once", "naming_series") - frappe.db.commit() From 081f5069928f8046903f927803f0f8986cd42391 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Mon, 1 Feb 2021 20:18:44 +0530 Subject: [PATCH 243/449] fix: consider select perm while setting party details (#24514) --- erpnext/accounts/party.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 64268b8064..38b228477f 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -39,7 +39,7 @@ def _get_party_details(party=None, account=None, party_type="Customer", company= party_details = frappe._dict(set_account_and_due_date(party, account, party_type, company, posting_date, bill_date, doctype)) party = party_details[party_type.lower()] - if not ignore_permissions and not frappe.has_permission(party_type, "read", party): + if not ignore_permissions and not (frappe.has_permission(party_type, "read", party) or frappe.has_permission(party_type, "select", party)): frappe.throw(_("Not permitted for {0}").format(party), frappe.PermissionError) party = frappe.get_doc(party_type, party) From 68edf749ec8781d4b784403d4f37fb011381ef24 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 1 Feb 2021 20:22:02 +0530 Subject: [PATCH 244/449] fix: multiple pricing rule issue (#24515) --- .../accounts/doctype/pricing_rule/utils.py | 41 ++++++++----------- erpnext/controllers/accounts_controller.py | 2 +- erpnext/controllers/taxes_and_totals.py | 5 +-- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index fb1fbe484e..bd9d0b3815 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -41,10 +41,11 @@ def get_pricing_rules(args, doc=None): if not pricing_rules: return [] if apply_multiple_pricing_rules(pricing_rules): - pricing_rules = sorted_by_priority(pricing_rules) + pricing_rules = sorted_by_priority(pricing_rules, args, doc) for pricing_rule in pricing_rules: - pricing_rule = filter_pricing_rules(args, pricing_rule, doc) - if pricing_rule: + if isinstance(pricing_rule, list): + rules.extend(pricing_rule) + else: rules.append(pricing_rule) else: pricing_rule = filter_pricing_rules(args, pricing_rules, doc) @@ -53,17 +54,23 @@ def get_pricing_rules(args, doc=None): return rules -def sorted_by_priority(pricing_rules): +def sorted_by_priority(pricing_rules, args, doc=None): # If more than one pricing rules, then sort by priority pricing_rules_list = [] pricing_rule_dict = {} + + priority = [] for pricing_rule in pricing_rules: - if not pricing_rule.get("priority"): continue + pricing_rule = filter_pricing_rules(args, pricing_rule, doc) + if pricing_rule: + if not pricing_rule.get('priority'): + pricing_rules_list.append(pricing_rule) + else: + priority.append(cint(pricing_rule.get('priority'))) + pricing_rule_dict.setdefault(cint(pricing_rule.get("priority")), []).append(pricing_rule) - pricing_rule_dict.setdefault(cint(pricing_rule.get("priority")), []).append(pricing_rule) - - for key in sorted(pricing_rule_dict): - pricing_rules_list.append(pricing_rule_dict.get(key)) + if priority: + pricing_rules_list.extend(pricing_rule_dict.get(min(priority))) return pricing_rules_list or pricing_rules @@ -144,9 +151,7 @@ def apply_multiple_pricing_rules(pricing_rules): if not apply_multiple_rule: return False - if (apply_multiple_rule - and len(apply_multiple_rule) == len(pricing_rules)): - return True + return True def _get_tree_conditions(args, parenttype, table, allow_blank=True): field = frappe.scrub(parenttype) @@ -264,18 +269,6 @@ def filter_pricing_rules(args, pricing_rules, doc=None): if max_priority: pricing_rules = list(filter(lambda x: cint(x.priority)==max_priority, pricing_rules)) - # apply internal priority - all_fields = ["item_code", "item_group", "brand", "customer", "customer_group", "territory", - "supplier", "supplier_group", "campaign", "sales_partner", "variant_of"] - - if len(pricing_rules) > 1: - for field_set in [["item_code", "variant_of", "item_group", "brand"], - ["customer", "customer_group", "territory"], ["supplier", "supplier_group"]]: - remaining_fields = list(set(all_fields) - set(field_set)) - if if_all_rules_same(pricing_rules, remaining_fields): - pricing_rules = apply_internal_priority(pricing_rules, field_set, args) - break - if pricing_rules and not isinstance(pricing_rules, list): pricing_rules = list(pricing_rules) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 9d9d1b363a..35c6cd33f9 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -121,7 +121,7 @@ class AccountsController(TransactionBase): def before_cancel(self): validate_einvoice_fields(self) - + def on_trash(self): # delete sl and gl entries on deletion of transaction if frappe.db.get_single_value('Accounts Settings', 'delete_linked_ledger_entries'): diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 76309f8799..452246e89c 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -616,7 +616,6 @@ class calculate_taxes_and_totals(object): self.doc.precision("base_write_off_amount")) def calculate_margin(self, item): - rate_with_margin = 0.0 base_rate_with_margin = 0.0 if item.price_list_rate: @@ -625,8 +624,8 @@ class calculate_taxes_and_totals(object): for d in get_applied_pricing_rules(item.pricing_rules): pricing_rule = frappe.get_cached_doc('Pricing Rule', d) - if (pricing_rule.margin_type in ['Amount', 'Percentage'] and pricing_rule.currency == self.doc.currency)\ - or (pricing_rule.margin_type == 'Percentage'): + if (pricing_rule.margin_rate_or_amount and pricing_rule.currency == self.doc.currency and + pricing_rule.margin_type in ['Amount', 'Percentage']): item.margin_type = pricing_rule.margin_type item.margin_rate_or_amount = pricing_rule.margin_rate_or_amount has_margin = True From 003ae90e12413d534878acef29aedf50c3b00db2 Mon Sep 17 00:00:00 2001 From: Marica Date: Mon, 1 Feb 2021 20:38:32 +0530 Subject: [PATCH 245/449] fix: Numeric/Non-numeric QI UX (#24517) * chore: Show 1 field each of both types of Insoections in grid view * fix: Make QI check Numeric by default and make checkbox "Numeric" - Reducing cognitive load --- .../item_quality_inspection_parameter.json | 16 ++++----- .../quality_inspection/quality_inspection.py | 4 +-- .../test_quality_inspection.py | 4 +-- .../quality_inspection_reading.json | 34 +++++++++---------- .../quality_inspection_template.py | 2 +- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json b/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json index 3e81619cfd..471e6853b5 100644 --- a/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json +++ b/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json @@ -8,7 +8,7 @@ "field_order": [ "specification", "value", - "non_numeric", + "numeric", "column_break_3", "min_value", "max_value", @@ -29,7 +29,7 @@ "width": "100px" }, { - "depends_on": "eval:(!doc.formula_based_criteria && doc.non_numeric)", + "depends_on": "eval:(!doc.formula_based_criteria && !doc.numeric)", "fieldname": "value", "fieldtype": "Data", "in_list_view": 1, @@ -55,32 +55,32 @@ "label": "Formula Based Criteria" }, { - "depends_on": "eval:(!doc.formula_based_criteria && !doc.non_numeric)", + "depends_on": "eval:(!doc.formula_based_criteria && doc.numeric)", "fieldname": "min_value", "fieldtype": "Float", "in_list_view": 1, "label": "Minimum Value" }, { - "depends_on": "eval:(!doc.formula_based_criteria && !doc.non_numeric)", + "depends_on": "eval:(!doc.formula_based_criteria && doc.numeric)", "fieldname": "max_value", "fieldtype": "Float", "in_list_view": 1, "label": "Maximum Value" }, { - "default": "0", - "fieldname": "non_numeric", + "default": "1", + "fieldname": "numeric", "fieldtype": "Check", "in_list_view": 1, - "label": "Non-Numeric", + "label": "Numeric", "width": "80px" } ], "idx": 1, "istable": 1, "links": [], - "modified": "2021-01-07 21:32:49.866439", + "modified": "2021-02-01 19:18:46.924399", "modified_by": "Administrator", "module": "Stock", "name": "Item Quality Inspection Parameter", diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.py b/erpnext/stock/doctype/quality_inspection/quality_inspection.py index b3acbc5ba0..58b1eca2d3 100644 --- a/erpnext/stock/doctype/quality_inspection/quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.py @@ -97,7 +97,7 @@ class QualityInspection(Document): self.set_status_based_on_acceptance_values(reading) def set_status_based_on_acceptance_values(self, reading): - if cint(reading.non_numeric): + if not cint(reading.numeric): result = reading.get("reading_value") == reading.get("value") else: # numeric readings @@ -136,7 +136,7 @@ class QualityInspection(Document): def get_formula_evaluation_data(self, reading): data = {} - if cint(reading.non_numeric): + if not cint(reading.numeric): data = {"reading_value": reading.get("reading_value")} else: # numeric readings diff --git a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py index 8c5a04b3f0..a7dfc9ee28 100644 --- a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py @@ -55,7 +55,7 @@ class TestQualityInspection(unittest.TestCase): }, { "specification": "Particle Inspection Needed", # non-numeric reading - "non_numeric": 1, + "numeric": 0, "value": "Yes", "reading_value": "Yes" }] @@ -96,7 +96,7 @@ class TestQualityInspection(unittest.TestCase): { "specification": "Calcium Content", # non-numeric reading "formula_based_criteria": 1, - "non_numeric": 1, + "numeric": 0, "acceptance_formula": "reading_value in ('Grade A', 'Grade B', 'Grade C')", "reading_value": "Grade B" }] diff --git a/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json b/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json index 30ff1fea3a..35d58eff58 100644 --- a/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json +++ b/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json @@ -9,7 +9,7 @@ "specification", "status", "value", - "non_numeric", + "numeric", "manual_inspection", "column_break_4", "min_value", @@ -46,7 +46,7 @@ }, { "columns": 2, - "depends_on": "eval:(!doc.formula_based_criteria && doc.non_numeric)", + "depends_on": "eval:(!doc.formula_based_criteria && !doc.numeric)", "fieldname": "value", "fieldtype": "Data", "label": "Acceptance Criteria Value", @@ -54,7 +54,7 @@ "oldfieldtype": "Data" }, { - "columns": 1, + "columns": 2, "fieldname": "reading_1", "fieldtype": "Data", "in_list_view": 1, @@ -66,7 +66,6 @@ "columns": 1, "fieldname": "reading_2", "fieldtype": "Data", - "in_list_view": 1, "label": "Reading 2", "oldfieldname": "reading_2", "oldfieldtype": "Data" @@ -140,7 +139,7 @@ "options": "\nAccepted\nRejected" }, { - "depends_on": "non_numeric", + "depends_on": "eval:!doc.numeric", "fieldname": "section_break_3", "fieldtype": "Section Break", "label": "Value Based Inspection" @@ -171,51 +170,52 @@ "label": "Formula Based Criteria" }, { - "depends_on": "eval:(!doc.formula_based_criteria && !doc.non_numeric)", + "depends_on": "eval:(!doc.formula_based_criteria && doc.numeric)", "description": "Applied on each reading.", "fieldname": "min_value", "fieldtype": "Float", "label": "Minimum Value" }, { - "depends_on": "eval:(!doc.formula_based_criteria && !doc.non_numeric)", + "depends_on": "eval:(!doc.formula_based_criteria && doc.numeric)", "description": "Applied on each reading.", "fieldname": "max_value", "fieldtype": "Float", "label": "Maximum Value" }, { - "depends_on": "non_numeric", + "columns": 2, + "depends_on": "eval:!doc.numeric", "fieldname": "reading_value", "fieldtype": "Data", "in_list_view": 1, "label": "Reading Value" }, { - "depends_on": "eval:!doc.non_numeric", + "depends_on": "numeric", "fieldname": "section_break_14", "fieldtype": "Section Break", "label": "Numeric Inspection" }, - { - "default": "0", - "fieldname": "non_numeric", - "fieldtype": "Check", - "in_list_view": 1, - "label": "Non-Numeric" - }, { "default": "0", "description": "Set the status manually.", "fieldname": "manual_inspection", "fieldtype": "Check", "label": "Manual Inspection" + }, + { + "default": "1", + "fieldname": "numeric", + "fieldtype": "Check", + "in_list_view": 1, + "label": "Numeric" } ], "idx": 1, "istable": 1, "links": [], - "modified": "2021-01-07 22:16:53.978410", + "modified": "2021-02-01 19:46:22.138018", "modified_by": "Administrator", "module": "Stock", "name": "Quality Inspection Reading", diff --git a/erpnext/stock/doctype/quality_inspection_template/quality_inspection_template.py b/erpnext/stock/doctype/quality_inspection_template/quality_inspection_template.py index c5a7974a73..01d2031b3a 100644 --- a/erpnext/stock/doctype/quality_inspection_template/quality_inspection_template.py +++ b/erpnext/stock/doctype/quality_inspection_template/quality_inspection_template.py @@ -14,6 +14,6 @@ def get_template_details(template): return frappe.get_all('Item Quality Inspection Parameter', fields=["specification", "value", "acceptance_formula", - "non_numeric", "formula_based_criteria", "min_value", "max_value"], + "numeric", "formula_based_criteria", "min_value", "max_value"], filters={'parenttype': 'Quality Inspection Template', 'parent': template}, order_by="idx") \ No newline at end of file From 5c28416daa8ac2b3b8968d750fa12fc214261088 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 1 Feb 2021 22:58:22 +0530 Subject: [PATCH 246/449] fix: test cases for pricing rule --- .../doctype/pricing_rule/test_pricing_rule.py | 3 +++ erpnext/accounts/doctype/pricing_rule/utils.py | 11 +++++------ erpnext/controllers/taxes_and_totals.py | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py index af8d21d9ce..f28cee7c5a 100644 --- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py @@ -56,6 +56,7 @@ class TestPricingRule(unittest.TestCase): self.assertEqual(details.get("discount_percentage"), 10) prule = frappe.get_doc(test_record.copy()) + prule.priority = 1 prule.applicable_for = "Customer" prule.title = "_Test Pricing Rule for Customer" self.assertRaises(MandatoryError, prule.insert) @@ -261,6 +262,7 @@ class TestPricingRule(unittest.TestCase): "rate_or_discount": "Discount Percentage", "rate": 0, "discount_percentage": 17.5, + "priority": 1, "company": "_Test Company" }).insert() @@ -557,6 +559,7 @@ def make_pricing_rule(**args): "rate": args.rate or 0.0, "margin_rate_or_amount": args.margin_rate_or_amount or 0.0, "condition": args.condition or '', + "priority": 1, "apply_multiple_pricing_rules": args.apply_multiple_pricing_rules or 0 }) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index bd9d0b3815..d163335996 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -59,18 +59,17 @@ def sorted_by_priority(pricing_rules, args, doc=None): pricing_rules_list = [] pricing_rule_dict = {} - priority = [] for pricing_rule in pricing_rules: pricing_rule = filter_pricing_rules(args, pricing_rule, doc) if pricing_rule: if not pricing_rule.get('priority'): - pricing_rules_list.append(pricing_rule) - else: - priority.append(cint(pricing_rule.get('priority'))) + pricing_rule['priority'] = 1 + + if pricing_rule.get('apply_multiple_pricing_rules'): pricing_rule_dict.setdefault(cint(pricing_rule.get("priority")), []).append(pricing_rule) - if priority: - pricing_rules_list.extend(pricing_rule_dict.get(min(priority))) + for key in sorted(pricing_rule_dict): + pricing_rules_list.extend(pricing_rule_dict.get(key)) return pricing_rules_list or pricing_rules diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 452246e89c..1f50e9c14d 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -624,8 +624,8 @@ class calculate_taxes_and_totals(object): for d in get_applied_pricing_rules(item.pricing_rules): pricing_rule = frappe.get_cached_doc('Pricing Rule', d) - if (pricing_rule.margin_rate_or_amount and pricing_rule.currency == self.doc.currency and - pricing_rule.margin_type in ['Amount', 'Percentage']): + if pricing_rule.margin_rate_or_amount and ((pricing_rule.currency == self.doc.currency and + pricing_rule.margin_type in ['Amount', 'Percentage']) or pricing_rule.margin_type == 'Percentage'): item.margin_type = pricing_rule.margin_type item.margin_rate_or_amount = pricing_rule.margin_rate_or_amount has_margin = True From bf97eb2d3bf7e3074c2fd84c7079bac4915b390d Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 2 Feb 2021 10:57:55 +0530 Subject: [PATCH 247/449] core: Added change log (#24526) --- erpnext/change_log/v13/v13_0_0-beta_11.md | 77 +++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 erpnext/change_log/v13/v13_0_0-beta_11.md diff --git a/erpnext/change_log/v13/v13_0_0-beta_11.md b/erpnext/change_log/v13/v13_0_0-beta_11.md new file mode 100644 index 0000000000..5c40ffbf73 --- /dev/null +++ b/erpnext/change_log/v13/v13_0_0-beta_11.md @@ -0,0 +1,77 @@ +### Version 13.0.0 Beta 11 Release Notes + +#### Features and Enhancements + +- Provision to disable serial no and batch selector ([#24398](https://github.com/frappe/erpnext/pull/24398)) +- Multi currency in landed cost voucher ([#24127](https://github.com/frappe/erpnext/pull/24127)) +- Putaway ([#23969](https://github.com/frappe/erpnext/pull/23969)) +- Item valuation for internal stock transfers ([#24200](https://github.com/frappe/erpnext/pull/24200)) +- Batch wise item pricing ([#24470](https://github.com/frappe/erpnext/pull/24470)) +- Project template with dependent tasks ([#24092](https://github.com/frappe/erpnext/pull/24092)) +- Patient History Enhancements ([#24033](https://github.com/frappe/erpnext/pull/24033)) +- Compute Year to Date for Salary Slip components ([#24362](https://github.com/frappe/erpnext/pull/24362)) +- Configurable accounting dimension filters and validations ([#23912](https://github.com/frappe/erpnext/pull/23912)) +- Issue Summary Script Report ([#23603](https://github.com/frappe/erpnext/pull/23603)) +- Issue Analytics Script Report ([#23604](https://github.com/frappe/erpnext/pull/23604)) +- Loan report and enhancements ([#24370](https://github.com/frappe/erpnext/pull/24370)) +- Enhancements to erpnext membership ([#23865](https://github.com/frappe/erpnext/pull/23865)) +- Allow Discharge despite Unbilled Healthcare Services ([#24281](https://github.com/frappe/erpnext/pull/24281)) +- Patient appointment status changes ([#24201](https://github.com/frappe/erpnext/pull/24201)) +- Allow selecting admission service unit in Patient Appointment for inpatients ([#24410](https://github.com/frappe/erpnext/pull/24410)) +- Separate equity tree in CoA SKR04 ([#24095](https://github.com/frappe/erpnext/pull/24095)) +- Do Not Bill Patient Encounters for Inpatients ([#24355](https://github.com/frappe/erpnext/pull/24355)) +- Value Based and Numeric Quality Inspection ([#24181](https://github.com/frappe/erpnext/pull/24181)) +- Deleting account & stock entries on deletion of transaction ([#24298](https://github.com/frappe/erpnext/pull/24298)) +- Remove german sales invoice validation ([#24441](https://github.com/frappe/erpnext/pull/24441)) +- Voice Call Settings doctype added ([#24126](https://github.com/frappe/erpnext/pull/24126)) +- Shopping portal changes ([#24445](https://github.com/frappe/erpnext/pull/24445)) +- Add "Sync Now" to Plaid Settings ([#23602](https://github.com/frappe/erpnext/pull/23602)) + +#### Fixes + +- Multiple pricing rule with margin type as Percentage is not working ([#24204](https://github.com/frappe/erpnext/pull/24204)) +- Allow statistical component in salary structure. ([#24424](https://github.com/frappe/erpnext/pull/24424)) +- Set current asset value before calculating difference amount ([#24119](https://github.com/frappe/erpnext/pull/24119)) +- To use Stock UoM in BOM Stock Report ([#24339](https://github.com/frappe/erpnext/pull/24339)) +- Accounting entries of asset when submitting purchase receipt ([#24191](https://github.com/frappe/erpnext/pull/24191)) +- Cancelling of asset value adjustement ([#24193](https://github.com/frappe/erpnext/pull/24193)) +- Batch/Serial Selector for Scanned Batched Item ([#24338](https://github.com/frappe/erpnext/pull/24338)) +- Link timesheets with corresponding projects ([#24346](https://github.com/frappe/erpnext/pull/24346)) +- Material request wrong status issue ([#24019](https://github.com/frappe/erpnext/pull/24019)) +- UX issues in e-invoicing ([#24358](https://github.com/frappe/erpnext/pull/24358)) +- Company Wise Valuation Rate for RM in BOM ([#24324](https://github.com/frappe/erpnext/pull/24324)) +- Stock ageing should not take cancelled stock entries. ([#24437](https://github.com/frappe/erpnext/pull/24437)) +- Partial loan security unpledging ([#24252](https://github.com/frappe/erpnext/pull/24252)) +- Asset depreciation ledger ([#24226](https://github.com/frappe/erpnext/pull/24226)) +- Back Update from QC based on Batch No ([#24329](https://github.com/frappe/erpnext/pull/24329)) +- Fix for not having fiscal year while creating new company ([#24130](https://github.com/frappe/erpnext/pull/24130)) +- E-invoice print format not showing other charges ([#24474](https://github.com/frappe/erpnext/pull/24474)) +- Tax template update on customer address change ([#24146](https://github.com/frappe/erpnext/pull/24146)) +- Do not manufacture same serial no multiple times ([#24164](https://github.com/frappe/erpnext/pull/24164)) +- Ignore group cost center validation for period closing voucher ([#24375](https://github.com/frappe/erpnext/pull/24375)) +- Partial serial no return issue ([#24207](https://github.com/frappe/erpnext/pull/24207)) +- GSTR-1 double entry issue ([#24376](https://github.com/frappe/erpnext/pull/24376)) +- Not able to create dunning from sales invoice ([#24349](https://github.com/frappe/erpnext/pull/24349)) +- Set company in leave allocation and leave ledger entry ([#24296](https://github.com/frappe/erpnext/pull/24296)) +- Allow leave policy assignment to be canceled. ([#24265](https://github.com/frappe/erpnext/pull/24265)) +- Removed all day event from shift assignment calendar ([#24397](https://github.com/frappe/erpnext/pull/24397)) +- Tax calculation on salary slip for the first month ([#24272](https://github.com/frappe/erpnext/pull/24272)) +- Validate tax template for tax category ([#24402](https://github.com/frappe/erpnext/pull/24402)) +- Numeric/Non-numeric QI UX ([#24517](https://github.com/frappe/erpnext/pull/24517)) +- Finished good produced qty validation ([#24220](https://github.com/frappe/erpnext/pull/24220)) +- Incorrect serial no in the subcontracted purchase receipt ([#24354](https://github.com/frappe/erpnext/pull/24354)) +- Don't validate warehouse values between Material Request and Stock Entry ([#24294](https://github.com/frappe/erpnext/pull/24294)) +- Don't cancel job card if manufacturing entry has made ([#24063](https://github.com/frappe/erpnext/pull/24063)) +- Subscription prepaid date validation ([#24356](https://github.com/frappe/erpnext/pull/24356)) +- Allow addition and removal of employee in payroll Entry ([#24169](https://github.com/frappe/erpnext/pull/24169)) +- Filter Therapy Types and Therapy Plan in Patient Appointment ([#24152](https://github.com/frappe/erpnext/pull/24152)) +- Payment Period based on invoice date report fix/refactor ([#24378](https://github.com/frappe/erpnext/pull/24378)) +- Drop ship partial order fixed ([#24072](https://github.com/frappe/erpnext/pull/24072)) +- E-invoicing qrcode image generation ([#24395](https://github.com/frappe/erpnext/pull/24395)) +- Payment entry multi-currency issue ([#24332](https://github.com/frappe/erpnext/pull/24332)) +- Multiple pricing rule issue ([#24515](https://github.com/frappe/erpnext/pull/24515)) +- Last purchase rate not updating when voucher cancelled if only one voucher is present ([#24322](https://github.com/frappe/erpnext/pull/24322)) +- Do not cancel reference document on Quality Inspection cancellation ([#24197](https://github.com/frappe/erpnext/pull/24197)) +- Refactored fetching & validating address from erpnext rather than gst portal ([#24297](https://github.com/frappe/erpnext/pull/24297)) +- Opportunity Status fix ([#22944](https://github.com/frappe/erpnext/pull/22944)) +- Extra transferred qty has not consumed against work order ([#24495](https://github.com/frappe/erpnext/pull/24495)) \ No newline at end of file From 8676089794abb8cd904d1aa7fdf6fd7de1b903bb Mon Sep 17 00:00:00 2001 From: Afshan <33727827+AfshanKhan@users.noreply.github.com> Date: Tue, 2 Feb 2021 11:02:22 +0530 Subject: [PATCH 248/449] fix: emp disappear (#24524) * fix: emp disappear * fix: renamed set_totals_call to set_totals Co-authored-by: Nabin Hait --- .../payroll/doctype/payroll_entry/payroll_entry.js | 1 - erpnext/payroll/doctype/salary_slip/salary_slip.js | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.js b/erpnext/payroll/doctype/payroll_entry/payroll_entry.js index 45f9aa170f..395e56fa92 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.js +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.js @@ -348,7 +348,6 @@ let render_employee_attendance = function (frm, data) { frappe.ui.form.on('Payroll Employee Detail', { employee: function(frm) { - frm.events.clear_employee_table(frm); if (!frm.doc.payroll_frequency) { frappe.throw(__("Please set a Payroll Frequency")); } diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.js b/erpnext/payroll/doctype/salary_slip/salary_slip.js index b50c774fbe..7460c75227 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.js +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.js @@ -116,7 +116,7 @@ frappe.ui.form.on("Salary Slip", { }, exchange_rate: function(frm) { - calculate_totals(frm); + set_totals(frm); }, hide_loan_section: function(frm) { @@ -205,14 +205,14 @@ frappe.ui.form.on("Salary Slip", { frappe.ui.form.on('Salary Slip Timesheet', { time_sheet: function(frm) { - calculate_totals(frm); + set_totals(frm); }, timesheets_remove: function(frm) { - calculate_totals(frm); + set_totals(frm); } }); -var calculate_totals = function(frm) { +var set_totals = function(frm) { if (frm.doc.docstatus === 0) { if (frm.doc.earnings || frm.doc.deductions) { frappe.call({ @@ -228,15 +228,15 @@ var calculate_totals = function(frm) { frappe.ui.form.on('Salary Detail', { amount: function(frm) { - calculate_totals(frm); + set_totals(frm); }, earnings_remove: function(frm) { - calculate_totals(frm); + set_totals(frm); }, deductions_remove: function(frm) { - calculate_totals(frm); + set_totals(frm); }, salary_component: function(frm, cdt, cdn) { From 10b00f9d0d827cf6664fbe134a94d09b7c14c1f8 Mon Sep 17 00:00:00 2001 From: Afshan <33727827+AfshanKhan@users.noreply.github.com> Date: Tue, 2 Feb 2021 16:24:01 +0530 Subject: [PATCH 249/449] fix: separation of salary creation from payroll (#24528) * fix: separation of salary creation from payroll * fix: removed unnecessary veriable * fix: check existing sal slips * fix: existing checks * style: refactoring query --- .../doctype/payroll_entry/payroll_entry.js | 11 ++++-- .../doctype/payroll_entry/payroll_entry.py | 35 +++++++------------ 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.js b/erpnext/payroll/doctype/payroll_entry/payroll_entry.js index 395e56fa92..94f3f3098e 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.js +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.js @@ -138,7 +138,6 @@ frappe.ui.form.on('Payroll Entry', { payroll_frequency: function (frm) { frm.trigger("set_start_end_dates").then( ()=> { frm.events.clear_employee_table(frm); - frm.events.get_employee_with_salary_slip_and_set_query(frm); }); }, @@ -146,13 +145,17 @@ frappe.ui.form.on('Payroll Entry', { frm.set_query('employee', 'employees', () => { return { filters: { - name: ["not in", emp_list] + name: ["not in", emp_list], + company: frm.doc.company } }; }); }, get_employee_with_salary_slip_and_set_query: function (frm) { + if (!frm.doc.company) { + frappe.throw(__("Please set a Company")); + } frappe.db.get_list('Salary Slip', { filters: { start_date: frm.doc.start_date, @@ -171,6 +174,7 @@ frappe.ui.form.on('Payroll Entry', { company: function (frm) { frm.events.clear_employee_table(frm); + frm.events.get_employee_with_salary_slip_and_set_query(frm); erpnext.accounts.dimensions.update_dimension(frm, frm.doctype); }, @@ -348,6 +352,9 @@ let render_employee_attendance = function (frm, data) { frappe.ui.form.on('Payroll Employee Detail', { employee: function(frm) { + if (!frm.doc.company) { + frappe.throw(__("Please set a Company")); + } if (!frm.doc.payroll_frequency) { frappe.throw(__("Please set a Payroll Frequency")); } diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py index 6bcd4e0c00..1ed3332d0f 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py @@ -14,7 +14,7 @@ from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee class PayrollEntry(Document): def onload(self): if not self.docstatus==1 or self.salary_slips_submitted: - return + return # check if salary slips were manually submitted entries = frappe.db.count("Salary Slip", {'payroll_entry': self.name, 'docstatus': 1}, ['name']) @@ -174,13 +174,12 @@ class PayrollEntry(Document): """ Returns list of salary slips based on selected criteria """ - cond = self.get_filter_condition() ss_list = frappe.db.sql(""" select t1.name, t1.salary_structure, t1.payroll_cost_center from `tabSalary Slip` t1 - where t1.docstatus = %s and t1.start_date >= %s and t1.end_date <= %s - and (t1.journal_entry is null or t1.journal_entry = "") and ifnull(salary_slip_based_on_timesheet,0) = %s %s - """ % ('%s', '%s', '%s','%s', cond), (ss_status, self.start_date, self.end_date, self.salary_slip_based_on_timesheet), as_dict=as_dict) + where t1.docstatus = %s and t1.start_date >= %s and t1.end_date <= %s and t1.payroll_entry = %s + and (t1.journal_entry is null or t1.journal_entry = "") and ifnull(salary_slip_based_on_timesheet,0) = %s + """, (ss_status, self.start_date, self.end_date, self.name, self.salary_slip_based_on_timesheet), as_dict=as_dict) return ss_list def submit_salary_slips(self): @@ -332,10 +331,9 @@ class PayrollEntry(Document): def make_payment_entry(self): self.check_permission('write') - cond = self.get_filter_condition() salary_slip_name_list = frappe.db.sql(""" select t1.name from `tabSalary Slip` t1 - where t1.docstatus = 1 and start_date >= %s and end_date <= %s %s - """ % ('%s', '%s', cond), (self.start_date, self.end_date), as_list = True) + where t1.docstatus = 1 and start_date >= %s and end_date <= %s and t1.payroll_entry = %s + """, (self.start_date, self.end_date, self.name), as_list = True) if salary_slip_name_list and len(salary_slip_name_list) > 0: salary_slip_total = 0 @@ -550,6 +548,7 @@ def payroll_entry_has_bank_entries(name): def create_salary_slips_for_employees(employees, args, publish_progress=True): salary_slips_exists_for = get_existing_salary_slips(employees, args) count=0 + salary_slips_not_created = [] for emp in employees: if emp not in salary_slips_exists_for: args.update({ @@ -562,26 +561,18 @@ def create_salary_slips_for_employees(employees, args, publish_progress=True): if publish_progress: frappe.publish_progress(count*100/len(set(employees) - set(salary_slips_exists_for)), title = _("Creating Salary Slips...")) - else: - salary_slip_name = frappe.db.sql( - '''SELECT - name - FROM `tabSalary Slip` - WHERE company=%s - AND start_date >= %s - AND end_date <= %s - AND employee = %s - ''', (args.company, args.start_date, args.end_date, emp), as_dict=True) - salary_slip_doc = frappe.get_doc('Salary Slip', salary_slip_name[0].name) - salary_slip_doc.exchange_rate = args.exchange_rate - salary_slip_doc.set_totals() - salary_slip_doc.db_update() + else: + salary_slips_not_created.append(emp) payroll_entry = frappe.get_doc("Payroll Entry", args.payroll_entry) payroll_entry.db_set("salary_slips_created", 1) payroll_entry.notify_update() + if salary_slips_not_created: + frappe.msgprint(_("Salary Slips already exists for employees {}, and will not be processed by this payroll.") + .format(frappe.bold(", ".join([emp for emp in salary_slips_not_created]))) , title=_("Message"), indicator="orange") + def get_existing_salary_slips(employees, args): return frappe.db.sql_list(""" select distinct employee from `tabSalary Slip` From 243d59b0c3ab030c10bca210376a8c199a97ec8d Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 2 Feb 2021 16:55:13 +0530 Subject: [PATCH 250/449] Reposting logic fixes (#24520) * fix: Dependant sle logic fixes * fix: negative qty validation * fix: Travis fixes * fix: test fix --- .../doctype/work_order/test_work_order.py | 4 +- .../united_states/test_united_states.py | 1 - erpnext/stock/doctype/bin/bin.py | 6 +-- .../purchase_receipt/test_purchase_receipt.py | 3 -- .../repost_item_valuation.js | 2 +- erpnext/stock/stock_ledger.py | 48 +++++++------------ .../report/issue_analytics/issue_analytics.py | 3 +- .../issue_analytics/test_issue_analytics.py | 7 ++- 8 files changed, 28 insertions(+), 46 deletions(-) diff --git a/erpnext/manufacturing/doctype/work_order/test_work_order.py b/erpnext/manufacturing/doctype/work_order/test_work_order.py index e562d6c4bd..06a8e1987d 100644 --- a/erpnext/manufacturing/doctype/work_order/test_work_order.py +++ b/erpnext/manufacturing/doctype/work_order/test_work_order.py @@ -544,7 +544,7 @@ class TestWorkOrder(unittest.TestCase): expected_qty = {"_Test Item": 2, "_Test Item Home Desktop 100": 4} for row in ste3.items: self.assertEquals(row.qty, expected_qty.get(row.item_code)) - + ste_cancel_list.reverse() for ste_doc in ste_cancel_list: ste_doc.cancel() @@ -586,7 +586,7 @@ class TestWorkOrder(unittest.TestCase): for ste_row in ste2.items: if itemwise_qty.get(ste_row.item_code) and ste_row.s_warehouse: self.assertEquals(ste_row.qty, itemwise_qty.get(ste_row.item_code) / 2) - + ste_cancel_list.reverse() for ste_doc in ste_cancel_list: ste_doc.cancel() diff --git a/erpnext/regional/united_states/test_united_states.py b/erpnext/regional/united_states/test_united_states.py index ad95010a9a..513570ed6d 100644 --- a/erpnext/regional/united_states/test_united_states.py +++ b/erpnext/regional/united_states/test_united_states.py @@ -26,7 +26,6 @@ class TestUnitedStates(unittest.TestCase): make_payment_entry_to_irs_1099_supplier() filters = frappe._dict({"fiscal_year": "_Test Fiscal Year 2016", "company": "_Test Company 1"}) columns, data = execute_1099_report(filters) - print(columns, data) expected_row = {'supplier': '_US 1099 Test Supplier', 'supplier_group': 'Services', 'payments': 100.0, diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py index ab19b77ad8..1088b4127d 100644 --- a/erpnext/stock/doctype/bin/bin.py +++ b/erpnext/stock/doctype/bin/bin.py @@ -17,7 +17,7 @@ class Bin(Document): '''Called from erpnext.stock.utils.update_bin''' self.update_qty(args) if args.get("actual_qty") or args.get("voucher_type") == "Stock Reconciliation": - from erpnext.stock.stock_ledger import update_entries_after, update_qty_in_future_sle + from erpnext.stock.stock_ledger import update_entries_after, validate_negative_qty_in_future_sle if not args.get("posting_date"): args["posting_date"] = nowdate() @@ -37,8 +37,8 @@ class Bin(Document): "sle_id": args.name }, allow_negative_stock=allow_negative_stock, via_landed_cost_voucher=via_landed_cost_voucher) - # Update qty_after_transaction in future SLEs of this item and warehouse - update_qty_in_future_sle(args) + # Validate negative qty in future transactions + validate_negative_qty_in_future_sle(args) def update_qty(self, args): # update the stock values (for current quantities) diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 37e0c7f344..ca58ab2823 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -580,9 +580,6 @@ class TestPurchaseReceipt(unittest.TestCase): dn.cancel() pr1.cancel() - dn.cancel() - pr1.cancel() - def test_auto_asset_creation(self): asset_item = "Test Asset Item" diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js index e429cd5e30..b3e4286bcc 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js @@ -31,7 +31,7 @@ frappe.ui.form.on('Repost Item Valuation', { } }, refresh: function(frm) { - if (frm.doc.status == "Failed") { + if (frm.doc.status == "Failed" && frm.doc.docstatus==1) { frm.add_custom_button(__('Restart'), function () { frm.trigger("restart_reposting"); }).addClass("btn-primary"); diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 2b2a7a202d..46919c8c8c 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -62,7 +62,7 @@ def make_entry(args, allow_negative_stock=False, via_landed_cost_voucher=False): sle.submit() return sle -def repost_future_sle(args=None, voucher_type=None, voucher_no=None, allow_negative_stock=False, via_landed_cost_voucher=False): +def repost_future_sle(args=None, voucher_type=None, voucher_no=None, allow_negative_stock=None, via_landed_cost_voucher=False): if not args and voucher_type and voucher_no: args = get_args_for_voucher(voucher_type, voucher_no) @@ -181,7 +181,7 @@ class update_entries_after(object): self.process_sle(sle) if sle.dependant_sle_voucher_detail_no: - self.get_dependent_entries_to_fix(entries_to_fix, sle) + entries_to_fix = self.get_dependent_entries_to_fix(entries_to_fix, sle) if self.exceptions: self.raise_exceptions() @@ -221,13 +221,15 @@ class update_entries_after(object): excluded_sle=sle.name) if not dependant_sle: - return + return entries_to_fix elif dependant_sle.item_code == self.item_code and dependant_sle.warehouse == self.args.warehouse: - return - elif dependant_sle.item_code != self.item_code \ - and (dependant_sle.item_code, dependant_sle.warehouse) not in self.new_items: - self.new_items[(dependant_sle.item_code, dependant_sle.warehouse)] = dependant_sle - return + return entries_to_fix + elif dependant_sle.item_code != self.item_code: + if (dependant_sle.item_code, dependant_sle.warehouse) not in self.new_items: + self.new_items[(dependant_sle.item_code, dependant_sle.warehouse)] = dependant_sle + return entries_to_fix + elif dependant_sle.item_code == self.item_code and dependant_sle.warehouse in self.data: + return entries_to_fix self.initialize_previous_data(dependant_sle) @@ -236,7 +238,7 @@ class update_entries_after(object): future_sle_for_dependant = list(self.get_sle_after_datetime(args)) entries_to_fix.extend(future_sle_for_dependant) - entries_to_fix = sorted(entries_to_fix, key=lambda k: k['timestamp']) + return sorted(entries_to_fix, key=lambda k: k['timestamp']) def process_sle(self, sle): # previous sle data for this warehouse @@ -612,11 +614,11 @@ class update_entries_after(object): frappe.local.flags.currently_saving): msg = _("{0} units of {1} needed in {2} to complete this transaction.").format( - abs(deficiency), frappe.get_desk_link('Item', self.item_code), + abs(deficiency), frappe.get_desk_link('Item', exceptions[0]["item_code"]), frappe.get_desk_link('Warehouse', warehouse)) else: msg = _("{0} units of {1} needed in {2} on {3} {4} for {5} to complete this transaction.").format( - abs(deficiency), frappe.get_desk_link('Item', self.item_code), + abs(deficiency), frappe.get_desk_link('Item', exceptions[0]["item_code"]), frappe.get_desk_link('Warehouse', warehouse), exceptions[0]["posting_date"], exceptions[0]["posting_time"], frappe.get_desk_link(exceptions[0]["voucher_type"], exceptions[0]["voucher_no"])) @@ -761,25 +763,6 @@ def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, return valuation_rate -def update_qty_in_future_sle(args, allow_negative_stock=None): - frappe.db.sql(""" - update `tabStock Ledger Entry` - set qty_after_transaction = qty_after_transaction + {qty} - where - item_code = %(item_code)s - and warehouse = %(warehouse)s - and voucher_no != %(voucher_no)s - and is_cancelled = 0 - and (timestamp(posting_date, posting_time) > timestamp(%(posting_date)s, %(posting_time)s) - or ( - timestamp(posting_date, posting_time) = timestamp(%(posting_date)s, %(posting_time)s) - and creation > %(creation)s - ) - ) - """.format(qty=args.actual_qty), args) - - validate_negative_qty_in_future_sle(args, allow_negative_stock) - def validate_negative_qty_in_future_sle(args, allow_negative_stock=None): allow_negative_stock = allow_negative_stock \ or cint(frappe.db.get_single_value("Stock Settings", "allow_negative_stock")) @@ -808,6 +791,7 @@ def get_future_sle_with_negative_qty(args): and voucher_no != %(voucher_no)s and timestamp(posting_date, posting_time) >= timestamp(%(posting_date)s, %(posting_time)s) and is_cancelled = 0 - and qty_after_transaction < 0 + and qty_after_transaction + {0} < 0 + order by timestamp(posting_date, posting_time) asc limit 1 - """, args, as_dict=1) \ No newline at end of file + """.format(args.actual_qty), args, as_dict=1) \ No newline at end of file diff --git a/erpnext/support/report/issue_analytics/issue_analytics.py b/erpnext/support/report/issue_analytics/issue_analytics.py index 0b629151a6..3fdb10ddf3 100644 --- a/erpnext/support/report/issue_analytics/issue_analytics.py +++ b/erpnext/support/report/issue_analytics/issue_analytics.py @@ -147,8 +147,7 @@ class IssueAnalytics(object): self.entries = frappe.db.get_all('Issue', fields=[self.field_map.get(self.filters.based_on), 'name', 'opening_date'], - filters=filters, - debug=1 + filters=filters ) def get_common_filters(self): diff --git a/erpnext/support/report/issue_analytics/test_issue_analytics.py b/erpnext/support/report/issue_analytics/test_issue_analytics.py index 432906db9b..fc6bb587be 100644 --- a/erpnext/support/report/issue_analytics/test_issue_analytics.py +++ b/erpnext/support/report/issue_analytics/test_issue_analytics.py @@ -17,8 +17,11 @@ class TestIssueAnalytics(unittest.TestCase): current_month_date = getdate() last_month_date = add_months(current_month_date, -1) - self.current_month = str(months[current_month_date.month - 1]).lower() + '_' + str(current_month_date.year) - self.last_month = str(months[last_month_date.month - 1]).lower() + '_' + str(last_month_date.year) + self.current_month = str(months[current_month_date.month - 1]).lower() + self.last_month = str(months[last_month_date.month - 1]).lower() + if current_month_date.year != last_month_date.year: + self.current_month += '_' + str(current_month_date.year) + self.last_month += '_' + str(last_month_date.year) def test_issue_analytics(self): create_service_level_agreements_for_issues() From 17433d2c908f77b8cc5c2586e437150fd0480c08 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 2 Feb 2021 17:40:11 +0530 Subject: [PATCH 251/449] fix: version number --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 8b90a51542..ad1167b0d8 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0-beta.9' +__version__ = '13.0.0-beta.10' def get_default_company(user=None): '''Get default company for user''' From c0f8f3280110f45a897f8002f46a05fa13b61851 Mon Sep 17 00:00:00 2001 From: Afshan <33727827+AfshanKhan@users.noreply.github.com> Date: Tue, 2 Feb 2021 20:27:23 +0530 Subject: [PATCH 252/449] fix: fetch query for employee (#24529) --- .../doctype/payroll_entry/payroll_entry.js | 68 +++++++------------ .../doctype/payroll_entry/payroll_entry.py | 55 +++++++++++++++ 2 files changed, 80 insertions(+), 43 deletions(-) diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.js b/erpnext/payroll/doctype/payroll_entry/payroll_entry.js index 94f3f3098e..0dcea88c89 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.js +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.js @@ -133,6 +133,31 @@ frappe.ui.form.on('Payroll Entry', { } }; }); + + frm.set_query('employee', 'employees', () => { + if (!frm.doc.company) { + frappe.msgprint(__("Please set a Company")); + return [] + } + let filters = {}; + filters['company'] = frm.doc.company; + filters['start_date'] = frm.doc.start_date; + filters['end_date'] = frm.doc.end_date; + + if (frm.doc.department) { + filters['department'] = frm.doc.department; + } + if (frm.doc.branch) { + filters['branch'] = frm.doc.branch; + } + if (frm.doc.designation) { + filters['designation'] = frm.doc.designation; + } + return { + query: "erpnext.payroll.doctype.payroll_entry.payroll_entry.employee_query", + filters: filters + } + }); }, payroll_frequency: function (frm) { @@ -141,40 +166,8 @@ frappe.ui.form.on('Payroll Entry', { }); }, - employee_filters: function (frm, emp_list) { - frm.set_query('employee', 'employees', () => { - return { - filters: { - name: ["not in", emp_list], - company: frm.doc.company - } - }; - }); - }, - - get_employee_with_salary_slip_and_set_query: function (frm) { - if (!frm.doc.company) { - frappe.throw(__("Please set a Company")); - } - frappe.db.get_list('Salary Slip', { - filters: { - start_date: frm.doc.start_date, - end_date: frm.doc.end_date, - docstatus: 1, - }, - fields: ['employee'] - }).then((emp) => { - var emp_list = []; - emp.forEach((employee_data) => { - emp_list.push(Object.values(employee_data)[0]); - }); - frm.events.employee_filters(frm, emp_list); - }); - }, - company: function (frm) { frm.events.clear_employee_table(frm); - frm.events.get_employee_with_salary_slip_and_set_query(frm); erpnext.accounts.dimensions.update_dimension(frm, frm.doctype); }, @@ -349,14 +342,3 @@ let render_employee_attendance = function (frm, data) { }) ); }; - -frappe.ui.form.on('Payroll Employee Detail', { - employee: function(frm) { - if (!frm.doc.company) { - frappe.throw(__("Please set a Company")); - } - if (!frm.doc.payroll_frequency) { - frappe.throw(__("Please set a Payroll Frequency")); - } - } -}); diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py index 1ed3332d0f..b520cdabdc 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py @@ -10,6 +10,7 @@ from frappe.utils import cint, flt, add_days, getdate, add_to_date, DATE_FORMAT, from frappe import _ from erpnext.accounts.utils import get_fiscal_year from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee +from frappe.desk.reportview import get_match_cond, get_filters_cond class PayrollEntry(Document): def onload(self): @@ -632,3 +633,57 @@ def get_payroll_entries_for_jv(doctype, txt, searchfield, start, page_len, filte 'txt': "%%%s%%" % frappe.db.escape(txt), 'start': start, 'page_len': page_len }) + +def get_employee_with_existing_salary_slip(start_date, end_date): + + return frappe.db.sql_list(""" + select employee from `tabSalary Slip` + where + (start_date between %(start_date)s and %(end_date)s + or + end_date between %(start_date)s and %(end_date)s + or + %(start_date)s between start_date and end_date) + and docstatus = 1 + """, {'start_date': start_date, 'end_date': end_date}) + +@frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs +def employee_query(doctype, txt, searchfield, start, page_len, filters): + filters = frappe._dict(filters) + conditions = [] + emp_cond = '' + if filters.start_date and filters.end_date: + employee_list = get_employee_with_existing_salary_slip(filters.start_date, filters.end_date) + filters.pop('start_date') + filters.pop('end_date') + if employee_list: + emp_cond += 'and employee not in %(employee_list)s' + else: + employee_list = [] + + + return frappe.db.sql("""select name, employee_name from `tabEmployee` + where status = 'Active' + and docstatus < 2 + and ({key} like %(txt)s + or employee_name like %(txt)s) + {emp_cond} + {fcond} {mcond} + order by + if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999), + if(locate(%(_txt)s, employee_name), locate(%(_txt)s, employee_name), 99999), + idx desc, + name, employee_name + limit %(start)s, %(page_len)s""".format(**{ + 'key': searchfield, + 'fcond': get_filters_cond(doctype, filters, conditions), + 'mcond': get_match_cond(doctype), + 'emp_cond': emp_cond + }), { + 'txt': "%%%s%%" % txt, + '_txt': txt.replace("%", ""), + 'start': start, + 'page_len': page_len, + 'employee_list': employee_list + }) From 7645e5319d53401e454117f35f5abe22f02217f0 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 2 Feb 2021 21:15:21 +0550 Subject: [PATCH 253/449] bumped to version 13.0.0-beta.11 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index ad1167b0d8..a754e1323b 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0-beta.10' +__version__ = '13.0.0-beta.11' def get_default_company(user=None): '''Get default company for user''' From 6485eeb302f87965e2179f226dafcf2cef1c573b Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Thu, 11 Feb 2021 11:12:13 +0530 Subject: [PATCH 254/449] fix: portal permission issue (#24577) --- .../setup/doctype/customer_group/customer_group.json | 11 ++++++++++- erpnext/setup/doctype/item_group/item_group.json | 9 +++++++++ erpnext/setup/doctype/territory/territory.json | 11 ++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/erpnext/setup/doctype/customer_group/customer_group.json b/erpnext/setup/doctype/customer_group/customer_group.json index 10f9bd0030..0e2ed9efcf 100644 --- a/erpnext/setup/doctype/customer_group/customer_group.json +++ b/erpnext/setup/doctype/customer_group/customer_group.json @@ -139,7 +139,7 @@ "idx": 1, "is_tree": 1, "links": [], - "modified": "2020-03-18 18:10:13.048492", + "modified": "2021-02-08 17:01:52.162202", "modified_by": "Administrator", "module": "Setup", "name": "Customer Group", @@ -189,6 +189,15 @@ "permlevel": 1, "read": 1, "role": "Sales Manager" + }, + { + "email": 1, + "export": 1, + "print": 1, + "report": 1, + "role": "Customer", + "select": 1, + "share": 1 } ], "search_fields": "parent_customer_group", diff --git a/erpnext/setup/doctype/item_group/item_group.json b/erpnext/setup/doctype/item_group/item_group.json index 004421d2bc..fc464b237c 100644 --- a/erpnext/setup/doctype/item_group/item_group.json +++ b/erpnext/setup/doctype/item_group/item_group.json @@ -245,6 +245,15 @@ "read": 1, "report": 1, "role": "Accounts User" + }, + { + "email": 1, + "export": 1, + "print": 1, + "report": 1, + "role": "Customer", + "select": 1, + "share": 1 } ], "search_fields": "parent_item_group", diff --git a/erpnext/setup/doctype/territory/territory.json b/erpnext/setup/doctype/territory/territory.json index aa8e0486f5..a25bda054b 100644 --- a/erpnext/setup/doctype/territory/territory.json +++ b/erpnext/setup/doctype/territory/territory.json @@ -123,7 +123,7 @@ "idx": 1, "is_tree": 1, "links": [], - "modified": "2020-03-18 18:11:36.623555", + "modified": "2021-02-08 17:10:03.767426", "modified_by": "Administrator", "module": "Setup", "name": "Territory", @@ -166,6 +166,15 @@ { "read": 1, "role": "Maintenance User" + }, + { + "email": 1, + "export": 1, + "print": 1, + "report": 1, + "role": "Customer", + "select": 1, + "share": 1 } ], "search_fields": "parent_territory,territory_manager", From 73c2d23a9a73057edddc70c247a408a2580ab614 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 18 Feb 2021 16:41:10 +0530 Subject: [PATCH 255/449] feat: Department Wise Appointment Type charges (#24572) * feat: Appointment Type Service Items Co-Authored-By: muhammad * fix: set practitioner service item charges mandatory on item selection Co-Authored-By: muhammad * feat: use charges from appointment type during billing * feat: handle appointment charges priority for invoice automation * test: patient appointment auto invoicing scenarios * fix: sider * fix: minor fixes Co-authored-by: muhammad Co-authored-by: Nabin Hait --- .../appointment_type/appointment_type.js | 78 ++++++++++++ .../appointment_type/appointment_type.json | 24 +++- .../appointment_type/appointment_type.py | 49 +++++++- .../appointment_type_service_item/__init__.py | 0 .../appointment_type_service_item.json | 67 +++++++++++ .../appointment_type_service_item.py | 10 ++ .../healthcare_practitioner.json | 6 +- .../patient_appointment.js | 112 +++++++++--------- .../patient_appointment.json | 26 ++-- .../patient_appointment.py | 67 +++++++---- .../test_patient_appointment.py | 84 ++++++++++++- erpnext/healthcare/utils.py | 85 ++++++++++--- 12 files changed, 485 insertions(+), 123 deletions(-) create mode 100644 erpnext/healthcare/doctype/appointment_type_service_item/__init__.py create mode 100644 erpnext/healthcare/doctype/appointment_type_service_item/appointment_type_service_item.json create mode 100644 erpnext/healthcare/doctype/appointment_type_service_item/appointment_type_service_item.py diff --git a/erpnext/healthcare/doctype/appointment_type/appointment_type.js b/erpnext/healthcare/doctype/appointment_type/appointment_type.js index 15916a5134..861675acea 100644 --- a/erpnext/healthcare/doctype/appointment_type/appointment_type.js +++ b/erpnext/healthcare/doctype/appointment_type/appointment_type.js @@ -2,4 +2,82 @@ // For license information, please see license.txt frappe.ui.form.on('Appointment Type', { + refresh: function(frm) { + frm.set_query('price_list', function() { + return { + filters: {'selling': 1} + }; + }); + + frm.set_query('medical_department', 'items', function(doc) { + let item_list = doc.items.map(({medical_department}) => medical_department); + return { + filters: [ + ['Medical Department', 'name', 'not in', item_list] + ] + }; + }); + + frm.set_query('op_consulting_charge_item', 'items', function() { + return { + filters: { + is_stock_item: 0 + } + }; + }); + + frm.set_query('inpatient_visit_charge_item', 'items', function() { + return { + filters: { + is_stock_item: 0 + } + }; + }); + } }); + +frappe.ui.form.on('Appointment Type Service Item', { + op_consulting_charge_item: function(frm, cdt, cdn) { + let d = locals[cdt][cdn]; + if (frm.doc.price_list && d.op_consulting_charge_item) { + frappe.call({ + 'method': 'frappe.client.get_value', + args: { + 'doctype': 'Item Price', + 'filters': { + 'item_code': d.op_consulting_charge_item, + 'price_list': frm.doc.price_list + }, + 'fieldname': ['price_list_rate'] + }, + callback: function(data) { + if (data.message.price_list_rate) { + frappe.model.set_value(cdt, cdn, 'op_consulting_charge', data.message.price_list_rate); + } + } + }); + } + }, + + inpatient_visit_charge_item: function(frm, cdt, cdn) { + let d = locals[cdt][cdn]; + if (frm.doc.price_list && d.inpatient_visit_charge_item) { + frappe.call({ + 'method': 'frappe.client.get_value', + args: { + 'doctype': 'Item Price', + 'filters': { + 'item_code': d.inpatient_visit_charge_item, + 'price_list': frm.doc.price_list + }, + 'fieldname': ['price_list_rate'] + }, + callback: function (data) { + if (data.message.price_list_rate) { + frappe.model.set_value(cdt, cdn, 'inpatient_visit_charge', data.message.price_list_rate); + } + } + }); + } + } +}); \ No newline at end of file diff --git a/erpnext/healthcare/doctype/appointment_type/appointment_type.json b/erpnext/healthcare/doctype/appointment_type/appointment_type.json index 58753bb4f0..3872318287 100644 --- a/erpnext/healthcare/doctype/appointment_type/appointment_type.json +++ b/erpnext/healthcare/doctype/appointment_type/appointment_type.json @@ -12,7 +12,10 @@ "appointment_type", "ip", "default_duration", - "color" + "color", + "billing_section", + "price_list", + "items" ], "fields": [ { @@ -52,10 +55,27 @@ "label": "Color", "no_copy": 1, "report_hide": 1 + }, + { + "fieldname": "billing_section", + "fieldtype": "Section Break", + "label": "Billing" + }, + { + "fieldname": "price_list", + "fieldtype": "Link", + "label": "Price List", + "options": "Price List" + }, + { + "fieldname": "items", + "fieldtype": "Table", + "label": "Appointment Type Service Items", + "options": "Appointment Type Service Item" } ], "links": [], - "modified": "2020-02-03 21:06:05.833050", + "modified": "2021-01-22 09:41:05.010524", "modified_by": "Administrator", "module": "Healthcare", "name": "Appointment Type", diff --git a/erpnext/healthcare/doctype/appointment_type/appointment_type.py b/erpnext/healthcare/doctype/appointment_type/appointment_type.py index 1dacffab35..67a24f31e0 100644 --- a/erpnext/healthcare/doctype/appointment_type/appointment_type.py +++ b/erpnext/healthcare/doctype/appointment_type/appointment_type.py @@ -4,6 +4,53 @@ from __future__ import unicode_literals from frappe.model.document import Document +import frappe class AppointmentType(Document): - pass + def validate(self): + if self.items and self.price_list: + for item in self.items: + existing_op_item_price = frappe.db.exists('Item Price', { + 'item_code': item.op_consulting_charge_item, + 'price_list': self.price_list + }) + + if not existing_op_item_price and item.op_consulting_charge_item and item.op_consulting_charge: + make_item_price(self.price_list, item.op_consulting_charge_item, item.op_consulting_charge) + + existing_ip_item_price = frappe.db.exists('Item Price', { + 'item_code': item.inpatient_visit_charge_item, + 'price_list': self.price_list + }) + + if not existing_ip_item_price and item.inpatient_visit_charge_item and item.inpatient_visit_charge: + make_item_price(self.price_list, item.inpatient_visit_charge_item, item.inpatient_visit_charge) + +@frappe.whitelist() +def get_service_item_based_on_department(appointment_type, department): + item_list = frappe.db.get_value('Appointment Type Service Item', + filters = {'medical_department': department, 'parent': appointment_type}, + fieldname = ['op_consulting_charge_item', + 'inpatient_visit_charge_item', 'op_consulting_charge', 'inpatient_visit_charge'], + as_dict = 1 + ) + + # if department wise items are not set up + # use the generic items + if not item_list: + item_list = frappe.db.get_value('Appointment Type Service Item', + filters = {'parent': appointment_type}, + fieldname = ['op_consulting_charge_item', + 'inpatient_visit_charge_item', 'op_consulting_charge', 'inpatient_visit_charge'], + as_dict = 1 + ) + + return item_list + +def make_item_price(price_list, item, item_price): + frappe.get_doc({ + 'doctype': 'Item Price', + 'price_list': price_list, + 'item_code': item, + 'price_list_rate': item_price + }).insert(ignore_permissions=True, ignore_mandatory=True) diff --git a/erpnext/healthcare/doctype/appointment_type_service_item/__init__.py b/erpnext/healthcare/doctype/appointment_type_service_item/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/healthcare/doctype/appointment_type_service_item/appointment_type_service_item.json b/erpnext/healthcare/doctype/appointment_type_service_item/appointment_type_service_item.json new file mode 100644 index 0000000000..5ff68cd682 --- /dev/null +++ b/erpnext/healthcare/doctype/appointment_type_service_item/appointment_type_service_item.json @@ -0,0 +1,67 @@ +{ + "actions": [], + "creation": "2021-01-22 09:34:53.373105", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "medical_department", + "op_consulting_charge_item", + "op_consulting_charge", + "column_break_4", + "inpatient_visit_charge_item", + "inpatient_visit_charge" + ], + "fields": [ + { + "fieldname": "medical_department", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Medical Department", + "options": "Medical Department" + }, + { + "fieldname": "op_consulting_charge_item", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Out Patient Consulting Charge Item", + "options": "Item" + }, + { + "fieldname": "op_consulting_charge", + "fieldtype": "Currency", + "in_list_view": 1, + "label": "Out Patient Consulting Charge" + }, + { + "fieldname": "column_break_4", + "fieldtype": "Column Break" + }, + { + "fieldname": "inpatient_visit_charge_item", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Inpatient Visit Charge Item", + "options": "Item" + }, + { + "fieldname": "inpatient_visit_charge", + "fieldtype": "Currency", + "in_list_view": 1, + "label": "Inpatient Visit Charge Item" + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-01-22 09:35:26.503443", + "modified_by": "Administrator", + "module": "Healthcare", + "name": "Appointment Type Service Item", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/healthcare/doctype/appointment_type_service_item/appointment_type_service_item.py b/erpnext/healthcare/doctype/appointment_type_service_item/appointment_type_service_item.py new file mode 100644 index 0000000000..b2e0e82bad --- /dev/null +++ b/erpnext/healthcare/doctype/appointment_type_service_item/appointment_type_service_item.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +# import frappe +from frappe.model.document import Document + +class AppointmentTypeServiceItem(Document): + pass diff --git a/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.json b/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.json index cb747f95ef..8162f03f6d 100644 --- a/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.json +++ b/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.json @@ -159,6 +159,7 @@ "fieldname": "op_consulting_charge", "fieldtype": "Currency", "label": "Out Patient Consulting Charge", + "mandatory_depends_on": "op_consulting_charge_item", "options": "Currency" }, { @@ -174,7 +175,8 @@ { "fieldname": "inpatient_visit_charge", "fieldtype": "Currency", - "label": "Inpatient Visit Charge" + "label": "Inpatient Visit Charge", + "mandatory_depends_on": "inpatient_visit_charge_item" }, { "depends_on": "eval: !doc.__islocal", @@ -280,7 +282,7 @@ ], "image_field": "image", "links": [], - "modified": "2020-04-06 13:44:24.759623", + "modified": "2021-01-22 10:14:43.187675", "modified_by": "Administrator", "module": "Healthcare", "name": "Healthcare Practitioner", diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js index 3d5073b13e..0354733dfb 100644 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js @@ -24,11 +24,13 @@ frappe.ui.form.on('Patient Appointment', { }); frm.set_query('practitioner', function() { - return { - filters: { - 'department': frm.doc.department - } - }; + if (frm.doc.department) { + return { + filters: { + 'department': frm.doc.department + } + }; + } }); frm.set_query('service_unit', function() { @@ -140,6 +142,20 @@ frappe.ui.form.on('Patient Appointment', { patient: function(frm) { if (frm.doc.patient) { frm.trigger('toggle_payment_fields'); + frappe.call({ + method: 'frappe.client.get', + args: { + doctype: 'Patient', + name: frm.doc.patient + }, + callback: function (data) { + let age = null; + if (data.message.dob) { + age = calculate_age(data.message.dob); + } + frappe.model.set_value(frm.doctype, frm.docname, 'patient_age', age); + } + }); } else { frm.set_value('patient_name', ''); frm.set_value('patient_sex', ''); @@ -148,6 +164,37 @@ frappe.ui.form.on('Patient Appointment', { } }, + practitioner: function(frm) { + if (frm.doc.practitioner ) { + frm.events.set_payment_details(frm); + } + }, + + appointment_type: function(frm) { + if (frm.doc.appointment_type) { + frm.events.set_payment_details(frm); + } + }, + + set_payment_details: function(frm) { + frappe.db.get_single_value('Healthcare Settings', 'automate_appointment_invoicing').then(val => { + if (val) { + frappe.call({ + method: 'erpnext.healthcare.utils.get_service_item_and_practitioner_charge', + args: { + doc: frm.doc + }, + callback: function(data) { + if (data.message) { + frappe.model.set_value(frm.doctype, frm.docname, 'paid_amount', data.message.practitioner_charge); + frappe.model.set_value(frm.doctype, frm.docname, 'billing_item', data.message.service_item); + } + } + }); + } + }); + }, + therapy_plan: function(frm) { frm.trigger('set_therapy_type_filter'); }, @@ -190,14 +237,18 @@ frappe.ui.form.on('Patient Appointment', { // show payment fields as non-mandatory frm.toggle_display('mode_of_payment', 0); frm.toggle_display('paid_amount', 0); + frm.toggle_display('billing_item', 0); frm.toggle_reqd('mode_of_payment', 0); frm.toggle_reqd('paid_amount', 0); + frm.toggle_reqd('billing_item', 0); } else { // if automated appointment invoicing is disabled, hide fields frm.toggle_display('mode_of_payment', data.message ? 1 : 0); frm.toggle_display('paid_amount', data.message ? 1 : 0); + frm.toggle_display('billing_item', data.message ? 1 : 0); frm.toggle_reqd('mode_of_payment', data.message ? 1 : 0); frm.toggle_reqd('paid_amount', data.message ? 1 :0); + frm.toggle_reqd('billing_item', data.message ? 1 : 0); } } }); @@ -540,57 +591,6 @@ let update_status = function(frm, status){ ); }; -frappe.ui.form.on('Patient Appointment', 'practitioner', function(frm) { - if (frm.doc.practitioner) { - frappe.call({ - method: 'frappe.client.get', - args: { - doctype: 'Healthcare Practitioner', - name: frm.doc.practitioner - }, - callback: function (data) { - frappe.model.set_value(frm.doctype, frm.docname, 'department', data.message.department); - frappe.model.set_value(frm.doctype, frm.docname, 'paid_amount', data.message.op_consulting_charge); - frappe.model.set_value(frm.doctype, frm.docname, 'billing_item', data.message.op_consulting_charge_item); - } - }); - } -}); - -frappe.ui.form.on('Patient Appointment', 'patient', function(frm) { - if (frm.doc.patient) { - frappe.call({ - method: 'frappe.client.get', - args: { - doctype: 'Patient', - name: frm.doc.patient - }, - callback: function (data) { - let age = null; - if (data.message.dob) { - age = calculate_age(data.message.dob); - } - frappe.model.set_value(frm.doctype,frm.docname, 'patient_age', age); - } - }); - } -}); - -frappe.ui.form.on('Patient Appointment', 'appointment_type', function(frm) { - if (frm.doc.appointment_type) { - frappe.call({ - method: 'frappe.client.get', - args: { - doctype: 'Appointment Type', - name: frm.doc.appointment_type - }, - callback: function(data) { - frappe.model.set_value(frm.doctype,frm.docname, 'duration',data.message.default_duration); - } - }); - } -}); - let calculate_age = function(birth) { let ageMS = Date.parse(Date()) - Date.parse(birth); let age = new Date(); diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json index 35600e4809..83c92af36a 100644 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json @@ -19,19 +19,19 @@ "inpatient_record", "column_break_1", "company", + "practitioner", + "practitioner_name", + "department", "service_unit", + "section_break_12", + "appointment_type", + "duration", "procedure_template", "get_procedure_from_encounter", "procedure_prescription", "therapy_plan", "therapy_type", "get_prescribed_therapies", - "practitioner", - "practitioner_name", - "department", - "section_break_12", - "appointment_type", - "duration", "column_break_17", "appointment_date", "appointment_time", @@ -79,6 +79,7 @@ "set_only_once": 1 }, { + "fetch_from": "appointment_type.default_duration", "fieldname": "duration", "fieldtype": "Int", "in_filter": 1, @@ -144,7 +145,6 @@ "in_standard_filter": 1, "label": "Healthcare Practitioner", "options": "Healthcare Practitioner", - "read_only": 1, "reqd": 1, "search_index": 1, "set_only_once": 1 @@ -158,7 +158,6 @@ "in_standard_filter": 1, "label": "Department", "options": "Medical Department", - "read_only": 1, "search_index": 1, "set_only_once": 1 }, @@ -227,12 +226,14 @@ "fieldname": "mode_of_payment", "fieldtype": "Link", "label": "Mode of Payment", - "options": "Mode of Payment" + "options": "Mode of Payment", + "read_only_depends_on": "invoiced" }, { "fieldname": "paid_amount", "fieldtype": "Currency", - "label": "Paid Amount" + "label": "Paid Amount", + "read_only_depends_on": "invoiced" }, { "fieldname": "column_break_2", @@ -302,7 +303,8 @@ "fieldname": "therapy_plan", "fieldtype": "Link", "label": "Therapy Plan", - "options": "Therapy Plan" + "options": "Therapy Plan", + "set_only_once": 1 }, { "fieldname": "ref_sales_invoice", @@ -347,7 +349,7 @@ } ], "links": [], - "modified": "2020-12-16 13:16:58.578503", + "modified": "2021-02-08 13:13:15.116833", "modified_by": "Administrator", "module": "Healthcare", "name": "Patient Appointment", diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py index b05c673d84..649f16dbf1 100755 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py @@ -26,6 +26,7 @@ class PatientAppointment(Document): def after_insert(self): self.update_prescription_details() + self.set_payment_details() invoice_appointment(self) self.update_fee_validity() send_confirmation_msg(self) @@ -85,6 +86,13 @@ class PatientAppointment(Document): def set_appointment_datetime(self): self.appointment_datetime = "%s %s" % (self.appointment_date, self.appointment_time or "00:00:00") + def set_payment_details(self): + if frappe.db.get_single_value('Healthcare Settings', 'automate_appointment_invoicing'): + details = get_service_item_and_practitioner_charge(self) + self.db_set('billing_item', details.get('service_item')) + if not self.paid_amount: + self.db_set('paid_amount', details.get('practitioner_charge')) + def validate_customer_created(self): if frappe.db.get_single_value('Healthcare Settings', 'automate_appointment_invoicing'): if not frappe.db.get_value('Patient', self.patient, 'customer'): @@ -148,31 +156,37 @@ def invoice_appointment(appointment_doc): fee_validity = None if automate_invoicing and not appointment_invoiced and not fee_validity: - sales_invoice = frappe.new_doc('Sales Invoice') - sales_invoice.patient = appointment_doc.patient - sales_invoice.customer = frappe.get_value('Patient', appointment_doc.patient, 'customer') - sales_invoice.appointment = appointment_doc.name - sales_invoice.due_date = getdate() - sales_invoice.company = appointment_doc.company - sales_invoice.debit_to = get_receivable_account(appointment_doc.company) + create_sales_invoice(appointment_doc) - item = sales_invoice.append('items', {}) - item = get_appointment_item(appointment_doc, item) - # Add payments if payment details are supplied else proceed to create invoice as Unpaid - if appointment_doc.mode_of_payment and appointment_doc.paid_amount: - sales_invoice.is_pos = 1 - payment = sales_invoice.append('payments', {}) - payment.mode_of_payment = appointment_doc.mode_of_payment - payment.amount = appointment_doc.paid_amount +def create_sales_invoice(appointment_doc): + sales_invoice = frappe.new_doc('Sales Invoice') + sales_invoice.patient = appointment_doc.patient + sales_invoice.customer = frappe.get_value('Patient', appointment_doc.patient, 'customer') + sales_invoice.appointment = appointment_doc.name + sales_invoice.due_date = getdate() + sales_invoice.company = appointment_doc.company + sales_invoice.debit_to = get_receivable_account(appointment_doc.company) - sales_invoice.set_missing_values(for_validate=True) - sales_invoice.flags.ignore_mandatory = True - sales_invoice.save(ignore_permissions=True) - sales_invoice.submit() - frappe.msgprint(_('Sales Invoice {0} created').format(sales_invoice.name), alert=True) - frappe.db.set_value('Patient Appointment', appointment_doc.name, 'invoiced', 1) - frappe.db.set_value('Patient Appointment', appointment_doc.name, 'ref_sales_invoice', sales_invoice.name) + item = sales_invoice.append('items', {}) + item = get_appointment_item(appointment_doc, item) + + # Add payments if payment details are supplied else proceed to create invoice as Unpaid + if appointment_doc.mode_of_payment and appointment_doc.paid_amount: + sales_invoice.is_pos = 1 + payment = sales_invoice.append('payments', {}) + payment.mode_of_payment = appointment_doc.mode_of_payment + payment.amount = appointment_doc.paid_amount + + sales_invoice.set_missing_values(for_validate=True) + sales_invoice.flags.ignore_mandatory = True + sales_invoice.save(ignore_permissions=True) + sales_invoice.submit() + frappe.msgprint(_('Sales Invoice {0} created').format(sales_invoice.name), alert=True) + frappe.db.set_value('Patient Appointment', appointment_doc.name, { + 'invoiced': 1, + 'ref_sales_invoice': sales_invoice.name + }) def check_is_new_patient(patient, name=None): @@ -187,13 +201,14 @@ def check_is_new_patient(patient, name=None): def get_appointment_item(appointment_doc, item): - service_item, practitioner_charge = get_service_item_and_practitioner_charge(appointment_doc) - item.item_code = service_item + details = get_service_item_and_practitioner_charge(appointment_doc) + charge = appointment_doc.paid_amount or details.get('practitioner_charge') + item.item_code = details.get('service_item') item.description = _('Consulting Charges: {0}').format(appointment_doc.practitioner) item.income_account = get_income_account(appointment_doc.practitioner, appointment_doc.company) item.cost_center = frappe.get_cached_value('Company', appointment_doc.company, 'cost_center') - item.rate = practitioner_charge - item.amount = practitioner_charge + item.rate = charge + item.amount = charge item.qty = 1 item.reference_dt = 'Patient Appointment' item.reference_dn = appointment_doc.name diff --git a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py index f7ec6f58fc..2bb8a53c45 100644 --- a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py @@ -32,7 +32,8 @@ class TestPatientAppointment(unittest.TestCase): patient, medical_department, practitioner = create_healthcare_docs() frappe.db.set_value('Healthcare Settings', None, 'automate_appointment_invoicing', 1) appointment = create_appointment(patient, practitioner, add_days(nowdate(), 4), invoice = 1) - self.assertEqual(frappe.db.get_value('Patient Appointment', appointment.name, 'invoiced'), 1) + appointment.reload() + self.assertEqual(appointment.invoiced, 1) encounter = make_encounter(appointment.name) self.assertTrue(encounter) self.assertEqual(encounter.company, appointment.company) @@ -41,7 +42,7 @@ class TestPatientAppointment(unittest.TestCase): # invoiced flag mapped from appointment self.assertEqual(encounter.invoiced, frappe.db.get_value('Patient Appointment', appointment.name, 'invoiced')) - def test_invoicing(self): + def test_auto_invoicing(self): patient, medical_department, practitioner = create_healthcare_docs() frappe.db.set_value('Healthcare Settings', None, 'enable_free_follow_ups', 0) frappe.db.set_value('Healthcare Settings', None, 'automate_appointment_invoicing', 0) @@ -57,6 +58,50 @@ class TestPatientAppointment(unittest.TestCase): self.assertEqual(frappe.db.get_value('Sales Invoice', sales_invoice_name, 'patient'), appointment.patient) self.assertEqual(frappe.db.get_value('Sales Invoice', sales_invoice_name, 'paid_amount'), appointment.paid_amount) + def test_auto_invoicing_based_on_department(self): + patient, medical_department, practitioner = create_healthcare_docs() + frappe.db.set_value('Healthcare Settings', None, 'enable_free_follow_ups', 0) + frappe.db.set_value('Healthcare Settings', None, 'automate_appointment_invoicing', 1) + appointment_type = create_appointment_type() + + appointment = create_appointment(patient, practitioner, add_days(nowdate(), 2), + invoice=1, appointment_type=appointment_type.name, department='_Test Medical Department') + appointment.reload() + + self.assertEqual(appointment.invoiced, 1) + self.assertEqual(appointment.billing_item, 'HLC-SI-001') + self.assertEqual(appointment.paid_amount, 200) + + sales_invoice_name = frappe.db.get_value('Sales Invoice Item', {'reference_dn': appointment.name}, 'parent') + self.assertTrue(sales_invoice_name) + self.assertEqual(frappe.db.get_value('Sales Invoice', sales_invoice_name, 'paid_amount'), appointment.paid_amount) + + def test_auto_invoicing_according_to_appointment_type_charge(self): + patient, medical_department, practitioner = create_healthcare_docs() + frappe.db.set_value('Healthcare Settings', None, 'enable_free_follow_ups', 0) + frappe.db.set_value('Healthcare Settings', None, 'automate_appointment_invoicing', 1) + + item = create_healthcare_service_items() + items = [{ + 'op_consulting_charge_item': item, + 'op_consulting_charge': 300 + }] + appointment_type = create_appointment_type(args={ + 'name': 'Generic Appointment Type charge', + 'items': items + }) + + appointment = create_appointment(patient, practitioner, add_days(nowdate(), 2), + invoice=1, appointment_type=appointment_type.name) + appointment.reload() + + self.assertEqual(appointment.invoiced, 1) + self.assertEqual(appointment.billing_item, item) + self.assertEqual(appointment.paid_amount, 300) + + sales_invoice_name = frappe.db.get_value('Sales Invoice Item', {'reference_dn': appointment.name}, 'parent') + self.assertTrue(sales_invoice_name) + def test_appointment_cancel(self): patient, medical_department, practitioner = create_healthcare_docs() frappe.db.set_value('Healthcare Settings', None, 'enable_free_follow_ups', 1) @@ -178,14 +223,15 @@ def create_encounter(appointment): encounter.submit() return encounter -def create_appointment(patient, practitioner, appointment_date, invoice=0, procedure_template=0, service_unit=None, save=1): +def create_appointment(patient, practitioner, appointment_date, invoice=0, procedure_template=0, + service_unit=None, appointment_type=None, save=1, department=None): item = create_healthcare_service_items() frappe.db.set_value('Healthcare Settings', None, 'inpatient_visit_charge_item', item) frappe.db.set_value('Healthcare Settings', None, 'op_consulting_charge_item', item) appointment = frappe.new_doc('Patient Appointment') appointment.patient = patient appointment.practitioner = practitioner - appointment.department = '_Test Medical Department' + appointment.department = department or '_Test Medical Department' appointment.appointment_date = appointment_date appointment.company = '_Test Company' appointment.duration = 15 @@ -193,7 +239,8 @@ def create_appointment(patient, practitioner, appointment_date, invoice=0, proce appointment.service_unit = service_unit if invoice: appointment.mode_of_payment = 'Cash' - appointment.paid_amount = 500 + if appointment_type: + appointment.appointment_type = appointment_type if procedure_template: appointment.procedure_template = create_clinical_procedure_template().get('name') if save: @@ -223,4 +270,29 @@ def create_clinical_procedure_template(): template.description = 'Knee Surgery and Rehab' template.rate = 50000 template.save() - return template \ No newline at end of file + return template + +def create_appointment_type(args=None): + if not args: + args = frappe.local.form_dict + + name = args.get('name') or 'Test Appointment Type wise Charge' + + if frappe.db.exists('Appointment Type', name): + return frappe.get_doc('Appointment Type', name) + + else: + item = create_healthcare_service_items() + items = [{ + 'medical_department': '_Test Medical Department', + 'op_consulting_charge_item': item, + 'op_consulting_charge': 200 + }] + return frappe.get_doc({ + 'doctype': 'Appointment Type', + 'appointment_type': args.get('name') or 'Test Appointment Type wise Charge', + 'default_duration': args.get('default_duration') or 20, + 'color': args.get('color') or '#7575ff', + 'price_list': args.get('price_list') or frappe.db.get_value("Price List", {"selling": 1}), + 'items': args.get('items') or items + }).insert() \ No newline at end of file diff --git a/erpnext/healthcare/utils.py b/erpnext/healthcare/utils.py index 40f7f9cabd..510ac9e475 100644 --- a/erpnext/healthcare/utils.py +++ b/erpnext/healthcare/utils.py @@ -5,9 +5,11 @@ from __future__ import unicode_literals import math import frappe +import json from frappe import _ from frappe.utils.formatters import format_value from frappe.utils import time_diff_in_hours, rounded +from six import string_types from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import get_income_account from erpnext.healthcare.doctype.fee_validity.fee_validity import create_fee_validity from erpnext.healthcare.doctype.lab_test.lab_test import create_multiple @@ -64,7 +66,9 @@ def get_appointments_to_invoice(patient, company): income_account = None service_item = None if appointment.practitioner: - service_item, practitioner_charge = get_service_item_and_practitioner_charge(appointment) + details = get_service_item_and_practitioner_charge(appointment) + service_item = details.get('service_item') + practitioner_charge = details.get('practitioner_charge') income_account = get_income_account(appointment.practitioner, appointment.company) appointments_to_invoice.append({ 'reference_type': 'Patient Appointment', @@ -97,7 +101,9 @@ def get_encounters_to_invoice(patient, company): frappe.db.get_single_value('Healthcare Settings', 'do_not_bill_inpatient_encounters'): continue - service_item, practitioner_charge = get_service_item_and_practitioner_charge(encounter) + details = get_service_item_and_practitioner_charge(encounter) + service_item = details.get('service_item') + practitioner_charge = details.get('practitioner_charge') income_account = get_income_account(encounter.practitioner, encounter.company) encounters_to_invoice.append({ @@ -173,7 +179,7 @@ def get_clinical_procedures_to_invoice(patient, company): if procedure.invoice_separately_as_consumables and procedure.consume_stock \ and procedure.status == 'Completed' and not procedure.consumption_invoiced: - service_item = get_healthcare_service_item('clinical_procedure_consumable_item') + service_item = frappe.db.get_single_value('Healthcare Settings', 'clinical_procedure_consumable_item') if not service_item: msg = _('Please Configure Clinical Procedure Consumable Item in ') msg += '''Healthcare Settings''' @@ -304,24 +310,50 @@ def get_therapy_sessions_to_invoice(patient, company): return therapy_sessions_to_invoice - +@frappe.whitelist() def get_service_item_and_practitioner_charge(doc): + if isinstance(doc, string_types): + doc = json.loads(doc) + doc = frappe.get_doc(doc) + + service_item = None + practitioner_charge = None + department = doc.medical_department if doc.doctype == 'Patient Encounter' else doc.department + is_inpatient = doc.inpatient_record - if is_inpatient: - service_item = get_practitioner_service_item(doc.practitioner, 'inpatient_visit_charge_item') + + if doc.get('appointment_type'): + service_item, practitioner_charge = get_appointment_type_service_item(doc.appointment_type, department, is_inpatient) + + if not service_item and not practitioner_charge: + service_item, practitioner_charge = get_practitioner_service_item(doc.practitioner, is_inpatient) if not service_item: - service_item = get_healthcare_service_item('inpatient_visit_charge_item') - else: - service_item = get_practitioner_service_item(doc.practitioner, 'op_consulting_charge_item') - if not service_item: - service_item = get_healthcare_service_item('op_consulting_charge_item') + service_item = get_healthcare_service_item(is_inpatient) + if not service_item: throw_config_service_item(is_inpatient) - practitioner_charge = get_practitioner_charge(doc.practitioner, is_inpatient) if not practitioner_charge: throw_config_practitioner_charge(is_inpatient, doc.practitioner) + return {'service_item': service_item, 'practitioner_charge': practitioner_charge} + + +def get_appointment_type_service_item(appointment_type, department, is_inpatient): + from erpnext.healthcare.doctype.appointment_type.appointment_type import get_service_item_based_on_department + + item_list = get_service_item_based_on_department(appointment_type, department) + service_item = None + practitioner_charge = None + + if item_list: + if is_inpatient: + service_item = item_list.get('inpatient_visit_charge_item') + practitioner_charge = item_list.get('inpatient_visit_charge') + else: + service_item = item_list.get('op_consulting_charge_item') + practitioner_charge = item_list.get('op_consulting_charge') + return service_item, practitioner_charge @@ -345,12 +377,27 @@ def throw_config_practitioner_charge(is_inpatient, practitioner): frappe.throw(msg, title=_('Missing Configuration')) -def get_practitioner_service_item(practitioner, service_item_field): - return frappe.db.get_value('Healthcare Practitioner', practitioner, service_item_field) +def get_practitioner_service_item(practitioner, is_inpatient): + service_item = None + practitioner_charge = None + + if is_inpatient: + service_item, practitioner_charge = frappe.db.get_value('Healthcare Practitioner', practitioner, ['inpatient_visit_charge_item', 'inpatient_visit_charge']) + else: + service_item, practitioner_charge = frappe.db.get_value('Healthcare Practitioner', practitioner, ['op_consulting_charge_item', 'op_consulting_charge']) + + return service_item, practitioner_charge -def get_healthcare_service_item(service_item_field): - return frappe.db.get_single_value('Healthcare Settings', service_item_field) +def get_healthcare_service_item(is_inpatient): + service_item = None + + if is_inpatient: + service_item = frappe.db.get_single_value('Healthcare Settings', 'inpatient_visit_charge_item') + else: + service_item = frappe.db.get_single_value('Healthcare Settings', 'op_consulting_charge_item') + + return service_item def get_practitioner_charge(practitioner, is_inpatient): @@ -381,7 +428,8 @@ def set_invoiced(item, method, ref_invoice=None): invoiced = True if item.reference_dt == 'Clinical Procedure': - if get_healthcare_service_item('clinical_procedure_consumable_item') == item.item_code: + service_item = frappe.db.get_single_value('Healthcare Settings', 'clinical_procedure_consumable_item') + if service_item == item.item_code: frappe.db.set_value(item.reference_dt, item.reference_dn, 'consumption_invoiced', invoiced) else: frappe.db.set_value(item.reference_dt, item.reference_dn, 'invoiced', invoiced) @@ -403,7 +451,8 @@ def set_invoiced(item, method, ref_invoice=None): def validate_invoiced_on_submit(item): - if item.reference_dt == 'Clinical Procedure' and get_healthcare_service_item('clinical_procedure_consumable_item') == item.item_code: + if item.reference_dt == 'Clinical Procedure' and \ + frappe.db.get_single_value('Healthcare Settings', 'clinical_procedure_consumable_item') == item.item_code: is_invoiced = frappe.db.get_value(item.reference_dt, item.reference_dn, 'consumption_invoiced') else: is_invoiced = frappe.db.get_value(item.reference_dt, item.reference_dn, 'invoiced') From 4dad1f01ba397aae5eddcc39366543ee7c5b85e7 Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Tue, 2 Feb 2021 12:43:13 +0530 Subject: [PATCH 256/449] fix: contact permmission issue (#24503) --- erpnext/crm/doctype/lead/lead.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/crm/doctype/lead/lead.py b/erpnext/crm/doctype/lead/lead.py index 1439adb015..938cbfdc85 100644 --- a/erpnext/crm/doctype/lead/lead.py +++ b/erpnext/crm/doctype/lead/lead.py @@ -176,7 +176,7 @@ class Lead(SellingController): "phone": self.mobile_no }) - contact.insert() + contact.insert(ignore_permissions=True) return contact From 57c2e07c45c24007ef419aef7daa231224b4365d Mon Sep 17 00:00:00 2001 From: Saqib Date: Thu, 11 Feb 2021 17:50:57 +0530 Subject: [PATCH 257/449] fix: validate cancellation only if irn generated (#24608) --- erpnext/regional/india/e_invoice/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 0f604efa1f..2df49a6655 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -35,7 +35,7 @@ def validate_einvoice_fields(doc): elif doc.docstatus == 1 and doc._action == 'submit' and not doc.irn: frappe.throw(_('You must generate IRN before submitting the document.'), title=_('Missing IRN')) - elif doc.docstatus == 2 and doc._action == 'cancel' and not doc.irn_cancelled: + elif doc.irn and doc.docstatus == 2 and doc._action == 'cancel' and not doc.irn_cancelled: frappe.throw(_('You must cancel IRN before cancelling the document.'), title=_('Cancel Not Allowed')) def raise_document_name_too_long_error(): From a439d19917f9c06958a1f62f215571355e0352f7 Mon Sep 17 00:00:00 2001 From: Saqib Date: Thu, 11 Feb 2021 14:06:15 +0530 Subject: [PATCH 258/449] feat(pos): mpesa related fixes & additions (#24306) * fix: switching of mode of payments * feat: transaction limit for mpesa integration * feat: resend payment request if one fails * feat: make new request only for failed ones * fix: invalid amount for mpesa request * fix: payment successful message not shown * fix: url and business shortcode for live env * fix: duplicate items validation for pos invoices * fix: pos closing entry queued status * fix: peroid end date for amended pos closing --- .../payment_request/payment_request.py | 50 +++-- .../payment_request/test_payment_request.py | 12 +- .../pos_closing_entry/pos_closing_entry.js | 2 +- .../doctype/pos_invoice/pos_invoice.js | 41 +++- .../doctype/pos_invoice/pos_invoice.py | 56 ++++-- erpnext/controllers/selling_controller.py | 6 +- .../doctype/mpesa_settings/mpesa_connector.py | 8 +- .../mpesa_settings/mpesa_settings.json | 18 +- .../doctype/mpesa_settings/mpesa_settings.py | 115 ++++++++--- .../mpesa_settings/test_mpesa_settings.py | 182 ++++++++++++++---- .../page/point_of_sale/pos_item_cart.js | 8 +- .../selling/page/point_of_sale/pos_payment.js | 75 +++++--- 12 files changed, 441 insertions(+), 132 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 1b97050eb1..53ac996290 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -3,6 +3,7 @@ # For license information, please see license.txt from __future__ import unicode_literals +import json import frappe from frappe import _ from frappe.model.document import Document @@ -82,18 +83,37 @@ class PaymentRequest(Document): self.make_communication_entry() elif self.payment_channel == "Phone": - controller = get_payment_gateway_controller(self.payment_gateway) - payment_record = dict( - reference_doctype="Payment Request", - reference_docname=self.name, - payment_reference=self.reference_name, - grand_total=self.grand_total, - sender=self.email_to, - currency=self.currency, - payment_gateway=self.payment_gateway - ) - controller.validate_transaction_currency(self.currency) - controller.request_for_payment(**payment_record) + self.request_phone_payment() + + def request_phone_payment(self): + controller = get_payment_gateway_controller(self.payment_gateway) + request_amount = self.get_request_amount() + + payment_record = dict( + reference_doctype="Payment Request", + reference_docname=self.name, + payment_reference=self.reference_name, + request_amount=request_amount, + sender=self.email_to, + currency=self.currency, + payment_gateway=self.payment_gateway + ) + + controller.validate_transaction_currency(self.currency) + controller.request_for_payment(**payment_record) + + def get_request_amount(self): + data_of_completed_requests = frappe.get_all("Integration Request", filters={ + 'reference_doctype': self.doctype, + 'reference_docname': self.name, + 'status': 'Completed' + }, pluck="data") + + if not data_of_completed_requests: + return self.grand_total + + request_amounts = sum([json.loads(d).get('request_amount') for d in data_of_completed_requests]) + return request_amounts def on_cancel(self): self.check_if_payment_entry_exists() @@ -351,8 +371,8 @@ def make_payment_request(**args): if args.order_type == "Shopping Cart" or args.mute_email: pr.flags.mute_email = True + pr.insert(ignore_permissions=True) if args.submit_doc: - pr.insert(ignore_permissions=True) pr.submit() if args.order_type == "Shopping Cart": @@ -412,8 +432,8 @@ def get_existing_payment_request_amount(ref_dt, ref_dn): def get_gateway_details(args): """return gateway and payment account of default payment gateway""" - if args.get("payment_gateway"): - return get_payment_gateway_account(args.get("payment_gateway")) + if args.get("payment_gateway_account"): + return get_payment_gateway_account(args.get("payment_gateway_account")) if args.order_type == "Shopping Cart": payment_gateway_account = frappe.get_doc("Shopping Cart Settings").payment_gateway_account diff --git a/erpnext/accounts/doctype/payment_request/test_payment_request.py b/erpnext/accounts/doctype/payment_request/test_payment_request.py index 8a10e2cbd9..5eba62c0b3 100644 --- a/erpnext/accounts/doctype/payment_request/test_payment_request.py +++ b/erpnext/accounts/doctype/payment_request/test_payment_request.py @@ -45,7 +45,8 @@ class TestPaymentRequest(unittest.TestCase): def test_payment_request_linkings(self): so_inr = make_sales_order(currency="INR") - pr = make_payment_request(dt="Sales Order", dn=so_inr.name, recipient_id="saurabh@erpnext.com") + pr = make_payment_request(dt="Sales Order", dn=so_inr.name, recipient_id="saurabh@erpnext.com", + payment_gateway_account="_Test Gateway - INR") self.assertEqual(pr.reference_doctype, "Sales Order") self.assertEqual(pr.reference_name, so_inr.name) @@ -54,7 +55,8 @@ class TestPaymentRequest(unittest.TestCase): conversion_rate = get_exchange_rate("USD", "INR") si_usd = create_sales_invoice(currency="USD", conversion_rate=conversion_rate) - pr = make_payment_request(dt="Sales Invoice", dn=si_usd.name, recipient_id="saurabh@erpnext.com") + pr = make_payment_request(dt="Sales Invoice", dn=si_usd.name, recipient_id="saurabh@erpnext.com", + payment_gateway_account="_Test Gateway - USD") self.assertEqual(pr.reference_doctype, "Sales Invoice") self.assertEqual(pr.reference_name, si_usd.name) @@ -68,7 +70,7 @@ class TestPaymentRequest(unittest.TestCase): so_inr = make_sales_order(currency="INR") pr = make_payment_request(dt="Sales Order", dn=so_inr.name, recipient_id="saurabh@erpnext.com", - mute_email=1, submit_doc=1, return_doc=1) + mute_email=1, payment_gateway_account="_Test Gateway - INR", submit_doc=1, return_doc=1) pe = pr.set_as_paid() so_inr = frappe.get_doc("Sales Order", so_inr.name) @@ -79,7 +81,7 @@ class TestPaymentRequest(unittest.TestCase): currency="USD", conversion_rate=50) pr = make_payment_request(dt="Sales Invoice", dn=si_usd.name, recipient_id="saurabh@erpnext.com", - mute_email=1, payment_gateway="_Test Gateway - USD", submit_doc=1, return_doc=1) + mute_email=1, payment_gateway_account="_Test Gateway - USD", submit_doc=1, return_doc=1) pe = pr.set_as_paid() @@ -106,7 +108,7 @@ class TestPaymentRequest(unittest.TestCase): currency="USD", conversion_rate=50) pr = make_payment_request(dt="Sales Invoice", dn=si_usd.name, recipient_id="saurabh@erpnext.com", - mute_email=1, payment_gateway="_Test Gateway - USD", submit_doc=1, return_doc=1) + mute_email=1, payment_gateway_account="_Test Gateway - USD", submit_doc=1, return_doc=1) pe = pr.create_payment_entry() pr.load_from_db() diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js index 57baac7681..e79eb421a0 100644 --- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js +++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js @@ -20,7 +20,7 @@ frappe.ui.form.on('POS Closing Entry', { return { filters: { 'status': 'Open', 'docstatus': 1 } }; }); - if (frm.doc.docstatus === 0) frm.set_value("period_end_date", frappe.datetime.now_datetime()); + if (frm.doc.docstatus === 0 && !frm.doc.amended_from) frm.set_value("period_end_date", frappe.datetime.now_datetime()); if (frm.doc.docstatus === 1) set_html_data(frm); }, diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js index 86062d1e7c..6a7c4be890 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js @@ -187,18 +187,43 @@ frappe.ui.form.on('POS Invoice', { }, request_for_payment: function (frm) { + if (!frm.doc.contact_mobile) { + frappe.throw(__('Please enter mobile number first.')); + } + frm.dirty(); frm.save().then(() => { - frappe.dom.freeze(); - frappe.call({ - method: 'create_payment_request', - doc: frm.doc, - }) + frappe.dom.freeze(__('Waiting for payment...')); + frappe + .call({ + method: 'create_payment_request', + doc: frm.doc + }) .fail(() => { frappe.dom.unfreeze(); - frappe.msgprint('Payment request failed'); + frappe.msgprint(__('Payment request failed')); }) - .then(() => { - frappe.msgprint('Payment request sent successfully'); + .then(({ message }) => { + const payment_request_name = message.name; + setTimeout(() => { + frappe.db.get_value('Payment Request', payment_request_name, ['status', 'grand_total']).then(({ message }) => { + if (message.status != 'Paid') { + frappe.dom.unfreeze(); + frappe.msgprint({ + message: __('Payment Request took too long to respond. Please try requesting for payment again.'), + title: __('Request Timeout') + }); + } else if (frappe.dom.freeze_count != 0) { + frappe.dom.unfreeze(); + cur_frm.reload_doc(); + cur_pos.payment.events.submit_invoice(); + + frappe.show_alert({ + message: __("Payment of {0} received successfully.", [format_currency(message.grand_total, frm.doc.currency, 0)]), + indicator: 'green' + }); + } + }); + }, 60000); }); }); } diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index bd664c59f2..f67cae308a 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -363,22 +363,48 @@ class POSInvoice(SalesInvoice): if not self.contact_mobile: frappe.throw(_("Please enter the phone number first")) - payment_gateway = frappe.db.get_value("Payment Gateway Account", { - "payment_account": pay.account, - }) - record = { - "payment_gateway": payment_gateway, - "dt": "POS Invoice", - "dn": self.name, - "payment_request_type": "Inward", - "party_type": "Customer", - "party": self.customer, - "mode_of_payment": pay.mode_of_payment, - "recipient_id": self.contact_mobile, - "submit_doc": True - } + pay_req = self.get_existing_payment_request(pay) + if not pay_req: + pay_req = self.get_new_payment_request(pay) + pay_req.submit() + else: + pay_req.request_phone_payment() - return make_payment_request(**record) + return pay_req + + def get_new_payment_request(self, mop): + payment_gateway_account = frappe.db.get_value("Payment Gateway Account", { + "payment_account": mop.account, + }, ["name"]) + + args = { + "dt": "POS Invoice", + "dn": self.name, + "recipient_id": self.contact_mobile, + "mode_of_payment": mop.mode_of_payment, + "payment_gateway_account": payment_gateway_account, + "payment_request_type": "Inward", + "party_type": "Customer", + "party": self.customer, + "return_doc": True + } + return make_payment_request(**args) + + def get_existing_payment_request(self, pay): + payment_gateway_account = frappe.db.get_value("Payment Gateway Account", { + "payment_account": pay.account, + }, ["name"]) + + args = { + 'doctype': 'Payment Request', + 'reference_doctype': 'POS Invoice', + 'reference_name': self.name, + 'payment_gateway_account': payment_gateway_account, + 'email_to': self.contact_mobile + } + pr = frappe.db.exists(args) + if pr: + return frappe.get_doc('Payment Request', pr[0][0]) def add_return_modes(doc, pos_profile): def append_payment(payment_mode): diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index e085048f99..aa7b27adf4 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -456,9 +456,13 @@ class SellingController(StockController): check_list, chk_dupl_itm = [], [] if cint(frappe.db.get_single_value("Selling Settings", "allow_multiple_items")): return + if self.doctype == "Sales Invoice" and self.is_consolidated: + return + if self.doctype == "POS Invoice": + return for d in self.get('items'): - if self.doctype in ["POS Invoice","Sales Invoice"]: + if self.doctype == "Sales Invoice": stock_items = [d.item_code, d.description, d.warehouse, d.sales_order or d.delivery_note, d.batch_no or ''] non_stock_items = [d.item_code, d.description, d.sales_order or d.delivery_note] elif self.doctype == "Delivery Note": diff --git a/erpnext/erpnext_integrations/doctype/mpesa_settings/mpesa_connector.py b/erpnext/erpnext_integrations/doctype/mpesa_settings/mpesa_connector.py index d33b0a7089..554c6b0eb0 100644 --- a/erpnext/erpnext_integrations/doctype/mpesa_settings/mpesa_connector.py +++ b/erpnext/erpnext_integrations/doctype/mpesa_settings/mpesa_connector.py @@ -5,7 +5,7 @@ import datetime class MpesaConnector(): def __init__(self, env="sandbox", app_key=None, app_secret=None, sandbox_url="https://sandbox.safaricom.co.ke", - live_url="https://safaricom.co.ke"): + live_url="https://api.safaricom.co.ke"): """Setup configuration for Mpesa connector and generate new access token.""" self.env = env self.app_key = app_key @@ -102,14 +102,14 @@ class MpesaConnector(): "BusinessShortCode": business_shortcode, "Password": encoded.decode("utf-8"), "Timestamp": time, - "TransactionType": "CustomerPayBillOnline", "Amount": amount, "PartyA": int(phone_number), - "PartyB": business_shortcode, + "PartyB": reference_code, "PhoneNumber": int(phone_number), "CallBackURL": callback_url, "AccountReference": reference_code, - "TransactionDesc": description + "TransactionDesc": description, + "TransactionType": "CustomerPayBillOnline" if self.env == "sandbox" else "CustomerBuyGoodsOnline" } headers = {'Authorization': 'Bearer {0}'.format(self.authentication_token), 'Content-Type': "application/json"} diff --git a/erpnext/erpnext_integrations/doctype/mpesa_settings/mpesa_settings.json b/erpnext/erpnext_integrations/doctype/mpesa_settings/mpesa_settings.json index fc7b310c08..407f82616f 100644 --- a/erpnext/erpnext_integrations/doctype/mpesa_settings/mpesa_settings.json +++ b/erpnext/erpnext_integrations/doctype/mpesa_settings/mpesa_settings.json @@ -11,8 +11,10 @@ "consumer_secret", "initiator_name", "till_number", + "transaction_limit", "sandbox", "column_break_4", + "business_shortcode", "online_passkey", "security_credential", "get_account_balance", @@ -84,10 +86,24 @@ "fieldname": "get_account_balance", "fieldtype": "Button", "label": "Get Account Balance" + }, + { + "depends_on": "eval:(doc.sandbox==0)", + "fieldname": "business_shortcode", + "fieldtype": "Data", + "label": "Business Shortcode", + "mandatory_depends_on": "eval:(doc.sandbox==0)" + }, + { + "default": "150000", + "fieldname": "transaction_limit", + "fieldtype": "Float", + "label": "Transaction Limit", + "non_negative": 1 } ], "links": [], - "modified": "2020-09-25 20:21:38.215494", + "modified": "2021-01-29 12:02:16.106942", "modified_by": "Administrator", "module": "ERPNext Integrations", "name": "Mpesa Settings", diff --git a/erpnext/erpnext_integrations/doctype/mpesa_settings/mpesa_settings.py b/erpnext/erpnext_integrations/doctype/mpesa_settings/mpesa_settings.py index 1cad84dcde..b5718026c1 100644 --- a/erpnext/erpnext_integrations/doctype/mpesa_settings/mpesa_settings.py +++ b/erpnext/erpnext_integrations/doctype/mpesa_settings/mpesa_settings.py @@ -33,13 +33,34 @@ class MpesaSettings(Document): create_mode_of_payment('Mpesa-' + self.payment_gateway_name, payment_type="Phone") def request_for_payment(self, **kwargs): - if frappe.flags.in_test: - from erpnext.erpnext_integrations.doctype.mpesa_settings.test_mpesa_settings import get_payment_request_response_payload - response = frappe._dict(get_payment_request_response_payload()) - else: - response = frappe._dict(generate_stk_push(**kwargs)) + args = frappe._dict(kwargs) + request_amounts = self.split_request_amount_according_to_transaction_limit(args) - self.handle_api_response("CheckoutRequestID", kwargs, response) + for i, amount in enumerate(request_amounts): + args.request_amount = amount + if frappe.flags.in_test: + from erpnext.erpnext_integrations.doctype.mpesa_settings.test_mpesa_settings import get_payment_request_response_payload + response = frappe._dict(get_payment_request_response_payload(amount)) + else: + response = frappe._dict(generate_stk_push(**args)) + + self.handle_api_response("CheckoutRequestID", args, response) + + def split_request_amount_according_to_transaction_limit(self, args): + request_amount = args.request_amount + if request_amount > self.transaction_limit: + # make multiple requests + request_amounts = [] + requests_to_be_made = frappe.utils.ceil(request_amount / self.transaction_limit) # 480/150 = ceil(3.2) = 4 + for i in range(requests_to_be_made): + amount = self.transaction_limit + if i == requests_to_be_made - 1: + amount = request_amount - (self.transaction_limit * i) # for 4th request, 480 - (150 * 3) = 30 + request_amounts.append(amount) + else: + request_amounts = [request_amount] + + return request_amounts def get_account_balance_info(self): payload = dict( @@ -67,7 +88,8 @@ class MpesaSettings(Document): req_name = getattr(response, global_id) error = None - create_request_log(request_dict, "Host", "Mpesa", req_name, error) + if not frappe.db.exists('Integration Request', req_name): + create_request_log(request_dict, "Host", "Mpesa", req_name, error) if error: frappe.throw(_(getattr(response, "errorMessage")), title=_("Transaction Error")) @@ -80,6 +102,8 @@ def generate_stk_push(**kwargs): mpesa_settings = frappe.get_doc("Mpesa Settings", args.payment_gateway[6:]) env = "production" if not mpesa_settings.sandbox else "sandbox" + # for sandbox, business shortcode is same as till number + business_shortcode = mpesa_settings.business_shortcode if env == "production" else mpesa_settings.till_number connector = MpesaConnector(env=env, app_key=mpesa_settings.consumer_key, @@ -87,10 +111,12 @@ def generate_stk_push(**kwargs): mobile_number = sanitize_mobile_number(args.sender) - response = connector.stk_push(business_shortcode=mpesa_settings.till_number, - passcode=mpesa_settings.get_password("online_passkey"), amount=args.grand_total, + response = connector.stk_push( + business_shortcode=business_shortcode, amount=args.request_amount, + passcode=mpesa_settings.get_password("online_passkey"), callback_url=callback_url, reference_code=mpesa_settings.till_number, - phone_number=mobile_number, description="POS Payment") + phone_number=mobile_number, description="POS Payment" + ) return response @@ -108,29 +134,72 @@ def verify_transaction(**kwargs): transaction_response = frappe._dict(kwargs["Body"]["stkCallback"]) checkout_id = getattr(transaction_response, "CheckoutRequestID", "") - request = frappe.get_doc("Integration Request", checkout_id) - transaction_data = frappe._dict(loads(request.data)) + integration_request = frappe.get_doc("Integration Request", checkout_id) + transaction_data = frappe._dict(loads(integration_request.data)) + total_paid = 0 # for multiple integration request made against a pos invoice + success = False # for reporting successfull callback to point of sale ui if transaction_response['ResultCode'] == 0: - if request.reference_doctype and request.reference_docname: + if integration_request.reference_doctype and integration_request.reference_docname: try: - doc = frappe.get_doc(request.reference_doctype, - request.reference_docname) - doc.run_method("on_payment_authorized", 'Completed') - item_response = transaction_response["CallbackMetadata"]["Item"] + amount = fetch_param_value(item_response, "Amount", "Name") mpesa_receipt = fetch_param_value(item_response, "MpesaReceiptNumber", "Name") - frappe.db.set_value("POS Invoice", doc.reference_name, "mpesa_receipt_number", mpesa_receipt) - request.handle_success(transaction_response) + pr = frappe.get_doc(integration_request.reference_doctype, integration_request.reference_docname) + + mpesa_receipts, completed_payments = get_completed_integration_requests_info( + integration_request.reference_doctype, + integration_request.reference_docname, + checkout_id + ) + + total_paid = amount + sum(completed_payments) + mpesa_receipts = ', '.join(mpesa_receipts + [mpesa_receipt]) + + if total_paid >= pr.grand_total: + pr.run_method("on_payment_authorized", 'Completed') + success = True + + frappe.db.set_value("POS Invoice", pr.reference_name, "mpesa_receipt_number", mpesa_receipts) + integration_request.handle_success(transaction_response) except Exception: - request.handle_failure(transaction_response) + integration_request.handle_failure(transaction_response) frappe.log_error(frappe.get_traceback()) else: - request.handle_failure(transaction_response) + integration_request.handle_failure(transaction_response) - frappe.publish_realtime('process_phone_payment', doctype="POS Invoice", - docname=transaction_data.payment_reference, user=request.owner, message=transaction_response) + frappe.publish_realtime( + event='process_phone_payment', + doctype="POS Invoice", + docname=transaction_data.payment_reference, + user=integration_request.owner, + message={ + 'amount': total_paid, + 'success': success, + 'failure_message': transaction_response["ResultDesc"] if transaction_response['ResultCode'] != 0 else '' + }, + ) + +def get_completed_integration_requests_info(reference_doctype, reference_docname, checkout_id): + output_of_other_completed_requests = frappe.get_all("Integration Request", filters={ + 'name': ['!=', checkout_id], + 'reference_doctype': reference_doctype, + 'reference_docname': reference_docname, + 'status': 'Completed' + }, pluck="output") + + mpesa_receipts, completed_payments = [], [] + + for out in output_of_other_completed_requests: + out = frappe._dict(loads(out)) + item_response = out["CallbackMetadata"]["Item"] + completed_amount = fetch_param_value(item_response, "Amount", "Name") + completed_mpesa_receipt = fetch_param_value(item_response, "MpesaReceiptNumber", "Name") + completed_payments.append(completed_amount) + mpesa_receipts.append(completed_mpesa_receipt) + + return mpesa_receipts, completed_payments def get_account_balance(request_payload): """Call account balance API to send the request to the Mpesa Servers.""" diff --git a/erpnext/erpnext_integrations/doctype/mpesa_settings/test_mpesa_settings.py b/erpnext/erpnext_integrations/doctype/mpesa_settings/test_mpesa_settings.py index 4e86d365e3..18d2732313 100644 --- a/erpnext/erpnext_integrations/doctype/mpesa_settings/test_mpesa_settings.py +++ b/erpnext/erpnext_integrations/doctype/mpesa_settings/test_mpesa_settings.py @@ -9,6 +9,10 @@ from erpnext.erpnext_integrations.doctype.mpesa_settings.mpesa_settings import p from erpnext.accounts.doctype.pos_invoice.test_pos_invoice import create_pos_invoice class TestMpesaSettings(unittest.TestCase): + def tearDown(self): + frappe.db.sql('delete from `tabMpesa Settings`') + frappe.db.sql('delete from `tabIntegration Request` where integration_request_service = "Mpesa"') + def test_creation_of_payment_gateway(self): create_mpesa_settings(payment_gateway_name="_Test") @@ -40,6 +44,8 @@ class TestMpesaSettings(unittest.TestCase): } })) + integration_request.delete() + def test_processing_of_callback_payload(self): create_mpesa_settings(payment_gateway_name="Payment") mpesa_account = frappe.db.get_value("Payment Gateway Account", {"payment_gateway": 'Mpesa-Payment'}, "payment_account") @@ -55,10 +61,16 @@ class TestMpesaSettings(unittest.TestCase): # test payment request creation self.assertEquals(pr.payment_gateway, "Mpesa-Payment") - callback_response = get_payment_callback_payload() + # submitting payment request creates integration requests with random id + integration_req_ids = frappe.get_all("Integration Request", filters={ + 'reference_doctype': pr.doctype, + 'reference_docname': pr.name, + }, pluck="name") + + callback_response = get_payment_callback_payload(Amount=500, CheckoutRequestID=integration_req_ids[0]) verify_transaction(**callback_response) # test creation of integration request - integration_request = frappe.get_doc("Integration Request", "ws_CO_061020201133231972") + integration_request = frappe.get_doc("Integration Request", integration_req_ids[0]) # test integration request creation and successful update of the status on receiving callback response self.assertTrue(integration_request) @@ -68,6 +80,120 @@ class TestMpesaSettings(unittest.TestCase): integration_request.reload() self.assertEquals(pos_invoice.mpesa_receipt_number, "LGR7OWQX0R") self.assertEquals(integration_request.status, "Completed") + + frappe.db.set_value("Customer", "_Test Customer", "default_currency", "") + integration_request.delete() + pr.reload() + pr.cancel() + pr.delete() + pos_invoice.delete() + + def test_processing_of_multiple_callback_payload(self): + create_mpesa_settings(payment_gateway_name="Payment") + mpesa_account = frappe.db.get_value("Payment Gateway Account", {"payment_gateway": 'Mpesa-Payment'}, "payment_account") + frappe.db.set_value("Account", mpesa_account, "account_currency", "KES") + frappe.db.set_value("Mpesa Settings", "Payment", "transaction_limit", "500") + frappe.db.set_value("Customer", "_Test Customer", "default_currency", "KES") + + pos_invoice = create_pos_invoice(do_not_submit=1) + pos_invoice.append("payments", {'mode_of_payment': 'Mpesa-Payment', 'account': mpesa_account, 'amount': 1000}) + pos_invoice.contact_mobile = "093456543894" + pos_invoice.currency = "KES" + pos_invoice.save() + + pr = pos_invoice.create_payment_request() + # test payment request creation + self.assertEquals(pr.payment_gateway, "Mpesa-Payment") + + # submitting payment request creates integration requests with random id + integration_req_ids = frappe.get_all("Integration Request", filters={ + 'reference_doctype': pr.doctype, + 'reference_docname': pr.name, + }, pluck="name") + + # create random receipt nos and send it as response to callback handler + mpesa_receipt_numbers = [frappe.utils.random_string(5) for d in integration_req_ids] + + integration_requests = [] + for i in range(len(integration_req_ids)): + callback_response = get_payment_callback_payload( + Amount=500, + CheckoutRequestID=integration_req_ids[i], + MpesaReceiptNumber=mpesa_receipt_numbers[i] + ) + # handle response manually + verify_transaction(**callback_response) + # test completion of integration request + integration_request = frappe.get_doc("Integration Request", integration_req_ids[i]) + self.assertEquals(integration_request.status, "Completed") + integration_requests.append(integration_request) + + # check receipt number once all the integration requests are completed + pos_invoice.reload() + self.assertEquals(pos_invoice.mpesa_receipt_number, ', '.join(mpesa_receipt_numbers)) + + frappe.db.set_value("Customer", "_Test Customer", "default_currency", "") + [d.delete() for d in integration_requests] + pr.reload() + pr.cancel() + pr.delete() + pos_invoice.delete() + + def test_processing_of_only_one_succes_callback_payload(self): + create_mpesa_settings(payment_gateway_name="Payment") + mpesa_account = frappe.db.get_value("Payment Gateway Account", {"payment_gateway": 'Mpesa-Payment'}, "payment_account") + frappe.db.set_value("Account", mpesa_account, "account_currency", "KES") + frappe.db.set_value("Mpesa Settings", "Payment", "transaction_limit", "500") + frappe.db.set_value("Customer", "_Test Customer", "default_currency", "KES") + + pos_invoice = create_pos_invoice(do_not_submit=1) + pos_invoice.append("payments", {'mode_of_payment': 'Mpesa-Payment', 'account': mpesa_account, 'amount': 1000}) + pos_invoice.contact_mobile = "093456543894" + pos_invoice.currency = "KES" + pos_invoice.save() + + pr = pos_invoice.create_payment_request() + # test payment request creation + self.assertEquals(pr.payment_gateway, "Mpesa-Payment") + + # submitting payment request creates integration requests with random id + integration_req_ids = frappe.get_all("Integration Request", filters={ + 'reference_doctype': pr.doctype, + 'reference_docname': pr.name, + }, pluck="name") + + # create random receipt nos and send it as response to callback handler + mpesa_receipt_numbers = [frappe.utils.random_string(5) for d in integration_req_ids] + + callback_response = get_payment_callback_payload( + Amount=500, + CheckoutRequestID=integration_req_ids[0], + MpesaReceiptNumber=mpesa_receipt_numbers[0] + ) + # handle response manually + verify_transaction(**callback_response) + # test completion of integration request + integration_request = frappe.get_doc("Integration Request", integration_req_ids[0]) + self.assertEquals(integration_request.status, "Completed") + + # now one request is completed + # second integration request fails + # now retrying payment request should make only one integration request again + pr = pos_invoice.create_payment_request() + new_integration_req_ids = frappe.get_all("Integration Request", filters={ + 'reference_doctype': pr.doctype, + 'reference_docname': pr.name, + 'name': ['not in', integration_req_ids] + }, pluck="name") + + self.assertEquals(len(new_integration_req_ids), 1) + + frappe.db.set_value("Customer", "_Test Customer", "default_currency", "") + frappe.db.sql("delete from `tabIntegration Request` where integration_request_service = 'Mpesa'") + pr.reload() + pr.cancel() + pr.delete() + pos_invoice.delete() def create_mpesa_settings(payment_gateway_name="Express"): if frappe.db.exists("Mpesa Settings", payment_gateway_name): @@ -157,16 +283,19 @@ def get_test_account_balance_response(): } } -def get_payment_request_response_payload(): +def get_payment_request_response_payload(Amount=500): """Response received after successfully calling the stk push process request API.""" + + CheckoutRequestID = frappe.utils.random_string(10) + return { "MerchantRequestID": "8071-27184008-1", - "CheckoutRequestID": "ws_CO_061020201133231972", + "CheckoutRequestID": CheckoutRequestID, "ResultCode": 0, "ResultDesc": "The service request is processed successfully.", "CallbackMetadata": { "Item": [ - { "Name": "Amount", "Value": 500.0 }, + { "Name": "Amount", "Value": Amount }, { "Name": "MpesaReceiptNumber", "Value": "LGR7OWQX0R" }, { "Name": "TransactionDate", "Value": 20201006113336 }, { "Name": "PhoneNumber", "Value": 254723575670 } @@ -174,41 +303,26 @@ def get_payment_request_response_payload(): } } - -def get_payment_callback_payload(): +def get_payment_callback_payload(Amount=500, CheckoutRequestID="ws_CO_061020201133231972", MpesaReceiptNumber="LGR7OWQX0R"): """Response received from the server as callback after calling the stkpush process request API.""" return { "Body":{ - "stkCallback":{ - "MerchantRequestID":"19465-780693-1", - "CheckoutRequestID":"ws_CO_061020201133231972", - "ResultCode":0, - "ResultDesc":"The service request is processed successfully.", - "CallbackMetadata":{ - "Item":[ - { - "Name":"Amount", - "Value":500 - }, - { - "Name":"MpesaReceiptNumber", - "Value":"LGR7OWQX0R" - }, - { - "Name":"Balance" - }, - { - "Name":"TransactionDate", - "Value":20170727154800 - }, - { - "Name":"PhoneNumber", - "Value":254721566839 + "stkCallback":{ + "MerchantRequestID":"19465-780693-1", + "CheckoutRequestID":CheckoutRequestID, + "ResultCode":0, + "ResultDesc":"The service request is processed successfully.", + "CallbackMetadata":{ + "Item":[ + { "Name":"Amount", "Value":Amount }, + { "Name":"MpesaReceiptNumber", "Value":MpesaReceiptNumber }, + { "Name":"Balance" }, + { "Name":"TransactionDate", "Value":20170727154800 }, + { "Name":"PhoneNumber", "Value":254721566839 } + ] } - ] } } - } } def get_account_balance_callback_payload(): diff --git a/erpnext/selling/page/point_of_sale/pos_item_cart.js b/erpnext/selling/page/point_of_sale/pos_item_cart.js index 3938300a2a..03d99c6bfa 100644 --- a/erpnext/selling/page/point_of_sale/pos_item_cart.js +++ b/erpnext/selling/page/point_of_sale/pos_item_cart.js @@ -482,8 +482,12 @@ erpnext.PointOfSale.ItemCart = class { this.render_net_total(frm.doc.base_net_total); this.render_grand_total(frm.doc.base_grand_total); - const taxes = frm.doc.taxes.map(t => { return { description: t.description, rate: t.rate }}) - this.render_taxes(frm.doc.base_total_taxes_and_charges, taxes); + const taxes = frm.doc.taxes.map(t => { + return { + description: t.description, rate: t.rate + }; + }); + this.render_taxes(frm.doc.total_taxes_and_charges, taxes); } render_net_total(value) { diff --git a/erpnext/selling/page/point_of_sale/pos_payment.js b/erpnext/selling/page/point_of_sale/pos_payment.js index e4d8965ac2..e150271fd0 100644 --- a/erpnext/selling/page/point_of_sale/pos_payment.js +++ b/erpnext/selling/page/point_of_sale/pos_payment.js @@ -168,30 +168,22 @@ erpnext.PointOfSale.Payment = class { me.toggle_numpad(true); me.selected_mode = me[`${mode}_control`]; - const doc = me.events.get_frm().doc; - me.selected_mode?.$input?.get(0).focus(); - const current_value = me.selected_mode?.get_value() - !current_value && doc.grand_total > doc.paid_amount ? me.selected_mode?.set_value(doc.grand_total - doc.paid_amount) : ''; + me.selected_mode && me.selected_mode.$input.get(0).focus(); + me.auto_set_remaining_amount(); } }) - frappe.realtime.on("process_phone_payment", function(data) { - frappe.dom.unfreeze(); - cur_frm.reload_doc(); - let message = data["ResultDesc"]; - let title = __("Payment Failed"); + frappe.ui.form.on('POS Invoice', 'contact_mobile', (frm) => { + const contact = frm.doc.contact_mobile; + const request_button = $(this.request_for_payment_field.$input[0]); + if (contact) { + request_button.removeClass('btn-default').addClass('btn-primary'); + } else { + request_button.removeClass('btn-primary').addClass('btn-default'); + } + }); - if (data["ResultCode"] == 0) { - title = __("Payment Received"); - $('.btn.btn-xs.btn-default[data-fieldname=request_for_payment]').html(`Payment Received`) - me.events.submit_invoice(); - } - - frappe.msgprint({ - "message": message, - "title": title - }); - }); + this.setup_listener_for_payments(); this.$payment_modes.on('click', '.shortcut', function(e) { const value = $(this).attr('data-value'); @@ -250,6 +242,41 @@ erpnext.PointOfSale.Payment = class { }) } + setup_listener_for_payments() { + frappe.realtime.on("process_phone_payment", (data) => { + const doc = this.events.get_frm().doc; + const { response, amount, success, failure_message } = data; + let message, title; + + if (success) { + title = __("Payment Received"); + if (amount >= doc.grand_total) { + frappe.dom.unfreeze(); + message = __("Payment of {0} received successfully.", [format_currency(amount, doc.currency, 0)]); + this.events.submit_invoice(); + cur_frm.reload_doc(); + + } else { + message = __("Payment of {0} received successfully. Waiting for other requests to complete...", [format_currency(amount, doc.currency, 0)]); + } + } else if (failure_message) { + message = failure_message; + title = __("Payment Failed"); + } + + frappe.msgprint({ "message": message, "title": title }); + }); + } + + auto_set_remaining_amount() { + const doc = this.events.get_frm().doc; + const remaining_amount = doc.grand_total - doc.paid_amount; + const current_value = this.selected_mode ? this.selected_mode.get_value() : undefined; + if (!current_value && remaining_amount > 0 && this.selected_mode) { + this.selected_mode.set_value(remaining_amount); + } + } + attach_shortcuts() { const ctrl_label = frappe.utils.is_mac() ? '⌘' : 'Ctrl'; this.$component.find('.submit-order').attr("title", `${ctrl_label}+Enter`); @@ -370,9 +397,11 @@ erpnext.PointOfSale.Payment = class { fieldtype: 'Currency', placeholder: __('Enter {0} amount.', [p.mode_of_payment]), onchange: function() { - if (this.value || this.value == 0) { - frappe.model.set_value(p.doctype, p.name, 'amount', flt(this.value)) - .then(() => me.update_totals_section()); + const current_value = frappe.model.get_value(p.doctype, p.name, 'amount'); + if (current_value != this.value) { + frappe.model + .set_value(p.doctype, p.name, 'amount', flt(this.value)) + .then(() => me.update_totals_section()) const formatted_currency = format_currency(this.value, currency); me.$payment_modes.find(`.${mode}-amount`).html(formatted_currency); From 4fb547179dbb1592ffd13be8972a74392f7749d6 Mon Sep 17 00:00:00 2001 From: Saqib Date: Thu, 11 Feb 2021 13:10:52 +0530 Subject: [PATCH 259/449] fix: customer_currency referenced before assignment (#24607) --- erpnext/accounts/doctype/pos_invoice/pos_invoice.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index f67cae308a..7312248456 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -299,6 +299,9 @@ class POSInvoice(SalesInvoice): customer_price_list, customer_group = frappe.db.get_value("Customer", self.customer, ['default_price_list', 'customer_group']) customer_group_price_list = frappe.db.get_value("Customer Group", customer_group, 'default_price_list') selling_price_list = customer_price_list or customer_group_price_list or profile.get('selling_price_list') + if customer_currency != profile.get('currency'): + self.set('currency', customer_currency) + else: selling_price_list = profile.get('selling_price_list') From 18c7c45cfe57611072be555d1f69840907a49cf5 Mon Sep 17 00:00:00 2001 From: Saqib Date: Wed, 10 Feb 2021 17:21:12 +0530 Subject: [PATCH 260/449] fix: NoneType has no len() (#24600) --- erpnext/regional/india/e_invoice/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 2df49a6655..4460d82da5 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -23,6 +23,10 @@ def validate_einvoice_fields(doc): invalid_doctype = doc.doctype not in ['Sales Invoice'] invalid_supply_type = doc.get('gst_category') not in ['Registered Regular', 'SEZ', 'Overseas', 'Deemed Export'] company_transaction = doc.get('billing_address_gstin') == doc.get('company_gstin') +<<<<<<< HEAD +======= + no_taxes_applied = len(doc.get('taxes', [])) == 0 +>>>>>>> 7b2afaf349... fix: NoneType has no len() (#24600) if not einvoicing_enabled or invalid_doctype or invalid_supply_type or company_transaction: return From ade96589b46970bc9a80e33a4dff915450437fe7 Mon Sep 17 00:00:00 2001 From: Saqib Date: Mon, 8 Feb 2021 11:40:56 +0530 Subject: [PATCH 261/449] fix(e-invoice): skip e-invoice generation for non-taxable invoices (#24568) --- erpnext/regional/india/e_invoice/utils.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 4460d82da5..876016fc19 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -20,15 +20,13 @@ from frappe.utils.data import cstr, cint, format_date, flt, time_diff_in_seconds def validate_einvoice_fields(doc): einvoicing_enabled = cint(frappe.db.get_value('E Invoice Settings', 'E Invoice Settings', 'enable')) - invalid_doctype = doc.doctype not in ['Sales Invoice'] + invalid_doctype = doc.doctype != 'Sales Invoice' invalid_supply_type = doc.get('gst_category') not in ['Registered Regular', 'SEZ', 'Overseas', 'Deemed Export'] company_transaction = doc.get('billing_address_gstin') == doc.get('company_gstin') -<<<<<<< HEAD -======= - no_taxes_applied = len(doc.get('taxes', [])) == 0 ->>>>>>> 7b2afaf349... fix: NoneType has no len() (#24600) - - if not einvoicing_enabled or invalid_doctype or invalid_supply_type or company_transaction: return + no_taxes_applied = not doc.get('taxes') + + if not einvoicing_enabled or invalid_doctype or invalid_supply_type or company_transaction or no_taxes_applied: + return if doc.docstatus == 0 and doc._action == 'save': if doc.irn: From fd4bed1a3866064cba77b49b53aa4a39800cb998 Mon Sep 17 00:00:00 2001 From: Saqib Date: Sat, 6 Feb 2021 17:55:20 +0530 Subject: [PATCH 262/449] fix(e-invoice): do not validate gstin for exports (#24561) --- erpnext/regional/india/e_invoice/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 876016fc19..4cf0b18f8c 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -304,7 +304,7 @@ def validate_mandatory_fields(invoice): _('GSTIN is mandatory to fetch company GSTIN details. Please enter GSTIN in selected company address.'), title=_('Missing Fields') ) - if not frappe.db.get_value('Address', invoice.customer_address, 'gstin'): + if invoice.gst_category != 'Overseas' and not frappe.db.get_value('Address', invoice.customer_address, 'gstin'): frappe.throw( _('GSTIN is mandatory to fetch customer GSTIN details. Please enter GSTIN in selected customer address.'), title=_('Missing Fields') From e965d0ff900714eece1028c888d5d4dbabdf9b28 Mon Sep 17 00:00:00 2001 From: Saqib Date: Fri, 29 Jan 2021 14:24:08 +0530 Subject: [PATCH 263/449] fix: discount amount calculation on net total (#24497) --- erpnext/regional/india/e_invoice/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 4cf0b18f8c..4b6bc251ad 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -163,7 +163,7 @@ def get_item_list(invoice): item.description = d.item_name.replace('"', '\\"') item.qty = abs(item.qty) - item.discount_amount = abs(item.discount_amount * item.qty) + item.discount_amount = 0 item.unit_rate = abs(item.base_net_amount / item.qty) item.gross_amount = abs(item.base_net_amount) item.taxable_value = abs(item.base_net_amount) @@ -223,11 +223,12 @@ def get_invoice_value_details(invoice): if invoice.apply_discount_on == 'Net Total' and invoice.discount_amount: invoice_value_details.base_total = abs(invoice.base_total) + invoice_value_details.invoice_discount_amt = invoice.base_discount_amount else: invoice_value_details.base_total = abs(invoice.base_net_total) + # since tax already considers discount amount + invoice_value_details.invoice_discount_amt = 0 - # since tax already considers discount amount - invoice_value_details.invoice_discount_amt = 0 # invoice.base_discount_amount invoice_value_details.round_off = invoice.base_rounding_adjustment invoice_value_details.base_grand_total = abs(invoice.base_rounded_total) or abs(invoice.base_grand_total) invoice_value_details.grand_total = abs(invoice.rounded_total) or abs(invoice.grand_total) From 90ff48baa35a240a29f241031e25bb5f246cfe21 Mon Sep 17 00:00:00 2001 From: Saqib Date: Thu, 28 Jan 2021 18:42:43 +0530 Subject: [PATCH 264/449] refactor: POS Invoice merging and cancellation (#24351) * feat: pos invoice merging with background jobs * fix: invoice threshold for queueing job * refactor: cancellation flow of point of sale * feat: tests for cancellation of pos closing Co-authored-by: Marica --- .../pos_closing_entry/pos_closing_entry.js | 1 + .../pos_closing_entry/pos_closing_entry.json | 21 +++- .../pos_closing_entry/pos_closing_entry.py | 28 +++-- .../pos_closing_entry_list.js | 16 +++ .../test_pos_closing_entry.py | 44 ++++++- .../doctype/pos_invoice/pos_invoice.js | 1 + .../doctype/pos_invoice/pos_invoice.py | 19 ++- .../doctype/pos_invoice/test_pos_invoice.py | 12 +- .../pos_invoice_merge_log.json | 15 ++- .../pos_invoice_merge_log.py | 113 +++++++++++++++--- .../test_pos_invoice_merge_log.py | 6 +- .../pos_opening_entry/pos_opening_entry.py | 1 - .../pos_opening_entry_list.js | 2 +- .../doctype/sales_invoice/sales_invoice.js | 1 + .../doctype/sales_invoice/sales_invoice.json | 11 +- .../doctype/sales_invoice/sales_invoice.py | 18 +++ erpnext/controllers/status_updater.py | 6 + erpnext/patches.txt | 1 + .../update_pos_closing_entry_in_merge_log.py | 25 ++++ 19 files changed, 291 insertions(+), 50 deletions(-) create mode 100644 erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry_list.js create mode 100644 erpnext/patches/v13_0/update_pos_closing_entry_in_merge_log.py diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js index e79eb421a0..9ea616f8e7 100644 --- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js +++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js @@ -3,6 +3,7 @@ frappe.ui.form.on('POS Closing Entry', { onload: function(frm) { + frm.ignore_doctypes_on_cancel_all = ['POS Invoice Merge Log']; frm.set_query("pos_profile", function(doc) { return { filters: { 'user': doc.user } diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.json b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.json index 32bca3b840..18d430f59f 100644 --- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.json +++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.json @@ -11,6 +11,7 @@ "column_break_3", "posting_date", "pos_opening_entry", + "status", "section_break_5", "company", "column_break_7", @@ -184,11 +185,27 @@ "label": "POS Opening Entry", "options": "POS Opening Entry", "reqd": 1 + }, + { + "allow_on_submit": 1, + "default": "Draft", + "fieldname": "status", + "fieldtype": "Select", + "hidden": 1, + "label": "Status", + "options": "Draft\nSubmitted\nQueued\nCancelled", + "print_hide": 1, + "read_only": 1 } ], "is_submittable": 1, - "links": [], - "modified": "2020-05-29 15:03:22.226113", + "links": [ + { + "link_doctype": "POS Invoice Merge Log", + "link_fieldname": "pos_closing_entry" + } + ], + "modified": "2021-01-12 12:21:05.388650", "modified_by": "Administrator", "module": "Accounts", "name": "POS Closing Entry", diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py index c26e14ff6f..edf3d5a574 100644 --- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py +++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py @@ -6,13 +6,12 @@ from __future__ import unicode_literals import frappe import json from frappe import _ -from frappe.model.document import Document -from frappe.utils import getdate, get_datetime, flt -from collections import defaultdict +from frappe.utils import get_datetime, flt +from erpnext.controllers.status_updater import StatusUpdater from erpnext.controllers.taxes_and_totals import get_itemised_tax_breakup_data -from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import merge_pos_invoices +from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import consolidate_pos_invoices, unconsolidate_pos_invoices -class POSClosingEntry(Document): +class POSClosingEntry(StatusUpdater): def validate(self): if frappe.db.get_value("POS Opening Entry", self.pos_opening_entry, "status") != "Open": frappe.throw(_("Selected POS Opening Entry should be open."), title=_("Invalid Opening Entry")) @@ -64,17 +63,22 @@ class POSClosingEntry(Document): frappe.throw(error_list, title=_("Invalid POS Invoices"), as_list=True) - def on_submit(self): - merge_pos_invoices(self.pos_transactions) - opening_entry = frappe.get_doc("POS Opening Entry", self.pos_opening_entry) - opening_entry.pos_closing_entry = self.name - opening_entry.set_status() - opening_entry.save() - def get_payment_reconciliation_details(self): currency = frappe.get_cached_value('Company', self.company, "default_currency") return frappe.render_template("erpnext/accounts/doctype/pos_closing_entry/closing_voucher_details.html", {"data": self, "currency": currency}) + + def on_submit(self): + consolidate_pos_invoices(closing_entry=self) + + def on_cancel(self): + unconsolidate_pos_invoices(closing_entry=self) + + def update_opening_entry(self, for_cancel=False): + opening_entry = frappe.get_doc("POS Opening Entry", self.pos_opening_entry) + opening_entry.pos_closing_entry = self.name if not for_cancel else None + opening_entry.set_status() + opening_entry.save() @frappe.whitelist() @frappe.validate_and_sanitize_search_inputs diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry_list.js b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry_list.js new file mode 100644 index 0000000000..20fd610899 --- /dev/null +++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry_list.js @@ -0,0 +1,16 @@ +// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +// License: GNU General Public License v3. See license.txt + +// render +frappe.listview_settings['POS Closing Entry'] = { + get_indicator: function(doc) { + var status_color = { + "Draft": "red", + "Submitted": "blue", + "Queued": "orange", + "Cancelled": "red" + + }; + return [__(doc.status), status_color[doc.status], "status,=,"+doc.status]; + } +}; diff --git a/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py b/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py index 8de54d5bde..40db09ec3b 100644 --- a/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py +++ b/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py @@ -13,7 +13,6 @@ from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profi class TestPOSClosingEntry(unittest.TestCase): def test_pos_closing_entry(self): test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) pos_inv1 = create_pos_invoice(rate=3500, do_not_submit=1) @@ -45,6 +44,49 @@ class TestPOSClosingEntry(unittest.TestCase): frappe.set_user("Administrator") frappe.db.sql("delete from `tabPOS Profile`") + def test_cancelling_of_pos_closing_entry(self): + test_user, pos_profile = init_user_and_profile() + opening_entry = create_opening_entry(pos_profile, test_user.name) + + pos_inv1 = create_pos_invoice(rate=3500, do_not_submit=1) + pos_inv1.append('payments', { + 'mode_of_payment': 'Cash', 'account': 'Cash - _TC', 'amount': 3500 + }) + pos_inv1.submit() + + pos_inv2 = create_pos_invoice(rate=3200, do_not_submit=1) + pos_inv2.append('payments', { + 'mode_of_payment': 'Cash', 'account': 'Cash - _TC', 'amount': 3200 + }) + pos_inv2.submit() + + pcv_doc = make_closing_entry_from_opening(opening_entry) + payment = pcv_doc.payment_reconciliation[0] + + self.assertEqual(payment.mode_of_payment, 'Cash') + + for d in pcv_doc.payment_reconciliation: + if d.mode_of_payment == 'Cash': + d.closing_amount = 6700 + + pcv_doc.submit() + + pos_inv1.load_from_db() + self.assertRaises(frappe.ValidationError, pos_inv1.cancel) + + si_doc = frappe.get_doc("Sales Invoice", pos_inv1.consolidated_invoice) + self.assertRaises(frappe.ValidationError, si_doc.cancel) + + pcv_doc.load_from_db() + pcv_doc.cancel() + si_doc.load_from_db() + pos_inv1.load_from_db() + self.assertEqual(si_doc.docstatus, 2) + self.assertEqual(pos_inv1.status, 'Paid') + + frappe.set_user("Administrator") + frappe.db.sql("delete from `tabPOS Profile`") + def init_user_and_profile(**args): user = 'test@example.com' test_user = frappe.get_doc('User', user) diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js index 6a7c4be890..465f0d31c4 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js @@ -11,6 +11,7 @@ erpnext.selling.POSInvoiceController = erpnext.selling.SellingController.extend( onload(doc) { this._super(); + this.frm.ignore_doctypes_on_cancel_all = ['POS Invoice Merge Log']; if(doc.__islocal && doc.is_pos && frappe.get_route_str() !== 'point-of-sale') { this.frm.script_manager.trigger("is_pos"); this.frm.refresh_fields(); diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index 7312248456..9d8f848b02 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -6,10 +6,9 @@ from __future__ import unicode_literals import frappe from frappe import _ from frappe.model.document import Document -from erpnext.controllers.selling_controller import SellingController -from frappe.utils import cint, flt, add_months, today, date_diff, getdate, add_days, cstr, nowdate from erpnext.accounts.utils import get_account_currency from erpnext.accounts.party import get_party_account, get_due_date +from frappe.utils import cint, flt, getdate, nowdate, get_link_to_form from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request from erpnext.accounts.doctype.loyalty_program.loyalty_program import validate_loyalty_points from erpnext.stock.doctype.serial_no.serial_no import get_pos_reserved_serial_nos, get_serial_nos @@ -58,6 +57,22 @@ class POSInvoice(SalesInvoice): self.apply_loyalty_points() self.check_phone_payments() self.set_status(update=True) + + def before_cancel(self): + if self.consolidated_invoice and frappe.db.get_value('Sales Invoice', self.consolidated_invoice, 'docstatus') == 1: + pos_closing_entry = frappe.get_all( + "POS Invoice Reference", + ignore_permissions=True, + filters={ 'pos_invoice': self.name }, + pluck="parent", + limit=1 + ) + frappe.throw( + _('You need to cancel POS Closing Entry {} to be able to cancel this document.').format( + get_link_to_form("POS Closing Entry", pos_closing_entry[0]) + ), + title=_('Not Allowed') + ) def on_cancel(self): # run on cancel method of selling controller diff --git a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py index c179360b01..57a23af8af 100644 --- a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py @@ -290,7 +290,7 @@ class TestPOSInvoice(unittest.TestCase): def test_merging_into_sales_invoice_with_discount(self): from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile - from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import merge_pos_invoices + from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import consolidate_pos_invoices frappe.db.sql("delete from `tabPOS Invoice`") test_user, pos_profile = init_user_and_profile() @@ -306,7 +306,7 @@ class TestPOSInvoice(unittest.TestCase): }) pos_inv2.submit() - merge_pos_invoices() + consolidate_pos_invoices() pos_inv.load_from_db() rounded_total = frappe.db.get_value("Sales Invoice", pos_inv.consolidated_invoice, "rounded_total") @@ -315,7 +315,7 @@ class TestPOSInvoice(unittest.TestCase): def test_merging_into_sales_invoice_with_discount_and_inclusive_tax(self): from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile - from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import merge_pos_invoices + from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import consolidate_pos_invoices frappe.db.sql("delete from `tabPOS Invoice`") test_user, pos_profile = init_user_and_profile() @@ -348,7 +348,7 @@ class TestPOSInvoice(unittest.TestCase): }) pos_inv2.submit() - merge_pos_invoices() + consolidate_pos_invoices() pos_inv.load_from_db() rounded_total = frappe.db.get_value("Sales Invoice", pos_inv.consolidated_invoice, "rounded_total") @@ -357,7 +357,7 @@ class TestPOSInvoice(unittest.TestCase): def test_merging_with_validate_selling_price(self): from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile - from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import merge_pos_invoices + from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import consolidate_pos_invoices if not frappe.db.get_single_value("Selling Settings", "validate_selling_price"): frappe.db.set_value("Selling Settings", "Selling Settings", "validate_selling_price", 1) @@ -393,7 +393,7 @@ class TestPOSInvoice(unittest.TestCase): }) pos_inv2.submit() - merge_pos_invoices() + consolidate_pos_invoices() pos_inv2.load_from_db() rounded_total = frappe.db.get_value("Sales Invoice", pos_inv2.consolidated_invoice, "rounded_total") diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.json b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.json index 8f97639bbc..da2984f05a 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.json +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.json @@ -7,6 +7,8 @@ "field_order": [ "posting_date", "customer", + "column_break_3", + "pos_closing_entry", "section_break_3", "pos_invoices", "references_section", @@ -76,11 +78,22 @@ "label": "Consolidated Credit Note", "options": "Sales Invoice", "read_only": 1 + }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, + { + "fieldname": "pos_closing_entry", + "fieldtype": "Link", + "label": "POS Closing Entry", + "options": "POS Closing Entry" } ], + "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2020-05-29 15:08:41.317100", + "modified": "2020-12-01 11:53:57.267579", "modified_by": "Administrator", "module": "Accounts", "name": "POS Invoice Merge Log", diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py index 5e43cfe030..5496804474 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py @@ -7,8 +7,11 @@ import frappe from frappe import _ from frappe.model import default_fields from frappe.model.document import Document +from frappe.utils import flt, getdate, nowdate +from frappe.utils.background_jobs import enqueue from frappe.model.mapper import map_doc, map_child_doc -from frappe.utils import cint, flt, add_months, today, date_diff, getdate, add_days, cstr, nowdate +from frappe.utils.scheduler import is_scheduler_inactive +from frappe.core.page.background_jobs.background_jobs import get_info from six import iteritems @@ -61,7 +64,13 @@ class POSInvoiceMergeLog(Document): self.save() # save consolidated_sales_invoice & consolidated_credit_note ref in merge log - self.update_pos_invoices(sales_invoice, credit_note) + self.update_pos_invoices(pos_invoice_docs, sales_invoice, credit_note) + + def on_cancel(self): + pos_invoice_docs = [frappe.get_doc("POS Invoice", d.pos_invoice) for d in self.pos_invoices] + + self.update_pos_invoices(pos_invoice_docs) + self.cancel_linked_invoices() def process_merging_into_sales_invoice(self, data): sales_invoice = self.get_new_sales_invoice() @@ -160,17 +169,21 @@ class POSInvoiceMergeLog(Document): return sales_invoice - def update_pos_invoices(self, sales_invoice, credit_note): - for d in self.pos_invoices: - doc = frappe.get_doc('POS Invoice', d.pos_invoice) - if not doc.is_return: - doc.update({'consolidated_invoice': sales_invoice}) - else: - doc.update({'consolidated_invoice': credit_note}) + def update_pos_invoices(self, invoice_docs, sales_invoice='', credit_note=''): + for doc in invoice_docs: + doc.load_from_db() + doc.update({ 'consolidated_invoice': None if self.docstatus==2 else (credit_note if doc.is_return else sales_invoice) }) doc.set_status(update=True) doc.save() -def get_all_invoices(): + def cancel_linked_invoices(self): + for si_name in [self.consolidated_invoice, self.consolidated_credit_note]: + if not si_name: continue + si = frappe.get_doc('Sales Invoice', si_name) + si.flags.ignore_validate = True + si.cancel() + +def get_all_unconsolidated_invoices(): filters = { 'consolidated_invoice': [ 'in', [ '', None ]], 'status': ['not in', ['Consolidated']], @@ -181,7 +194,7 @@ def get_all_invoices(): return pos_invoices -def get_invoices_customer_map(pos_invoices): +def get_invoice_customer_map(pos_invoices): # pos_invoice_customer_map = { 'Customer 1': [{}, {}, {}], 'Custoemr 2' : [{}] } pos_invoice_customer_map = {} for invoice in pos_invoices: @@ -191,20 +204,82 @@ def get_invoices_customer_map(pos_invoices): return pos_invoice_customer_map -def merge_pos_invoices(pos_invoices=[]): - if not pos_invoices: - pos_invoices = get_all_invoices() - - pos_invoice_map = get_invoices_customer_map(pos_invoices) - create_merge_logs(pos_invoice_map) +def consolidate_pos_invoices(pos_invoices=[], closing_entry={}): + invoices = pos_invoices or closing_entry.get('pos_transactions') or get_all_unconsolidated_invoices() + invoice_by_customer = get_invoice_customer_map(invoices) -def create_merge_logs(pos_invoice_customer_map): - for customer, invoices in iteritems(pos_invoice_customer_map): + if len(invoices) >= 5 and closing_entry: + enqueue_job(create_merge_logs, invoice_by_customer, closing_entry) + closing_entry.set_status(update=True, status='Queued') + else: + create_merge_logs(invoice_by_customer, closing_entry) + +def unconsolidate_pos_invoices(closing_entry): + merge_logs = frappe.get_all( + 'POS Invoice Merge Log', + filters={ 'pos_closing_entry': closing_entry.name }, + pluck='name' + ) + + if len(merge_logs) >= 5: + enqueue_job(cancel_merge_logs, merge_logs, closing_entry) + closing_entry.set_status(update=True, status='Queued') + else: + cancel_merge_logs(merge_logs, closing_entry) + +def create_merge_logs(invoice_by_customer, closing_entry={}): + for customer, invoices in iteritems(invoice_by_customer): merge_log = frappe.new_doc('POS Invoice Merge Log') merge_log.posting_date = getdate(nowdate()) merge_log.customer = customer + merge_log.pos_closing_entry = closing_entry.get('name', None) merge_log.set('pos_invoices', invoices) merge_log.save(ignore_permissions=True) merge_log.submit() + + if closing_entry: + closing_entry.set_status(update=True, status='Submitted') + closing_entry.update_opening_entry() +def cancel_merge_logs(merge_logs, closing_entry={}): + for log in merge_logs: + merge_log = frappe.get_doc('POS Invoice Merge Log', log) + merge_log.flags.ignore_permissions = True + merge_log.cancel() + + if closing_entry: + closing_entry.set_status(update=True, status='Cancelled') + closing_entry.update_opening_entry(for_cancel=True) + +def enqueue_job(job, invoice_by_customer, closing_entry): + check_scheduler_status() + + job_name = closing_entry.get("name") + if not job_already_enqueued(job_name): + enqueue( + job, + queue="long", + timeout=10000, + event="processing_merge_logs", + job_name=job_name, + closing_entry=closing_entry, + invoice_by_customer=invoice_by_customer, + now=frappe.conf.developer_mode or frappe.flags.in_test + ) + + if job == create_merge_logs: + msg = _('POS Invoices will be consolidated in a background process') + else: + msg = _('POS Invoices will be unconsolidated in a background process') + + frappe.msgprint(msg, alert=1) + +def check_scheduler_status(): + if is_scheduler_inactive() and not frappe.flags.in_test: + frappe.throw(_("Scheduler is inactive. Cannot enqueue job."), title=_("Scheduler Inactive")) + +def job_already_enqueued(job_name): + enqueued_jobs = [d.get("job_name") for d in get_info()] + if job_name in enqueued_jobs: + return True \ No newline at end of file diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py index 0f34272eb4..db046c9800 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py @@ -7,7 +7,7 @@ import frappe import unittest from erpnext.accounts.doctype.pos_invoice.test_pos_invoice import create_pos_invoice from erpnext.accounts.doctype.pos_invoice.pos_invoice import make_sales_return -from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import merge_pos_invoices +from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import consolidate_pos_invoices from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile class TestPOSInvoiceMergeLog(unittest.TestCase): @@ -34,7 +34,7 @@ class TestPOSInvoiceMergeLog(unittest.TestCase): }) pos_inv3.submit() - merge_pos_invoices() + consolidate_pos_invoices() pos_inv.load_from_db() self.assertTrue(frappe.db.exists("Sales Invoice", pos_inv.consolidated_invoice)) @@ -79,7 +79,7 @@ class TestPOSInvoiceMergeLog(unittest.TestCase): pos_inv_cn.paid_amount = -300 pos_inv_cn.submit() - merge_pos_invoices() + consolidate_pos_invoices() pos_inv.load_from_db() self.assertTrue(frappe.db.exists("Sales Invoice", pos_inv.consolidated_invoice)) diff --git a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py index acac1c4072..cb5b3a58fe 100644 --- a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py +++ b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py @@ -6,7 +6,6 @@ from __future__ import unicode_literals import frappe from frappe import _ from frappe.utils import cint, get_link_to_form -from frappe.model.document import Document from erpnext.controllers.status_updater import StatusUpdater class POSOpeningEntry(StatusUpdater): diff --git a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry_list.js b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry_list.js index 6c26dedc54..1ad3c919b7 100644 --- a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry_list.js +++ b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry_list.js @@ -5,7 +5,7 @@ frappe.listview_settings['POS Opening Entry'] = { get_indicator: function(doc) { var status_color = { - "Draft": "grey", + "Draft": "red", "Open": "orange", "Closed": "green", "Cancelled": "red" diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index f2a62cdacd..5bef9e242d 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -20,6 +20,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte var me = this; this._super(); + this.frm.ignore_doctypes_on_cancel_all = ['POS Invoice']; if(!this.frm.doc.__islocal && !this.frm.doc.customer && this.frm.doc.debit_to) { // show debit_to in print format this.frm.set_df_property("debit_to", "print_hide", 0); diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index 447cee42a7..018bc7e641 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -1987,8 +1987,15 @@ "icon": "fa fa-file-text", "idx": 181, "is_submittable": 1, - "links": [], - "modified": "2020-12-25 22:57:32.555067", + "links": [ + { + "custom": 1, + "group": "Reference", + "link_doctype": "POS Invoice", + "link_fieldname": "consolidated_invoice" + } + ], + "modified": "2021-01-12 12:16:15.192520", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index f45e076ce1..c39bd3954c 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -236,7 +236,25 @@ class SalesInvoice(SellingController): if len(self.payments) == 0 and self.is_pos: frappe.throw(_("At least one mode of payment is required for POS invoice.")) + def check_if_consolidated_invoice(self): + # since POS Invoice extends Sales Invoice, we explicitly check if doctype is Sales Invoice + if self.doctype == "Sales Invoice" and self.is_consolidated: + invoice_or_credit_note = "consolidated_credit_note" if self.is_return else "consolidated_invoice" + pos_closing_entry = frappe.get_all( + "POS Invoice Merge Log", + filters={ invoice_or_credit_note: self.name }, + pluck="pos_closing_entry" + ) + if pos_closing_entry: + msg = _("To cancel a {} you need to cancel the POS Closing Entry {}. ").format( + frappe.bold("Consolidated Sales Invoice"), + get_link_to_form("POS Closing Entry", pos_closing_entry[0]) + ) + frappe.throw(msg, title=_("Not Allowed")) + def before_cancel(self): + self.check_if_consolidated_invoice() + super(SalesInvoice, self).before_cancel() self.update_time_sheet(None) diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py index 8c05134ae4..0987d0985e 100644 --- a/erpnext/controllers/status_updater.py +++ b/erpnext/controllers/status_updater.py @@ -93,6 +93,12 @@ status_map = { ["Open", "eval:self.docstatus == 1 and not self.pos_closing_entry"], ["Closed", "eval:self.docstatus == 1 and self.pos_closing_entry"], ["Cancelled", "eval:self.docstatus == 2"], + ], + "POS Closing Entry": [ + ["Draft", None], + ["Submitted", "eval:self.docstatus == 1"], + ["Queued", "eval:self.status == 'Queued'"], + ["Cancelled", "eval:self.docstatus == 2"], ] } diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 6e28865a54..0c0b307c75 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -741,6 +741,7 @@ erpnext.patches.v13_0.update_member_email_address erpnext.patches.v13_0.update_custom_fields_for_shopify erpnext.patches.v13_0.updates_for_multi_currency_payroll erpnext.patches.v13_0.create_leave_policy_assignment_based_on_employee_current_leave_policy +erpnext.patches.v13_0.update_pos_closing_entry_in_merge_log erpnext.patches.v13_0.add_po_to_global_search erpnext.patches.v13_0.update_returned_qty_in_pr_dn erpnext.patches.v13_0.create_uae_pos_invoice_fields diff --git a/erpnext/patches/v13_0/update_pos_closing_entry_in_merge_log.py b/erpnext/patches/v13_0/update_pos_closing_entry_in_merge_log.py new file mode 100644 index 0000000000..42bca7c53a --- /dev/null +++ b/erpnext/patches/v13_0/update_pos_closing_entry_in_merge_log.py @@ -0,0 +1,25 @@ +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + frappe.reload_doc("accounts", "doctype", "POS Invoice Merge Log") + frappe.reload_doc("accounts", "doctype", "POS Closing Entry") + if frappe.db.count('POS Invoice Merge Log'): + frappe.db.sql(''' + UPDATE + `tabPOS Invoice Merge Log` log, `tabPOS Invoice Reference` log_ref + SET + log.pos_closing_entry = ( + SELECT clo_ref.parent FROM `tabPOS Invoice Reference` clo_ref + WHERE clo_ref.pos_invoice = log_ref.pos_invoice + AND clo_ref.parenttype = 'POS Closing Entry' + ) + WHERE + log_ref.parent = log.name + ''') + + frappe.db.sql('''UPDATE `tabPOS Closing Entry` SET status = 'Submitted' where docstatus = 1''') + frappe.db.sql('''UPDATE `tabPOS Closing Entry` SET status = 'Cancelled' where docstatus = 2''') From 83768b68c1e856e958e888db629a46dbbadf4644 Mon Sep 17 00:00:00 2001 From: Afshan <33727827+AfshanKhan@users.noreply.github.com> Date: Tue, 2 Feb 2021 11:04:25 +0530 Subject: [PATCH 265/449] fix: emp disappear (#24525) * fix: emp disappear * fix: renamed set_totals_call to set_totals Co-authored-by: Nabin Hait --- erpnext/payroll/doctype/payroll_entry/payroll_entry.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.js b/erpnext/payroll/doctype/payroll_entry/payroll_entry.js index 0dcea88c89..7ead0b3882 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.js +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.js @@ -342,3 +342,11 @@ let render_employee_attendance = function (frm, data) { }) ); }; + +frappe.ui.form.on('Payroll Employee Detail', { + employee: function(frm) { + if (!frm.doc.payroll_frequency) { + frappe.throw(__("Please set a Payroll Frequency")); + } + } +}); From d60a40ae822e3dc0d715d234d30ee416d502ad41 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 3 Feb 2021 12:06:36 +0530 Subject: [PATCH 266/449] fix: Add accounts user role permission for accounting dimension filter --- .../accounting_dimension_filter.json | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json index c0327ad0ad..0f3fbc0b8d 100644 --- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json +++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json @@ -108,7 +108,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2020-12-16 15:27:23.659285", + "modified": "2021-02-03 12:04:58.678402", "modified_by": "Administrator", "module": "Accounts", "name": "Accounting Dimension Filter", @@ -125,6 +125,30 @@ "role": "System Manager", "share": 1, "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts User", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts Manager", + "share": 1, + "write": 1 } ], "quick_entry": 1, From 33f4419a7833ba0d1c0c36a635cec18380c79463 Mon Sep 17 00:00:00 2001 From: Afshan <33727827+AfshanKhan@users.noreply.github.com> Date: Mon, 8 Feb 2021 12:32:42 +0530 Subject: [PATCH 267/449] fix: StopIteration error when e-invoice not enabled (#24548) * fix: StopIteration error when e-invoice not enabled * chore: update message Co-authored-by: Saqib --- erpnext/regional/india/e_invoice/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 4b6bc251ad..410c09396d 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -446,6 +446,8 @@ class GSPConnector(): def get_credentials(self): if self.invoice: gstin = self.get_seller_gstin() + if not self.e_invoice_settings.enable: + frappe.throw(_("E-Invoicing is disabled. Please enable it from {} to generate e-invoices.").format(get_link_to_form("E Invoice Settings", "E Invoice Settings"))) credentials = next(d for d in self.e_invoice_settings.credentials if d.gstin == gstin) else: credentials = self.e_invoice_settings.credentials[0] if self.e_invoice_settings.credentials else None @@ -816,4 +818,4 @@ def generate_eway_bill(doctype, docname, **kwargs): @frappe.whitelist() def cancel_eway_bill(doctype, docname, eway_bill, reason, remark): gsp_connector = GSPConnector(doctype, docname) - gsp_connector.cancel_eway_bill(eway_bill, reason, remark) \ No newline at end of file + gsp_connector.cancel_eway_bill(eway_bill, reason, remark) From 56e6ca628545604011995a04eb0b53350f4a8bbc Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 5 Feb 2021 10:04:18 -0800 Subject: [PATCH 268/449] fix: couple of travis fixes (#24554) Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> --- .../doctype/inpatient_record/test_inpatient_record.py | 1 + erpnext/hr/doctype/employee/test_employee.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py b/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py index 8a918b0275..ea0d1e982d 100644 --- a/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py +++ b/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py @@ -139,6 +139,7 @@ def create_inpatient(patient): inpatient_record.phone = patient_obj.phone inpatient_record.inpatient = "Scheduled" inpatient_record.scheduled_date = today() + inpatient_record.company = "_Test Company" return inpatient_record diff --git a/erpnext/hr/doctype/employee/test_employee.py b/erpnext/hr/doctype/employee/test_employee.py index f4b214adc3..c0e614ac08 100644 --- a/erpnext/hr/doctype/employee/test_employee.py +++ b/erpnext/hr/doctype/employee/test_employee.py @@ -16,11 +16,13 @@ class TestEmployee(unittest.TestCase): employee = frappe.get_doc("Employee", frappe.db.sql_list("select name from tabEmployee limit 1")[0]) employee.date_of_birth = "1992" + frappe.utils.nowdate()[4:] employee.company_email = "test@example.com" + employee.company = "_Test Company" employee.save() from erpnext.hr.doctype.employee.employee import get_employees_who_are_born_today, send_birthday_reminders - self.assertTrue(employee.name in [e.name for e in get_employees_who_are_born_today()]) + employees_born_today = get_employees_who_are_born_today() + self.assertTrue(employees_born_today.get("_Test Company")) frappe.db.sql("delete from `tabEmail Queue`") From 83792ec0091b0fffbcf340ba415071032e7e8a71 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Thu, 11 Feb 2021 13:23:01 +0530 Subject: [PATCH 269/449] fix: reposting issue with same posting date and posting time (#24570) * fix: reposting issue with same posting date and posting time * Update erpnext/stock/stock_ledger.py Co-authored-by: Nabin Hait --- erpnext/stock/stock_ledger.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 46919c8c8c..95f8c438b3 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -202,8 +202,7 @@ class update_entries_after(object): where item_code = %(item_code)s and warehouse = %(warehouse)s - and voucher_type = %(voucher_type)s - and voucher_no = %(voucher_no)s + and timestamp(posting_date, time_format(posting_time, '%H:%i:%s')) = timestamp(%(posting_date)s, time_format(%(posting_time)s, '%H:%i:%s')) order by creation ASC for update @@ -794,4 +793,4 @@ def get_future_sle_with_negative_qty(args): and qty_after_transaction + {0} < 0 order by timestamp(posting_date, posting_time) asc limit 1 - """.format(args.actual_qty), args, as_dict=1) \ No newline at end of file + """.format(args.actual_qty), args, as_dict=1) From 4b2cbdc2dd1a3391f1338b95008ba73b2d5473bc Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 11 Feb 2021 11:04:39 +0530 Subject: [PATCH 270/449] fix: update total in words after updating items (#24602) * fix: Update total in words after Updating items Update total in words after Updating items in sales/purchase orders. Port of #24592 Closes ISS-20-21-09425 * test: Add test for total & words after update item Add test for total & words after updating items in sales order. --- erpnext/controllers/accounts_controller.py | 1 + erpnext/selling/doctype/sales_order/test_sales_order.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 35c6cd33f9..a838259862 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1503,6 +1503,7 @@ def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name, chil parent.flags.ignore_validate_update_after_submit = True parent.set_qty_as_per_stock_uom() parent.calculate_taxes_and_totals() + parent.set_total_in_words() if parent_doctype == "Sales Order": make_packing_list(parent) parent.set_gross_profit() diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py index e259367e58..cbfab8204f 100644 --- a/erpnext/selling/doctype/sales_order/test_sales_order.py +++ b/erpnext/selling/doctype/sales_order/test_sales_order.py @@ -325,6 +325,9 @@ class TestSalesOrder(unittest.TestCase): create_dn_against_so(so.name, 4) make_sales_invoice(so.name) + prev_total = so.get("base_total") + prev_total_in_words = so.get("base_in_words") + first_item_of_so = so.get("items")[0] trans_item = json.dumps([ {'item_code' : first_item_of_so.item_code, 'rate' : first_item_of_so.rate, \ @@ -340,6 +343,12 @@ class TestSalesOrder(unittest.TestCase): self.assertEqual(so.get("items")[-1].amount, 1400) self.assertEqual(so.status, 'To Deliver and Bill') + updated_total = so.get("base_total") + updated_total_in_words = so.get("base_in_words") + + self.assertEqual(updated_total, prev_total+1400) + self.assertNotEqual(updated_total_in_words, prev_total_in_words) + def test_update_child_removing_item(self): so = make_sales_order(**{ "item_list": [{ From 76f616565eedb96dfe9db871fa0d31a6d1563d53 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Thu, 11 Feb 2021 11:07:59 +0530 Subject: [PATCH 271/449] fix: Consolidated Financial Statement report not works if child company account not present in parent company (#24580) Fixed conflicts --- .../consolidated_financial_statement.py | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py index d0116890b6..76f3c50578 100644 --- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py +++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py @@ -222,7 +222,7 @@ def get_data(companies, root_type, balance_must_be, fiscal_year, filters=None, i set_gl_entries_by_account(start_date, end_date, root.lft, root.rgt, filters, - gl_entries_by_account, accounts_by_name, ignore_closing_entries=False) + gl_entries_by_account, accounts_by_name, accounts, ignore_closing_entries=False) calculate_values(accounts_by_name, gl_entries_by_account, companies, start_date, filters) accumulate_values_into_parents(accounts, accounts_by_name, companies) @@ -339,7 +339,7 @@ def prepare_data(accounts, start_date, end_date, balance_must_be, companies, com return data def set_gl_entries_by_account(from_date, to_date, root_lft, root_rgt, filters, gl_entries_by_account, - accounts_by_name, ignore_closing_entries=False): + accounts_by_name, accounts, ignore_closing_entries=False): """Returns a dict like { "account": [gl entries], ... }""" company_lft, company_rgt = frappe.get_cached_value('Company', @@ -382,15 +382,31 @@ def set_gl_entries_by_account(from_date, to_date, root_lft, root_rgt, filters, g for entry in gl_entries: key = entry.account_number or entry.account_name - validate_entries(key, entry, accounts_by_name) + validate_entries(key, entry, accounts_by_name, accounts) gl_entries_by_account.setdefault(key, []).append(entry) return gl_entries_by_account -def validate_entries(key, entry, accounts_by_name): +def get_account_details(account): + return frappe.get_cached_value('Account', account, ['name', 'report_type', 'root_type', 'company', + 'is_group', 'account_name', 'account_number', 'parent_account', 'lft', 'rgt'], as_dict=1) + +def validate_entries(key, entry, accounts_by_name, accounts): if key not in accounts_by_name: - field = "Account number" if entry.account_number else "Account name" - frappe.throw(_("{0} {1} is not present in the parent company").format(field, key)) + args = get_account_details(entry.account) + + if args.parent_account: + parent_args = get_account_details(args.parent_account) + + args.update({ + 'lft': parent_args.lft + 1, + 'rgt': parent_args.rgt - 1, + 'root_type': parent_args.root_type, + 'report_type': parent_args.report_type + }) + + accounts_by_name.setdefault(key, args) + accounts.append(args) def get_additional_conditions(from_date, ignore_closing_entries, filters): additional_conditions = [] From f2be0805f7463a8983be4febdd2abb68af73455c Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 15 Feb 2021 19:27:49 +0530 Subject: [PATCH 272/449] fix: formatting query args (#24627) --- erpnext/stock/stock_ledger.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 95f8c438b3..8c9c172ebd 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -194,6 +194,8 @@ class update_entries_after(object): self.process_sle(sle) def get_sle_against_current_voucher(self): + self.args['time_format'] = '%H:%i:%s' + return frappe.db.sql(""" select *, timestamp(posting_date, posting_time) as "timestamp" @@ -202,7 +204,7 @@ class update_entries_after(object): where item_code = %(item_code)s and warehouse = %(warehouse)s - and timestamp(posting_date, time_format(posting_time, '%H:%i:%s')) = timestamp(%(posting_date)s, time_format(%(posting_time)s, '%H:%i:%s')) + and timestamp(posting_date, time_format(posting_time, %(time_format)s)) = timestamp(%(posting_date)s, time_format(%(posting_time)s, %(time_format)s)) order by creation ASC for update From 7797e9d3ac027135b94115fa7f6f11d97dec2945 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Tue, 16 Feb 2021 09:12:27 +0530 Subject: [PATCH 273/449] fix: added patch to fix incorrect stock qty and account value (#24628) --- erpnext/accounts/utils.py | 13 ++++++--- erpnext/patches.txt | 1 + .../item_reposting_for_incorrect_sl_and_gl.py | 27 +++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 67c7fd2d22..80319056dd 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -82,7 +82,7 @@ def get_fiscal_years(transaction_date=None, fiscal_year=None, label="Date", verb error_msg = _("""{0} {1} is not in any active Fiscal Year""").format(label, formatdate(transaction_date)) if company: error_msg = _("""{0} for {1}""").format(error_msg, frappe.bold(company)) - + if verbose==1: frappe.msgprint(error_msg) raise FiscalYearError(error_msg) @@ -895,7 +895,8 @@ def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for if not warehouse_account: warehouse_account = get_warehouse_account_map(company) - future_stock_vouchers = get_future_stock_vouchers(posting_date, posting_time, for_warehouses, for_items) + future_stock_vouchers = get_future_stock_vouchers(posting_date, posting_time, + for_warehouses, for_items, company) gle = get_voucherwise_gl_entries(future_stock_vouchers, posting_date) for voucher_type, voucher_no in future_stock_vouchers: @@ -909,7 +910,7 @@ def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for else: _delete_gl_entries(voucher_type, voucher_no) -def get_future_stock_vouchers(posting_date, posting_time, for_warehouses=None, for_items=None): +def get_future_stock_vouchers(posting_date, posting_time, for_warehouses=None, for_items=None, company=None): future_stock_vouchers = [] values = [] @@ -922,6 +923,10 @@ def get_future_stock_vouchers(posting_date, posting_time, for_warehouses=None, f condition += " and warehouse in ({})".format(", ".join(["%s"] * len(for_warehouses))) values += for_warehouses + if company: + condition += " and company = %s " + values.append(company) + for d in frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no from `tabStock Ledger Entry` sle where @@ -982,7 +987,7 @@ def check_if_stock_and_account_balance_synced(posting_date, company, voucher_typ error_reason = _("Stock Value ({0}) and Account Balance ({1}) are out of sync for account {2} and it's linked warehouses as on {3}.").format( stock_bal, account_bal, frappe.bold(account), posting_date) error_resolution = _("Please create an adjustment Journal Entry for amount {0} on {1}")\ - .format(frappe.bold(diff), frappe.bold(posting_date)) + .format(frappe.bold(diff), frappe.bold(posting_date)) frappe.msgprint( msg="""{0}

{1}

""".format(error_reason, error_resolution), diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 0c0b307c75..25ebf67dc1 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -750,3 +750,4 @@ erpnext.patches.v13_0.set_company_in_leave_ledger_entry erpnext.patches.v13_0.convert_qi_parameter_to_link_field erpnext.patches.v13_0.setup_patient_history_settings_for_standard_doctypes erpnext.patches.v13_0.add_naming_series_to_old_projects # 1-02-2021 +erpnext.patches.v13_0.item_reposting_for_incorrect_sl_and_gl diff --git a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py new file mode 100644 index 0000000000..7c4835a813 --- /dev/null +++ b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py @@ -0,0 +1,27 @@ +import frappe +from frappe import _ +from erpnext.stock.stock_ledger import update_entries_after +from erpnext.accounts.utils import update_gl_entries_after + + +data = frappe.db.sql(''' SELECT name, item_code, warehouse, voucher_type, voucher_no, posting_date, posting_time + from `tabStock Ledger Entry` where creation > '2020-12-26 12:58:55.903836' and is_cancelled = 0 + order by timestamp(posting_date, posting_time) asc, creation asc''', as_dict=1) + +for index, d in enumerate(data): + update_entries_after({ + "item_code": d.item_code, + "warehouse": d.warehouse, + "posting_date": d.posting_date, + "posting_time": d.posting_time, + "voucher_type": d.voucher_type, + "voucher_no": d.voucher_no, + "sle_id": d.name + }, allow_negative_stock=True) + +frappe.db.auto_commit_on_many_writes = 1 + +for row in frappe.get_all('Company', filters= {'enable_perpetual_inventory': 1}): + update_gl_entries_after('2020-12-25', '01:58:55', company=row.name) + +frappe.db.auto_commit_on_many_writes = 0 \ No newline at end of file From 83f5468ca1d712b69714a81cc855ffe6607eed27 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 16 Feb 2021 10:35:10 +0530 Subject: [PATCH 274/449] fix: patch --- .../item_reposting_for_incorrect_sl_and_gl.py | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py index 7c4835a813..eff0ae4694 100644 --- a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py +++ b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py @@ -4,24 +4,25 @@ from erpnext.stock.stock_ledger import update_entries_after from erpnext.accounts.utils import update_gl_entries_after -data = frappe.db.sql(''' SELECT name, item_code, warehouse, voucher_type, voucher_no, posting_date, posting_time - from `tabStock Ledger Entry` where creation > '2020-12-26 12:58:55.903836' and is_cancelled = 0 - order by timestamp(posting_date, posting_time) asc, creation asc''', as_dict=1) +def execute(): + data = frappe.db.sql(''' SELECT name, item_code, warehouse, voucher_type, voucher_no, posting_date, posting_time + from `tabStock Ledger Entry` where creation > '2020-12-26 12:58:55.903836' and is_cancelled = 0 + order by timestamp(posting_date, posting_time) asc, creation asc''', as_dict=1) -for index, d in enumerate(data): - update_entries_after({ - "item_code": d.item_code, - "warehouse": d.warehouse, - "posting_date": d.posting_date, - "posting_time": d.posting_time, - "voucher_type": d.voucher_type, - "voucher_no": d.voucher_no, - "sle_id": d.name - }, allow_negative_stock=True) + for index, d in enumerate(data): + update_entries_after({ + "item_code": d.item_code, + "warehouse": d.warehouse, + "posting_date": d.posting_date, + "posting_time": d.posting_time, + "voucher_type": d.voucher_type, + "voucher_no": d.voucher_no, + "sle_id": d.name + }, allow_negative_stock=True) -frappe.db.auto_commit_on_many_writes = 1 + frappe.db.auto_commit_on_many_writes = 1 -for row in frappe.get_all('Company', filters= {'enable_perpetual_inventory': 1}): - update_gl_entries_after('2020-12-25', '01:58:55', company=row.name) + for row in frappe.get_all('Company', filters= {'enable_perpetual_inventory': 1}): + update_gl_entries_after('2020-12-25', '01:58:55', company=row.name) -frappe.db.auto_commit_on_many_writes = 0 \ No newline at end of file + frappe.db.auto_commit_on_many_writes = 0 \ No newline at end of file From deddcc513d043f8198a114b2b585818150c91ab8 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 16 Feb 2021 14:57:00 +0530 Subject: [PATCH 275/449] fix: stock and account balance syncing (#24644) * fix: stock and account balance syncing * fix: stock and account balance syncing * fix: stock and account balance syncing * fix: minor fix --- erpnext/accounts/utils.py | 14 +++++++++----- erpnext/controllers/stock_controller.py | 3 +-- .../clinical_procedure/clinical_procedure.py | 1 + .../clinical_procedure/test_clinical_procedure.py | 5 +++-- .../item_reposting_for_incorrect_sl_and_gl.py | 1 - erpnext/stock/__init__.py | 2 +- erpnext/stock/doctype/batch/test_batch.py | 6 +++--- .../test_landed_cost_voucher.py | 5 ++++- .../repost_item_valuation/repost_item_valuation.py | 2 +- erpnext/stock/doctype/shipment/test_shipment.py | 1 + erpnext/stock/stock_ledger.py | 3 ++- 11 files changed, 26 insertions(+), 17 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 80319056dd..60d1e20fea 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -888,18 +888,22 @@ def get_coa(doctype, parent, is_root, chart=None): def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for_items=None, warehouse_account=None, company=None): + stock_vouchers = get_future_stock_vouchers(posting_date, posting_time, for_warehouses, for_items, company) + repost_gle_for_stock_vouchers(stock_vouchers, posting_date, company, warehouse_account) + + +def repost_gle_for_stock_vouchers(stock_vouchers, posting_date, company=None, warehouse_account=None): def _delete_gl_entries(voucher_type, voucher_no): frappe.db.sql("""delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no)) + if not warehouse_account: warehouse_account = get_warehouse_account_map(company) - future_stock_vouchers = get_future_stock_vouchers(posting_date, posting_time, - for_warehouses, for_items, company) - gle = get_voucherwise_gl_entries(future_stock_vouchers, posting_date) + gle = get_voucherwise_gl_entries(stock_vouchers, posting_date) - for voucher_type, voucher_no in future_stock_vouchers: + for voucher_type, voucher_no in stock_vouchers: existing_gle = gle.get((voucher_type, voucher_no), []) voucher_obj = frappe.get_doc(voucher_type, voucher_no) expected_gle = voucher_obj.get_gl_entries(warehouse_account) @@ -924,7 +928,7 @@ def get_future_stock_vouchers(posting_date, posting_time, for_warehouses=None, f values += for_warehouses if company: - condition += " and company = %s " + condition += " and company = %s" values.append(company) for d in frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 4b5e347970..94735733b2 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -481,13 +481,12 @@ class StockController(AccountsController): "voucher_no": self.name, "company": self.company }) - if check_if_future_sle_exists(args): create_repost_item_valuation_entry(args) elif not is_reposting_pending(): check_if_stock_and_account_balance_synced(self.posting_date, self.company, self.doctype, self.name) - + def is_reposting_pending(): return frappe.db.exists("Repost Item Valuation", {'docstatus': 1, 'status': ['in', ['Queued','In Progress']]}) diff --git a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py index c324228467..325c2094fb 100644 --- a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py +++ b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py @@ -121,6 +121,7 @@ class ClinicalProcedure(Document): stock_entry.stock_entry_type = 'Material Receipt' stock_entry.to_warehouse = self.warehouse + stock_entry.company = self.company expense_account = get_account(None, 'expense_account', 'Healthcare Settings', self.company) for item in self.items: if item.qty > item.actual_qty: diff --git a/erpnext/healthcare/doctype/clinical_procedure/test_clinical_procedure.py b/erpnext/healthcare/doctype/clinical_procedure/test_clinical_procedure.py index 4ee5f6bad3..fb72073a07 100644 --- a/erpnext/healthcare/doctype/clinical_procedure/test_clinical_procedure.py +++ b/erpnext/healthcare/doctype/clinical_procedure/test_clinical_procedure.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + # -*- coding: utf-8 -*- # Copyright (c) 2017, ESS LLP and Contributors # See license.txt from __future__ import unicode_literals @@ -60,6 +60,7 @@ def create_procedure(procedure_template, patient, practitioner): procedure.practitioner = practitioner procedure.consume_stock = procedure_template.allow_stock_consumption procedure.items = procedure_template.items - procedure.warehouse = frappe.db.get_single_value('Stock Settings', 'default_warehouse') + procedure.company = "_Test Company" + procedure.warehouse = "_Test Warehouse - _TC" procedure.submit() return procedure \ No newline at end of file diff --git a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py index eff0ae4694..f60e0d3036 100644 --- a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py +++ b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py @@ -3,7 +3,6 @@ from frappe import _ from erpnext.stock.stock_ledger import update_entries_after from erpnext.accounts.utils import update_gl_entries_after - def execute(): data = frappe.db.sql(''' SELECT name, item_code, warehouse, voucher_type, voucher_no, posting_date, posting_time from `tabStock Ledger Entry` where creation > '2020-12-26 12:58:55.903836' and is_cancelled = 0 diff --git a/erpnext/stock/__init__.py b/erpnext/stock/__init__.py index 8d64efe41d..b3ae804b1c 100644 --- a/erpnext/stock/__init__.py +++ b/erpnext/stock/__init__.py @@ -64,7 +64,7 @@ def get_warehouse_account(warehouse, warehouse_account=None): if not account and warehouse.company: account = get_company_default_inventory_account(warehouse.company) - if not account and warehouse.company: + if not account and warehouse.company and not warehouse.is_group: frappe.throw(_("Please set Account in Warehouse {0} or Default Inventory Account in Company {1}") .format(warehouse.name, warehouse.company)) return account diff --git a/erpnext/stock/doctype/batch/test_batch.py b/erpnext/stock/doctype/batch/test_batch.py index 97f85bafd9..cbd272df4b 100644 --- a/erpnext/stock/doctype/batch/test_batch.py +++ b/erpnext/stock/doctype/batch/test_batch.py @@ -298,9 +298,9 @@ class TestBatch(unittest.TestCase): self.assertEqual(details.get('price_list_rate'), 400) def create_batch(item_code, rate, create_item_price_for_batch): - pi = make_purchase_invoice(company="_Test Company with perpetual inventory", - warehouse= "Stores - TCP1", cost_center = "Main - TCP1", update_stock=1, - expense_account ="_Test Account Cost for Goods Sold - TCP1", item_code=item_code) + pi = make_purchase_invoice(company="_Test Company", + warehouse= "Stores - _TC", cost_center = "Main - _TC", update_stock=1, + expense_account ="_Test Account Cost for Goods Sold - _TC", item_code=item_code) batch = frappe.db.get_value('Batch', {'item': item_code, 'reference_name': pi.name}) diff --git a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py index 144101c67d..984ae46c66 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py +++ b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py @@ -148,7 +148,6 @@ class TestLandedCostVoucher(unittest.TestCase): def test_landed_cost_voucher_for_odd_numbers (self): - pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1", do_not_save=True) pr.items[0].cost_center = "Main - TCP1" for x in range(2): @@ -208,6 +207,10 @@ class TestLandedCostVoucher(unittest.TestCase): self.assertEqual(pr.items[1].landed_cost_voucher_amount, 100) def test_multi_currency_lcv(self): + from erpnext.setup.doctype.currency_exchange.test_currency_exchange import test_records, save_new_records + + save_new_records(test_records) + ## Create USD Shipping charges_account usd_shipping = create_account(account_name="Shipping Charges USD", parent_account="Duties and Taxes - TCP1", company="_Test Company with perpetual inventory", diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py index ba2c2c6f44..f22c6018d4 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -64,7 +64,7 @@ def repost(doc): message += "
" + "Traceback:
" + traceback frappe.db.set_value(doc.doctype, doc.name, 'error_log', message) - notify_error_to_stock_managers(doc) + notify_error_to_stock_managers(doc, message) doc.set_status('Failed') raise finally: diff --git a/erpnext/stock/doctype/shipment/test_shipment.py b/erpnext/stock/doctype/shipment/test_shipment.py index e1fa207a21..9c3e22f023 100644 --- a/erpnext/stock/doctype/shipment/test_shipment.py +++ b/erpnext/stock/doctype/shipment/test_shipment.py @@ -190,6 +190,7 @@ def create_shipment_company(company_name, abbr): company.abbr = abbr company.default_currency = 'EUR' company.country = 'Germany' + company.enable_perpetual_inventory = 0 company.insert() return company diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 8c9c172ebd..21860b6863 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -204,7 +204,8 @@ class update_entries_after(object): where item_code = %(item_code)s and warehouse = %(warehouse)s - and timestamp(posting_date, time_format(posting_time, %(time_format)s)) = timestamp(%(posting_date)s, time_format(%(posting_time)s, %(time_format)s)) + and voucher_type = %(voucher_type)s + and voucher_no = %(voucher_no)s order by creation ASC for update From 186a045e28ae10b17e0aeeb83b847372a6b32354 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 18 Feb 2021 14:14:21 +0530 Subject: [PATCH 276/449] fix: update qty in future sle (#24649) * fix: update qty in future sle * fix: validate cancellation due to ongoing reposting * fix: process sle against current timestamp --- .../doctype/work_order/test_work_order.py | 10 +-- erpnext/stock/__init__.py | 2 +- erpnext/stock/doctype/bin/bin.py | 13 +-- .../delivery_note/test_delivery_note.py | 5 +- .../purchase_receipt/test_purchase_receipt.py | 9 +- .../repost_item_valuation.py | 3 + .../stock_ledger_entry/stock_ledger_entry.py | 1 + erpnext/stock/stock_ledger.py | 87 ++++++++++++++++--- 8 files changed, 102 insertions(+), 28 deletions(-) diff --git a/erpnext/manufacturing/doctype/work_order/test_work_order.py b/erpnext/manufacturing/doctype/work_order/test_work_order.py index 06a8e1987d..00e8c5418a 100644 --- a/erpnext/manufacturing/doctype/work_order/test_work_order.py +++ b/erpnext/manufacturing/doctype/work_order/test_work_order.py @@ -94,11 +94,11 @@ class TestWorkOrder(unittest.TestCase): wo_order = make_wo_order_test_record(item="_Test FG Item", qty=2, source_warehouse=warehouse, skip_transfer=1) - bin1_on_submit = get_bin(item, warehouse) + reserved_qty_on_submission = cint(get_bin(item, warehouse).reserved_qty_for_production) # reserved qty for production is updated - self.assertEqual(cint(bin1_at_start.reserved_qty_for_production) + 2, - cint(bin1_on_submit.reserved_qty_for_production)) + self.assertEqual(cint(bin1_at_start.reserved_qty_for_production) + 2, reserved_qty_on_submission) + test_stock_entry.make_stock_entry(item_code="_Test Item", target=warehouse, qty=100, basic_rate=100) @@ -109,9 +109,9 @@ class TestWorkOrder(unittest.TestCase): s.submit() bin1_at_completion = get_bin(item, warehouse) - + self.assertEqual(cint(bin1_at_completion.reserved_qty_for_production), - cint(bin1_on_submit.reserved_qty_for_production) - 1) + reserved_qty_on_submission - 1) def test_production_item(self): wo_order = make_wo_order_test_record(item="_Test FG Item", qty=1, do_not_save=True) diff --git a/erpnext/stock/__init__.py b/erpnext/stock/__init__.py index b3ae804b1c..9e240cc2b3 100644 --- a/erpnext/stock/__init__.py +++ b/erpnext/stock/__init__.py @@ -70,4 +70,4 @@ def get_warehouse_account(warehouse, warehouse_account=None): return account def get_company_default_inventory_account(company): - return frappe.get_cached_value('Company', company, 'default_inventory_account') + return frappe.get_cached_value('Company', company, 'default_inventory_account') diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py index 1088b4127d..0514bd2394 100644 --- a/erpnext/stock/doctype/bin/bin.py +++ b/erpnext/stock/doctype/bin/bin.py @@ -16,8 +16,9 @@ class Bin(Document): def update_stock(self, args, allow_negative_stock=False, via_landed_cost_voucher=False): '''Called from erpnext.stock.utils.update_bin''' self.update_qty(args) + if args.get("actual_qty") or args.get("voucher_type") == "Stock Reconciliation": - from erpnext.stock.stock_ledger import update_entries_after, validate_negative_qty_in_future_sle + from erpnext.stock.stock_ledger import update_entries_after, update_qty_in_future_sle if not args.get("posting_date"): args["posting_date"] = nowdate() @@ -34,11 +35,13 @@ class Bin(Document): "posting_time": args.get("posting_time"), "voucher_type": args.get("voucher_type"), "voucher_no": args.get("voucher_no"), - "sle_id": args.name + "sle_id": args.name, + "creation": args.creation }, allow_negative_stock=allow_negative_stock, via_landed_cost_voucher=via_landed_cost_voucher) - # Validate negative qty in future transactions - validate_negative_qty_in_future_sle(args) + # update qty in future ale and Validate negative qty + update_qty_in_future_sle(args, allow_negative_stock) + def update_qty(self, args): # update the stock values (for current quantities) @@ -51,7 +54,7 @@ class Bin(Document): self.reserved_qty = flt(self.reserved_qty) + flt(args.get("reserved_qty")) self.indented_qty = flt(self.indented_qty) + flt(args.get("indented_qty")) self.planned_qty = flt(self.planned_qty) + flt(args.get("planned_qty")) - + self.set_projected_qty() self.db_update() diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py index 559f8be0de..d39b22965e 100644 --- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py @@ -489,7 +489,10 @@ class TestDeliveryNote(unittest.TestCase): def test_closed_delivery_note(self): from erpnext.stock.doctype.delivery_note.delivery_note import update_delivery_note_status - dn = create_delivery_note(company='_Test Company with perpetual inventory', warehouse='Stores - TCP1', cost_center = 'Main - TCP1', expense_account = "Cost of Goods Sold - TCP1", do_not_submit=True) + make_stock_entry(target="Stores - TCP1", qty=5, basic_rate=100) + + dn = create_delivery_note(company='_Test Company with perpetual inventory', warehouse='Stores - TCP1', + cost_center = 'Main - TCP1', expense_account = "Cost of Goods Sold - TCP1", do_not_submit=True) dn.submit() diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index ca58ab2823..7741ee7f60 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -94,10 +94,15 @@ class TestPurchaseReceipt(unittest.TestCase): frappe.get_doc('Payment Terms Template', '_Test Payment Terms Template For Purchase Invoice').delete() def test_purchase_receipt_no_gl_entry(self): + from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry + company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC', 'company') - existing_bin_stock_value = frappe.db.get_value("Bin", {"item_code": "_Test Item", - "warehouse": "_Test Warehouse - _TC"}, "stock_value") + existing_bin_qty, existing_bin_stock_value = frappe.db.get_value("Bin", {"item_code": "_Test Item", + "warehouse": "_Test Warehouse - _TC"}, ["actual_qty", "stock_value"]) + + if existing_bin_qty < 0: + make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=abs(existing_bin_qty)) pr = make_purchase_receipt() diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py index f22c6018d4..8436acbed2 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -46,6 +46,9 @@ class RepostItemValuation(Document): def repost(doc): try: + if not frappe.db.exists("Repost Item Valuation", doc.name): + return + doc.set_status('In Progress') frappe.db.commit() diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py index a5c303ccb4..78457e4809 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py @@ -37,6 +37,7 @@ class StockLedgerEntry(Document): self.block_transactions_against_group_warehouse() self.validate_with_last_transaction_posting_time() + def on_submit(self): self.check_stock_frozen_date() self.actual_amt_check() diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 21860b6863..e4f5725c68 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -23,6 +23,7 @@ def make_sl_entries(sl_entries, allow_negative_stock=False, via_landed_cost_vouc cancel = sl_entries[0].get("is_cancelled") if cancel: + validate_cancellation(sl_entries) set_as_cancel(sl_entries[0].get('voucher_type'), sl_entries[0].get('voucher_no')) for sle in sl_entries: @@ -45,6 +46,20 @@ def make_sl_entries(sl_entries, allow_negative_stock=False, via_landed_cost_vouc args = sle_doc.as_dict() update_bin(args, allow_negative_stock, via_landed_cost_voucher) +def validate_cancellation(args): + if args[0].get("is_cancelled"): + repost_entry = frappe.db.get_value("Repost Item Valuation", { + 'voucher_type': args[0].voucher_type, + 'voucher_no': args[0].voucher_no, + 'docstatus': 1 + }, ['name', 'status'], as_dict=1) + + if repost_entry: + if repost_entry.status == 'In Progress': + frappe.throw(_("Cannot cancel the transaction. Reposting of item valuation on submission is not completed yet.")) + if repost_entry.status == 'Queued': + frappe.delete_doc("Repost Item Valuation", repost_entry.name) + def set_as_cancel(voucher_type, voucher_no): frappe.db.sql("""update `tabStock Ledger Entry` set is_cancelled=1, @@ -74,7 +89,8 @@ def repost_future_sle(args=None, voucher_type=None, voucher_no=None, allow_negat "item_code": args[i].item_code, "warehouse": args[i].warehouse, "posting_date": args[i].posting_date, - "posting_time": args[i].posting_time + "posting_time": args[i].posting_time, + "creation": args[i].get("creation") }, allow_negative_stock=allow_negative_stock, via_landed_cost_voucher=via_landed_cost_voucher) for item_wh, new_sle in iteritems(obj.new_items): @@ -86,7 +102,7 @@ def repost_future_sle(args=None, voucher_type=None, voucher_no=None, allow_negat def get_args_for_voucher(voucher_type, voucher_no): return frappe.db.get_all("Stock Ledger Entry", filters={"voucher_type": voucher_type, "voucher_no": voucher_no}, - fields=["item_code", "warehouse", "posting_date", "posting_time"], + fields=["item_code", "warehouse", "posting_date", "posting_time", "creation"], order_by="creation asc", group_by="item_code, warehouse" ) @@ -117,7 +133,7 @@ class update_entries_after(object): self.item_code = args.get("item_code") if self.args.sle_id: self.args['name'] = self.args.sle_id - + self.company = frappe.get_cached_value("Warehouse", self.args.warehouse, "company") self.get_precision() self.valuation_method = get_valuation_method(self.item_code) @@ -155,7 +171,7 @@ class update_entries_after(object): """ self.data.setdefault(args.warehouse, frappe._dict()) warehouse_dict = self.data[args.warehouse] - previous_sle = self.get_sle_before_datetime(args) + previous_sle = self.get_previous_sle_of_current_voucher(args) warehouse_dict.previous_sle = previous_sle for key in ("qty_after_transaction", "valuation_rate", "stock_value"): @@ -167,9 +183,35 @@ class update_entries_after(object): "stock_value_difference": 0.0 }) + def get_previous_sle_of_current_voucher(self, args): + """get stock ledger entries filtered by specific posting datetime conditions""" + + args['time_format'] = '%H:%i:%s' + if not args.get("posting_date"): + args["posting_date"] = "1900-01-01" + if not args.get("posting_time"): + args["posting_time"] = "00:00" + + sle = frappe.db.sql(""" + select *, timestamp(posting_date, posting_time) as "timestamp" + from `tabStock Ledger Entry` + where item_code = %(item_code)s + and warehouse = %(warehouse)s + and is_cancelled = 0 + and timestamp(posting_date, time_format(posting_time, %(time_format)s)) < timestamp(%(posting_date)s, time_format(%(posting_time)s, %(time_format)s)) + order by timestamp(posting_date, posting_time) desc, creation desc + limit 1""", args, as_dict=1) + + return sle[0] if sle else frappe._dict() + + def build(self): + from erpnext.controllers.stock_controller import check_if_future_sle_exists + if self.args.get("sle_id"): - self.process_sle_against_current_voucher() + self.process_sle_against_current_timestamp() + if not check_if_future_sle_exists(self.args): + self.update_bin() else: entries_to_fix = self.get_future_entries_to_fix() @@ -182,13 +224,13 @@ class update_entries_after(object): if sle.dependant_sle_voucher_detail_no: entries_to_fix = self.get_dependent_entries_to_fix(entries_to_fix, sle) + + self.update_bin() if self.exceptions: self.raise_exceptions() - self.update_bin() - - def process_sle_against_current_voucher(self): + def process_sle_against_current_timestamp(self): sl_entries = self.get_sle_against_current_voucher() for sle in sl_entries: self.process_sle(sle) @@ -204,8 +246,8 @@ class update_entries_after(object): where item_code = %(item_code)s and warehouse = %(warehouse)s - and voucher_type = %(voucher_type)s - and voucher_no = %(voucher_no)s + and timestamp(posting_date, time_format(posting_time, %(time_format)s)) = timestamp(%(posting_date)s, time_format(%(posting_time)s, %(time_format)s)) + order by creation ASC for update @@ -232,7 +274,6 @@ class update_entries_after(object): return entries_to_fix elif dependant_sle.item_code == self.item_code and dependant_sle.warehouse in self.data: return entries_to_fix - self.initialize_previous_data(dependant_sle) args = self.data[dependant_sle.warehouse].previous_sle \ @@ -639,7 +680,6 @@ class update_entries_after(object): # update bin for each warehouse for warehouse, data in iteritems(self.data): bin_doc = get_bin(self.item_code, warehouse) - bin_doc.update({ "valuation_rate": data.valuation_rate, "actual_qty": data.qty_after_transaction, @@ -765,6 +805,25 @@ def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, return valuation_rate +def update_qty_in_future_sle(args, allow_negative_stock=None): + frappe.db.sql(""" + update `tabStock Ledger Entry` + set qty_after_transaction = qty_after_transaction + {qty} + where + item_code = %(item_code)s + and warehouse = %(warehouse)s + and voucher_no != %(voucher_no)s + and is_cancelled = 0 + and (timestamp(posting_date, posting_time) > timestamp(%(posting_date)s, %(posting_time)s) + or ( + timestamp(posting_date, posting_time) = timestamp(%(posting_date)s, %(posting_time)s) + and creation > %(creation)s + ) + ) + """.format(qty=args.actual_qty), args) + + validate_negative_qty_in_future_sle(args, allow_negative_stock) + def validate_negative_qty_in_future_sle(args, allow_negative_stock=None): allow_negative_stock = allow_negative_stock \ or cint(frappe.db.get_single_value("Stock Settings", "allow_negative_stock")) @@ -793,7 +852,7 @@ def get_future_sle_with_negative_qty(args): and voucher_no != %(voucher_no)s and timestamp(posting_date, posting_time) >= timestamp(%(posting_date)s, %(posting_time)s) and is_cancelled = 0 - and qty_after_transaction + {0} < 0 + and qty_after_transaction < 0 order by timestamp(posting_date, posting_time) asc limit 1 - """.format(args.actual_qty), args, as_dict=1) + """, args, as_dict=1) \ No newline at end of file From 3508ed176beb59085b31faae6fd7c23e5e6b1f3e Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 16 Feb 2021 18:45:39 +0530 Subject: [PATCH 277/449] test(selling): add test for cancelling sales order Add failing test to reproduce bug in cancelling sales order with advance payments Related issue: ISS-20-21-09586 --- .../doctype/sales_order/test_sales_order.py | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py index cbfab8204f..52a0174798 100644 --- a/erpnext/selling/doctype/sales_order/test_sales_order.py +++ b/erpnext/selling/doctype/sales_order/test_sales_order.py @@ -17,6 +17,18 @@ from erpnext.selling.doctype.product_bundle.test_product_bundle import make_prod from erpnext.stock.doctype.item.test_item import make_item class TestSalesOrder(unittest.TestCase): + + @classmethod + def setUpClass(cls): + cls.unlink_setting = int(frappe.db.get_value("Accounts Settings", "Accounts Settings", + "unlink_advance_payment_on_cancelation_of_order")) + + @classmethod + def tearDownClass(cls) -> None: + # reset config to previous state + frappe.db.set_value("Accounts Settings", "Accounts Settings", + "unlink_advance_payment_on_cancelation_of_order", cls.unlink_setting) + def tearDown(self): frappe.set_user("Administrator") @@ -1049,6 +1061,38 @@ class TestSalesOrder(unittest.TestCase): self.assertRaises(frappe.LinkExistsError, so_doc.cancel) + def test_cancel_sales_order_after_cancel_payment_entry(self): + from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry + # make a sales order + so = make_sales_order() + + # disable unlinking of payment entry + frappe.db.set_value("Accounts Settings", "Accounts Settings", + "unlink_advance_payment_on_cancelation_of_order", 0) + + # create a payment entry against sales order + pe = get_payment_entry("Sales Order", so.name, bank_account="_Test Bank - _TC") + pe.reference_no = "1" + pe.reference_date = nowdate() + pe.paid_from_account_currency = so.currency + pe.paid_to_account_currency = so.currency + pe.source_exchange_rate = 1 + pe.target_exchange_rate = 1 + pe.paid_amount = so.grand_total + pe.save(ignore_permissions=True) + pe.submit() + + # Cancel payment entry + po_doc = frappe.get_doc("Payment Entry", pe.name) + po_doc.cancel() + + # Cancel sales order + try: + so_doc = frappe.get_doc('Sales Order', so.name) + so_doc.cancel() + except Exception: + self.fail("Can not cancel sales order with linked cancelled payment entry") + def test_request_for_raw_materials(self): item = make_item("_Test Finished Item", {"is_stock_item": 1, "maintain_stock": 1, @@ -1207,4 +1251,4 @@ def make_sales_order_workflow(): )) workflow.insert(ignore_permissions=True) - return workflow \ No newline at end of file + return workflow From d9c84dff0f8eff0c719a63e1a0cc01d3ea09fca2 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 16 Feb 2021 18:46:32 +0530 Subject: [PATCH 278/449] fix(selling): cancel sales order with cancelled PE Allow cancelling sales order with cancelled payment entry. Ignoring GL entries while cancelling the document is required to cancel it, reverse entries are created by accounts controller. Related issue: ISS-20-21-09586 --- erpnext/selling/doctype/sales_order/sales_order.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 1516dd6d95..e56129170c 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -180,6 +180,7 @@ class SalesOrder(SellingController): update_coupon_code_count(self.coupon_code,'used') def on_cancel(self): + self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry') super(SalesOrder, self).on_cancel() # Cannot cancel closed SO From 4cef0f59837d2161ac1c8309540e501b4b57a672 Mon Sep 17 00:00:00 2001 From: Jannat Patel <31363128+pateljannat@users.noreply.github.com> Date: Thu, 18 Feb 2021 15:52:29 +0530 Subject: [PATCH 279/449] fix: salary slip attribute error (#24455) Co-authored-by: Rucha Mahabal --- erpnext/payroll/doctype/salary_slip/salary_slip.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index 2d3bc57900..60aff02b38 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -1103,10 +1103,10 @@ class SalarySlip(TransactionBase): self.calculate_total_for_salary_slip_based_on_timesheet() else: self.total_deduction = 0.0 - if self.earnings: + if hasattr(self, "earnings"): for earning in self.earnings: self.gross_pay += flt(earning.amount, earning.precision("amount")) - if self.deductions: + if hasattr(self, "deductions"): for deduction in self.deductions: self.total_deduction += flt(deduction.amount, deduction.precision("amount")) self.net_pay = flt(self.gross_pay) - flt(self.total_deduction) - flt(self.total_loan_repayment) From b1997da4883dafdc54cfef6d6bfdabf98b894247 Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Thu, 11 Feb 2021 20:19:30 +0530 Subject: [PATCH 280/449] feat: capture Rate of stock UOM in purchase (#24315) * feat: capture Rate of stock UOM in purchase * fix: review changes * added server side code * added stock uom rate in sales transactions * fix: review changes * fix: resolving conflicts * adding patch * fix: removing patch --- .../purchase_invoice_item/purchase_invoice_item.json | 11 ++++++++++- .../sales_invoice_item/sales_invoice_item.json | 11 ++++++++++- .../purchase_order_item/purchase_order_item.json | 11 ++++++++++- erpnext/controllers/stock_controller.py | 6 ++++++ erpnext/public/js/controllers/buying.js | 1 - erpnext/public/js/controllers/transaction.js | 12 ++++++++++-- .../doctype/quotation_item/quotation_item.json | 11 ++++++++++- .../doctype/sales_order_item/sales_order_item.json | 12 ++++++++++-- .../delivery_note_item/delivery_note_item.json | 11 ++++++++++- .../purchase_receipt_item/purchase_receipt_item.json | 11 ++++++++++- 10 files changed, 86 insertions(+), 11 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json index 1f7853dbf7..07e75acb41 100644 --- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json +++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json @@ -40,6 +40,7 @@ "base_rate", "base_amount", "pricing_rules", + "stock_uom_rate", "is_free_item", "section_break_22", "net_rate", @@ -783,6 +784,14 @@ "print_hide": 1, "read_only": 1 }, + { + "depends_on": "eval: doc.uom != doc.stock_uom", + "fieldname": "stock_uom_rate", + "fieldtype": "Currency", + "label": "Rate of Stock UOM", + "options": "currency", + "read_only": 1 + }, { "fieldname": "sales_invoice_item", "fieldtype": "Data", @@ -795,7 +804,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2020-12-26 17:20:36.415791", + "modified": "2021-01-30 21:43:21.488258", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice Item", diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json index 7a98afff36..b403c7b237 100644 --- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json +++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json @@ -45,6 +45,7 @@ "base_rate", "base_amount", "pricing_rules", + "stock_uom_rate", "is_free_item", "section_break_21", "net_rate", @@ -811,12 +812,20 @@ "no_copy": 1, "print_hide": 1, "read_only": 1 + }, + { + "depends_on": "eval: doc.uom != doc.stock_uom", + "fieldname": "stock_uom_rate", + "fieldtype": "Currency", + "label": "Rate of Stock UOM", + "options": "currency", + "read_only": 1 } ], "idx": 1, "istable": 1, "links": [], - "modified": "2020-12-26 17:25:04.090630", + "modified": "2021-01-30 21:42:37.796771", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice Item", diff --git a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json index c691e9f9f8..75b2954ddd 100644 --- a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json +++ b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json @@ -40,6 +40,7 @@ "base_rate", "base_amount", "pricing_rules", + "stock_uom_rate", "is_free_item", "section_break_29", "net_rate", @@ -726,13 +727,21 @@ "fieldname": "more_info_section_break", "fieldtype": "Section Break", "label": "More Information" + }, + { + "depends_on": "eval: doc.uom != doc.stock_uom", + "fieldname": "stock_uom_rate", + "fieldtype": "Currency", + "label": "Rate of Stock UOM", + "options": "currency", + "read_only": 1 } ], "idx": 1, "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2020-12-07 11:59:47.670951", + "modified": "2021-01-30 21:44:41.816974", "modified_by": "Administrator", "module": "Buying", "name": "Purchase Order Item", diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 94735733b2..8c0a62c026 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -24,6 +24,7 @@ class StockController(AccountsController): self.validate_inspection() self.validate_serialized_batch() self.validate_customer_provided_item() + self.set_rate_of_stock_uom() self.validate_internal_transfer() self.validate_putaway_capacity() @@ -395,6 +396,11 @@ class StockController(AccountsController): if frappe.db.get_value('Item', d.item_code, 'is_customer_provided_item'): d.allow_zero_valuation_rate = 1 + def set_rate_of_stock_uom(self): + if self.doctype in ["Purchase Receipt", "Purchase Invoice", "Purchase Order", "Sales Invoice", "Sales Order", "Delivery Note", "Quotation"]: + for d in self.get("items"): + d.stock_uom_rate = d.rate / d.conversion_factor + def validate_internal_transfer(self): if self.doctype in ('Sales Invoice', 'Delivery Note', 'Purchase Invoice', 'Purchase Receipt') \ and self.is_internal_transfer(): diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index a2a723dd77..c96386611b 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -191,7 +191,6 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ item.rejected_qty = flt(item.received_qty - item.qty, precision("rejected_qty", item)); item.received_stock_qty = flt(item.conversion_factor, precision("conversion_factor", item)) * flt(item.received_qty); } - this._super(doc, cdt, cdn); }, diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 9627600a17..123d998838 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -40,7 +40,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ cur_frm.cscript.set_gross_profit(item); cur_frm.cscript.calculate_taxes_and_totals(); - + cur_frm.cscript.calculate_stock_uom_rate(frm, cdt, cdn); }); @@ -1121,6 +1121,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ } }); } + me.calculate_stock_uom_rate(doc, cdt, cdn); }, conversion_factor: function(doc, cdt, cdn, dont_fetch_price_list_rate) { @@ -1141,6 +1142,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ frappe.meta.has_field(doc.doctype, "price_list_currency")) { this.apply_price_list(item, true); } + this.calculate_stock_uom_rate(doc, cdt, cdn); } }, @@ -1161,9 +1163,15 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ qty: function(doc, cdt, cdn) { let item = frappe.get_doc(cdt, cdn); this.conversion_factor(doc, cdt, cdn, true); + this.calculate_stock_uom_rate(doc, cdt, cdn); this.apply_pricing_rule(item, true); }, + calculate_stock_uom_rate: function(doc, cdt, cdn) { + let item = frappe.get_doc(cdt, cdn); + item.stock_uom_rate = flt(item.rate)/flt(item.conversion_factor); + refresh_field("stock_uom_rate", item.name, item.parentfield); + }, service_stop_date: function(frm, cdt, cdn) { var child = locals[cdt][cdn]; @@ -1274,7 +1282,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ this.frm.set_currency_labels(["base_rate", "base_net_rate", "base_price_list_rate", "base_amount", "base_net_amount"], company_currency, "items"); - this.frm.set_currency_labels(["rate", "net_rate", "price_list_rate", "amount", "net_amount"], + this.frm.set_currency_labels(["rate", "net_rate", "price_list_rate", "amount", "net_amount", "stock_uom_rate"], this.frm.doc.currency, "items"); if(this.frm.fields_dict["operations"]) { diff --git a/erpnext/selling/doctype/quotation_item/quotation_item.json b/erpnext/selling/doctype/quotation_item/quotation_item.json index 59ae7b2323..a6785f709a 100644 --- a/erpnext/selling/doctype/quotation_item/quotation_item.json +++ b/erpnext/selling/doctype/quotation_item/quotation_item.json @@ -47,6 +47,7 @@ "base_amount", "base_net_amount", "pricing_rules", + "stock_uom_rate", "is_free_item", "section_break_43", "valuation_rate", @@ -634,12 +635,20 @@ "print_hide": 1, "read_only": 1, "report_hide": 1 + }, + { + "depends_on": "eval: doc.uom != doc.stock_uom", + "fieldname": "stock_uom_rate", + "fieldtype": "Currency", + "label": "Rate of Stock UOM", + "options": "currency", + "read_only": 1 } ], "idx": 1, "istable": 1, "links": [], - "modified": "2020-05-19 20:48:43.222229", + "modified": "2021-01-30 21:39:40.174551", "modified_by": "Administrator", "module": "Selling", "name": "Quotation Item", diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.json b/erpnext/selling/doctype/sales_order_item/sales_order_item.json index 159655b74b..37e47a9d41 100644 --- a/erpnext/selling/doctype/sales_order_item/sales_order_item.json +++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.json @@ -46,6 +46,7 @@ "base_rate", "base_amount", "pricing_rules", + "stock_uom_rate", "is_free_item", "section_break_24", "net_rate", @@ -214,7 +215,6 @@ "fieldtype": "Link", "label": "UOM", "options": "UOM", - "print_hide": 0, "reqd": 1 }, { @@ -780,12 +780,20 @@ "fieldname": "manufacturing_section_section", "fieldtype": "Section Break", "label": "Manufacturing Section" + }, + { + "depends_on": "eval: doc.uom != doc.stock_uom", + "fieldname": "stock_uom_rate", + "fieldtype": "Currency", + "label": "Rate of Stock UOM", + "options": "currency", + "read_only": 1 } ], "idx": 1, "istable": 1, "links": [], - "modified": "2020-012-07 20:54:32.309460", + "modified": "2021-01-30 21:35:07.617320", "modified_by": "Administrator", "module": "Selling", "name": "Sales Order Item", diff --git a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json index 9de088df0e..17996247c5 100644 --- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json +++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json @@ -47,6 +47,7 @@ "base_rate", "base_amount", "pricing_rules", + "stock_uom_rate", "is_free_item", "section_break_25", "net_rate", @@ -743,13 +744,21 @@ "no_copy": 1, "print_hide": 1, "read_only": 1 + }, + { + "depends_on": "eval: doc.uom != doc.stock_uom", + "fieldname": "stock_uom_rate", + "fieldtype": "Currency", + "label": "Rate of Stock UOM", + "options": "currency", + "read_only": 1 } ], "idx": 1, "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2020-12-26 17:31:27.029803", + "modified": "2021-01-30 21:42:03.767968", "modified_by": "Administrator", "module": "Stock", "name": "Delivery Note Item", diff --git a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json index e99119202e..8974ad9318 100644 --- a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json +++ b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json @@ -48,6 +48,7 @@ "base_rate", "base_amount", "pricing_rules", + "stock_uom_rate", "is_free_item", "section_break_29", "net_rate", @@ -874,6 +875,14 @@ "label": "Received Qty in Stock UOM", "print_hide": 1 }, + { + "depends_on": "eval: doc.uom != doc.stock_uom", + "fieldname": "stock_uom_rate", + "fieldtype": "Currency", + "label": "Rate of Stock UOM", + "options": "currency", + "read_only": 1 + }, { "fieldname": "delivery_note_item", "fieldtype": "Data", @@ -886,7 +895,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2020-12-26 16:50:56.479347", + "modified": "2021-01-30 21:44:06.918515", "modified_by": "Administrator", "module": "Stock", "name": "Purchase Receipt Item", From 3248da9089448063e45e2d17c7e332192803b16d Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 15 Feb 2021 14:16:00 +0530 Subject: [PATCH 281/449] fix(India): Add GST state code for Ladakh --- erpnext/patches.txt | 1 + .../patches/v12_0/add_state_code_for_ladakh.py | 16 ++++++++++++++++ erpnext/regional/india/__init__.py | 4 +++- erpnext/regional/india/gst_state_code_data.json | 5 +++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 erpnext/patches/v12_0/add_state_code_for_ladakh.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 25ebf67dc1..0003bb3b1a 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -751,3 +751,4 @@ erpnext.patches.v13_0.convert_qi_parameter_to_link_field erpnext.patches.v13_0.setup_patient_history_settings_for_standard_doctypes erpnext.patches.v13_0.add_naming_series_to_old_projects # 1-02-2021 erpnext.patches.v13_0.item_reposting_for_incorrect_sl_and_gl +erpnext.patches.v12_0.add_state_code_for_ladakh diff --git a/erpnext/patches/v12_0/add_state_code_for_ladakh.py b/erpnext/patches/v12_0/add_state_code_for_ladakh.py new file mode 100644 index 0000000000..d41101cc46 --- /dev/null +++ b/erpnext/patches/v12_0/add_state_code_for_ladakh.py @@ -0,0 +1,16 @@ +import frappe +from erpnext.regional.india import states + +def execute(): + + company = frappe.get_all('Company', filters = {'country': 'India'}) + if not company: + return + + custom_fields = ['Address-gst_state', 'Tax Category-gst_state'] + + # Update options in gst_state custom fields + for field in custom_fields: + gst_state_field = frappe.get_doc('Custom Field', field) + gst_state_field.options = '\n'.join(states) + gst_state_field.save() diff --git a/erpnext/regional/india/__init__.py b/erpnext/regional/india/__init__.py index d6221a80aa..378b735e07 100644 --- a/erpnext/regional/india/__init__.py +++ b/erpnext/regional/india/__init__.py @@ -20,6 +20,7 @@ states = [ 'Jharkhand', 'Karnataka', 'Kerala', + 'Ladakh', 'Lakshadweep Islands', 'Madhya Pradesh', 'Maharashtra', @@ -59,6 +60,7 @@ state_numbers = { "Jharkhand": "20", "Karnataka": "29", "Kerala": "32", + "Ladakh": "38", "Lakshadweep Islands": "31", "Madhya Pradesh": "23", "Maharashtra": "27", @@ -80,4 +82,4 @@ state_numbers = { "West Bengal": "19", } -number_state_mapping = {v: k for k, v in iteritems(state_numbers)} \ No newline at end of file +number_state_mapping = {v: k for k, v in iteritems(state_numbers)} diff --git a/erpnext/regional/india/gst_state_code_data.json b/erpnext/regional/india/gst_state_code_data.json index ff88e0f9d6..8481c27972 100644 --- a/erpnext/regional/india/gst_state_code_data.json +++ b/erpnext/regional/india/gst_state_code_data.json @@ -168,5 +168,10 @@ "state_number": "37", "state_code": "AD", "state_name": "Andhra Pradesh (New)" + }, + { + "state_number": "38", + "state_code": "LA", + "state_name": "Ladakh" } ] From d46b23699c145de64c8998146d2152ad12314dfa Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 23 Feb 2021 16:38:52 +0530 Subject: [PATCH 282/449] fix: optimize reposting of gle and sle (#24702) * fix(india): escape for special characters in JSON (#24695) JSON does not accept special whitespace characters like tab, carriage return, line feed Ref: https://www.ecma-international.org/wp-content/uploads/ECMA-404_2nd_edition_december_2017.pdf Related issue: ISS-20-21-09811 * fix: Accounting Dimension creation background job timeout * fix(regional): vehicle no is mandatory for ewaybill generation (#24679) * fix: vehicle no required for e-invoice * fix: ewaybill generation dialog condition * fix: excluding unidentified accounts from gstr-1 * fix: optimize reposting of sle and gle (#24694) * fix: optimize update_gl_entries_after method * fix: Optimized reposting patch * fix: accounting dimensions * added reload_doc in patch * Update item_reposting_for_incorrect_sl_and_gl.py Co-authored-by: Rohit Waghchaure * fix: Replaced spaces with tabs * fix: merge conflict * fix: test cases Co-authored-by: Ankush Menat Co-authored-by: Deepesh Garg Co-authored-by: Saqib Co-authored-by: pateljannat Co-authored-by: Rohit Waghchaure --- .../accounting_dimension.py | 19 ++++--- erpnext/accounts/doctype/gl_entry/gl_entry.py | 50 ++++++++----------- .../doctype/pos_invoice/pos_invoice.js | 7 +++ .../doctype/pos_invoice/pos_invoice.py | 8 ++- .../pos_invoice_merge_log.py | 3 ++ .../doctype/pos_profile/pos_profile.json | 34 +++++++++++-- .../doctype/sales_invoice/sales_invoice.py | 4 +- erpnext/accounts/general_ledger.py | 14 +++--- erpnext/accounts/utils.py | 3 +- erpnext/controllers/accounts_controller.py | 1 + erpnext/controllers/selling_controller.py | 10 +++- erpnext/controllers/stock_controller.py | 14 ++++-- erpnext/controllers/taxes_and_totals.py | 2 +- .../mpesa_settings/test_mpesa_settings.py | 3 ++ erpnext/hr/doctype/employee/test_employee.py | 3 +- erpnext/patches.txt | 3 +- .../item_reposting_for_incorrect_sl_and_gl.py | 31 +++++++++--- .../v13_0/replace_pos_payment_mode_table.py | 4 +- .../v13_0/update_vehicle_no_reqd_condition.py | 9 ++++ .../payroll_entry/test_payroll_entry.py | 34 ------------- erpnext/regional/india/e_invoice/einvoice.js | 1 - erpnext/regional/india/e_invoice/utils.py | 2 +- erpnext/regional/report/gstr_1/gstr_1.py | 4 +- .../regional/united_arab_emirates/setup.py | 2 + .../page/point_of_sale/pos_controller.js | 38 ++++++++------ .../page/point_of_sale/pos_item_cart.js | 29 ++++++++--- .../page/point_of_sale/pos_item_details.js | 44 +++++++++++----- .../point_of_sale/pos_past_order_summary.js | 10 +++- erpnext/stock/doctype/item/item.py | 11 ++-- erpnext/stock/get_item_details.py | 2 +- erpnext/stock/stock_ledger.py | 13 ++--- 31 files changed, 257 insertions(+), 155 deletions(-) create mode 100644 erpnext/patches/v13_0/update_vehicle_no_reqd_condition.py diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py index 52e9ff8b76..239588f897 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py @@ -33,11 +33,11 @@ class AccountingDimension(Document): if frappe.flags.in_test: make_dimension_in_accounting_doctypes(doc=self) else: - frappe.enqueue(make_dimension_in_accounting_doctypes, doc=self) + frappe.enqueue(make_dimension_in_accounting_doctypes, doc=self, queue='long') def on_trash(self): if frappe.flags.in_test: - delete_accounting_dimension(doc=self) + delete_accounting_dimension(doc=self, queue='long') else: frappe.enqueue(delete_accounting_dimension, doc=self) @@ -48,6 +48,9 @@ class AccountingDimension(Document): if not self.fieldname: self.fieldname = scrub(self.label) + def on_update(self): + frappe.flags.accounting_dimensions = None + def make_dimension_in_accounting_doctypes(doc): doclist = get_doctypes_with_dimensions() doc_count = len(get_accounting_dimensions()) @@ -165,9 +168,9 @@ def toggle_disabling(doc): frappe.clear_cache(doctype=doctype) def get_doctypes_with_dimensions(): - doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "Asset", + doclist = ["GL Entry", "Sales Invoice", "POS Invoice", "Purchase Invoice", "Payment Entry", "Asset", "Expense Claim", "Expense Claim Detail", "Expense Taxes and Charges", "Stock Entry", "Budget", "Payroll Entry", "Delivery Note", - "Sales Invoice Item", "Purchase Invoice Item", "Purchase Order Item", "Journal Entry Account", "Material Request Item", "Delivery Note Item", + "Sales Invoice Item", "POS Invoice Item", "Purchase Invoice Item", "Purchase Order Item", "Journal Entry Account", "Material Request Item", "Delivery Note Item", "Purchase Receipt Item", "Stock Entry Detail", "Payment Entry Deduction", "Sales Taxes and Charges", "Purchase Taxes and Charges", "Shipping Rule", "Landed Cost Item", "Asset Value Adjustment", "Loyalty Program", "Fee Schedule", "Fee Structure", "Stock Reconciliation", "Travel Request", "Fees", "POS Profile", "Opening Invoice Creation Tool", "Opening Invoice Creation Tool Item", "Subscription", @@ -176,12 +179,14 @@ def get_doctypes_with_dimensions(): return doclist def get_accounting_dimensions(as_list=True): - accounting_dimensions = frappe.get_all("Accounting Dimension", fields=["label", "fieldname", "disabled", "document_type"]) + if frappe.flags.accounting_dimensions is None: + frappe.flags.accounting_dimensions = frappe.get_all("Accounting Dimension", + fields=["label", "fieldname", "disabled", "document_type"]) if as_list: - return [d.fieldname for d in accounting_dimensions] + return [d.fieldname for d in frappe.flags.accounting_dimensions] else: - return accounting_dimensions + return frappe.flags.accounting_dimensions def get_checks_for_pl_and_bs_accounts(): dimensions = frappe.db.sql("""SELECT p.label, p.disabled, p.fieldname, c.default_dimension, c.company, c.mandatory_for_pl, c.mandatory_for_bs diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py index b0a864f76c..ce76d0a39c 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py @@ -27,30 +27,30 @@ class GLEntry(Document): def validate(self): self.flags.ignore_submit_comment = True - self.check_mandatory() self.validate_and_set_fiscal_year() self.pl_must_have_cost_center() - self.validate_cost_center() if not self.flags.from_repost: + self.check_mandatory() + self.validate_cost_center() self.check_pl_account() self.validate_party() self.validate_currency() - def on_update_with_args(self, adv_adj, update_outstanding = 'Yes', from_repost=False): - if not from_repost: + def on_update(self): + adv_adj = self.flags.adv_adj + if not self.flags.from_repost: self.validate_account_details(adv_adj) self.validate_dimensions_for_pl_and_bs() self.validate_allowed_dimensions() + validate_balance_type(self.account, adv_adj) + validate_frozen_account(self.account, adv_adj) - validate_frozen_account(self.account, adv_adj) - validate_balance_type(self.account, adv_adj) - - # Update outstanding amt on against voucher - if self.against_voucher_type in ['Journal Entry', 'Sales Invoice', 'Purchase Invoice', 'Fees'] \ - and self.against_voucher and update_outstanding == 'Yes' and not from_repost: - update_outstanding_amt(self.account, self.party_type, self.party, self.against_voucher_type, - self.against_voucher) + # Update outstanding amt on against voucher + if (self.against_voucher_type in ['Journal Entry', 'Sales Invoice', 'Purchase Invoice', 'Fees'] + and self.against_voucher and self.flags.update_outstanding == 'Yes'): + update_outstanding_amt(self.account, self.party_type, self.party, self.against_voucher_type, + self.against_voucher) def check_mandatory(self): mandatory = ['account','voucher_type','voucher_no','company'] @@ -58,7 +58,7 @@ class GLEntry(Document): if not self.get(k): frappe.throw(_("{0} is required").format(_(self.meta.get_label(k)))) - account_type = frappe.db.get_value("Account", self.account, "account_type") + account_type = frappe.get_cached_value("Account", self.account, "account_type") if not (self.party_type and self.party): if account_type == "Receivable": frappe.throw(_("{0} {1}: Customer is required against Receivable account {2}") @@ -73,7 +73,7 @@ class GLEntry(Document): .format(self.voucher_type, self.voucher_no, self.account)) def pl_must_have_cost_center(self): - if frappe.db.get_value("Account", self.account, "report_type") == "Profit and Loss": + if frappe.get_cached_value("Account", self.account, "report_type") == "Profit and Loss": if not self.cost_center and self.voucher_type != 'Period Closing Voucher': frappe.throw(_("{0} {1}: Cost Center is required for 'Profit and Loss' account {2}. Please set up a default Cost Center for the Company.") .format(self.voucher_type, self.voucher_no, self.account)) @@ -140,25 +140,16 @@ class GLEntry(Document): .format(self.voucher_type, self.voucher_no, self.account, self.company)) def validate_cost_center(self): - if not hasattr(self, "cost_center_company"): - self.cost_center_company = {} + if not self.cost_center: return - def _get_cost_center_company(): - if not self.cost_center_company.get(self.cost_center): - self.cost_center_company[self.cost_center] = frappe.db.get_value( - "Cost Center", self.cost_center, "company") + is_group, company = frappe.get_cached_value('Cost Center', + self.cost_center, ['is_group', 'company']) - return self.cost_center_company[self.cost_center] - - def _check_is_group(): - return cint(frappe.get_cached_value('Cost Center', self.cost_center, 'is_group')) - - if self.cost_center and _get_cost_center_company() != self.company: + if company != self.company: frappe.throw(_("{0} {1}: Cost Center {2} does not belong to Company {3}") .format(self.voucher_type, self.voucher_no, self.cost_center, self.company)) - if not self.flags.from_repost and not self.voucher_type == 'Period Closing Voucher' \ - and self.cost_center and _check_is_group(): + if (self.voucher_type != 'Period Closing Voucher' and is_group): frappe.throw(_("""{0} {1}: Cost Center {2} is a group cost center and group cost centers cannot be used in transactions""").format( self.voucher_type, self.voucher_no, frappe.bold(self.cost_center))) @@ -184,7 +175,6 @@ class GLEntry(Document): if not self.fiscal_year: self.fiscal_year = get_fiscal_year(self.posting_date, company=self.company)[0] - def validate_balance_type(account, adv_adj=False): if not adv_adj and account: balance_must_be = frappe.db.get_value("Account", account, "balance_must_be") @@ -250,7 +240,7 @@ def update_outstanding_amt(account, party_type, party, against_voucher_type, aga def validate_frozen_account(account, adv_adj=None): - frozen_account = frappe.db.get_value("Account", account, "freeze_account") + frozen_account = frappe.get_cached_value("Account", account, "freeze_account") if frozen_account == 'Yes' and not adv_adj: frozen_accounts_modifier = frappe.db.get_value( 'Accounts Settings', None, 'frozen_accounts_modifier') diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js index 465f0d31c4..493bd44802 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js @@ -2,6 +2,7 @@ // For license information, please see license.txt {% include 'erpnext/selling/sales_common.js' %}; +frappe.provide("erpnext.accounts"); erpnext.selling.POSInvoiceController = erpnext.selling.SellingController.extend({ setup(doc) { @@ -9,6 +10,10 @@ erpnext.selling.POSInvoiceController = erpnext.selling.SellingController.extend( this._super(doc); }, + company: function() { + erpnext.accounts.dimensions.update_dimension(this.frm, this.frm.doctype); + }, + onload(doc) { this._super(); this.frm.ignore_doctypes_on_cancel_all = ['POS Invoice Merge Log']; @@ -16,6 +21,8 @@ erpnext.selling.POSInvoiceController = erpnext.selling.SellingController.extend( this.frm.script_manager.trigger("is_pos"); this.frm.refresh_fields(); } + + erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype); }, refresh(doc) { diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index 9d8f848b02..0c1406c1ce 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -93,7 +93,7 @@ class POSInvoice(SalesInvoice): mode_of_payment=pay.mode_of_payment, status="Paid"), fieldname="grand_total") - if pay.amount != paid_amt: + if paid_amt and pay.amount != paid_amt: return frappe.throw(_("Payment related to {0} is not completed").format(pay.mode_of_payment)) def validate_stock_availablility(self): @@ -311,7 +311,9 @@ class POSInvoice(SalesInvoice): self.set(fieldname, profile.get(fieldname)) if self.customer: - customer_price_list, customer_group = frappe.db.get_value("Customer", self.customer, ['default_price_list', 'customer_group']) + customer_price_list, customer_group, customer_currency = frappe.db.get_value( + "Customer", self.customer, ['default_price_list', 'customer_group', 'default_currency'] + ) customer_group_price_list = frappe.db.get_value("Customer Group", customer_group, 'default_price_list') selling_price_list = customer_price_list or customer_group_price_list or profile.get('selling_price_list') if customer_currency != profile.get('currency'): @@ -322,6 +324,8 @@ class POSInvoice(SalesInvoice): if selling_price_list: self.set('selling_price_list', selling_price_list) + if customer_currency != profile.get('currency'): + self.set('currency', customer_currency) # set pos values in items for item in self.get("items"): diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py index 5496804474..58409cd3c6 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py @@ -120,6 +120,7 @@ class POSInvoiceMergeLog(Document): i.qty = i.qty + item.qty if not found: item.rate = item.net_rate + item.price_list_rate = 0 si_item = map_child_doc(item, invoice, {"doctype": "Sales Invoice Item"}) items.append(si_item) @@ -157,6 +158,8 @@ class POSInvoiceMergeLog(Document): invoice.set('taxes', taxes) invoice.additional_discount_percentage = 0 invoice.discount_amount = 0.0 + invoice.taxes_and_charges = None + invoice.ignore_pricing_rule = 1 return invoice diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.json b/erpnext/accounts/doctype/pos_profile/pos_profile.json index 750ed82d15..4b69f6e2ef 100644 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.json +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.json @@ -12,8 +12,6 @@ "company", "country", "column_break_9", - "update_stock", - "ignore_pricing_rule", "warehouse", "campaign", "company_address", @@ -25,8 +23,14 @@ "hide_images", "hide_unavailable_items", "auto_add_item_to_cart", - "item_groups", "column_break_16", + "update_stock", + "ignore_pricing_rule", + "allow_rate_change", + "allow_discount_change", + "section_break_23", + "item_groups", + "column_break_25", "customer_groups", "section_break_16", "print_format", @@ -309,6 +313,7 @@ "default": "1", "fieldname": "update_stock", "fieldtype": "Check", + "hidden": 1, "label": "Update Stock", "read_only": 1 }, @@ -329,13 +334,34 @@ "fieldname": "auto_add_item_to_cart", "fieldtype": "Check", "label": "Automatically Add Filtered Item To Cart" + }, + { + "default": "0", + "fieldname": "allow_rate_change", + "fieldtype": "Check", + "label": "Allow User to Edit Rate" + }, + { + "default": "0", + "fieldname": "allow_discount_change", + "fieldtype": "Check", + "label": "Allow User to Edit Discount" + }, + { + "collapsible": 1, + "fieldname": "section_break_23", + "fieldtype": "Section Break" + }, + { + "fieldname": "column_break_25", + "fieldtype": "Column Break" } ], "icon": "icon-cog", "idx": 1, "index_web_pages_for_search": 1, "links": [], - "modified": "2020-12-20 13:59:28.877572", + "modified": "2021-01-06 14:42:41.713864", "modified_by": "Administrator", "module": "Accounts", "name": "POS Profile", diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index c39bd3954c..903a2ef5f7 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -456,7 +456,9 @@ class SalesInvoice(SellingController): if not for_validate and not self.customer: self.customer = pos.customer - self.ignore_pricing_rule = pos.ignore_pricing_rule + if not for_validate: + self.ignore_pricing_rule = pos.ignore_pricing_rule + if pos.get('account_for_change_amount'): self.account_for_change_amount = pos.get('account_for_change_amount') diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 287c79f13f..b42c0c61d9 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -44,9 +44,9 @@ def validate_accounting_period(gl_map): frappe.throw(_("You cannot create or cancel any accounting entries with in the closed Accounting Period {0}") .format(frappe.bold(accounting_periods[0].name)), ClosedAccountingPeriod) -def process_gl_map(gl_map, merge_entries=True): +def process_gl_map(gl_map, merge_entries=True, precision=None): if merge_entries: - gl_map = merge_similar_entries(gl_map) + gl_map = merge_similar_entries(gl_map, precision) for entry in gl_map: # toggle debit, credit if negative entry if flt(entry.debit) < 0: @@ -69,7 +69,7 @@ def process_gl_map(gl_map, merge_entries=True): return gl_map -def merge_similar_entries(gl_map): +def merge_similar_entries(gl_map, precision=None): merged_gl_map = [] accounting_dimensions = get_accounting_dimensions() for entry in gl_map: @@ -88,7 +88,9 @@ def merge_similar_entries(gl_map): company = gl_map[0].company if gl_map else erpnext.get_default_company() company_currency = erpnext.get_company_currency(company) - precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"), company_currency) + + if not precision: + precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"), company_currency) # filter zero debit and credit entries merged_gl_map = filter(lambda x: flt(x.debit, precision)!=0 or flt(x.credit, precision)!=0, merged_gl_map) @@ -132,8 +134,8 @@ def make_entry(args, adv_adj, update_outstanding, from_repost=False): gle.update(args) gle.flags.ignore_permissions = 1 gle.flags.from_repost = from_repost - gle.insert() - gle.run_method("on_update_with_args", adv_adj, update_outstanding, from_repost) + gle.flags.adv_adj = adv_adj + gle.flags.update_outstanding = update_outstanding or 'Yes' gle.submit() if not from_repost: diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 60d1e20fea..5eb2aab393 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -902,10 +902,9 @@ def repost_gle_for_stock_vouchers(stock_vouchers, posting_date, company=None, wa warehouse_account = get_warehouse_account_map(company) gle = get_voucherwise_gl_entries(stock_vouchers, posting_date) - for voucher_type, voucher_no in stock_vouchers: existing_gle = gle.get((voucher_type, voucher_no), []) - voucher_obj = frappe.get_doc(voucher_type, voucher_no) + voucher_obj = frappe.get_cached_doc(voucher_type, voucher_no) expected_gle = voucher_obj.get_gl_entries(warehouse_account) if expected_gle: if not existing_gle or not compare_existing_and_expected_gle(existing_gle, expected_gle): diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index a838259862..e6b14c2e40 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -302,6 +302,7 @@ class AccountsController(TransactionBase): args["doctype"] = self.doctype args["name"] = self.name args["child_docname"] = item.name + args["ignore_pricing_rule"] = self.ignore_pricing_rule if hasattr(self, 'ignore_pricing_rule') else 0 if not args.get("transaction_date"): args["transaction_date"] = args.get("posting_date") diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index aa7b27adf4..3e82d46c2d 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -473,13 +473,19 @@ class SellingController(StockController): non_stock_items = [d.item_code, d.description] if frappe.db.get_value("Item", d.item_code, "is_stock_item") == 1: + duplicate_items_msg = _("Item {0} entered multiple times.").format(frappe.bold(d.item_code)) + duplicate_items_msg += "

" + duplicate_items_msg += _("Please enable {} in {} to allow same item in multiple rows").format( + frappe.bold("Allow Item to Be Added Multiple Times in a Transaction"), + get_link_to_form("Selling Settings", "Selling Settings") + ) if stock_items in check_list: - frappe.throw(_("Note: Item {0} entered multiple times").format(d.item_code)) + frappe.throw(duplicate_items_msg) else: check_list.append(stock_items) else: if non_stock_items in chk_dupl_itm: - frappe.throw(_("Note: Item {0} entered multiple times").format(d.item_code)) + frappe.throw(duplicate_items_msg) else: chk_dupl_itm.append(non_stock_items) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 8c0a62c026..cb44b73caf 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -74,7 +74,7 @@ class StockController(AccountsController): gl_list = [] warehouse_with_no_account = [] - precision = frappe.get_precision("GL Entry", "debit_in_account_currency") + precision = self.get_debit_field_precision() for item_row in voucher_details: sle_list = sle_map.get(item_row.name) @@ -131,7 +131,13 @@ class StockController(AccountsController): if frappe.db.get_value("Warehouse", wh, "company"): frappe.throw(_("Warehouse {0} is not linked to any account, please mention the account in the warehouse record or set default inventory account in company {1}.").format(wh, self.company)) - return process_gl_map(gl_list) + return process_gl_map(gl_list, precision=precision) + + def get_debit_field_precision(self): + if not frappe.flags.debit_field_precision: + frappe.flags.debit_field_precision = frappe.get_precision("GL Entry", "debit_in_account_currency") + + return frappe.flags.debit_field_precision def update_stock_ledger_entries(self, sle): sle.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, @@ -244,7 +250,7 @@ class StockController(AccountsController): .format(item.idx, frappe.bold(item.item_code), msg), title=_("Expense Account Missing")) else: - is_expense_account = frappe.db.get_value("Account", + is_expense_account = frappe.get_cached_value("Account", item.get("expense_account"), "report_type")=="Profit and Loss" if self.doctype not in ("Purchase Receipt", "Purchase Invoice", "Stock Reconciliation", "Stock Entry") and not is_expense_account: frappe.throw(_("Expense / Difference account ({0}) must be a 'Profit or Loss' account") @@ -492,7 +498,7 @@ class StockController(AccountsController): elif not is_reposting_pending(): check_if_stock_and_account_balance_synced(self.posting_date, self.company, self.doctype, self.name) - + def is_reposting_pending(): return frappe.db.exists("Repost Item Valuation", {'docstatus': 1, 'status': ['in', ['Queued','In Progress']]}) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 1f50e9c14d..6c7eb92221 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -107,7 +107,7 @@ class calculate_taxes_and_totals(object): elif item.discount_amount and item.pricing_rules: item.rate = item.price_list_rate - item.discount_amount - if item.doctype in ['Quotation Item', 'Sales Order Item', 'Delivery Note Item', 'Sales Invoice Item']: + if item.doctype in ['Quotation Item', 'Sales Order Item', 'Delivery Note Item', 'Sales Invoice Item', 'POS Invoice Item']: item.rate_with_margin, item.base_rate_with_margin = self.calculate_margin(item) if flt(item.rate_with_margin) > 0: item.rate = flt(item.rate_with_margin * (1.0 - (item.discount_percentage / 100.0)), item.precision("rate")) diff --git a/erpnext/erpnext_integrations/doctype/mpesa_settings/test_mpesa_settings.py b/erpnext/erpnext_integrations/doctype/mpesa_settings/test_mpesa_settings.py index 18d2732313..08b2bc2fa8 100644 --- a/erpnext/erpnext_integrations/doctype/mpesa_settings/test_mpesa_settings.py +++ b/erpnext/erpnext_integrations/doctype/mpesa_settings/test_mpesa_settings.py @@ -50,6 +50,7 @@ class TestMpesaSettings(unittest.TestCase): create_mpesa_settings(payment_gateway_name="Payment") mpesa_account = frappe.db.get_value("Payment Gateway Account", {"payment_gateway": 'Mpesa-Payment'}, "payment_account") frappe.db.set_value("Account", mpesa_account, "account_currency", "KES") + frappe.db.set_value("Customer", "_Test Customer", "default_currency", "KES") pos_invoice = create_pos_invoice(do_not_submit=1) pos_invoice.append("payments", {'mode_of_payment': 'Mpesa-Payment', 'account': mpesa_account, 'amount': 500}) @@ -195,6 +196,8 @@ class TestMpesaSettings(unittest.TestCase): pr.delete() pos_invoice.delete() + frappe.db.set_value("Customer", "_Test Customer", "default_currency", "") + def create_mpesa_settings(payment_gateway_name="Express"): if frappe.db.exists("Mpesa Settings", payment_gateway_name): return frappe.get_doc("Mpesa Settings", payment_gateway_name) diff --git a/erpnext/hr/doctype/employee/test_employee.py b/erpnext/hr/doctype/employee/test_employee.py index c0e614ac08..b88daaa34f 100644 --- a/erpnext/hr/doctype/employee/test_employee.py +++ b/erpnext/hr/doctype/employee/test_employee.py @@ -21,8 +21,7 @@ class TestEmployee(unittest.TestCase): from erpnext.hr.doctype.employee.employee import get_employees_who_are_born_today, send_birthday_reminders - employees_born_today = get_employees_who_are_born_today() - self.assertTrue(employees_born_today.get("_Test Company")) + self.assertTrue(employee.name in [e.name for e in get_employees_who_are_born_today()]) frappe.db.sql("delete from `tabEmail Queue`") diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 0003bb3b1a..80e2f1c01a 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -677,7 +677,7 @@ erpnext.patches.v13_0.move_tax_slabs_from_payroll_period_to_income_tax_slab #123 erpnext.patches.v12_0.fix_quotation_expired_status erpnext.patches.v12_0.update_appointment_reminder_scheduler_entry erpnext.patches.v12_0.rename_pos_closing_doctype -erpnext.patches.v13_0.replace_pos_payment_mode_table +erpnext.patches.v13_0.replace_pos_payment_mode_table #2020-12-29 erpnext.patches.v12_0.remove_duplicate_leave_ledger_entries #2020-05-22 erpnext.patches.v13_0.patch_to_fix_reverse_linking_in_additional_salary_encashment_and_incentive execute:frappe.reload_doc("HR", "doctype", "Employee Advance") @@ -752,3 +752,4 @@ erpnext.patches.v13_0.setup_patient_history_settings_for_standard_doctypes erpnext.patches.v13_0.add_naming_series_to_old_projects # 1-02-2021 erpnext.patches.v13_0.item_reposting_for_incorrect_sl_and_gl erpnext.patches.v12_0.add_state_code_for_ladakh +erpnext.patches.v13_0.update_vehicle_no_reqd_condition diff --git a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py index f60e0d3036..06f7f989bb 100644 --- a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py +++ b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py @@ -4,11 +4,26 @@ from erpnext.stock.stock_ledger import update_entries_after from erpnext.accounts.utils import update_gl_entries_after def execute(): - data = frappe.db.sql(''' SELECT name, item_code, warehouse, voucher_type, voucher_no, posting_date, posting_time - from `tabStock Ledger Entry` where creation > '2020-12-26 12:58:55.903836' and is_cancelled = 0 - order by timestamp(posting_date, posting_time) asc, creation asc''', as_dict=1) + frappe.reload_doc('stock', 'doctype', 'repost_item_valuation') - for index, d in enumerate(data): + reposting_project_deployed_on = frappe.db.get_value("DocType", "Repost Item Valuation", "creation") + + data = frappe.db.sql(''' + SELECT + name, item_code, warehouse, voucher_type, voucher_no, posting_date, posting_time + FROM + `tabStock Ledger Entry` + WHERE + creation > %s + and is_cancelled = 0 + ORDER BY timestamp(posting_date, posting_time) asc, creation asc + ''', reposting_project_deployed_on, as_dict=1) + + frappe.db.auto_commit_on_many_writes = 1 + print("Reposting Stock Ledger Entries...") + total_sle = len(data) + i = 0 + for d in data: update_entries_after({ "item_code": d.item_code, "warehouse": d.warehouse, @@ -19,9 +34,13 @@ def execute(): "sle_id": d.name }, allow_negative_stock=True) - frappe.db.auto_commit_on_many_writes = 1 + i += 1 + if i%100 == 0: + print(i, "/", total_sle) + + print("Reposting General Ledger Entries...") for row in frappe.get_all('Company', filters= {'enable_perpetual_inventory': 1}): update_gl_entries_after('2020-12-25', '01:58:55', company=row.name) - frappe.db.auto_commit_on_many_writes = 0 \ No newline at end of file + frappe.db.auto_commit_on_many_writes = 0 diff --git a/erpnext/patches/v13_0/replace_pos_payment_mode_table.py b/erpnext/patches/v13_0/replace_pos_payment_mode_table.py index 1ca211bf1b..7cb264830a 100644 --- a/erpnext/patches/v13_0/replace_pos_payment_mode_table.py +++ b/erpnext/patches/v13_0/replace_pos_payment_mode_table.py @@ -6,12 +6,10 @@ from __future__ import unicode_literals import frappe def execute(): - frappe.reload_doc("accounts", "doctype", "POS Payment Method") + frappe.reload_doc("accounts", "doctype", "pos_payment_method") pos_profiles = frappe.get_all("POS Profile") for pos_profile in pos_profiles: - if not pos_profile.get("payments"): return - payments = frappe.db.sql(""" select idx, parentfield, parenttype, parent, mode_of_payment, `default` from `tabSales Invoice Payment` where parent=%s """, pos_profile.name, as_dict=1) diff --git a/erpnext/patches/v13_0/update_vehicle_no_reqd_condition.py b/erpnext/patches/v13_0/update_vehicle_no_reqd_condition.py new file mode 100644 index 0000000000..c26cddbe4e --- /dev/null +++ b/erpnext/patches/v13_0/update_vehicle_no_reqd_condition.py @@ -0,0 +1,9 @@ +import frappe + +def execute(): + company = frappe.get_all('Company', filters = {'country': 'India'}) + if not company: + return + + if frappe.db.exists('Custom Field', { 'fieldname': 'vehicle_no' }): + frappe.db.set_value('Custom Field', { 'fieldname': 'vehicle_no' }, 'mandatory_depends_on', '') diff --git a/erpnext/payroll/doctype/payroll_entry/test_payroll_entry.py b/erpnext/payroll/doctype/payroll_entry/test_payroll_entry.py index e098ec79b0..9e68df99eb 100644 --- a/erpnext/payroll/doctype/payroll_entry/test_payroll_entry.py +++ b/erpnext/payroll/doctype/payroll_entry/test_payroll_entry.py @@ -41,40 +41,6 @@ class TestPayrollEntry(unittest.TestCase): make_payroll_entry(start_date=dates.start_date, end_date=dates.end_date, payable_account=company_doc.default_payroll_payable_account, currency=company_doc.default_currency) - def test_multi_currency_payroll_entry(self): # pylint: disable=no-self-use - company = erpnext.get_default_company() - employee = make_employee("test_muti_currency_employee@payroll.com", company=company) - for data in frappe.get_all('Salary Component', fields = ["name"]): - if not frappe.db.get_value('Salary Component Account', - {'parent': data.name, 'company': company}, 'name'): - get_salary_component_account(data.name) - - company_doc = frappe.get_doc('Company', company) - salary_structure = make_salary_structure("_Test Multi Currency Salary Structure", "Monthly", company=company, currency='USD') - create_salary_structure_assignment(employee, salary_structure.name, company=company) - frappe.db.sql("""delete from `tabSalary Slip` where employee=%s""",(frappe.db.get_value("Employee", {"user_id": "test_muti_currency_employee@payroll.com"}))) - salary_slip = get_salary_slip("test_muti_currency_employee@payroll.com", "Monthly", "_Test Multi Currency Salary Structure") - dates = get_start_end_dates('Monthly', nowdate()) - payroll_entry = make_payroll_entry(start_date=dates.start_date, end_date=dates.end_date, - payable_account=company_doc.default_payroll_payable_account, currency='USD', exchange_rate=70) - payroll_entry.make_payment_entry() - - salary_slip.load_from_db() - - payroll_je = salary_slip.journal_entry - payroll_je_doc = frappe.get_doc('Journal Entry', payroll_je) - - self.assertEqual(salary_slip.base_gross_pay, payroll_je_doc.total_debit) - self.assertEqual(salary_slip.base_gross_pay, payroll_je_doc.total_credit) - - payment_entry = frappe.db.sql(''' - Select ifnull(sum(je.total_debit),0) as total_debit, ifnull(sum(je.total_credit),0) as total_credit from `tabJournal Entry` je, `tabJournal Entry Account` jea - Where je.name = jea.parent - And jea.reference_name = %s - ''', (payroll_entry.name), as_dict=1) - - self.assertEqual(salary_slip.base_net_pay, payment_entry[0].total_debit) - self.assertEqual(salary_slip.base_net_pay, payment_entry[0].total_credit) def test_payroll_entry_with_employee_cost_center(self): # pylint: disable=no-self-use for data in frappe.get_all('Salary Component', fields = ["name"]): diff --git a/erpnext/regional/india/e_invoice/einvoice.js b/erpnext/regional/india/e_invoice/einvoice.js index a5306839b9..e8a7c30e19 100644 --- a/erpnext/regional/india/e_invoice/einvoice.js +++ b/erpnext/regional/india/e_invoice/einvoice.js @@ -188,7 +188,6 @@ const get_ewaybill_fields = (frm) => { 'fieldname': 'vehicle_no', 'label': 'Vehicle No', 'fieldtype': 'Data', - 'depends_on': 'eval:(doc.mode_of_transport === "Road")', 'default': frm.doc.vehicle_no }, { diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 410c09396d..438ec79ed1 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -160,7 +160,7 @@ def get_item_list(invoice): item.update(d.as_dict()) item.sr_no = d.idx - item.description = d.item_name.replace('"', '\\"') + item.description = json.dumps(d.item_name)[1:-1] item.qty = abs(item.qty) item.discount_amount = 0 diff --git a/erpnext/regional/report/gstr_1/gstr_1.py b/erpnext/regional/report/gstr_1/gstr_1.py index 96dc3f728d..09b04ff367 100644 --- a/erpnext/regional/report/gstr_1/gstr_1.py +++ b/erpnext/regional/report/gstr_1/gstr_1.py @@ -236,6 +236,7 @@ class Gstr1Report(object): self.cgst_sgst_invoices = [] unidentified_gst_accounts = [] + unidentified_gst_accounts_invoice = [] for parent, account, item_wise_tax_detail, tax_amount in self.tax_details: if account in self.gst_accounts.cess_account: self.invoice_cess.setdefault(parent, tax_amount) @@ -251,6 +252,7 @@ class Gstr1Report(object): if not (cgst_or_sgst or account in self.gst_accounts.igst_account): if "gst" in account.lower() and account not in unidentified_gst_accounts: unidentified_gst_accounts.append(account) + unidentified_gst_accounts_invoice.append(parent) continue for item_code, tax_amounts in item_wise_tax_detail.items(): @@ -273,7 +275,7 @@ class Gstr1Report(object): # Build itemised tax for export invoices where tax table is blank for invoice, items in iteritems(self.invoice_items): - if invoice not in self.items_based_on_tax_rate \ + if invoice not in self.items_based_on_tax_rate and invoice not in unidentified_gst_accounts_invoice \ and frappe.db.get_value(self.doctype, invoice, "export_type") == "Without Payment of Tax": self.items_based_on_tax_rate.setdefault(invoice, {}).setdefault(0, items.keys()) diff --git a/erpnext/regional/united_arab_emirates/setup.py b/erpnext/regional/united_arab_emirates/setup.py index 013ae5cf73..776a82c730 100644 --- a/erpnext/regional/united_arab_emirates/setup.py +++ b/erpnext/regional/united_arab_emirates/setup.py @@ -110,9 +110,11 @@ def make_custom_fields(): 'Purchase Order': purchase_invoice_fields + invoice_fields, 'Purchase Receipt': purchase_invoice_fields + invoice_fields, 'Sales Invoice': sales_invoice_fields + invoice_fields, + 'POS Invoice': sales_invoice_fields + invoice_fields, 'Sales Order': sales_invoice_fields + invoice_fields, 'Delivery Note': sales_invoice_fields + invoice_fields, 'Sales Invoice Item': invoice_item_fields + delivery_date_field + [is_zero_rated, is_exempt], + 'POS Invoice Item': invoice_item_fields + delivery_date_field + [is_zero_rated, is_exempt], 'Purchase Invoice Item': invoice_item_fields, 'Sales Order Item': invoice_item_fields, 'Delivery Note Item': invoice_item_fields, diff --git a/erpnext/selling/page/point_of_sale/pos_controller.js b/erpnext/selling/page/point_of_sale/pos_controller.js index d4cde43359..45b4e30bf0 100644 --- a/erpnext/selling/page/point_of_sale/pos_controller.js +++ b/erpnext/selling/page/point_of_sale/pos_controller.js @@ -69,6 +69,10 @@ erpnext.PointOfSale.Controller = class { dialog.fields_dict.balance_details.grid.refresh(); }); } + const pos_profile_query = { + query: 'erpnext.accounts.doctype.pos_profile.pos_profile.pos_profile_query', + filters: { company: frappe.defaults.get_default('company') } + } const dialog = new frappe.ui.Dialog({ title: __('Create POS Opening Entry'), static: true, @@ -80,6 +84,7 @@ erpnext.PointOfSale.Controller = class { { fieldtype: 'Link', label: __('POS Profile'), options: 'POS Profile', fieldname: 'pos_profile', reqd: 1, + get_query: () => pos_profile_query, onchange: () => fetch_pos_payment_methods() }, { @@ -124,9 +129,8 @@ erpnext.PointOfSale.Controller = class { }); frappe.db.get_doc("POS Profile", this.pos_profile).then((profile) => { + Object.assign(this.settings, profile); this.settings.customer_groups = profile.customer_groups.map(group => group.customer_group); - this.settings.hide_images = profile.hide_images; - this.settings.auto_add_item_to_cart = profile.auto_add_item_to_cart; this.make_app(); }); } @@ -255,11 +259,9 @@ erpnext.PointOfSale.Controller = class { get_frm: () => this.frm, cart_item_clicked: (item_code, batch_no, uom) => { - const item_row = this.frm.doc.items.find( - i => i.item_code === item_code - && i.uom === uom - && (!batch_no || (batch_no && i.batch_no === batch_no)) - ); + const search_field = batch_no ? 'batch_no' : 'item_code'; + const search_value = batch_no || item_code; + const item_row = this.frm.doc.items.find(i => i[search_field] === search_value && i.uom === uom); this.item_details.toggle_item_details_section(item_row); }, @@ -281,6 +283,7 @@ erpnext.PointOfSale.Controller = class { init_item_details() { this.item_details = new erpnext.PointOfSale.ItemDetails({ wrapper: this.$components_wrapper, + settings: this.settings, events: { get_frm: () => this.frm, @@ -415,6 +418,11 @@ erpnext.PointOfSale.Controller = class { () => this.item_selector.toggle_component(true) ]); }, + delete_order: (name) => { + frappe.model.delete_doc(this.frm.doc.doctype, name, () => { + this.recent_order_list.refresh_list(); + }); + }, new_order: () => { frappe.run_serially([ () => frappe.dom.freeze(), @@ -696,14 +704,14 @@ erpnext.PointOfSale.Controller = class { frappe.dom.freeze(); const { doctype, name, current_item } = this.item_details; - frappe.model.set_value(doctype, name, 'qty', 0); - - this.frm.script_manager.trigger('qty', doctype, name).then(() => { - frappe.model.clear_doc(doctype, name); - this.update_cart_html(current_item, true); - this.item_details.toggle_item_details_section(undefined); - frappe.dom.unfreeze(); - }) + frappe.model.set_value(doctype, name, 'qty', 0) + .then(() => { + frappe.model.clear_doc(doctype, name); + this.update_cart_html(current_item, true); + this.item_details.toggle_item_details_section(undefined); + frappe.dom.unfreeze(); + }) + .catch(e => console.log(e)); } } diff --git a/erpnext/selling/page/point_of_sale/pos_item_cart.js b/erpnext/selling/page/point_of_sale/pos_item_cart.js index 03d99c6bfa..de70f167a5 100644 --- a/erpnext/selling/page/point_of_sale/pos_item_cart.js +++ b/erpnext/selling/page/point_of_sale/pos_item_cart.js @@ -5,6 +5,8 @@ erpnext.PointOfSale.ItemCart = class { this.customer_info = undefined; this.hide_images = settings.hide_images; this.allowed_customer_groups = settings.customer_groups; + this.allow_rate_change = settings.allow_rate_change; + this.allow_discount_change = settings.allow_discount_change; this.init_component(); } @@ -201,7 +203,7 @@ erpnext.PointOfSale.ItemCart = class { me.events.checkout(); me.toggle_checkout_btn(false); - me.$add_discount_elem.removeClass("d-none"); + me.allow_discount_change && me.$add_discount_elem.removeClass("d-none"); }); this.$totals_section.on('click', '.edit-cart-btn', () => { @@ -479,8 +481,8 @@ erpnext.PointOfSale.ItemCart = class { update_totals_section(frm) { if (!frm) frm = this.events.get_frm(); - this.render_net_total(frm.doc.base_net_total); - this.render_grand_total(frm.doc.base_grand_total); + this.render_net_total(frm.doc.net_total); + this.render_grand_total(frm.doc.grand_total); const taxes = frm.doc.taxes.map(t => { return { @@ -549,7 +551,7 @@ erpnext.PointOfSale.ItemCart = class { get_cart_item({ item_code, batch_no, uom }) { const batch_attr = `[data-batch-no="${escape(batch_no)}"]`; const item_code_attr = `[data-item-code="${escape(item_code)}"]`; - const uom_attr = `[data-uom=${escape(uom)}]`; + const uom_attr = `[data-uom="${escape(uom)}"]`; const item_selector = batch_no ? `.cart-item-wrapper${batch_attr}${uom_attr}` : `.cart-item-wrapper${item_code_attr}${uom_attr}`; @@ -671,7 +673,7 @@ erpnext.PointOfSale.ItemCart = class { update_selector_value_in_cart_item(selector, value, item) { const $item_to_update = this.get_cart_item(item); - $item_to_update.attr(`data-${selector}`, value); + $item_to_update.attr(`data-${selector}`, escape(value)); } toggle_checkout_btn(show_checkout) { @@ -706,14 +708,26 @@ erpnext.PointOfSale.ItemCart = class { on_numpad_event($btn) { const current_action = $btn.attr('data-button-value'); const action_is_field_edit = ['qty', 'discount_percentage', 'rate'].includes(current_action); - - this.highlight_numpad_btn($btn, current_action); + const action_is_allowed = action_is_field_edit ? ( + (current_action == 'rate' && this.allow_rate_change) || + (current_action == 'discount_percentage' && this.allow_discount_change) || + (current_action == 'qty')) : true; const action_is_pressed_twice = this.prev_action === current_action; const first_click_event = !this.prev_action; const field_to_edit_changed = this.prev_action && this.prev_action != current_action; if (action_is_field_edit) { + if (!action_is_allowed) { + const label = current_action == 'rate' ? 'Rate'.bold() : 'Discount'.bold(); + const message = __('Editing {0} is not allowed as per POS Profile settings', [label]); + frappe.show_alert({ + indicator: 'red', + message: message + }); + frappe.utils.play_sound("error"); + return; + } if (first_click_event || field_to_edit_changed) { this.prev_action = current_action; @@ -757,6 +771,7 @@ erpnext.PointOfSale.ItemCart = class { this.numpad_value = current_action; } + this.highlight_numpad_btn($btn, current_action); this.events.numpad_event(this.numpad_value, this.prev_action); } diff --git a/erpnext/selling/page/point_of_sale/pos_item_details.js b/erpnext/selling/page/point_of_sale/pos_item_details.js index a4de9f165d..259631d14d 100644 --- a/erpnext/selling/page/point_of_sale/pos_item_details.js +++ b/erpnext/selling/page/point_of_sale/pos_item_details.js @@ -1,7 +1,9 @@ erpnext.PointOfSale.ItemDetails = class { - constructor({ wrapper, events }) { + constructor({ wrapper, events, settings }) { this.wrapper = wrapper; this.events = events; + this.allow_rate_change = settings.allow_rate_change; + this.allow_discount_change = settings.allow_discount_change; this.current_item = {}; this.init_component(); @@ -207,17 +209,27 @@ erpnext.PointOfSale.ItemDetails = class { bind_custom_control_change_event() { const me = this; if (this.rate_control) { - this.rate_control.df.onchange = function() { - if (this.value || flt(this.value) === 0) { - me.events.form_updated(me.doctype, me.name, 'rate', this.value).then(() => { - const item_row = frappe.get_doc(me.doctype, me.name); - const doc = me.events.get_frm().doc; - - me.$item_price.html(format_currency(item_row.rate, doc.currency)); - me.render_discount_dom(item_row); - }); - } + if (this.allow_rate_change) { + this.rate_control.df.onchange = function() { + if (this.value || flt(this.value) === 0) { + me.events.form_updated(me.doctype, me.name, 'rate', this.value).then(() => { + const item_row = frappe.get_doc(me.doctype, me.name); + const doc = me.events.get_frm().doc; + + me.$item_price.html(format_currency(item_row.rate, doc.currency)); + me.render_discount_dom(item_row); + }); + } + }; + } else { + this.rate_control.df.read_only = 1; } + this.rate_control.refresh(); + } + + if (this.discount_percentage_control && !this.allow_discount_change) { + this.discount_percentage_control.df.read_only = 1; + this.discount_percentage_control.refresh(); } if (this.warehouse_control) { @@ -294,8 +306,16 @@ erpnext.PointOfSale.ItemDetails = class { } frappe.model.on("POS Invoice Item", "*", (fieldname, value, item_row) => { + const { item_code, batch_no, uom } = this.current_item; + const item_code_is_same = item_code === item_row.item_code; + const batch_is_same = batch_no == item_row.batch_no; + const uom_is_same = uom === item_row.uom; + // check if current_item is same as item_row + const item_is_same = item_code_is_same && batch_is_same && uom_is_same ? true : false; + const field_control = me[`${fieldname}_control`]; - if (field_control) { + + if (item_is_same && field_control && field_control.get_value() !== value) { field_control.set_value(value); cur_pos.update_cart_html(item_row); } diff --git a/erpnext/selling/page/point_of_sale/pos_past_order_summary.js b/erpnext/selling/page/point_of_sale/pos_past_order_summary.js index 6fd4c26bea..598f50f192 100644 --- a/erpnext/selling/page/point_of_sale/pos_past_order_summary.js +++ b/erpnext/selling/page/point_of_sale/pos_past_order_summary.js @@ -265,6 +265,14 @@ erpnext.PointOfSale.PastOrderSummary = class { this.$summary_wrapper.addClass('d-none'); }); + this.$summary_container.on('click', '.delete-btn', () => { + this.events.delete_order(this.doc.name); + this.show_summary_placeholder(); + // this.toggle_component(false); + // this.$component.find('.no-summary-placeholder').removeClass('d-none'); + // this.$summary_wrapper.addClass('d-none'); + }); + this.$summary_container.on('click', '.new-btn', () => { this.events.new_order(); this.toggle_component(false); @@ -401,7 +409,7 @@ erpnext.PointOfSale.PastOrderSummary = class { return [{ condition: true, visible_btns: ['Print Receipt', 'Email Receipt', 'New Order'] }]; return [ - { condition: this.doc.docstatus === 0, visible_btns: ['Edit Order'] }, + { condition: this.doc.docstatus === 0, visible_btns: ['Edit Order', 'Delete Order'] }, { condition: !this.doc.is_return && this.doc.docstatus === 1, visible_btns: ['Print Receipt', 'Email Receipt', 'Return']}, { condition: this.doc.is_return && this.doc.docstatus === 1, visible_btns: ['Print Receipt', 'Email Receipt']} ]; diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index be845d9d9d..cda1069891 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -672,13 +672,14 @@ class Item(WebsiteGenerator): if not records: return document = _("Stock Reconciliation") if len(records) == 1 else _("Stock Reconciliations") - msg = _("The items {0} and {1} are present in the following {2} :
" - .format(frappe.bold(old_name), frappe.bold(new_name), document)) + msg = _("The items {0} and {1} are present in the following {2} : ").format( + frappe.bold(old_name), frappe.bold(new_name), document) + msg += '
' msg += ', '.join([get_link_to_form("Stock Reconciliation", d.parent) for d in records]) + "

" - msg += _("Note: To merge the items, create a separate Stock Reconciliation for the old item {0}" - .format(frappe.bold(old_name))) + msg += _("Note: To merge the items, create a separate Stock Reconciliation for the old item {0}").format( + frappe.bold(old_name)) frappe.throw(_(msg), title=_("Merge not allowed")) @@ -971,7 +972,7 @@ class Item(WebsiteGenerator): frappe.throw(_("As there are existing transactions against item {0}, you can not change the value of {1}").format(self.name, frappe.bold(self.meta.get_label(field)))) def check_if_linked_document_exists(self, field): - linked_doctypes = ["Delivery Note Item", "Sales Invoice Item", "Purchase Receipt Item", + linked_doctypes = ["Delivery Note Item", "Sales Invoice Item", "POS Invoice Item", "Purchase Receipt Item", "Purchase Invoice Item", "Stock Entry Detail", "Stock Reconciliation Item"] # For "Is Stock Item", following doctypes is important diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index dfe8fea67b..873cfec85e 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -19,7 +19,7 @@ from erpnext.stock.doctype.item_manufacturer.item_manufacturer import get_item_m from six import string_types, iteritems -sales_doctypes = ['Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice'] +sales_doctypes = ['Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice', 'POS Invoice'] purchase_doctypes = ['Material Request', 'Supplier Quotation', 'Purchase Order', 'Purchase Receipt', 'Purchase Invoice'] @frappe.whitelist() diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index e4f5725c68..f54b3c1bb2 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -58,8 +58,9 @@ def validate_cancellation(args): if repost_entry.status == 'In Progress': frappe.throw(_("Cannot cancel the transaction. Reposting of item valuation on submission is not completed yet.")) if repost_entry.status == 'Queued': - frappe.delete_doc("Repost Item Valuation", repost_entry.name) - + doc = frappe.get_doc("Repost Item Valuation", repost_entry.name) + doc.cancel() + doc.delete() def set_as_cancel(voucher_type, voucher_no): frappe.db.sql("""update `tabStock Ledger Entry` set is_cancelled=1, @@ -133,7 +134,7 @@ class update_entries_after(object): self.item_code = args.get("item_code") if self.args.sle_id: self.args['name'] = self.args.sle_id - + self.company = frappe.get_cached_value("Warehouse", self.args.warehouse, "company") self.get_precision() self.valuation_method = get_valuation_method(self.item_code) @@ -201,7 +202,7 @@ class update_entries_after(object): and timestamp(posting_date, time_format(posting_time, %(time_format)s)) < timestamp(%(posting_date)s, time_format(%(posting_time)s, %(time_format)s)) order by timestamp(posting_date, posting_time) desc, creation desc limit 1""", args, as_dict=1) - + return sle[0] if sle else frappe._dict() @@ -224,7 +225,7 @@ class update_entries_after(object): if sle.dependant_sle_voucher_detail_no: entries_to_fix = self.get_dependent_entries_to_fix(entries_to_fix, sle) - + self.update_bin() if self.exceptions: @@ -439,7 +440,7 @@ class update_entries_after(object): # Recalculate subcontracted item's rate in case of subcontracted purchase receipt/invoice if frappe.db.get_value(sle.voucher_type, sle.voucher_no, "is_subcontracted"): - doc = frappe.get_cached_doc(sle.voucher_type, sle.voucher_no) + doc = frappe.get_doc(sle.voucher_type, sle.voucher_no) doc.update_valuation_rate(reset_outgoing_rate=False) for d in (doc.items + doc.supplied_items): d.db_update() From 39b5ad8e6910806163c93e651cb48e6442559a37 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 23 Feb 2021 17:50:49 +0530 Subject: [PATCH 283/449] fix: patch failing because of incorrect gl entries --- erpnext/accounts/utils.py | 14 ++++++++------ .../item_reposting_for_incorrect_sl_and_gl.py | 6 +++++- .../doctype/purchase_receipt/purchase_receipt.py | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 5eb2aab393..89a05b187d 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -897,17 +897,18 @@ def repost_gle_for_stock_vouchers(stock_vouchers, posting_date, company=None, wa frappe.db.sql("""delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no)) - if not warehouse_account: warehouse_account = get_warehouse_account_map(company) + precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit")) or 2 + gle = get_voucherwise_gl_entries(stock_vouchers, posting_date) for voucher_type, voucher_no in stock_vouchers: existing_gle = gle.get((voucher_type, voucher_no), []) voucher_obj = frappe.get_cached_doc(voucher_type, voucher_no) expected_gle = voucher_obj.get_gl_entries(warehouse_account) if expected_gle: - if not existing_gle or not compare_existing_and_expected_gle(existing_gle, expected_gle): + if not existing_gle or not compare_existing_and_expected_gle(existing_gle, expected_gle, precision): _delete_gl_entries(voucher_type, voucher_no) voucher_obj.make_gl_entries(gl_entries=expected_gle, from_repost=True) else: @@ -953,16 +954,17 @@ def get_voucherwise_gl_entries(future_stock_vouchers, posting_date): return gl_entries -def compare_existing_and_expected_gle(existing_gle, expected_gle): +def compare_existing_and_expected_gle(existing_gle, expected_gle, precision): matched = True for entry in expected_gle: account_existed = False for e in existing_gle: if entry.account == e.account: account_existed = True - if entry.account == e.account and entry.against_account == e.against_account \ - and (not entry.cost_center or not e.cost_center or entry.cost_center == e.cost_center) \ - and (entry.debit != e.debit or entry.credit != e.credit): + if (entry.account == e.account and entry.against_account == e.against_account + and (not entry.cost_center or not e.cost_center or entry.cost_center == e.cost_center) + and ( flt(entry.debit, precision) != flt(e.debit, precision) or + flt(entry.credit, precision) != flt(e.credit, precision))): matched = False break if not account_existed: diff --git a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py index 06f7f989bb..ca04e8acc2 100644 --- a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py +++ b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py @@ -1,5 +1,6 @@ import frappe from frappe import _ +from frappe.utils import getdate, get_time from erpnext.stock.stock_ledger import update_entries_after from erpnext.accounts.utils import update_gl_entries_after @@ -40,7 +41,10 @@ def execute(): print("Reposting General Ledger Entries...") + posting_date = getdate(reposting_project_deployed_on) + posting_time = get_time(reposting_project_deployed_on) + for row in frappe.get_all('Company', filters= {'enable_perpetual_inventory': 1}): - update_gl_entries_after('2020-12-25', '01:58:55', company=row.name) + update_gl_entries_after(posting_date, posting_time, company=row.name) frappe.db.auto_commit_on_many_writes = 0 diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 550c849c5d..d72101412e 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -295,7 +295,8 @@ class PurchaseReceipt(BuyingController): "against": warehouse_account[d.warehouse]["account"], "cost_center": d.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), - "credit": flt(amount["base_amount"]), + "credit": (flt(amount["base_amount"]) if (amount["base_amount"] or + account_currency!=self.company_currency) else flt(amount["amount"])), "credit_in_account_currency": flt(amount["amount"]), "project": d.project }, item=d)) From f613d4140856d0ca47883a1359ba1b10c8f4ce06 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 24 Feb 2021 11:19:55 +0530 Subject: [PATCH 284/449] chore: change log --- erpnext/change_log/v13/v13_0_0-beta_12.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 erpnext/change_log/v13/v13_0_0-beta_12.md diff --git a/erpnext/change_log/v13/v13_0_0-beta_12.md b/erpnext/change_log/v13/v13_0_0-beta_12.md new file mode 100644 index 0000000000..cb981f1488 --- /dev/null +++ b/erpnext/change_log/v13/v13_0_0-beta_12.md @@ -0,0 +1,14 @@ +### Version 13.0.0 Beta 12 Release Notes +#### Features +- Department wise Appointment Type charges ([#24572](https://github.com/frappe/erpnext/pull/24572)) +- Capture Rate of stock UOM in purchase ([#24315](https://github.com/frappe/erpnext/pull/24315)) + +#### Fixes + +- Fixed stock and account balance syncing ([#24644](https://github.com/frappe/erpnext/pull/24644)) +- Fixed incorrect stock ledger qty in the stock ledger report and bin ([#24649](https://github.com/frappe/erpnext/pull/24649)) +- Added patch to fix incorrect stock ledger and stock account value ([#24702](https://github.com/frappe/erpnext/pull/24702)) +- Skip e-invoice generation for non-taxable invoices ([#24568](https://github.com/frappe/erpnext/pull/24568)) +- Cannot cancel old invoices if eligible for e-invoicing ([#24608](https://github.com/frappe/erpnext/pull/24608)) +- Mpesa fixes and enhancement ([#24306](https://github.com/frappe/erpnext/pull/24306)) +- Fixed Consolidated Financial Statement report ([#24580](https://github.com/frappe/erpnext/pull/24580)) \ No newline at end of file From fefacced13168b6e76e8171ad04dd2ca29e93d75 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 24 Feb 2021 15:21:19 +0550 Subject: [PATCH 285/449] bumped to version 13.0.0-beta.12 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index a754e1323b..2a474bfe7d 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0-beta.11' +__version__ = '13.0.0-beta.12' def get_default_company(user=None): '''Get default company for user''' From 9f13a060f0cd78277e304c1ba0f2b6780a24cadc Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 26 Feb 2021 17:34:53 +0530 Subject: [PATCH 286/449] fix: reposting patch --- .../patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py | 6 +++++- erpnext/stock/__init__.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py index ca04e8acc2..3200363e01 100644 --- a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py +++ b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py @@ -7,7 +7,7 @@ from erpnext.accounts.utils import update_gl_entries_after def execute(): frappe.reload_doc('stock', 'doctype', 'repost_item_valuation') - reposting_project_deployed_on = frappe.db.get_value("DocType", "Repost Item Valuation", "creation") + reposting_project_deployed_on = get_creation_time() data = frappe.db.sql(''' SELECT @@ -48,3 +48,7 @@ def execute(): update_gl_entries_after(posting_date, posting_time, company=row.name) frappe.db.auto_commit_on_many_writes = 0 + +def get_creation_time(): + return frappe.db.sql(''' SELECT create_time FROM + INFORMATION_SCHEMA.TABLES where TABLE_NAME = "tabRepost Item Valuation" ''', as_list=1)[0][0] \ No newline at end of file diff --git a/erpnext/stock/__init__.py b/erpnext/stock/__init__.py index 9e240cc2b3..283f7d5fda 100644 --- a/erpnext/stock/__init__.py +++ b/erpnext/stock/__init__.py @@ -38,7 +38,7 @@ def get_warehouse_account_map(company=None): frappe.flags.warehouse_account_map[company] = warehouse_account else: frappe.flags.warehouse_account_map = warehouse_account - + return frappe.flags.warehouse_account_map.get(company) or frappe.flags.warehouse_account_map def get_warehouse_account(warehouse, warehouse_account=None): @@ -64,6 +64,10 @@ def get_warehouse_account(warehouse, warehouse_account=None): if not account and warehouse.company: account = get_company_default_inventory_account(warehouse.company) + if not account and warehouse.company: + account = frappe.db.get_value('Account', + {'account_type': 'Stock', 'is_group': 0, 'company': warehouse.company}, 'name') + if not account and warehouse.company and not warehouse.is_group: frappe.throw(_("Please set Account in Warehouse {0} or Default Inventory Account in Company {1}") .format(warehouse.name, warehouse.company)) From d96be3f9f14b74d649a7e8c65d7444aeedeee9fa Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 2 Mar 2021 17:02:47 +0530 Subject: [PATCH 287/449] Reposting patch and earned leave rounding (#24783) * fix: rounding of earned leave is optional (#24782) * fix: reposting patch fixes (#24775) --- .../leave_allocation/leave_allocation.py | 6 --- .../leave_policy_assignment.json | 6 ++- .../leave_policy_assignment.py | 48 ++++++++++++++++--- erpnext/hr/doctype/leave_type/leave_type.json | 5 +- erpnext/hr/utils.py | 23 ++++++--- .../item_reposting_for_incorrect_sl_and_gl.py | 17 +++++-- .../purchase_receipt/purchase_receipt.py | 4 +- 7 files changed, 81 insertions(+), 28 deletions(-) diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.py b/erpnext/hr/doctype/leave_allocation/leave_allocation.py index a09cd2ea11..a4f4f1ace9 100755 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.py +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.py @@ -18,7 +18,6 @@ class ValueMultiplierError(frappe.ValidationError): pass class LeaveAllocation(Document): def validate(self): self.validate_period() - self.validate_new_leaves_allocated_value() self.validate_allocation_overlap() self.validate_back_dated_allocation() self.set_total_leaves_allocated() @@ -72,11 +71,6 @@ class LeaveAllocation(Document): if frappe.db.get_value("Leave Type", self.leave_type, "is_lwp"): frappe.throw(_("Leave Type {0} cannot be allocated since it is leave without pay").format(self.leave_type)) - def validate_new_leaves_allocated_value(self): - """validate that leave allocation is in multiples of 0.5""" - if flt(self.new_leaves_allocated) % 0.5: - frappe.throw(_("Leaves must be allocated in multiples of 0.5"), ValueMultiplierError) - def validate_allocation_overlap(self): leave_allocation = frappe.db.sql(""" SELECT diff --git a/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json b/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json index a0327bdaa0..3373350e73 100644 --- a/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json +++ b/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json @@ -106,12 +106,14 @@ "fieldname": "leaves_allocated", "fieldtype": "Check", "hidden": 1, - "label": "Leaves Allocated" + "label": "Leaves Allocated", + "no_copy": 1, + "print_hide": 1 } ], "is_submittable": 1, "links": [], - "modified": "2020-12-31 16:43:30.695206", + "modified": "2021-03-01 17:54:01.014509", "modified_by": "Administrator", "module": "HR", "name": "Leave Policy Assignment", diff --git a/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.py b/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.py index a5068bc26d..4064c56e44 100644 --- a/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.py +++ b/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document from frappe import _, bold -from frappe.utils import getdate, date_diff, comma_and, formatdate +from frappe.utils import getdate, date_diff, comma_and, formatdate, get_datetime, flt from math import ceil import json from six import string_types @@ -84,17 +84,52 @@ class LeavePolicyAssignment(Document): return allocation.name, new_leaves_allocated def get_new_leaves(self, leave_type, new_leaves_allocated, leave_type_details, date_of_joining): + from frappe.model.meta import get_field_precision + precision = get_field_precision(frappe.get_meta("Leave Allocation").get_field("new_leaves_allocated")) + + # Earned Leaves and Compensatory Leaves are allocated by scheduler, initially allocate 0 + if leave_type_details.get(leave_type).is_compensatory == 1: + new_leaves_allocated = 0 + + elif leave_type_details.get(leave_type).is_earned_leave == 1: + if self.assignment_based_on == "Leave Period": + new_leaves_allocated = self.get_leaves_for_passed_months(leave_type, new_leaves_allocated, leave_type_details, date_of_joining) + else: + new_leaves_allocated = 0 # Calculate leaves at pro-rata basis for employees joining after the beginning of the given leave period - if getdate(date_of_joining) > getdate(self.effective_from): + elif getdate(date_of_joining) > getdate(self.effective_from): remaining_period = ((date_diff(self.effective_to, date_of_joining) + 1) / (date_diff(self.effective_to, self.effective_from) + 1)) new_leaves_allocated = ceil(new_leaves_allocated * remaining_period) - # Earned Leaves and Compensatory Leaves are allocated by scheduler, initially allocate 0 - if leave_type_details.get(leave_type).is_earned_leave == 1 or leave_type_details.get(leave_type).is_compensatory == 1: - new_leaves_allocated = 0 + return flt(new_leaves_allocated, precision) + + def get_leaves_for_passed_months(self, leave_type, new_leaves_allocated, leave_type_details, date_of_joining): + from erpnext.hr.utils import get_monthly_earned_leave + + current_month = get_datetime().month + current_year = get_datetime().year + + from_date = frappe.db.get_value("Leave Period", self.leave_period, "from_date") + if getdate(date_of_joining) > getdate(from_date): + from_date = date_of_joining + + from_date_month = get_datetime(from_date).month + from_date_year = get_datetime(from_date).year + + months_passed = 0 + if current_year == from_date_year and current_month > from_date_month: + months_passed = current_month - from_date_month + elif current_year > from_date_year: + months_passed = (12 - from_date_month) + current_month + + if months_passed > 0: + monthly_earned_leave = get_monthly_earned_leave(new_leaves_allocated, + leave_type_details.get(leave_type).earned_leave_frequency, leave_type_details.get(leave_type).rounding) + new_leaves_allocated = monthly_earned_leave * months_passed return new_leaves_allocated + @frappe.whitelist() def grant_leave_for_multiple_employees(leave_policy_assignments): leave_policy_assignments = json.loads(leave_policy_assignments) @@ -156,7 +191,8 @@ def automatically_allocate_leaves_based_on_leave_policy(): def get_leave_type_details(): leave_type_details = frappe._dict() leave_types = frappe.get_all("Leave Type", - fields=["name", "is_lwp", "is_earned_leave", "is_compensatory", "is_carry_forward", "expire_carry_forwarded_leaves_after_days"]) + fields=["name", "is_lwp", "is_earned_leave", "is_compensatory", + "is_carry_forward", "expire_carry_forwarded_leaves_after_days", "earned_leave_frequency", "rounding"]) for d in leave_types: leave_type_details.setdefault(d.name, d) return leave_type_details diff --git a/erpnext/hr/doctype/leave_type/leave_type.json b/erpnext/hr/doctype/leave_type/leave_type.json index a2092919f8..fc577ef1d3 100644 --- a/erpnext/hr/doctype/leave_type/leave_type.json +++ b/erpnext/hr/doctype/leave_type/leave_type.json @@ -172,7 +172,7 @@ "fieldname": "rounding", "fieldtype": "Select", "label": "Rounding", - "options": "0.5\n1.0" + "options": "\n0.25\n0.5\n1.0" }, { "depends_on": "is_carry_forward", @@ -197,6 +197,7 @@ "label": "Based On Date Of Joining" }, { + "default": "0", "depends_on": "eval:doc.is_lwp == 0", "fieldname": "is_ppl", "fieldtype": "Check", @@ -213,7 +214,7 @@ "icon": "fa fa-flag", "idx": 1, "links": [], - "modified": "2020-10-15 15:49:47.555105", + "modified": "2021-03-02 11:22:33.776320", "modified_by": "Administrator", "module": "HR", "name": "Leave Type", diff --git a/erpnext/hr/utils.py b/erpnext/hr/utils.py index d700e7fccf..3f8d61d414 100644 --- a/erpnext/hr/utils.py +++ b/erpnext/hr/utils.py @@ -316,13 +316,7 @@ def allocate_earned_leaves(): update_previous_leave_allocation(allocation, annual_allocation, e_leave_type) def update_previous_leave_allocation(allocation, annual_allocation, e_leave_type): - divide_by_frequency = {"Yearly": 1, "Half-Yearly": 6, "Quarterly": 4, "Monthly": 12} - if annual_allocation: - earned_leaves = flt(annual_allocation) / divide_by_frequency[e_leave_type.earned_leave_frequency] - if e_leave_type.rounding == "0.5": - earned_leaves = round(earned_leaves * 2) / 2 - else: - earned_leaves = round(earned_leaves) + earned_leaves = get_monthly_earned_leave(annual_allocation, e_leave_type.earned_leave_frequency, e_leave_type.rounding) allocation = frappe.get_doc('Leave Allocation', allocation.name) new_allocation = flt(allocation.total_leaves_allocated) + flt(earned_leaves) @@ -335,6 +329,21 @@ def update_previous_leave_allocation(allocation, annual_allocation, e_leave_type today_date = today() create_additional_leave_ledger_entry(allocation, earned_leaves, today_date) +def get_monthly_earned_leave(annual_leaves, frequency, rounding): + earned_leaves = 0.0 + divide_by_frequency = {"Yearly": 1, "Half-Yearly": 6, "Quarterly": 4, "Monthly": 12} + if annual_leaves: + earned_leaves = flt(annual_leaves) / divide_by_frequency[frequency] + if rounding: + if rounding == "0.25": + earned_leaves = round(earned_leaves * 4) / 4 + elif rounding == "0.5": + earned_leaves = round(earned_leaves * 2) / 2 + else: + earned_leaves = round(earned_leaves) + + return earned_leaves + def get_leave_allocations(date, leave_type): return frappe.db.sql("""select name, employee, from_date, to_date, leave_policy_assignment, leave_policy diff --git a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py index 3200363e01..d968e1fb76 100644 --- a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py +++ b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py @@ -1,13 +1,24 @@ import frappe from frappe import _ -from frappe.utils import getdate, get_time +from frappe.utils import getdate, get_time, today from erpnext.stock.stock_ledger import update_entries_after from erpnext.accounts.utils import update_gl_entries_after def execute(): - frappe.reload_doc('stock', 'doctype', 'repost_item_valuation') + for doctype in ('repost_item_valuation', 'stock_entry_detail', 'purchase_receipt_item', + 'purchase_invoice_item', 'delivery_note_item', 'sales_invoice_item', 'packed_item'): + frappe.reload_doc('stock', 'doctype', doctype) + frappe.reload_doc('buying', 'doctype', 'purchase_receipt_item_supplied') reposting_project_deployed_on = get_creation_time() + posting_date = getdate(reposting_project_deployed_on) + posting_time = get_time(reposting_project_deployed_on) + + if posting_date == today(): + return + + frappe.clear_cache() + frappe.flags.warehouse_account_map = {} data = frappe.db.sql(''' SELECT @@ -41,8 +52,6 @@ def execute(): print("Reposting General Ledger Entries...") - posting_date = getdate(reposting_project_deployed_on) - posting_time = get_time(reposting_project_deployed_on) for row in frappe.get_all('Company', filters= {'enable_perpetual_inventory': 1}): update_gl_entries_after(posting_date, posting_time, company=row.name) diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index d72101412e..70687bdac2 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -324,10 +324,12 @@ class PurchaseReceipt(BuyingController): else: loss_account = self.get_company_default("default_expense_account") + cost_center = d.cost_center or frappe.get_cached_value("Company", self.company, "cost_center") + gl_entries.append(self.get_gl_dict({ "account": loss_account, "against": warehouse_account[d.warehouse]["account"], - "cost_center": d.cost_center, + "cost_center": cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "debit": divisional_loss, "project": d.project From 11092d08240ce53139aefe3768ba994ee6466d01 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Tue, 2 Mar 2021 18:36:48 +0530 Subject: [PATCH 288/449] feat: Additon of leave details in Salary Slip (#24674) * feat: Additon of leave details in Salary Slip * fix: Change leaves to leave --- .../payroll_settings/payroll_settings.json | 50 +++++------- .../doctype/salary_slip/salary_slip.json | 16 +++- .../doctype/salary_slip/salary_slip.py | 18 +++++ .../doctype/salary_slip_leave/__init__.py | 0 .../salary_slip_leave/salary_slip_leave.json | 78 +++++++++++++++++++ .../salary_slip_leave/salary_slip_leave.py | 10 +++ 6 files changed, 140 insertions(+), 32 deletions(-) create mode 100644 erpnext/payroll/doctype/salary_slip_leave/__init__.py create mode 100644 erpnext/payroll/doctype/salary_slip_leave/salary_slip_leave.json create mode 100644 erpnext/payroll/doctype/salary_slip_leave/salary_slip_leave.py diff --git a/erpnext/payroll/doctype/payroll_settings/payroll_settings.json b/erpnext/payroll/doctype/payroll_settings/payroll_settings.json index c47caa1227..680e518ca0 100644 --- a/erpnext/payroll/doctype/payroll_settings/payroll_settings.json +++ b/erpnext/payroll/doctype/payroll_settings/payroll_settings.json @@ -15,6 +15,7 @@ "daily_wages_fraction_for_half_day", "email_salary_slip_to_employee", "encrypt_salary_slips_in_emails", + "show_leave_balances_in_salary_slip", "password_policy" ], "fields": [ @@ -23,58 +24,44 @@ "fieldname": "payroll_based_on", "fieldtype": "Select", "label": "Calculate Payroll Working Days Based On", - "options": "Leave\nAttendance", - "show_days": 1, - "show_seconds": 1 + "options": "Leave\nAttendance" }, { "fieldname": "max_working_hours_against_timesheet", "fieldtype": "Float", - "label": "Max working hours against Timesheet", - "show_days": 1, - "show_seconds": 1 + "label": "Max working hours against Timesheet" }, { "default": "0", "description": "If checked, Total no. of Working Days will include holidays, and this will reduce the value of Salary Per Day", "fieldname": "include_holidays_in_total_working_days", "fieldtype": "Check", - "label": "Include holidays in Total no. of Working Days", - "show_days": 1, - "show_seconds": 1 + "label": "Include holidays in Total no. of Working Days" }, { "default": "0", "description": "If checked, hides and disables Rounded Total field in Salary Slips", "fieldname": "disable_rounded_total", "fieldtype": "Check", - "label": "Disable Rounded Total", - "show_days": 1, - "show_seconds": 1 + "label": "Disable Rounded Total" }, { "fieldname": "column_break_11", - "fieldtype": "Column Break", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "Column Break" }, { "default": "0.5", "description": "The fraction of daily wages to be paid for half-day attendance", "fieldname": "daily_wages_fraction_for_half_day", "fieldtype": "Float", - "label": "Fraction of Daily Salary for Half Day", - "show_days": 1, - "show_seconds": 1 + "label": "Fraction of Daily Salary for Half Day" }, { "default": "1", "description": "Emails salary slip to employee based on preferred email selected in Employee", "fieldname": "email_salary_slip_to_employee", "fieldtype": "Check", - "label": "Email Salary Slip to Employee", - "show_days": 1, - "show_seconds": 1 + "label": "Email Salary Slip to Employee" }, { "default": "0", @@ -82,9 +69,7 @@ "description": "The salary slip emailed to the employee will be password protected, the password will be generated based on the password policy.", "fieldname": "encrypt_salary_slips_in_emails", "fieldtype": "Check", - "label": "Encrypt Salary Slips in Emails", - "show_days": 1, - "show_seconds": 1 + "label": "Encrypt Salary Slips in Emails" }, { "depends_on": "eval: doc.encrypt_salary_slips_in_emails == 1", @@ -92,24 +77,27 @@ "fieldname": "password_policy", "fieldtype": "Data", "in_list_view": 1, - "label": "Password Policy", - "show_days": 1, - "show_seconds": 1 + "label": "Password Policy" }, { "depends_on": "eval:doc.payroll_based_on == 'Attendance'", "fieldname": "consider_unmarked_attendance_as", "fieldtype": "Select", "label": "Consider Unmarked Attendance As", - "options": "Present\nAbsent", - "show_days": 1, - "show_seconds": 1 + "options": "Present\nAbsent" + }, + { + "default": "0", + "fieldname": "show_leave_balances_in_salary_slip", + "fieldtype": "Check", + "label": "Show Leave Balances in Salary Slip" } ], "icon": "fa fa-cog", + "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2020-06-22 17:00:58.408030", + "modified": "2021-02-19 11:07:55.873991", "modified_by": "Administrator", "module": "Payroll", "name": "Payroll Settings", diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.json b/erpnext/payroll/doctype/salary_slip/salary_slip.json index 9f9691b59d..6688368262 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.json +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.json @@ -80,6 +80,8 @@ "total_in_words", "column_break_69", "base_total_in_words", + "leave_details_section", + "leave_details", "section_break_75", "amended_from" ], @@ -612,13 +614,25 @@ "label": "Month To Date(Company Currency)", "options": "Company:company:default_currency", "read_only": 1 + }, + { + "fieldname": "leave_details_section", + "fieldtype": "Section Break", + "label": "Leave Details" + }, + { + "fieldname": "leave_details", + "fieldtype": "Table", + "label": "Leave Details", + "options": "Salary Slip Leave", + "read_only": 1 } ], "icon": "fa fa-file-text", "idx": 9, "is_submittable": 1, "links": [], - "modified": "2021-01-14 13:37:38.180920", + "modified": "2021-02-19 11:48:05.383945", "modified_by": "Administrator", "module": "Payroll", "name": "Salary Slip", diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index 60aff02b38..5c5eccd7e5 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -19,6 +19,7 @@ from erpnext.payroll.doctype.employee_benefit_application.employee_benefit_appli from erpnext.payroll.doctype.employee_benefit_claim.employee_benefit_claim import get_benefit_claim_amount, get_last_payroll_period_benefits from erpnext.loan_management.doctype.loan_repayment.loan_repayment import calculate_amounts, create_repayment_entry from erpnext.accounts.utils import get_fiscal_year +from six import iteritems class SalarySlip(TransactionBase): def __init__(self, *args, **kwargs): @@ -53,6 +54,7 @@ class SalarySlip(TransactionBase): self.compute_year_to_date() self.compute_month_to_date() self.compute_component_wise_year_to_date() + self.add_leave_balances() if frappe.db.get_single_value("Payroll Settings", "max_working_hours_against_timesheet"): max_working_hours = frappe.db.get_single_value("Payroll Settings", "max_working_hours_against_timesheet") @@ -1212,6 +1214,22 @@ class SalarySlip(TransactionBase): return period_start_date, period_end_date + def add_leave_balances(self): + self.set('leave_details', []) + + if frappe.db.get_single_value('Payroll Settings', 'show_leave_balances_in_salary_slip'): + from erpnext.hr.doctype.leave_application.leave_application import get_leave_details + leave_details = get_leave_details(self.employee, self.end_date) + + for leave_type, leave_values in iteritems(leave_details['leave_allocation']): + self.append('leave_details', { + 'leave_type': leave_type, + 'total_allocated_leaves': flt(leave_values.get('total_leaves')), + 'expired_leaves': flt(leave_values.get('expired_leaves')), + 'used_leaves': flt(leave_values.get('leaves_taken')), + 'pending_leaves': flt(leave_values.get('pending_leaves')), + 'available_leaves': flt(leave_values.get('remaining_leaves')) + }) def unlink_ref_doc_from_salary_slip(ref_no): linked_ss = frappe.db.sql_list("""select name from `tabSalary Slip` diff --git a/erpnext/payroll/doctype/salary_slip_leave/__init__.py b/erpnext/payroll/doctype/salary_slip_leave/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/payroll/doctype/salary_slip_leave/salary_slip_leave.json b/erpnext/payroll/doctype/salary_slip_leave/salary_slip_leave.json new file mode 100644 index 0000000000..7ac453b3c3 --- /dev/null +++ b/erpnext/payroll/doctype/salary_slip_leave/salary_slip_leave.json @@ -0,0 +1,78 @@ +{ + "actions": [], + "creation": "2021-02-19 11:45:18.173417", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "leave_type", + "total_allocated_leaves", + "expired_leaves", + "used_leaves", + "pending_leaves", + "available_leaves" + ], + "fields": [ + { + "fieldname": "leave_type", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Leave Type", + "no_copy": 1, + "options": "Leave Type", + "read_only": 1 + }, + { + "fieldname": "total_allocated_leaves", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Total Allocated Leave", + "no_copy": 1, + "read_only": 1 + }, + { + "fieldname": "expired_leaves", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Expired Leave", + "no_copy": 1, + "read_only": 1 + }, + { + "fieldname": "used_leaves", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Used Leave", + "no_copy": 1, + "read_only": 1 + }, + { + "fieldname": "pending_leaves", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Pending Leave", + "no_copy": 1, + "read_only": 1 + }, + { + "fieldname": "available_leaves", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Available Leave", + "no_copy": 1, + "read_only": 1 + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-02-19 10:47:48.546724", + "modified_by": "Administrator", + "module": "Payroll", + "name": "Salary Slip Leave", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/payroll/doctype/salary_slip_leave/salary_slip_leave.py b/erpnext/payroll/doctype/salary_slip_leave/salary_slip_leave.py new file mode 100644 index 0000000000..7a92bf18f7 --- /dev/null +++ b/erpnext/payroll/doctype/salary_slip_leave/salary_slip_leave.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +# import frappe +from frappe.model.document import Document + +class SalarySlipLeave(Document): + pass From 49e4693abf6314de9973b735a07954395a0748b5 Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Thu, 4 Mar 2021 11:58:45 +0530 Subject: [PATCH 289/449] fix(patch): updating pos closing reference in merge log --- erpnext/patches/v13_0/update_pos_closing_entry_in_merge_log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/patches/v13_0/update_pos_closing_entry_in_merge_log.py b/erpnext/patches/v13_0/update_pos_closing_entry_in_merge_log.py index 42bca7c53a..262e38dd05 100644 --- a/erpnext/patches/v13_0/update_pos_closing_entry_in_merge_log.py +++ b/erpnext/patches/v13_0/update_pos_closing_entry_in_merge_log.py @@ -15,7 +15,7 @@ def execute(): log.pos_closing_entry = ( SELECT clo_ref.parent FROM `tabPOS Invoice Reference` clo_ref WHERE clo_ref.pos_invoice = log_ref.pos_invoice - AND clo_ref.parenttype = 'POS Closing Entry' + AND clo_ref.parenttype = 'POS Closing Entry' LIMIT 1 ) WHERE log_ref.parent = log.name From dcfc3d7d1278d90e0a9154c9d7d7d2dcd2b57bc4 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Thu, 4 Mar 2021 19:29:55 +0100 Subject: [PATCH 290/449] fix: remove redundant calls to create_sales_tax --- erpnext/regional/saudi_arabia/setup.py | 5 +---- erpnext/regional/united_arab_emirates/setup.py | 4 +--- erpnext/setup/setup_wizard/utils.py | 1 - 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/erpnext/regional/saudi_arabia/setup.py b/erpnext/regional/saudi_arabia/setup.py index d9ac6cb0f6..9b3677d2c6 100644 --- a/erpnext/regional/saudi_arabia/setup.py +++ b/erpnext/regional/saudi_arabia/setup.py @@ -4,11 +4,8 @@ from __future__ import unicode_literals from erpnext.regional.united_arab_emirates.setup import make_custom_fields, add_print_formats -from erpnext.setup.setup_wizard.operations.taxes_setup import create_sales_tax + def setup(company=None, patch=True): make_custom_fields() add_print_formats() - - if company: - create_sales_tax(company) \ No newline at end of file diff --git a/erpnext/regional/united_arab_emirates/setup.py b/erpnext/regional/united_arab_emirates/setup.py index 776a82c730..d5a29fc200 100644 --- a/erpnext/regional/united_arab_emirates/setup.py +++ b/erpnext/regional/united_arab_emirates/setup.py @@ -6,15 +6,13 @@ from __future__ import unicode_literals import frappe, os, json from frappe.custom.doctype.custom_field.custom_field import create_custom_fields from frappe.permissions import add_permission, update_permission_property -from erpnext.setup.setup_wizard.operations.taxes_setup import create_sales_tax + def setup(company=None, patch=True): make_custom_fields() add_print_formats() add_custom_roles_for_reports() add_permissions() - if company: - create_sales_tax(company) def make_custom_fields(): is_zero_rated = dict(fieldname='is_zero_rated', label='Is Zero Rated', diff --git a/erpnext/setup/setup_wizard/utils.py b/erpnext/setup/setup_wizard/utils.py index e82bc96d93..4223f000a6 100644 --- a/erpnext/setup/setup_wizard/utils.py +++ b/erpnext/setup/setup_wizard/utils.py @@ -9,5 +9,4 @@ def complete(): 'data', 'test_mfg.json'), 'r') as f: data = json.loads(f.read()) - #setup_wizard.create_sales_tax(data) setup_complete(data) From 25afad3dc1d75031ba09b405ff8b12de5f0d8007 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Thu, 4 Mar 2021 21:11:31 +0100 Subject: [PATCH 291/449] refactor: extend taxes and charges setup Add option to specify taxes and charges template depending on the CoA used. Differentiate between purchase, sales and item taxes. Maintain flexibility by using wildcards. --- erpnext/setup/doctype/company/company.py | 7 +- .../setup_wizard/data/country_wise_tax.json | 307 ++++++++++++++-- .../setup_wizard/operations/taxes_setup.py | 330 ++++++++++++------ 3 files changed, 513 insertions(+), 131 deletions(-) diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index 819ba78e66..d3021bafea 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -17,6 +17,7 @@ from frappe.utils.nestedset import NestedSet from past.builtins import cmp import functools from erpnext.accounts.doctype.account.account import get_account_currency +from erpnext.setup.setup_wizard.operations.taxes_setup import setup_taxes_and_charges class Company(NestedSet): nsm_parent_field = 'parent_company' @@ -67,11 +68,7 @@ class Company(NestedSet): frappe.throw(_("Abbreviation already used for another company")) def create_default_tax_template(self): - from erpnext.setup.setup_wizard.operations.taxes_setup import create_sales_tax - create_sales_tax({ - 'country': self.country, - 'company_name': self.name - }) + setup_taxes_and_charges(self.name, self.country) def validate_default_accounts(self): accounts = [ diff --git a/erpnext/setup/setup_wizard/data/country_wise_tax.json b/erpnext/setup/setup_wizard/data/country_wise_tax.json index beddaeed79..9ccbdb965b 100644 --- a/erpnext/setup/setup_wizard/data/country_wise_tax.json +++ b/erpnext/setup/setup_wizard/data/country_wise_tax.json @@ -481,14 +481,230 @@ }, "Germany": { - "Germany VAT 19%": { - "account_name": "VAT 19%", - "tax_rate": 19.00, - "default": 1 - }, - "Germany VAT 7%": { - "account_name": "VAT 7%", - "tax_rate": 7.00 + "chart_of_accounts": { + "SKR04 mit Kontonummern": { + "sales_tax_templates": [ + { + "title": "Umsatzsteuer 19%", + "is_default": 1, + "accounts": [ + { + "type": "On Net Total", + "account_name": "Umsatzsteuer 19%", + "account_number": "3806", + "rate": 19.00 + } + ] + }, + { + "title": "Umsatzsteuer 7%", + "accounts": [ + { + "type": "On Net Total", + "account_name": "Umsatzsteuer 7%", + "account_number": "3801", + "tax_rate": 7.00 + } + ] + } + ], + "purchase_tax_templates": [ + { + "title": "Abziehbare Vorsteuer 19%", + "is_default": 1, + "accounts": [ + { + "account_name": "Abziehbare Vorsteuer 19%", + "account_number": "1406", + "root_type": "Asset", + "tax_rate": 19.00 + } + ] + }, + { + "title": "Abziehbare Vorsteuer 7%", + "accounts": [ + { + "account_name": "Abziehbare Vorsteuer 7%", + "account_number": "1401", + "root_type": "Asset", + "tax_rate": 7.00 + } + ] + }, + { + "title": "Innergemeinschaftlicher Erwerb 19% Umsatzsteuer und 19% Vorsteuer", + "accounts": [ + { + "account_name": "Abziehbare Vorsteuer nach § 13b UStG 19%", + "account_number": "1407", + "root_type": "Asset", + "tax_rate": 19.00, + "add_deduct_tax": "Add" + }, + { + "account_name": "Umsatzsteuer nach § 13b UStG 19%", + "account_number": "3837", + "root_type": "Liability", + "tax_rate": 19.00, + "add_deduct_tax": "Deduct" + } + ] + } + ] + }, + "SKR03 mit Kontonummern": { + "sales_tax_templates": [ + { + "title": "Umsatzsteuer 19%", + "is_default": 1, + "accounts": [ + { + "type": "On Net Total", + "account_name": "Umsatzsteuer 19%", + "account_number": "1776", + "rate": 19.00 + } + ] + }, + { + "title": "Umsatzsteuer 7%", + "accounts": [ + { + "type": "On Net Total", + "account_name": "Umsatzsteuer 7%", + "account_number": "1771", + "tax_rate": 7.00 + } + ] + } + ], + "purchase_tax_templates": [ + { + "title": "Abziehbare Vorsteuer 19%", + "is_default": 1, + "accounts": [ + { + "account_name": "Abziehbare Vorsteuer 19%", + "account_number": "1576", + "root_type": "Asset", + "tax_rate": 19.00 + } + ] + }, + { + "title": "Abziehbare Vorsteuer 7%", + "accounts": [ + { + "account_name": "Abziehbare Vorsteuer 7%", + "account_number": "1571", + "root_type": "Asset", + "tax_rate": 7.00 + } + ] + } + ] + }, + "Standard with Numbers": { + "sales_tax_templates": [ + { + "title": "Umsatzsteuer 19%", + "is_default": 1, + "accounts": [ + { + "type": "On Net Total", + "account_name": "Umsatzsteuer 19%", + "account_number": "2301", + "rate": 19.00 + } + ] + }, + { + "title": "Umsatzsteuer 7%", + "accounts": [ + { + "type": "On Net Total", + "account_name": "Umsatzsteuer 7%", + "account_number": "2302", + "tax_rate": 7.00 + } + ] + } + ], + "purchase_tax_templates": [ + { + "title": "Abziehbare Vorsteuer 19%", + "is_default": 1, + "accounts": [ + { + "account_name": "Abziehbare Vorsteuer 19%", + "account_number": "1501", + "root_type": "Asset", + "tax_rate": 19.00 + } + ] + }, + { + "title": "Abziehbare Vorsteuer 7%", + "accounts": [ + { + "account_name": "Abziehbare Vorsteuer 7%", + "account_number": "1502", + "root_type": "Asset", + "tax_rate": 7.00 + } + ] + } + ] + }, + "*": { + "sales_tax_templates": [ + { + "title": "Umsatzsteuer 19%", + "is_default": 1, + "accounts": [ + { + "type": "On Net Total", + "account_name": "Umsatzsteuer 19%", + "rate": 19.00 + } + ] + }, + { + "title": "Umsatzsteuer 7%", + "accounts": [ + { + "type": "On Net Total", + "account_name": "Umsatzsteuer 7%", + "tax_rate": 7.00 + } + ] + } + ], + "purchase_tax_templates": [ + { + "title": "Abziehbare Vorsteuer 19%", + "is_default": 1, + "accounts": [ + { + "account_name": "Abziehbare Vorsteuer 19%", + "root_type": "Asset", + "tax_rate": 19.00 + } + ] + }, + { + "title": "Abziehbare Vorsteuer 7%", + "accounts": [ + { + "account_name": "Abziehbare Vorsteuer 7%", + "root_type": "Asset", + "tax_rate": 7.00 + } + ] + } + ] + } } }, @@ -580,26 +796,61 @@ }, "India": { - "In State GST": { - "account_name": ["SGST", "CGST"], - "tax_rate": [9.00, 9.00], - "default": 1 - }, - "Out of State GST": { - "account_name": "IGST", - "tax_rate": 18.00 - }, - "VAT 5%": { - "account_name": "VAT 5%", - "tax_rate": 5.00 - }, - "VAT 4%": { - "account_name": "VAT 4%", - "tax_rate": 4.00 - }, - "VAT 14%": { - "account_name": "VAT 14%", - "tax_rate": 14.00 + "chart_of_accounts": { + "*": { + "*": [ + { + "title": "In State GST", + "is_default": 1, + "accounts": [ + { + "account_name": "SGST", + "tax_rate": 9.00 + }, + { + "account_name": "CGST", + "tax_rate": 9.00 + } + ] + }, + { + "title": "Out of State GST", + "accounts": [ + { + "account_name": "IGST", + "tax_rate": 18.00 + } + ] + }, + { + "title": "VAT 5%", + "accounts": [ + { + "account_name": "VAT 5%", + "tax_rate": 5.00 + } + ] + }, + { + "title": "VAT 4%", + "accounts": [ + { + "account_name": "VAT 4%", + "tax_rate": 4.00 + } + ] + }, + { + "title": "VAT 14%", + "accounts": [ + { + "account_name": "VAT 14%", + "tax_rate": 14.00 + } + ] + } + ] + } } }, diff --git a/erpnext/setup/setup_wizard/operations/taxes_setup.py b/erpnext/setup/setup_wizard/operations/taxes_setup.py index c3c1593c04..81506c4352 100644 --- a/erpnext/setup/setup_wizard/operations/taxes_setup.py +++ b/erpnext/setup/setup_wizard/operations/taxes_setup.py @@ -1,123 +1,257 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt from __future__ import unicode_literals -import frappe, copy, os, json -from frappe.utils import flt -from erpnext.accounts.doctype.account.account import RootNotEditable -def create_sales_tax(args): - country_wise_tax = get_country_wise_tax(args.get("country")) - if country_wise_tax and len(country_wise_tax) > 0: - for sales_tax, tax_data in country_wise_tax.items(): - make_tax_account_and_template( - args.get("company_name"), - tax_data.get('account_name'), - tax_data.get('tax_rate'), sales_tax) +import os +import json -def make_tax_account_and_template(company, account_name, tax_rate, template_name=None): - if not isinstance(account_name, (list, tuple)): - account_name = [account_name] - tax_rate = [tax_rate] +import frappe +from frappe import _ - accounts = [] - for i, name in enumerate(account_name): - tax_account = make_tax_account(company, account_name[i], tax_rate[i]) - if tax_account: - accounts.append(tax_account) - try: - if accounts: - make_sales_and_purchase_tax_templates(accounts, template_name) - make_item_tax_templates(accounts, template_name) - except frappe.NameError: - if frappe.message_log: frappe.message_log.pop() - except RootNotEditable: - pass +def setup_taxes_and_charges(company_name: str, country: str): + file_path = os.path.join(os.path.dirname(__file__), '..', 'data', 'country_wise_tax.json') + with open(file_path, 'r') as json_file: + tax_data = json.load(json_file) -def make_tax_account(company, account_name, tax_rate): - tax_group = get_tax_account_group(company) - if tax_group: - try: - return frappe.get_doc({ - "doctype":"Account", - "company": company, - "parent_account": tax_group, - "account_name": account_name, - "is_group": 0, - "report_type": "Balance Sheet", - "root_type": "Liability", - "account_type": "Tax", - "tax_rate": flt(tax_rate) if tax_rate else None - }).insert(ignore_permissions=True, ignore_mandatory=True) - except frappe.NameError: - if frappe.message_log: frappe.message_log.pop() - abbr = frappe.get_cached_value('Company', company, 'abbr') - account = '{0} - {1}'.format(account_name, abbr) - return frappe.get_doc('Account', account) + country_wise_tax = tax_data.get(country) -def make_sales_and_purchase_tax_templates(accounts, template_name=None): - if not template_name: - template_name = accounts[0].name + if country_wise_tax: + if 'chart_of_accounts' in country_wise_tax: + from_detailed_data(company_name, country_wise_tax.get('chart_of_accounts')) + else: + from_simple_data(company_name, country_wise_tax) - sales_tax_template = { - "doctype": "Sales Taxes and Charges Template", - "title": template_name, - "company": accounts[0].company, - 'taxes': [] + +def from_detailed_data(company_name, data): + """ + Create Taxes and Charges Templates from detailed data like this: + + { + "chart_of_accounts": { + coa_name: { + "sales_tax_templates": [ + { + 'title': '', + 'is_default': 1, + 'accounts': [ + { + 'account_name': '', + 'account_number': '', + 'root_type': '', + } + ] + } + ], + "purchase_tax_templates": [ ... ], + "item_tax_templates": [ ... ], + "*": [ ... ] + } + } } + """ + coa_name = frappe.db.get_value('Company', company_name, 'chart_of_accounts') + tax_templates = data.get(coa_name) or data.get('*') + sales_tax_templates = tax_templates.get('sales_tax_templates') or tax_templates.get('*') + purchase_tax_templates = tax_templates.get('purchase_tax_templates') or tax_templates.get('*') + item_tax_templates = tax_templates.get('item_tax_templates') or tax_templates.get('*') + + if sales_tax_templates: + for template in sales_tax_templates: + make_tax_template(company_name, 'Sales Taxes and Charges Template', template) + + if purchase_tax_templates: + for template in purchase_tax_templates: + make_tax_template(company_name, 'Purchase Taxes and Charges Template', template) + + if item_tax_templates: + for template in item_tax_templates: + make_item_tax_template(company_name, template) + + +def from_simple_data(company_name, data): + """ + Create Taxes and Charges Templates from simple data like this: + + "Austria Tax": { + "account_name": "VAT", + "tax_rate": 20.00 + } + """ + for template_name, tax_data in data.items(): + template = { + 'title': template_name, + 'is_default': tax_data.get('default'), + 'accounts': [ + { + 'account_name': tax_data.get('account_name'), + 'tax_rate': tax_data.get('tax_rate') + } + ] + } + make_tax_template(company_name, 'Sales Taxes and Charges Template', template) + make_tax_template(company_name, 'Purchase Taxes and Charges Template', template) + make_item_tax_template(company_name, template) + + +def make_tax_template(company_name, doctype, template): + if frappe.db.exists(doctype, {'title': template.get('title'), 'company': company_name}): + return + + accounts = get_or_create_accounts(company_name, template.get('accounts')) + + # Get all fields of the Taxes and Charges Template + tax_template = {'doctype': doctype} + tax_template_fields = frappe.get_meta(doctype).fields + tax_template_fieldnames = [field.fieldname for field in tax_template_fields] + + # Get all fields of the taxes child table + table_doctype = [field.options for field in tax_template_fields if field.fieldname=='taxes'][0] + table_fields = frappe.get_meta(table_doctype).fields + table_field_names = [field.fieldname for field in table_fields] + + # Check if field exists as a key in the import data and, if yes, set the + # value accordingly + for field in tax_template_fieldnames: + if field in template: + tax_template[field] = template.get(field) + + # However, company always fixed and taxes table must be empty to start with + tax_template['company'] = company_name + tax_template['taxes'] = [] for account in accounts: - sales_tax_template['taxes'].append({ - "category": "Total", - "charge_type": "On Net Total", - "account_head": account.name, - "description": "{0} @ {1}".format(account.account_name, account.tax_rate), - "rate": account.tax_rate - }) - # Sales - frappe.get_doc(copy.deepcopy(sales_tax_template)).insert(ignore_permissions=True) + row = { + 'category': 'Total', + 'charge_type': 'On Net Total', + 'account_head': account.get('name'), + 'description': '{0} @ {1}'.format(account.get('account_name'), account.get('tax_rate')), + 'rate': account.get('tax_rate') + } + # Check if field exists as a key in the import data and, if yes, set the + # value accordingly + for field in table_field_names: + if field in account: + row[field] = account.get(field) - # Purchase - purchase_tax_template = copy.deepcopy(sales_tax_template) - purchase_tax_template["doctype"] = "Purchase Taxes and Charges Template" + tax_template['taxes'].append(row) - doc = frappe.get_doc(purchase_tax_template) - doc.insert(ignore_permissions=True) + return frappe.get_doc(tax_template).insert(ignore_permissions=True) -def make_item_tax_templates(accounts, template_name=None): - if not template_name: - template_name = accounts[0].name + +def make_item_tax_template(company_name, template): + """Create an Item Tax Template. + + This requires a separate method because Item Tax Template is structured + differently from Sales and Purchase Tax Templates. + """ + doctype = 'Item Tax Template' + if frappe.db.exists(doctype, {'title': template.get('title'), 'company': company_name}): + return + + accounts = get_or_create_accounts(company_name, template.get('accounts')) item_tax_template = { - "doctype": "Item Tax Template", - "title": template_name, - "company": accounts[0].company, - 'taxes': [] + 'doctype': doctype, + 'title': template.get('title'), + 'company': company_name, + 'taxes': [{ + 'tax_type': account.get('name'), + 'tax_rate': account.get('tax_rate') + } for account in accounts] } + return frappe.get_doc(item_tax_template).insert(ignore_permissions=True) - for account in accounts: - item_tax_template['taxes'].append({ - "tax_type": account.name, - "tax_rate": account.tax_rate - }) - # Items - frappe.get_doc(copy.deepcopy(item_tax_template)).insert(ignore_permissions=True) +def get_or_create_accounts(company: str, account_data: list): + for account in account_data: + if 'creation' in account: + # Hack to check if account already contains a real Account doc + # or just the attibutes from country_wise_tax.json + continue -def get_tax_account_group(company): - tax_group = frappe.db.get_value("Account", - {"account_name": "Duties and Taxes", "is_group": 1, "company": company}) - if not tax_group: - tax_group = frappe.db.get_value("Account", {"is_group": 1, "root_type": "Liability", - "account_type": "Tax", "company": company}) + # tax_rate should survive the following lines because it might not be + # specified in an existing account or different rates might get booked + # onto the same account. + tax_rate = account.get('tax_rate') + doc = get_or_create_account(company, account) + account.update(doc.as_dict()) + account['tax_rate'] = tax_rate + + return account_data + + +def get_or_create_account(company, account_data): + """ + Check if account already exists. If not, create it. + Return a tax account or None. + """ + root_type = account_data.get('root_type', 'Liability') + account_name = account_data.get('account_name') + account_number = account_data.get('account_number') + + existing_accounts = frappe.get_list('Account', + filters={ + 'company': company, + 'root_type': root_type + }, + or_filters={ + 'account_name': account_name, + 'account_number': account_number + } + ) + + if existing_accounts: + return frappe.get_doc('Account', existing_accounts[0].name) + + tax_group = get_or_create_tax_account_group(company, root_type) + full_account_data = { + 'doctype': 'Account', + 'account_name': account_name, + 'account_number': account_number, + 'tax_rate': account_data.get('tax_rate'), + 'company': company, + 'parent_account': tax_group, + 'is_group': 0, + 'report_type': 'Balance Sheet', + 'root_type': root_type, + 'account_type': 'Tax' + } + return frappe.get_doc(full_account_data).insert(ignore_permissions=True, ignore_mandatory=True) + + +def get_or_create_tax_account_group(company, root_type): + tax_group = frappe.db.get_value('Account', { + 'is_group': 1, + 'root_type': root_type, + 'account_type': 'Tax', + 'company': company + }) + + if tax_group: + return tax_group + + root = frappe.get_list('Account', { + 'is_group': 1, + 'root_type': root_type, + 'company': company, + 'report_type': 'Balance Sheet', + 'parent_account': ('is', 'not set') + }, limit=1)[0].name + + doc = frappe.get_doc({ + 'doctype': 'Account', + 'company': company, + 'is_group': 1, + 'report_type': 'Balance Sheet', + 'root_type': root_type, + 'account_type': 'Tax', + 'account_name': _('Duties and Taxes') if root_type == 'Liability' else _('Tax Assets'), + 'parent_account': root + }).insert(ignore_permissions=True) + + tax_group = doc.name return tax_group - -def get_country_wise_tax(country): - data = {} - with open (os.path.join(os.path.dirname(__file__), "..", "data", "country_wise_tax.json")) as countrywise_tax: - data = json.load(countrywise_tax).get(country) - - return data From 4e1206bf21aadb105ac7165e8fe7889f42d163cd Mon Sep 17 00:00:00 2001 From: Saurabh Date: Fri, 5 Mar 2021 09:54:01 +0550 Subject: [PATCH 292/449] bumped to version 13.0.0-beta.13 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 2a474bfe7d..b122e5fa11 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0-beta.12' +__version__ = '13.0.0-beta.13' def get_default_company(user=None): '''Get default company for user''' From ebd1d08e55b8146e652096d2c591754f8d676504 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Mon, 8 Mar 2021 19:53:50 +0100 Subject: [PATCH 293/449] refactor: taxes setup Better structure of input data. --- .../setup_wizard/data/country_wise_tax.json | 310 ++++++++++++------ .../setup_wizard/operations/taxes_setup.py | 279 +++++++--------- 2 files changed, 334 insertions(+), 255 deletions(-) diff --git a/erpnext/setup/setup_wizard/data/country_wise_tax.json b/erpnext/setup/setup_wizard/data/country_wise_tax.json index 9ccbdb965b..6305442ef2 100644 --- a/erpnext/setup/setup_wizard/data/country_wise_tax.json +++ b/erpnext/setup/setup_wizard/data/country_wise_tax.json @@ -487,23 +487,25 @@ { "title": "Umsatzsteuer 19%", "is_default": 1, - "accounts": [ + "taxes": [ { - "type": "On Net Total", - "account_name": "Umsatzsteuer 19%", - "account_number": "3806", - "rate": 19.00 + "account_head": { + "account_name": "Umsatzsteuer 19%", + "account_number": "3806", + "tax_rate": 19.00 + } } ] }, { "title": "Umsatzsteuer 7%", - "accounts": [ + "taxes": [ { - "type": "On Net Total", - "account_name": "Umsatzsteuer 7%", - "account_number": "3801", - "tax_rate": 7.00 + "account_head": { + "account_name": "Umsatzsteuer 7%", + "account_number": "3801", + "tax_rate": 7.00 + } } ] } @@ -512,41 +514,49 @@ { "title": "Abziehbare Vorsteuer 19%", "is_default": 1, - "accounts": [ + "taxes": [ { - "account_name": "Abziehbare Vorsteuer 19%", - "account_number": "1406", - "root_type": "Asset", - "tax_rate": 19.00 + "account_head": { + "account_name": "Abziehbare Vorsteuer 19%", + "account_number": "1406", + "root_type": "Asset", + "tax_rate": 19.00 + } } ] }, { "title": "Abziehbare Vorsteuer 7%", - "accounts": [ + "taxes": [ { - "account_name": "Abziehbare Vorsteuer 7%", - "account_number": "1401", - "root_type": "Asset", - "tax_rate": 7.00 + "account_head": { + "account_name": "Abziehbare Vorsteuer 7%", + "account_number": "1401", + "root_type": "Asset", + "tax_rate": 7.00 + } } ] }, { "title": "Innergemeinschaftlicher Erwerb 19% Umsatzsteuer und 19% Vorsteuer", - "accounts": [ + "taxes": [ { - "account_name": "Abziehbare Vorsteuer nach § 13b UStG 19%", - "account_number": "1407", - "root_type": "Asset", - "tax_rate": 19.00, + "account_head": { + "account_name": "Abziehbare Vorsteuer nach § 13b UStG 19%", + "account_number": "1407", + "root_type": "Asset", + "tax_rate": 19.00 + }, "add_deduct_tax": "Add" }, { - "account_name": "Umsatzsteuer nach § 13b UStG 19%", - "account_number": "3837", - "root_type": "Liability", - "tax_rate": 19.00, + "account_head": { + "account_name": "Umsatzsteuer nach § 13b UStG 19%", + "account_number": "3837", + "root_type": "Liability", + "tax_rate": 19.00 + }, "add_deduct_tax": "Deduct" } ] @@ -558,23 +568,25 @@ { "title": "Umsatzsteuer 19%", "is_default": 1, - "accounts": [ + "taxes": [ { - "type": "On Net Total", - "account_name": "Umsatzsteuer 19%", - "account_number": "1776", - "rate": 19.00 + "account_head": { + "account_name": "Umsatzsteuer 19%", + "account_number": "1776", + "tax_rate": 19.00 + } } ] }, { "title": "Umsatzsteuer 7%", - "accounts": [ + "taxes": [ { - "type": "On Net Total", - "account_name": "Umsatzsteuer 7%", - "account_number": "1771", - "tax_rate": 7.00 + "account_head": { + "account_name": "Umsatzsteuer 7%", + "account_number": "1771", + "tax_rate": 7.00 + } } ] } @@ -583,23 +595,27 @@ { "title": "Abziehbare Vorsteuer 19%", "is_default": 1, - "accounts": [ + "taxes": [ { - "account_name": "Abziehbare Vorsteuer 19%", - "account_number": "1576", - "root_type": "Asset", - "tax_rate": 19.00 + "account_head": { + "account_name": "Abziehbare Vorsteuer 19%", + "account_number": "1576", + "root_type": "Asset", + "tax_rate": 19.00 + } } ] }, { "title": "Abziehbare Vorsteuer 7%", - "accounts": [ + "taxes": [ { - "account_name": "Abziehbare Vorsteuer 7%", - "account_number": "1571", - "root_type": "Asset", - "tax_rate": 7.00 + "account_head": { + "account_name": "Abziehbare Vorsteuer 7%", + "account_number": "1571", + "root_type": "Asset", + "tax_rate": 7.00 + } } ] } @@ -610,23 +626,25 @@ { "title": "Umsatzsteuer 19%", "is_default": 1, - "accounts": [ + "taxes": [ { - "type": "On Net Total", - "account_name": "Umsatzsteuer 19%", - "account_number": "2301", - "rate": 19.00 + "account_head": { + "account_name": "Umsatzsteuer 19%", + "account_number": "2301", + "tax_rate": 19.00 + } } ] }, { "title": "Umsatzsteuer 7%", - "accounts": [ + "taxes": [ { - "type": "On Net Total", - "account_name": "Umsatzsteuer 7%", - "account_number": "2302", - "tax_rate": 7.00 + "account_head": { + "account_name": "Umsatzsteuer 7%", + "account_number": "2302", + "tax_rate": 7.00 + } } ] } @@ -635,23 +653,27 @@ { "title": "Abziehbare Vorsteuer 19%", "is_default": 1, - "accounts": [ + "taxes": [ { - "account_name": "Abziehbare Vorsteuer 19%", - "account_number": "1501", - "root_type": "Asset", - "tax_rate": 19.00 + "account_head": { + "account_name": "Abziehbare Vorsteuer 19%", + "account_number": "1501", + "root_type": "Asset", + "tax_rate": 19.00 + } } ] }, { "title": "Abziehbare Vorsteuer 7%", - "accounts": [ + "taxes": [ { - "account_name": "Abziehbare Vorsteuer 7%", - "account_number": "1502", - "root_type": "Asset", - "tax_rate": 7.00 + "account_head": { + "account_name": "Abziehbare Vorsteuer 7%", + "account_number": "1502", + "root_type": "Asset", + "tax_rate": 7.00 + } } ] } @@ -662,21 +684,23 @@ { "title": "Umsatzsteuer 19%", "is_default": 1, - "accounts": [ + "taxes": [ { - "type": "On Net Total", - "account_name": "Umsatzsteuer 19%", - "rate": 19.00 + "account_head": { + "account_name": "Umsatzsteuer 19%", + "tax_rate": 19.00 + } } ] }, { "title": "Umsatzsteuer 7%", - "accounts": [ + "taxes": [ { - "type": "On Net Total", - "account_name": "Umsatzsteuer 7%", - "tax_rate": 7.00 + "account_head": { + "account_name": "Umsatzsteuer 7%", + "tax_rate": 7.00 + } } ] } @@ -685,21 +709,25 @@ { "title": "Abziehbare Vorsteuer 19%", "is_default": 1, - "accounts": [ + "taxes": [ { - "account_name": "Abziehbare Vorsteuer 19%", - "root_type": "Asset", - "tax_rate": 19.00 + "account_head": { + "account_name": "Abziehbare Vorsteuer 19%", + "tax_rate": 19.00, + "root_type": "Asset" + } } ] }, { "title": "Abziehbare Vorsteuer 7%", - "accounts": [ + "taxes": [ { - "account_name": "Abziehbare Vorsteuer 7%", - "root_type": "Asset", - "tax_rate": 7.00 + "account_head": { + "account_name": "Abziehbare Vorsteuer 7%", + "root_type": "Asset", + "tax_rate": 7.00 + } } ] } @@ -798,54 +826,130 @@ "India": { "chart_of_accounts": { "*": { - "*": [ + "item_tax_templates": [ { "title": "In State GST", "is_default": 1, - "accounts": [ + "taxes": [ { - "account_name": "SGST", - "tax_rate": 9.00 + "tax_type": { + "account_name": "SGST", + "tax_rate": 9.00 + } }, { - "account_name": "CGST", - "tax_rate": 9.00 + "tax_type": { + "account_name": "CGST", + "tax_rate": 9.00 + } } ] }, { "title": "Out of State GST", - "accounts": [ + "taxes": [ { - "account_name": "IGST", - "tax_rate": 18.00 + "tax_type": { + "account_name": "IGST", + "tax_rate": 18.00 + } } ] }, { "title": "VAT 5%", - "accounts": [ + "taxes": [ { - "account_name": "VAT 5%", - "tax_rate": 5.00 + "tax_type": { + "account_name": "VAT 5%", + "tax_rate": 5.00 + } } ] }, { "title": "VAT 4%", - "accounts": [ + "taxes": [ { - "account_name": "VAT 4%", - "tax_rate": 4.00 + "tax_type": { + "account_name": "VAT 4%", + "tax_rate": 4.00 + } } ] }, { "title": "VAT 14%", - "accounts": [ + "taxes": [ { - "account_name": "VAT 14%", - "tax_rate": 14.00 + "tax_type": { + "account_name": "VAT 14%", + "tax_rate": 14.00 + } + } + ] + } + ], + "*": [ + { + "title": "In State GST", + "is_default": 1, + "taxes": [ + { + "account_head": { + "account_name": "SGST", + "tax_rate": 9.00 + } + }, + { + "account_head": { + "account_name": "CGST", + "tax_rate": 9.00 + } + } + ] + }, + { + "title": "Out of State GST", + "taxes": [ + { + "account_head": { + "account_name": "IGST", + "tax_rate": 18.00 + } + } + ] + }, + { + "title": "VAT 5%", + "taxes": [ + { + "account_head": { + "account_name": "VAT 5%", + "tax_rate": 5.00 + } + } + ] + }, + { + "title": "VAT 4%", + "taxes": [ + { + "account_head": { + "account_name": "VAT 4%", + "tax_rate": 4.00 + } + } + ] + }, + { + "title": "VAT 14%", + "taxes": [ + { + "account_head": { + "account_name": "VAT 14%", + "tax_rate": 14.00 + } } ] } diff --git a/erpnext/setup/setup_wizard/operations/taxes_setup.py b/erpnext/setup/setup_wizard/operations/taxes_setup.py index 81506c4352..429a558c58 100644 --- a/erpnext/setup/setup_wizard/operations/taxes_setup.py +++ b/erpnext/setup/setup_wizard/operations/taxes_setup.py @@ -17,40 +17,62 @@ def setup_taxes_and_charges(company_name: str, country: str): country_wise_tax = tax_data.get(country) - if country_wise_tax: - if 'chart_of_accounts' in country_wise_tax: - from_detailed_data(company_name, country_wise_tax.get('chart_of_accounts')) - else: - from_simple_data(company_name, country_wise_tax) + if not country_wise_tax: + return + + if 'chart_of_accounts' not in country_wise_tax: + country_wise_tax = simple_to_detailed(country_wise_tax) + + from_detailed_data(company_name, country_wise_tax.get('chart_of_accounts')) -def from_detailed_data(company_name, data): +def simple_to_detailed(templates): """ - Create Taxes and Charges Templates from detailed data like this: + Convert a simple taxes object into a more detailed data structure. + + Example input: { - "chart_of_accounts": { - coa_name: { - "sales_tax_templates": [ - { - 'title': '', - 'is_default': 1, - 'accounts': [ - { - 'account_name': '', - 'account_number': '', - 'root_type': '', - } - ] - } - ], - "purchase_tax_templates": [ ... ], - "item_tax_templates": [ ... ], - "*": [ ... ] - } + "France VAT 20%": { + "account_name": "VAT 20%", + "tax_rate": 20, + "default": 1 + }, + "France VAT 10%": { + "account_name": "VAT 10%", + "tax_rate": 10 } } """ + return { + 'chart_of_accounts': { + '*': { + 'item_tax_templates': [{ + 'title': title, + 'taxes': [{ + 'tax_type': { + 'account_name': data.get('account_name'), + 'tax_rate': data.get('tax_rate') + } + }] + } for title, data in templates.items()], + '*': [{ + 'title': title, + 'is_default': data.get('default', 0), + 'taxes': [{ + 'account_head': { + 'account_name': data.get('account_name'), + 'tax_rate': data.get('tax_rate') + } + }] + } for title, data in templates.items()] + } + } + } + + +def from_detailed_data(company_name, data): + """Create Taxes and Charges Templates from detailed data.""" coa_name = frappe.db.get_value('Company', company_name, 'chart_of_accounts') tax_templates = data.get(coa_name) or data.get('*') sales_tax_templates = tax_templates.get('sales_tax_templates') or tax_templates.get('*') @@ -59,85 +81,44 @@ def from_detailed_data(company_name, data): if sales_tax_templates: for template in sales_tax_templates: - make_tax_template(company_name, 'Sales Taxes and Charges Template', template) + make_taxes_and_charges_template(company_name, 'Sales Taxes and Charges Template', template) if purchase_tax_templates: for template in purchase_tax_templates: - make_tax_template(company_name, 'Purchase Taxes and Charges Template', template) + make_taxes_and_charges_template(company_name, 'Purchase Taxes and Charges Template', template) if item_tax_templates: for template in item_tax_templates: make_item_tax_template(company_name, template) -def from_simple_data(company_name, data): - """ - Create Taxes and Charges Templates from simple data like this: +def make_taxes_and_charges_template(company_name, doctype, template): + template['company'] = company_name + template['doctype'] = doctype - "Austria Tax": { - "account_name": "VAT", - "tax_rate": 20.00 - } - """ - for template_name, tax_data in data.items(): - template = { - 'title': template_name, - 'is_default': tax_data.get('default'), - 'accounts': [ - { - 'account_name': tax_data.get('account_name'), - 'tax_rate': tax_data.get('tax_rate') - } - ] - } - make_tax_template(company_name, 'Sales Taxes and Charges Template', template) - make_tax_template(company_name, 'Purchase Taxes and Charges Template', template) - make_item_tax_template(company_name, template) - - -def make_tax_template(company_name, doctype, template): if frappe.db.exists(doctype, {'title': template.get('title'), 'company': company_name}): return - accounts = get_or_create_accounts(company_name, template.get('accounts')) - - # Get all fields of the Taxes and Charges Template - tax_template = {'doctype': doctype} - tax_template_fields = frappe.get_meta(doctype).fields - tax_template_fieldnames = [field.fieldname for field in tax_template_fields] - - # Get all fields of the taxes child table - table_doctype = [field.options for field in tax_template_fields if field.fieldname=='taxes'][0] - table_fields = frappe.get_meta(table_doctype).fields - table_field_names = [field.fieldname for field in table_fields] - - # Check if field exists as a key in the import data and, if yes, set the - # value accordingly - for field in tax_template_fieldnames: - if field in template: - tax_template[field] = template.get(field) - - # However, company always fixed and taxes table must be empty to start with - tax_template['company'] = company_name - tax_template['taxes'] = [] - - for account in accounts: - row = { + for tax_row in template.get('taxes'): + account_data = tax_row.get('account_head') + tax_row_defaults = { 'category': 'Total', - 'charge_type': 'On Net Total', - 'account_head': account.get('name'), - 'description': '{0} @ {1}'.format(account.get('account_name'), account.get('tax_rate')), - 'rate': account.get('tax_rate') + 'charge_type': 'On Net Total' } - # Check if field exists as a key in the import data and, if yes, set the - # value accordingly - for field in table_field_names: - if field in account: - row[field] = account.get(field) - tax_template['taxes'].append(row) + # if account_head is a dict, search or create the account and get it's name + if isinstance(account_data, dict): + tax_row_defaults['description'] = '{0} @ {1}'.format(account_data.get('account_name'), account_data.get('tax_rate')) + tax_row_defaults['rate'] = account_data.get('tax_rate') + account = get_or_create_account(company_name, account_data) + tax_row['account_head'] = account.name - return frappe.get_doc(tax_template).insert(ignore_permissions=True) + # use the default value if nothing other is specified + for fieldname, default_value in tax_row_defaults.items(): + if fieldname not in tax_row: + tax_row[fieldname] = default_value + + return frappe.get_doc(template).insert(ignore_permissions=True) def make_item_tax_template(company_name, template): @@ -147,111 +128,105 @@ def make_item_tax_template(company_name, template): differently from Sales and Purchase Tax Templates. """ doctype = 'Item Tax Template' + template['company'] = company_name + template['doctype'] = doctype + if frappe.db.exists(doctype, {'title': template.get('title'), 'company': company_name}): return - accounts = get_or_create_accounts(company_name, template.get('accounts')) + for tax_row in template.get('taxes'): + account_data = tax_row.get('tax_type') - item_tax_template = { - 'doctype': doctype, - 'title': template.get('title'), - 'company': company_name, - 'taxes': [{ - 'tax_type': account.get('name'), - 'tax_rate': account.get('tax_rate') - } for account in accounts] - } + # if tax_type is a dict, search or create the account and get it's name + if isinstance(account_data, dict): + account = get_or_create_account(company_name, account_data) + tax_row['tax_type'] = account.name + if 'tax_rate' not in tax_row: + tax_row['tax_rate'] = account_data.get('tax_rate') - return frappe.get_doc(item_tax_template).insert(ignore_permissions=True) + return frappe.get_doc(template).insert(ignore_permissions=True) -def get_or_create_accounts(company: str, account_data: list): - for account in account_data: - if 'creation' in account: - # Hack to check if account already contains a real Account doc - # or just the attibutes from country_wise_tax.json - continue - - # tax_rate should survive the following lines because it might not be - # specified in an existing account or different rates might get booked - # onto the same account. - tax_rate = account.get('tax_rate') - doc = get_or_create_account(company, account) - account.update(doc.as_dict()) - account['tax_rate'] = tax_rate - - return account_data - - -def get_or_create_account(company, account_data): +def get_or_create_account(company_name, account): """ Check if account already exists. If not, create it. Return a tax account or None. """ - root_type = account_data.get('root_type', 'Liability') - account_name = account_data.get('account_name') - account_number = account_data.get('account_number') + default_root_type = 'Liability' + root_type = account.get('root_type', default_root_type) existing_accounts = frappe.get_list('Account', filters={ - 'company': company, + 'company': company_name, 'root_type': root_type }, or_filters={ - 'account_name': account_name, - 'account_number': account_number + 'account_name': account.get('account_name'), + 'account_number': account.get('account_number') } ) if existing_accounts: return frappe.get_doc('Account', existing_accounts[0].name) - tax_group = get_or_create_tax_account_group(company, root_type) - full_account_data = { - 'doctype': 'Account', - 'account_name': account_name, - 'account_number': account_number, - 'tax_rate': account_data.get('tax_rate'), - 'company': company, - 'parent_account': tax_group, - 'is_group': 0, - 'report_type': 'Balance Sheet', - 'root_type': root_type, - 'account_type': 'Tax' - } - return frappe.get_doc(full_account_data).insert(ignore_permissions=True, ignore_mandatory=True) + tax_group = get_or_create_tax_group(company_name, root_type) + + account['doctype'] = 'Account' + account['company'] = company_name + account['parent_account'] = tax_group + account['report_type'] = 'Balance Sheet' + account['account_type'] = 'Tax' + account['root_type'] = root_type + account['is_group'] = 0 + + return frappe.get_doc(account).insert(ignore_permissions=True, ignore_mandatory=True) -def get_or_create_tax_account_group(company, root_type): - tax_group = frappe.db.get_value('Account', { +def get_or_create_tax_group(company_name, root_type): + # Look for a group account of type 'Tax' + tax_group_name = frappe.db.get_value('Account', { 'is_group': 1, 'root_type': root_type, 'account_type': 'Tax', - 'company': company + 'company': company_name }) - if tax_group: - return tax_group + if tax_group_name: + return tax_group_name - root = frappe.get_list('Account', { + # Look for a group account named 'Duties and Taxes' or 'Tax Assets' + account_name = _('Duties and Taxes') if root_type == 'Liability' else _('Tax Assets') + tax_group_name = frappe.db.get_value('Account', { 'is_group': 1, 'root_type': root_type, - 'company': company, + 'account_name': account_name, + 'company': company_name + }) + + if tax_group_name: + return tax_group_name + + # Create a new group account named 'Duties and Taxes' or 'Tax Assets' just + # below the root account + root_account = frappe.get_list('Account', { + 'is_group': 1, + 'root_type': root_type, + 'company': company_name, 'report_type': 'Balance Sheet', 'parent_account': ('is', 'not set') - }, limit=1)[0].name + }, limit=1)[0] - doc = frappe.get_doc({ + tax_group_account = frappe.get_doc({ 'doctype': 'Account', - 'company': company, + 'company': company_name, 'is_group': 1, 'report_type': 'Balance Sheet', 'root_type': root_type, 'account_type': 'Tax', - 'account_name': _('Duties and Taxes') if root_type == 'Liability' else _('Tax Assets'), - 'parent_account': root + 'account_name': account_name, + 'parent_account': root_account.name }).insert(ignore_permissions=True) - tax_group = doc.name + tax_group_name = tax_group_account.name - return tax_group + return tax_group_name From 535406cb0cdc83a5493bc0e62fecc3b8846be253 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 1 Mar 2021 11:32:39 +0530 Subject: [PATCH 294/449] fix: allow to select item code in batch naming --- erpnext/stock/doctype/batch/batch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py index c8424f13e1..8fdda565d2 100644 --- a/erpnext/stock/doctype/batch/batch.py +++ b/erpnext/stock/doctype/batch/batch.py @@ -93,7 +93,7 @@ class Batch(Document): if create_new_batch: if batch_number_series: - self.batch_id = make_autoname(batch_number_series) + self.batch_id = make_autoname(batch_number_series, doc=self) elif batch_uses_naming_series(): self.batch_id = self.get_name_from_naming_series() else: From 0623a3421009d35536308875e666a93d6b85264d Mon Sep 17 00:00:00 2001 From: Afshan <33727827+AfshanKhan@users.noreply.github.com> Date: Wed, 10 Mar 2021 09:46:38 +0530 Subject: [PATCH 295/449] fix: added supplier warehouse field back again (#24827) --- .../purchase_invoice/purchase_invoice.json | 16 ++++++++++++++-- erpnext/controllers/buying_controller.py | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index 451c936881..3ff0efe29e 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -58,6 +58,7 @@ "rejected_warehouse", "col_break_warehouse", "set_from_warehouse", + "supplier_warehouse", "is_subcontracted", "items_section", "update_stock", @@ -1350,7 +1351,7 @@ "options": "Company" }, { - "depends_on": "eval:doc.update_stock && (doc.is_subcontracted==\"Yes\" || doc.is_internal_supplier)", + "depends_on": "eval:doc.update_stock && doc.is_internal_supplier", "description": "Sets 'From Warehouse' in each row of the items table.", "fieldname": "set_from_warehouse", "fieldtype": "Link", @@ -1360,13 +1361,24 @@ "print_hide": 1, "print_width": "50px", "width": "50px" + }, + { + "depends_on": "eval:doc.update_stock && doc.is_subcontracted==\"Yes\"", + "fieldname": "supplier_warehouse", + "fieldtype": "Link", + "label": "Supplier Warehouse", + "no_copy": 1, + "options": "Warehouse", + "print_hide": 1, + "print_width": "50px", + "width": "50px" } ], "icon": "fa fa-file-text", "idx": 204, "is_submittable": 1, "links": [], - "modified": "2020-12-26 20:49:03.305063", + "modified": "2021-03-09 21:56:28.748582", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice", diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index ab1f02779b..305a162d12 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -288,7 +288,7 @@ class BuyingController(StockController): if self.is_subcontracted == "Yes": if self.doctype in ["Purchase Receipt", "Purchase Invoice"] and not self.supplier_warehouse: - frappe.throw(_("Supplier Warehouse mandatory for sub-contracted Purchase Receipt")) + frappe.throw(_("Supplier Warehouse mandatory for sub-contracted {0}").format(self.doctype)) for item in self.get("items"): if item in self.sub_contracted_items and not item.bom: From 0b29f87fa26ef68eaaba546a238129f32eae00a4 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 11 Mar 2021 16:02:23 +0530 Subject: [PATCH 296/449] feat(Non Profit): 80G Certificates and Donations (#24848) * feat(Non Profit): 80G Certificates and Donations * fix(Membership): Generate Invoice for membership webhook only if automation is enabled (#24849) --- .../doctype/payment_entry/payment_entry.js | 26 +- .../doctype/payment_entry/payment_entry.py | 23 +- .../__init__.py | 0 .../non_profit/doctype/donation/donation.js | 26 ++ .../non_profit/doctype/donation/donation.json | 156 +++++++++ .../non_profit/doctype/donation/donation.py | 215 +++++++++++++ .../doctype/donation/donation_dashboard.py | 16 + .../doctype/donation/test_donation.py | 76 +++++ erpnext/non_profit/doctype/donor/donor.json | 9 +- erpnext/non_profit/doctype/donor/donor.py | 5 + erpnext/non_profit/doctype/member/member.js | 2 +- erpnext/non_profit/doctype/member/member.py | 11 +- .../doctype/membership/membership.js | 4 +- .../doctype/membership/membership.json | 10 +- .../doctype/membership/membership.py | 96 ++++-- .../doctype/membership/test_membership.py | 63 ++-- .../membership_settings.json | 192 ----------- .../membership_type/membership_type.js | 4 +- .../doctype/non_profit_settings/__init__.py | 0 .../non_profit_settings.js} | 73 +++-- .../non_profit_settings.json | 273 ++++++++++++++++ .../non_profit_settings.py} | 21 +- .../test_non_profit_settings.py} | 2 +- .../workspace/non_profit/non_profit.json | 251 +++++++++++++++ erpnext/patches.txt | 2 + ...bership_settings_to_non_profit_settings.py | 22 ++ ...fields_for_80g_certificate_and_donation.py | 16 + .../tax_exemption_80g_certificate/__init__.py | 0 .../tax_exemption_80g_certificate.js | 67 ++++ .../tax_exemption_80g_certificate.json | 297 ++++++++++++++++++ .../tax_exemption_80g_certificate.py | 89 ++++++ .../test_tax_exemption_80g_certificate.py | 101 ++++++ .../__init__.py | 0 .../tax_exemption_80g_certificate_detail.json | 66 ++++ .../tax_exemption_80g_certificate_detail.py | 10 + erpnext/regional/india/setup.py | 26 +- .../80g_certificate_for_donation.json | 26 ++ .../80g_certificate_for_donation/__init__.py | 0 .../80g_certificate_for_membership.json | 26 ++ .../__init__.py | 0 .../operations/install_fixtures.py | 1 + 41 files changed, 1997 insertions(+), 306 deletions(-) rename erpnext/non_profit/doctype/{membership_settings => donation}/__init__.py (100%) create mode 100644 erpnext/non_profit/doctype/donation/donation.js create mode 100644 erpnext/non_profit/doctype/donation/donation.json create mode 100644 erpnext/non_profit/doctype/donation/donation.py create mode 100644 erpnext/non_profit/doctype/donation/donation_dashboard.py create mode 100644 erpnext/non_profit/doctype/donation/test_donation.py delete mode 100644 erpnext/non_profit/doctype/membership_settings/membership_settings.json create mode 100644 erpnext/non_profit/doctype/non_profit_settings/__init__.py rename erpnext/non_profit/doctype/{membership_settings/membership_settings.js => non_profit_settings/non_profit_settings.js} (50%) create mode 100644 erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.json rename erpnext/non_profit/doctype/{membership_settings/membership_settings.py => non_profit_settings/non_profit_settings.py} (51%) rename erpnext/non_profit/doctype/{membership_settings/test_membership_settings.py => non_profit_settings/test_non_profit_settings.py} (79%) create mode 100644 erpnext/non_profit/workspace/non_profit/non_profit.json create mode 100644 erpnext/patches/v13_0/rename_membership_settings_to_non_profit_settings.py create mode 100644 erpnext/patches/v13_0/setup_fields_for_80g_certificate_and_donation.py create mode 100644 erpnext/regional/doctype/tax_exemption_80g_certificate/__init__.py create mode 100644 erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.js create mode 100644 erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.json create mode 100644 erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py create mode 100644 erpnext/regional/doctype/tax_exemption_80g_certificate/test_tax_exemption_80g_certificate.py create mode 100644 erpnext/regional/doctype/tax_exemption_80g_certificate_detail/__init__.py create mode 100644 erpnext/regional/doctype/tax_exemption_80g_certificate_detail/tax_exemption_80g_certificate_detail.json create mode 100644 erpnext/regional/doctype/tax_exemption_80g_certificate_detail/tax_exemption_80g_certificate_detail.py create mode 100644 erpnext/regional/print_format/80g_certificate_for_donation/80g_certificate_for_donation.json create mode 100644 erpnext/regional/print_format/80g_certificate_for_donation/__init__.py create mode 100644 erpnext/regional/print_format/80g_certificate_for_membership/80g_certificate_for_membership.json create mode 100644 erpnext/regional/print_format/80g_certificate_for_membership/__init__.py diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index f5c488d0f9..6412772073 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -92,14 +92,16 @@ frappe.ui.form.on('Payment Entry', { }); frm.set_query("reference_doctype", "references", function() { - if (frm.doc.party_type=="Customer") { + if (frm.doc.party_type == "Customer") { var doctypes = ["Sales Order", "Sales Invoice", "Journal Entry", "Dunning"]; - } else if (frm.doc.party_type=="Supplier") { + } else if (frm.doc.party_type == "Supplier") { var doctypes = ["Purchase Order", "Purchase Invoice", "Journal Entry"]; - } else if (frm.doc.party_type=="Employee") { + } else if (frm.doc.party_type == "Employee") { var doctypes = ["Expense Claim", "Journal Entry"]; - } else if (frm.doc.party_type=="Student") { + } else if (frm.doc.party_type == "Student") { var doctypes = ["Fees"]; + } else if (frm.doc.party_type == "Donor") { + var doctypes = ["Donation"]; } else { var doctypes = ["Journal Entry"]; } @@ -128,7 +130,7 @@ frappe.ui.form.on('Payment Entry', { const child = locals[cdt][cdn]; const filters = {"docstatus": 1, "company": doc.company}; const party_type_doctypes = ['Sales Invoice', 'Sales Order', 'Purchase Invoice', - 'Purchase Order', 'Expense Claim', 'Fees', 'Dunning']; + 'Purchase Order', 'Expense Claim', 'Fees', 'Dunning', 'Donation']; if (in_list(party_type_doctypes, child.reference_doctype)) { filters[doc.party_type.toLowerCase()] = doc.party; @@ -281,7 +283,7 @@ frappe.ui.form.on('Payment Entry', { let party_types = Object.keys(frappe.boot.party_account_types); if(frm.doc.party_type && !party_types.includes(frm.doc.party_type)){ frm.set_value("party_type", ""); - frappe.throw(__("Party can only be one of "+ party_types.join(", "))); + frappe.throw(__("Party can only be one of {0}", [party_types.join(", ")])); } frm.set_query("party", function() { @@ -705,7 +707,8 @@ frappe.ui.form.on('Payment Entry', { (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") || (frm.doc.payment_type=="Pay" && frm.doc.party_type=="Supplier") || (frm.doc.payment_type=="Pay" && frm.doc.party_type=="Employee") || - (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Student") + (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Student") || + (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Donor") ) { if(total_positive_outstanding > total_negative_outstanding) if (!frm.doc.paid_amount) @@ -748,7 +751,8 @@ frappe.ui.form.on('Payment Entry', { (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") || (frm.doc.payment_type=="Pay" && frm.doc.party_type=="Supplier") || (frm.doc.payment_type=="Pay" && frm.doc.party_type=="Employee") || - (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Student") + (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Student") || + (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Donor") ) { if(total_positive_outstanding_including_order > paid_amount) { var remaining_outstanding = total_positive_outstanding_including_order - paid_amount; @@ -905,6 +909,12 @@ frappe.ui.form.on('Payment Entry', { frappe.msgprint(__("Row #{0}: Reference Document Type must be one of Expense Claim or Journal Entry", [row.idx])); return false; } + + if (frm.doc.party_type == "Donor" && row.reference_doctype != "Donation") { + frappe.model.set_value(row.doctype, row.name, "reference_doctype", null); + frappe.msgprint(__("Row #{0}: Reference Document Type must be Donation", [row.idx])); + return false; + } } if (row) { diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 31a4c8a387..203d06a41f 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -72,6 +72,7 @@ class PaymentEntry(AccountsController): self.update_outstanding_amounts() self.update_advance_paid() self.update_expense_claim() + self.update_donation() self.update_payment_schedule() self.set_status() @@ -82,6 +83,7 @@ class PaymentEntry(AccountsController): self.update_outstanding_amounts() self.update_advance_paid() self.update_expense_claim() + self.update_donation(cancel=1) self.delink_advance_entry_references() self.update_payment_schedule(cancel=1) self.set_payment_req_status() @@ -245,6 +247,8 @@ class PaymentEntry(AccountsController): valid_reference_doctypes = ("Expense Claim", "Journal Entry", "Employee Advance") elif self.party_type == "Shareholder": valid_reference_doctypes = ("Journal Entry") + elif self.party_type == "Donor": + valid_reference_doctypes = ("Donation") for d in self.get("references"): if not d.allocated_amount: @@ -614,6 +618,13 @@ class PaymentEntry(AccountsController): doc = frappe.get_doc("Expense Claim", d.reference_name) update_reimbursed_amount(doc, self.name) + def update_donation(self, cancel=0): + if self.payment_type == "Receive" and self.party_type == "Donor" and self.party: + for d in self.get("references"): + if d.reference_doctype=="Donation" and d.reference_name: + is_paid = 0 if cancel else 1 + frappe.db.set_value("Donation", d.reference_name, "paid", is_paid) + def on_recurring(self, reference_doc, auto_repeat_doc): self.reference_no = reference_doc.name self.reference_date = nowdate() @@ -913,6 +924,9 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre total_amount = ref_doc.get("grand_total") exchange_rate = 1 outstanding_amount = ref_doc.get("outstanding_amount") + elif reference_doctype == "Donation": + total_amount = ref_doc.get("amount") + exchange_rate = 1 elif reference_doctype == "Dunning": total_amount = ref_doc.get("dunning_amount") exchange_rate = 1 @@ -1162,8 +1176,10 @@ def set_party_type(dt): party_type = "Supplier" elif dt in ("Expense Claim", "Employee Advance"): party_type = "Employee" - elif dt in ("Fees"): + elif dt == "Fees": party_type = "Student" + elif dt == "Donation": + party_type = "Donor" return party_type def set_party_account(dt, dn, doc, party_type): @@ -1189,7 +1205,7 @@ def set_party_account_currency(dt, party_account, doc): return party_account_currency def set_payment_type(dt, doc): - if (dt == "Sales Order" or (dt in ("Sales Invoice", "Fees", "Dunning") and doc.outstanding_amount > 0)) \ + if (dt in ("Sales Order", "Donation") or (dt in ("Sales Invoice", "Fees", "Dunning") and doc.outstanding_amount > 0)) \ or (dt=="Purchase Invoice" and doc.outstanding_amount < 0): payment_type = "Receive" else: @@ -1222,6 +1238,9 @@ def set_grand_total_and_outstanding_amount(party_amount, dt, party_account_curre elif dt == "Dunning": grand_total = doc.grand_total outstanding_amount = doc.grand_total + elif dt == "Donation": + grand_total = doc.amount + outstanding_amount = doc.amount else: if party_account_currency == doc.company_currency: grand_total = flt(doc.get("base_rounded_total") or doc.base_grand_total) diff --git a/erpnext/non_profit/doctype/membership_settings/__init__.py b/erpnext/non_profit/doctype/donation/__init__.py similarity index 100% rename from erpnext/non_profit/doctype/membership_settings/__init__.py rename to erpnext/non_profit/doctype/donation/__init__.py diff --git a/erpnext/non_profit/doctype/donation/donation.js b/erpnext/non_profit/doctype/donation/donation.js new file mode 100644 index 0000000000..10e8220144 --- /dev/null +++ b/erpnext/non_profit/doctype/donation/donation.js @@ -0,0 +1,26 @@ +// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Donation', { + refresh: function(frm) { + if (frm.doc.docstatus === 1 && !frm.doc.paid) { + frm.add_custom_button(__('Create Payment Entry'), function() { + frm.events.make_payment_entry(frm); + }); + } + }, + + make_payment_entry: function(frm) { + return frappe.call({ + method: 'erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry', + args: { + 'dt': frm.doc.doctype, + 'dn': frm.doc.name + }, + callback: function(r) { + var doc = frappe.model.sync(r.message); + frappe.set_route('Form', doc[0].doctype, doc[0].name); + } + }); + }, +}); diff --git a/erpnext/non_profit/doctype/donation/donation.json b/erpnext/non_profit/doctype/donation/donation.json new file mode 100644 index 0000000000..6759569d54 --- /dev/null +++ b/erpnext/non_profit/doctype/donation/donation.json @@ -0,0 +1,156 @@ +{ + "actions": [], + "autoname": "naming_series:", + "creation": "2021-02-17 10:28:52.645731", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "naming_series", + "donor", + "donor_name", + "email", + "column_break_4", + "company", + "date", + "payment_details_section", + "paid", + "amount", + "mode_of_payment", + "razorpay_payment_id", + "amended_from" + ], + "fields": [ + { + "fieldname": "donor", + "fieldtype": "Link", + "label": "Donor", + "options": "Donor", + "reqd": 1 + }, + { + "fetch_from": "donor.donor_name", + "fieldname": "donor_name", + "fieldtype": "Data", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Donor Name", + "read_only": 1 + }, + { + "fetch_from": "donor.email", + "fieldname": "email", + "fieldtype": "Data", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Email", + "read_only": 1 + }, + { + "fieldname": "column_break_4", + "fieldtype": "Column Break" + }, + { + "fieldname": "date", + "fieldtype": "Date", + "label": "Date", + "reqd": 1 + }, + { + "fieldname": "payment_details_section", + "fieldtype": "Section Break", + "label": "Payment Details" + }, + { + "fieldname": "amount", + "fieldtype": "Currency", + "label": "Amount", + "reqd": 1 + }, + { + "fieldname": "mode_of_payment", + "fieldtype": "Link", + "label": "Mode of Payment", + "options": "Mode of Payment" + }, + { + "fieldname": "razorpay_payment_id", + "fieldtype": "Data", + "label": "Razorpay Payment ID", + "read_only": 1 + }, + { + "fieldname": "naming_series", + "fieldtype": "Select", + "label": "Naming Series", + "options": "NPO-DTN-.YYYY.-" + }, + { + "default": "0", + "fieldname": "paid", + "fieldtype": "Check", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Paid" + }, + { + "fieldname": "company", + "fieldtype": "Link", + "label": "Company", + "options": "Company", + "reqd": 1 + }, + { + "fieldname": "amended_from", + "fieldtype": "Link", + "label": "Amended From", + "no_copy": 1, + "options": "Donation", + "print_hide": 1, + "read_only": 1 + } + ], + "index_web_pages_for_search": 1, + "is_submittable": 1, + "links": [], + "modified": "2021-03-11 10:53:11.269005", + "modified_by": "Administrator", + "module": "Non Profit", + "name": "Donation", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "select": 1, + "share": 1, + "submit": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Non Profit Manager", + "select": 1, + "share": 1, + "submit": 1, + "write": 1 + } + ], + "search_fields": "donor_name, email", + "sort_field": "modified", + "sort_order": "DESC", + "title_field": "donor_name", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/non_profit/doctype/donation/donation.py b/erpnext/non_profit/doctype/donation/donation.py new file mode 100644 index 0000000000..e947588482 --- /dev/null +++ b/erpnext/non_profit/doctype/donation/donation.py @@ -0,0 +1,215 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +import six +import json +from frappe.model.document import Document +from frappe import _ +from frappe.utils import getdate, flt, get_link_to_form +from frappe.email import sendmail_to_system_managers +from erpnext.non_profit.doctype.membership.membership import verify_signature + +class Donation(Document): + def validate(self): + if not self.donor or not frappe.db.exists('Donor', self.donor): + # for web forms + user_type = frappe.db.get_value('User', frappe.session.user, 'user_type') + if user_type == 'Website User': + self.create_donor_for_website_user() + else: + frappe.throw(_('Please select a Member')) + + def create_donor_for_website_user(self): + donor_name = frappe.get_value('Donor', dict(email=frappe.session.user)) + + if not donor_name: + user = frappe.get_doc('User', frappe.session.user) + donor = frappe.get_doc(dict( + doctype='Donor', + donor_type=self.get('donor_type'), + email=frappe.session.user, + member_name=user.get_fullname() + )).insert(ignore_permissions=True) + donor_name = donor.name + + if self.get('__islocal'): + self.donor = donor_name + + def on_payment_authorized(self, *args, **kwargs): + self.load_from_db() + self.create_payment_entry() + + def create_payment_entry(self): + settings = frappe.get_doc('Non Profit Settings') + if not settings.automate_donation_payment_entries: + return + + if not settings.donation_payment_account: + frappe.throw(_('You need to set Payment Account for Donation in {0}').format( + get_link_to_form('Non Profit Settings', 'Non Profit Settings'))) + + from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry + + frappe.flags.ignore_account_permission = True + pe = get_payment_entry(dt=self.doctype, dn=self.name) + frappe.flags.ignore_account_permission = False + pe.paid_from = settings.donation_debit_account + pe.paid_to = settings.donation_payment_account + pe.reference_no = self.name + pe.reference_date = getdate() + pe.flags.ignore_mandatory = True + pe.insert() + pe.submit() + + +@frappe.whitelist(allow_guest=True) +def capture_razorpay_donations(*args, **kwargs): + """ + Creates Donation from Razorpay Webhook Request Data on payment.captured event + Creates Donor from email if not found + """ + data = frappe.request.get_data(as_text=True) + + try: + verify_signature(data, endpoint='Donation') + except Exception as e: + log = frappe.log_error(e, 'Donation Webhook Verification Error') + notify_failure(log) + return { 'status': 'Failed', 'reason': e } + + if isinstance(data, six.string_types): + data = json.loads(data) + data = frappe._dict(data) + + payment = data.payload.get('payment', {}).get('entity', {}) + payment = frappe._dict(payment) + + try: + if not data.event == 'payment.captured': + return + + donor = get_donor(payment.email) + if not donor: + donor = create_donor(payment) + + donation = create_donation(donor, payment) + donation.run_method('create_payment_entry') + + except Exception as e: + message = '{0}\n\n{1}\n\n{2}: {3}'.format(e, frappe.get_traceback(), _('Payment ID'), payment.id) + log = frappe.log_error(message, _('Error creating donation entry for {0}').format(donor.name)) + notify_failure(log) + return { 'status': 'Failed', 'reason': e } + + return { 'status': 'Success' } + + +def create_donation(donor, payment): + if not frappe.db.exists('Mode of Payment', payment.method): + create_mode_of_payment(payment.method) + + company = get_company_for_donations() + donation = frappe.get_doc({ + 'doctype': 'Donation', + 'company': company, + 'donor': donor.name, + 'donor_name': donor.donor_name, + 'email': donor.email, + 'date': getdate(), + 'amount': flt(payment.amount), + 'mode_of_payment': payment.method, + 'razorpay_payment_id': payment.id + }).insert(ignore_mandatory=True) + + donation.submit() + return donation + + +def get_donor(email): + donors = frappe.get_all('Donor', + filters={'email': email}, + order_by='creation desc') + + try: + return frappe.get_doc('Donor', donors[0]['name']) + except Exception: + return None + + +@frappe.whitelist() +def create_donor(payment): + donor_details = frappe._dict(payment) + donor_type = frappe.db.get_single_value('Non Profit Settings', 'default_donor_type') + + donor = frappe.new_doc('Donor') + donor.update({ + 'donor_name': donor_details.email, + 'donor_type': donor_type, + 'email': donor_details.email, + 'contact': donor_details.contact + }) + + if donor_details.get('notes'): + donor = get_additional_notes(donor, donor_details) + + donor.insert(ignore_mandatory=True) + return donor + + +def get_company_for_donations(): + company = frappe.db.get_single_value('Non Profit Settings', 'donation_company') + if not company: + from erpnext.healthcare.setup import get_company + company = get_company() + return company + + +def get_additional_notes(donor, donor_details): + if type(donor_details.notes) == dict: + for k, v in donor_details.notes.items(): + notes = '\n'.join('{}: {}'.format(k, v)) + + # extract donor name from notes + if 'name' in k.lower(): + donor.update({ + 'donor_name': donor_details.notes.get(k) + }) + + # extract pan from notes + if 'pan' in k.lower(): + donor.update({ + 'pan_number': donor_details.notes.get(k) + }) + + donor.add_comment('Comment', notes) + + elif type(donor_details.notes) == str: + donor.add_comment('Comment', donor_details.notes) + + return donor + + +def create_mode_of_payment(method): + frappe.get_doc({ + 'doctype': 'Mode of Payment', + 'mode_of_payment': method + }).insert(ignore_mandatory=True) + + +def notify_failure(log): + try: + content = ''' + Dear System Manager, + Razorpay webhook for creating donation failed due to some reason. + Please check the error log linked below + Error Log: {0} + Regards, Administrator + '''.format(get_link_to_form('Error Log', log.name)) + + sendmail_to_system_managers(_('[Important] [ERPNext] Razorpay donation webhook failed, please check.'), content) + except Exception: + pass + diff --git a/erpnext/non_profit/doctype/donation/donation_dashboard.py b/erpnext/non_profit/doctype/donation/donation_dashboard.py new file mode 100644 index 0000000000..7e25c8d217 --- /dev/null +++ b/erpnext/non_profit/doctype/donation/donation_dashboard.py @@ -0,0 +1,16 @@ +from __future__ import unicode_literals +from frappe import _ + +def get_data(): + return { + 'fieldname': 'donation', + 'non_standard_fieldnames': { + 'Payment Entry': 'reference_name' + }, + 'transactions': [ + { + 'label': _('Payment'), + 'items': ['Payment Entry'] + } + ] + } \ No newline at end of file diff --git a/erpnext/non_profit/doctype/donation/test_donation.py b/erpnext/non_profit/doctype/donation/test_donation.py new file mode 100644 index 0000000000..c6a534dac3 --- /dev/null +++ b/erpnext/non_profit/doctype/donation/test_donation.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +import frappe +import unittest +from erpnext.non_profit.doctype.donation.donation import create_donation + +class TestDonation(unittest.TestCase): + def setUp(self): + create_donor_type() + settings = frappe.get_doc('Non Profit Settings') + settings.company = '_Test Company' + settings.donation_company = '_Test Company' + settings.default_donor_type = '_Test Donor' + settings.automate_donation_payment_entries = 1 + settings.donation_debit_account = 'Debtors - _TC' + settings.donation_payment_account = 'Cash - _TC' + settings.creation_user = 'Administrator' + settings.flags.ignore_permissions = True + settings.save() + + def test_payment_entry_for_donations(self): + donor = create_donor() + create_mode_of_payment() + payment = frappe._dict({ + 'amount': 100, + 'method': 'Debit Card', + 'id': 'pay_MeXAmsgeKOhq7O' + }) + donation = create_donation(donor, payment) + + self.assertTrue(donation.name) + + # Naive test to check if at all payment entry is generated + # This method is actually triggered from Payment Gateway + # In any case if details were missing, this would throw an error + donation.on_payment_authorized() + donation.reload() + + self.assertEquals(donation.paid, 1) + self.assertTrue(frappe.db.exists('Payment Entry', {'reference_no': donation.name})) + + +def create_donor_type(): + if not frappe.db.exists('Donor Type', '_Test Donor'): + frappe.get_doc({ + 'doctype': 'Donor Type', + 'donor_type': '_Test Donor' + }).insert() + + +def create_donor(): + donor = frappe.db.exists('Donor', 'donor@test.com') + if donor: + return frappe.get_doc('Donor', 'donor@test.com') + else: + return frappe.get_doc({ + 'doctype': 'Donor', + 'donor_name': '_Test Donor', + 'donor_type': '_Test Donor', + 'email': 'donor@test.com' + }).insert() + + +def create_mode_of_payment(): + if not frappe.db.exists('Mode of Payment', 'Debit Card'): + frappe.get_doc({ + 'doctype': 'Mode of Payment', + 'mode_of_payment': 'Debit Card', + 'accounts': [{ + 'company': '_Test Company', + 'default_account': 'Cash - _TC' + }] + }).insert() \ No newline at end of file diff --git a/erpnext/non_profit/doctype/donor/donor.json b/erpnext/non_profit/doctype/donor/donor.json index 96392658f1..72f24ef922 100644 --- a/erpnext/non_profit/doctype/donor/donor.json +++ b/erpnext/non_profit/doctype/donor/donor.json @@ -76,8 +76,13 @@ } ], "image_field": "image", - "links": [], - "modified": "2020-09-16 23:46:04.083274", + "links": [ + { + "link_doctype": "Donation", + "link_fieldname": "donor" + } + ], + "modified": "2021-02-17 16:36:33.470731", "modified_by": "Administrator", "module": "Non Profit", "name": "Donor", diff --git a/erpnext/non_profit/doctype/donor/donor.py b/erpnext/non_profit/doctype/donor/donor.py index 9121d0cdfc..fb70e59575 100644 --- a/erpnext/non_profit/doctype/donor/donor.py +++ b/erpnext/non_profit/doctype/donor/donor.py @@ -11,3 +11,8 @@ class Donor(Document): """Load address and contacts in `__onload`""" load_address_and_contact(self) + def validate(self): + from frappe.utils import validate_email_address + if self.email: + validate_email_address(self.email.strip(), True) + diff --git a/erpnext/non_profit/doctype/member/member.js b/erpnext/non_profit/doctype/member/member.js index 199dcfc04f..6b8f1b1deb 100644 --- a/erpnext/non_profit/doctype/member/member.js +++ b/erpnext/non_profit/doctype/member/member.js @@ -3,7 +3,7 @@ frappe.ui.form.on('Member', { setup: function(frm) { - frappe.db.get_single_value("Membership Settings", "enable_razorpay").then(val => { + frappe.db.get_single_value('Non Profit Settings', 'enable_razorpay_for_memberships').then(val => { if (val && (frm.doc.subscription_id || frm.doc.customer_id)) { frm.set_df_property('razorpay_details_section', 'hidden', false); } diff --git a/erpnext/non_profit/doctype/member/member.py b/erpnext/non_profit/doctype/member/member.py index 04b99f93f2..3ba2ee71c6 100644 --- a/erpnext/non_profit/doctype/member/member.py +++ b/erpnext/non_profit/doctype/member/member.py @@ -7,7 +7,7 @@ import frappe from frappe import _ from frappe.model.document import Document from frappe.contacts.address_and_contact import load_address_and_contact -from frappe.utils import cint +from frappe.utils import cint, get_link_to_form from frappe.integrations.utils import get_payment_gateway_controller from erpnext.non_profit.doctype.membership_type.membership_type import get_membership_type @@ -26,9 +26,10 @@ class Member(Document): validate_email_address(email.strip(), True) def setup_subscription(self): - membership_settings = frappe.get_doc("Membership Settings") - if not membership_settings.enable_razorpay: - frappe.throw("Please enable Razorpay to setup subscription") + non_profit_settings = frappe.get_doc('Non Profit Settings') + if not non_profit_settings.enable_razorpay_for_memberships: + frappe.throw('Please check Enable Razorpay for Memberships in {0} to setup subscription').format( + get_link_to_form('Non Profit Settings', 'Non Profit Settings')) controller = get_payment_gateway_controller("Razorpay") settings = controller.get_settings({}) @@ -40,7 +41,7 @@ class Member(Document): subscription_details = { "plan_id": plan_id, - "billing_frequency": cint(membership_settings.billing_frequency), + "billing_frequency": cint(non_profit_settings.billing_frequency), "customer_notify": 1 } diff --git a/erpnext/non_profit/doctype/membership/membership.js b/erpnext/non_profit/doctype/membership/membership.js index 573ac3319a..31872048a0 100644 --- a/erpnext/non_profit/doctype/membership/membership.js +++ b/erpnext/non_profit/doctype/membership/membership.js @@ -3,7 +3,7 @@ frappe.ui.form.on('Membership', { setup: function(frm) { - frappe.db.get_single_value("Membership Settings", "enable_razorpay").then(val => { + frappe.db.get_single_value("Non Profit Settings", "enable_razorpay_for_memberships").then(val => { if (val) frm.set_df_property("razorpay_details_section", "hidden", false); }) }, @@ -26,7 +26,7 @@ frappe.ui.form.on('Membership', { }); }); - frappe.db.get_single_value("Membership Settings", "send_email").then(val => { + frappe.db.get_single_value("Non Profit Settings", "send_email").then(val => { if (val) frm.add_custom_button("Send Acknowledgement", () => { frm.call("send_acknowlement").then(() => { frm.reload_doc(); diff --git a/erpnext/non_profit/doctype/membership/membership.json b/erpnext/non_profit/doctype/membership/membership.json index 6da053f9fc..11d32f9c2b 100644 --- a/erpnext/non_profit/doctype/membership/membership.json +++ b/erpnext/non_profit/doctype/membership/membership.json @@ -10,6 +10,7 @@ "member_name", "membership_type", "column_break_3", + "company", "membership_status", "membership_validity_section", "from_date", @@ -132,11 +133,18 @@ "fieldtype": "Data", "label": "Member Name", "read_only": 1 + }, + { + "fieldname": "company", + "fieldtype": "Link", + "label": "Company", + "options": "Company", + "reqd": 1 } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-01-21 16:31:20.032656", + "modified": "2021-02-19 14:33:44.925122", "modified_by": "Administrator", "module": "Non Profit", "name": "Membership", diff --git a/erpnext/non_profit/doctype/membership/membership.py b/erpnext/non_profit/doctype/membership/membership.py index c113b80d56..191281f4ce 100644 --- a/erpnext/non_profit/doctype/membership/membership.py +++ b/erpnext/non_profit/doctype/membership/membership.py @@ -6,6 +6,7 @@ from __future__ import unicode_literals import json import frappe import six +import os from datetime import datetime from frappe.model.document import Document from frappe.email import sendmail_to_system_managers @@ -58,7 +59,7 @@ class Membership(Document): else: self.from_date = nowdate() - if frappe.db.get_single_value("Membership Settings", "billing_cycle") == "Yearly": + if frappe.db.get_single_value("Non Profit Settings", "billing_cycle") == "Yearly": self.to_date = add_years(self.from_date, 1) else: self.to_date = add_months(self.from_date, 1) @@ -68,9 +69,9 @@ class Membership(Document): return self.load_from_db() self.db_set("paid", 1) - settings = frappe.get_doc("Membership Settings") - if settings.enable_invoicing and settings.create_for_web_forms: - self.generate_invoice(with_payment_entry=settings.make_payment_entry, save=True) + settings = frappe.get_doc("Non Profit Settings") + if settings.allow_invoicing and settings.automate_membership_invoicing: + self.generate_invoice(with_payment_entry=settings.automate_membership_payment_entries, save=True) def generate_invoice(self, save=True, with_payment_entry=False): @@ -85,7 +86,7 @@ class Membership(Document): frappe.throw(_("No customer linked to member {0}").format(frappe.bold(self.member))) plan = frappe.get_doc("Membership Type", self.membership_type) - settings = frappe.get_doc("Membership Settings") + settings = frappe.get_doc("Non Profit Settings") self.validate_membership_type_and_settings(plan, settings) invoice = make_invoice(self, member, plan, settings) @@ -102,7 +103,7 @@ class Membership(Document): def validate_membership_type_and_settings(self, plan, settings): settings_link = get_link_to_form("Membership Type", self.membership_type) - if not settings.debit_account: + if not settings.membership_debit_account: frappe.throw(_("You need to set Debit Account in {0}").format(settings_link)) if not settings.company: @@ -113,25 +114,26 @@ class Membership(Document): get_link_to_form("Membership Type", self.membership_type))) def make_payment_entry(self, settings, invoice): - if not settings.payment_account: - frappe.throw(_("You need to set Payment Account in {0}").format( - get_link_to_form("Membership Type", self.membership_type))) + if not settings.membership_payment_account: + frappe.throw(_("You need to set Payment Account for Membership in {0}").format( + get_link_to_form("Non Profit Settings", "Non Profit Settings"))) from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry frappe.flags.ignore_account_permission = True pe = get_payment_entry(dt="Sales Invoice", dn=invoice.name, bank_amount=invoice.grand_total) frappe.flags.ignore_account_permission=False - pe.paid_to = settings.payment_account + pe.paid_to = settings.membership_payment_account pe.reference_no = self.name pe.reference_date = getdate() - pe.save(ignore_permissions=True) + pe.flags.ignore_mandatory = True + pe.save() pe.submit() def send_acknowlement(self): - settings = frappe.get_doc("Membership Settings") + settings = frappe.get_doc("Non Profit Settings") if not settings.send_email: frappe.throw(_("You need to enable Send Acknowledge Email in {0}").format( - get_link_to_form("Membership Settings", "Membership Settings"))) + get_link_to_form("Non Profit Settings", "Non Profit Settings"))) member = frappe.get_doc("Member", self.member) if not member.email_id: @@ -170,7 +172,7 @@ def make_invoice(membership, member, plan, settings): invoice = frappe.get_doc({ "doctype": "Sales Invoice", "customer": member.customer, - "debit_to": settings.debit_account, + "debit_to": settings.membership_debit_account, "currency": membership.currency, "company": settings.company, "is_pos": 0, @@ -183,7 +185,7 @@ def make_invoice(membership, member, plan, settings): ] }) invoice.set_missing_values() - invoice.insert(ignore_permissions=True) + invoice.insert() invoice.submit() frappe.msgprint(_("Sales Invoice created successfully")) @@ -203,17 +205,18 @@ def get_member_based_on_subscription(subscription_id, email): return None -def verify_signature(data): - if frappe.flags.in_test: +def verify_signature(data, endpoint="Membership"): + if frappe.flags.in_test or os.environ.get("CI"): return True signature = frappe.request.headers.get("X-Razorpay-Signature") - settings = frappe.get_doc("Membership Settings") - key = settings.get_webhook_secret() + settings = frappe.get_doc("Non Profit Settings") + key = settings.get_webhook_secret(endpoint) controller = frappe.get_doc("Razorpay Settings") controller.verify_signature(data, signature, key) + frappe.set_user(settings.creation_user) @frappe.whitelist(allow_guest=True) @@ -222,7 +225,7 @@ def trigger_razorpay_subscription(*args, **kwargs): try: verify_signature(data) except Exception as e: - log = frappe.log_error(e, "Webhook Verification Error") + log = frappe.log_error(e, "Membership Webhook Verification Error") notify_failure(log) return { "status": "Failed", "reason": e} @@ -250,16 +253,15 @@ def trigger_razorpay_subscription(*args, **kwargs): member.subscription_id = subscription.id member.customer_id = payment.customer_id - if subscription.notes and type(subscription.notes) == dict: - notes = "\n".join("{}: {}".format(k, v) for k, v in subscription.notes.items()) - member.add_comment("Comment", notes) - elif subscription.notes and type(subscription.notes) == str: - member.add_comment("Comment", subscription.notes) + if subscription.get("notes"): + member = get_additional_notes(member, subscription) + company = get_company_for_memberships() # Update Membership membership = frappe.new_doc("Membership") membership.update({ + "company": company, "member": member.name, "membership_status": "Current", "membership_type": member.membership_type, @@ -270,13 +272,20 @@ def trigger_razorpay_subscription(*args, **kwargs): "to_date": datetime.fromtimestamp(subscription.current_end), "amount": payment.amount / 100 # Convert to rupees from paise }) - membership.insert(ignore_permissions=True) + membership.flags.ignore_mandatory = True + membership.insert() # Update membership values member.subscription_start = datetime.fromtimestamp(subscription.start_at) member.subscription_end = datetime.fromtimestamp(subscription.end_at) member.subscription_activated = 1 - member.save(ignore_permissions=True) + member.flags.ignore_mandatory = True + member.save() + + settings = frappe.get_doc("Non Profit Settings") + if settings.allow_invoicing and settings.automate_membership_invoicing: + membership.generate_invoice(with_payment_entry=settings.automate_membership_payment_entries, save=True) + except Exception as e: message = "{0}\n\n{1}\n\n{2}: {3}".format(e, frappe.get_traceback(), __("Payment ID"), payment.id) log = frappe.log_error(message, _("Error creating membership entry for {0}").format(member.name)) @@ -286,6 +295,39 @@ def trigger_razorpay_subscription(*args, **kwargs): return { "status": "Success" } +def get_company_for_memberships(): + company = frappe.db.get_single_value("Non Profit Settings", "company") + if not company: + from erpnext.healthcare.setup import get_company + company = get_company() + return company + + +def get_additional_notes(member, subscription): + if type(subscription.notes) == dict: + for k, v in subscription.notes.items(): + notes = "\n".join("{}: {}".format(k, v)) + + # extract member name from notes + if "name" in k.lower(): + member.update({ + "member_name": subscription.notes.get(k) + }) + + # extract pan number from notes + if "pan" in k.lower(): + member.update({ + "pan_number": subscription.notes.get(k) + }) + + member.add_comment("Comment", notes) + + elif type(subscription.notes) == str: + member.add_comment("Comment", subscription.notes) + + return member + + def notify_failure(log): try: content = """ diff --git a/erpnext/non_profit/doctype/membership/test_membership.py b/erpnext/non_profit/doctype/membership/test_membership.py index ff7e6c473c..31da792e53 100644 --- a/erpnext/non_profit/doctype/membership/test_membership.py +++ b/erpnext/non_profit/doctype/membership/test_membership.py @@ -10,33 +10,7 @@ from frappe.utils import nowdate, add_months class TestMembership(unittest.TestCase): def setUp(self): - # Get default company - company = frappe.get_doc("Company", erpnext.get_default_company()) - - # update membership settings - settings = frappe.get_doc("Membership Settings") - # Enable razorpay - settings.enable_razorpay = 1 - settings.billing_cycle = "Monthly" - settings.billing_frequency = 24 - # Enable invoicing - settings.enable_invoicing = 1 - settings.make_payment_entry = 1 - settings.company = company.name - settings.payment_account = company.default_cash_account - settings.debit_account = company.default_receivable_account - settings.save() - - # make test plan - if not frappe.db.exists("Membership Type", "_rzpy_test_milythm"): - plan = frappe.new_doc("Membership Type") - plan.membership_type = "_rzpy_test_milythm" - plan.amount = 100 - plan.razorpay_plan_id = "_rzpy_test_milythm" - plan.linked_item = create_item("_Test Item for Non Profit Membership").name - plan.insert() - else: - plan = frappe.get_doc("Membership Type", "_rzpy_test_milythm") + plan = setup_membership() # make test member self.member_doc = create_member(frappe._dict({ @@ -78,7 +52,7 @@ class TestMembership(unittest.TestCase): }) def set_config(key, value): - frappe.db.set_value("Membership Settings", None, key, value) + frappe.db.set_value("Non Profit Settings", None, key, value) def make_membership(member, payload={}): data = { @@ -109,3 +83,36 @@ def create_item(item_code): else: item = frappe.get_doc("Item", item_code) return item + +def setup_membership(): + # Get default company + company = frappe.get_doc("Company", erpnext.get_default_company()) + + # update non profit settings + settings = frappe.get_doc("Non Profit Settings") + # Enable razorpay + settings.enable_razorpay_for_memberships = 1 + settings.billing_cycle = "Monthly" + settings.billing_frequency = 24 + # Enable invoicing + settings.allow_invoicing = 1 + settings.automate_membership_payment_entries = 1 + settings.company = company.name + settings.donation_company = company.name + settings.membership_payment_account = company.default_cash_account + settings.membership_debit_account = company.default_receivable_account + settings.flags.ignore_mandatory = True + settings.save() + + # make test plan + if not frappe.db.exists("Membership Type", "_rzpy_test_milythm"): + plan = frappe.new_doc("Membership Type") + plan.membership_type = "_rzpy_test_milythm" + plan.amount = 100 + plan.razorpay_plan_id = "_rzpy_test_milythm" + plan.linked_item = create_item("_Test Item for Non Profit Membership").name + plan.insert() + else: + plan = frappe.get_doc("Membership Type", "_rzpy_test_milythm") + + return plan \ No newline at end of file diff --git a/erpnext/non_profit/doctype/membership_settings/membership_settings.json b/erpnext/non_profit/doctype/membership_settings/membership_settings.json deleted file mode 100644 index 3887b0a2be..0000000000 --- a/erpnext/non_profit/doctype/membership_settings/membership_settings.json +++ /dev/null @@ -1,192 +0,0 @@ -{ - "actions": [], - "creation": "2020-03-29 12:57:03.005120", - "doctype": "DocType", - "editable_grid": 1, - "engine": "InnoDB", - "field_order": [ - "enable_razorpay", - "razorpay_settings_section", - "billing_cycle", - "billing_frequency", - "webhook_secret", - "column_break_6", - "enable_invoicing", - "create_for_web_forms", - "make_payment_entry", - "company", - "debit_account", - "payment_account", - "column_break_9", - "send_email", - "send_invoice", - "membership_print_format", - "inv_print_format", - "email_template" - ], - "fields": [ - { - "fieldname": "billing_cycle", - "fieldtype": "Select", - "label": "Billing Cycle", - "options": "Monthly\nYearly" - }, - { - "default": "0", - "fieldname": "enable_razorpay", - "fieldtype": "Check", - "label": "Enable RazorPay For Memberships" - }, - { - "depends_on": "eval:doc.enable_razorpay", - "fieldname": "razorpay_settings_section", - "fieldtype": "Section Break", - "label": "RazorPay Settings" - }, - { - "description": "The number of billing cycles for which the customer should be charged. For example, if a customer is buying a 1-year membership that should be billed on a monthly basis, this value should be 12.", - "fieldname": "billing_frequency", - "fieldtype": "Int", - "label": "Billing Frequency" - }, - { - "fieldname": "webhook_secret", - "fieldtype": "Password", - "label": "Webhook Secret", - "read_only": 1 - }, - { - "fieldname": "column_break_6", - "fieldtype": "Section Break", - "label": "Invoicing" - }, - { - "depends_on": "eval:doc.enable_invoicing", - "fieldname": "debit_account", - "fieldtype": "Link", - "label": "Debit Account", - "mandatory_depends_on": "eval:doc.enable_auto_invoicing", - "options": "Account" - }, - { - "fieldname": "column_break_9", - "fieldtype": "Column Break" - }, - { - "depends_on": "eval:doc.enable_invoicing", - "fieldname": "company", - "fieldtype": "Link", - "label": "Company", - "mandatory_depends_on": "eval:doc.enable_auto_invoicing", - "options": "Company" - }, - { - "default": "0", - "depends_on": "eval:doc.enable_invoicing && doc.send_email", - "fieldname": "send_invoice", - "fieldtype": "Check", - "label": "Send Invoice with Email" - }, - { - "default": "0", - "fieldname": "send_email", - "fieldtype": "Check", - "label": "Send Membership Acknowledgement" - }, - { - "depends_on": "eval: doc.send_invoice", - "fieldname": "inv_print_format", - "fieldtype": "Link", - "label": "Invoice Print Format", - "mandatory_depends_on": "eval: doc.send_invoice", - "options": "Print Format" - }, - { - "depends_on": "eval:doc.send_email", - "fieldname": "membership_print_format", - "fieldtype": "Link", - "label": "Membership Print Format", - "options": "Print Format" - }, - { - "depends_on": "eval:doc.send_email", - "fieldname": "email_template", - "fieldtype": "Link", - "label": "Email Template", - "mandatory_depends_on": "eval:doc.send_email", - "options": "Email Template" - }, - { - "default": "0", - "fieldname": "enable_invoicing", - "fieldtype": "Check", - "label": "Enable Invoicing", - "mandatory_depends_on": "eval:doc.send_invoice || doc.make_payment_entry" - }, - { - "default": "0", - "depends_on": "eval:doc.enable_invoicing", - "description": "Auto creates Payment Entry for Sales Invoices created for Membership from web forms.", - "fieldname": "make_payment_entry", - "fieldtype": "Check", - "label": "Make Payment Entry" - }, - { - "depends_on": "eval:doc.make_payment_entry", - "fieldname": "payment_account", - "fieldtype": "Link", - "label": "Payment To", - "mandatory_depends_on": "eval:doc.make_payment_entry", - "options": "Account" - }, - { - "default": "0", - "depends_on": "eval:doc.enable_invoicing", - "description": "Automatically create an invoice when payment is authorized from a web form entry", - "fieldname": "create_for_web_forms", - "fieldtype": "Check", - "label": "Auto Create Invoice for Web Forms" - } - ], - "index_web_pages_for_search": 1, - "issingle": 1, - "links": [], - "modified": "2021-01-21 19:57:53.213286", - "modified_by": "Administrator", - "module": "Non Profit", - "name": "Membership Settings", - "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "print": 1, - "read": 1, - "role": "System Manager", - "share": 1, - "write": 1 - }, - { - "create": 1, - "delete": 1, - "email": 1, - "print": 1, - "read": 1, - "role": "Non Profit Manager", - "share": 1, - "write": 1 - }, - { - "email": 1, - "print": 1, - "read": 1, - "role": "Non Profit Member", - "share": 1 - } - ], - "quick_entry": 1, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1 -} \ No newline at end of file diff --git a/erpnext/non_profit/doctype/membership_type/membership_type.js b/erpnext/non_profit/doctype/membership_type/membership_type.js index 91a5cb74ba..2f2427629c 100644 --- a/erpnext/non_profit/doctype/membership_type/membership_type.js +++ b/erpnext/non_profit/doctype/membership_type/membership_type.js @@ -3,11 +3,11 @@ frappe.ui.form.on('Membership Type', { refresh: function (frm) { - frappe.db.get_single_value('Membership Settings', 'enable_razorpay').then(val => { + frappe.db.get_single_value('Non Profit Settings', 'enable_razorpay_for_memberships').then(val => { if (val) frm.set_df_property('razorpay_plan_id', 'hidden', false); }); - frappe.db.get_single_value('Membership Settings', 'enable_invoicing').then(val => { + frappe.db.get_single_value('Non Profit Settings', 'allow_invoicing').then(val => { if (val) frm.set_df_property('linked_item', 'hidden', false); }); diff --git a/erpnext/non_profit/doctype/non_profit_settings/__init__.py b/erpnext/non_profit/doctype/non_profit_settings/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/non_profit/doctype/membership_settings/membership_settings.js b/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.js similarity index 50% rename from erpnext/non_profit/doctype/membership_settings/membership_settings.js rename to erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.js index c95aab2a7a..cff92b42ab 100644 --- a/erpnext/non_profit/doctype/membership_settings/membership_settings.js +++ b/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.js @@ -1,16 +1,8 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on("Membership Settings", { +frappe.ui.form.on("Non Profit Settings", { refresh: function(frm) { - if (frm.doc.webhook_secret) { - frm.add_custom_button(__("Revoke "), () => { - frm.call("revoke_key").then(() => { - frm.refresh(); - }) - }); - } - frm.set_query("inv_print_format", function() { return { filters: { @@ -37,7 +29,7 @@ frappe.ui.form.on("Membership Settings", { }; }); - frm.set_query("payment_account", function () { + frm.set_query("membership_payment_account", function () { var account_types = ["Bank", "Cash"]; return { filters: { @@ -51,31 +43,70 @@ frappe.ui.form.on("Membership Settings", { let docs_url = "https://docs.erpnext.com/docs/user/manual/en/non_profit/membership"; frm.set_intro(__("You can learn more about memberships in the manual. ") + `${__('ERPNext Docs')}`, true); - - frm.trigger("add_generate_button"); - frm.trigger("add_copy_buttonn"); + frm.trigger("setup_buttons_for_membership"); + frm.trigger("setup_buttons_for_donation"); }, - add_generate_button: function(frm) { + setup_buttons_for_membership: function(frm) { let label; - if (frm.doc.webhook_secret) { + if (frm.doc.membership_webhook_secret) { + + frm.add_custom_button(__("Copy Webhook URL"), () => { + frappe.utils.copy_to_clipboard(`https://${frappe.boot.sitename}/api/method/erpnext.non_profit.doctype.membership.membership.trigger_razorpay_subscription`); + }, __("Memberships")); + + frm.add_custom_button(__("Revoke Key"), () => { + frm.call("revoke_key", { + key: "membership_webhook_secret" + }).then(() => { + frm.refresh(); + }); + }, __("Memberships")); + label = __("Regenerate Webhook Secret"); + } else { label = __("Generate Webhook Secret"); } + frm.add_custom_button(label, () => { - frm.call("generate_webhook_key").then(() => { + frm.call("generate_webhook_secret", { + field: "membership_webhook_secret" + }).then(() => { frm.refresh(); }); - }); + }, __("Memberships")); }, - add_copy_buttonn: function(frm) { - if (frm.doc.webhook_secret) { + setup_buttons_for_donation: function(frm) { + let label; + + if (frm.doc.donation_webhook_secret) { + label = __("Regenerate Webhook Secret"); + frm.add_custom_button(__("Copy Webhook URL"), () => { - frappe.utils.copy_to_clipboard(`https://${frappe.boot.sitename}/api/method/erpnext.non_profit.doctype.membership.membership.trigger_razorpay_subscription`); - }); + frappe.utils.copy_to_clipboard(`https://${frappe.boot.sitename}/api/method/erpnext.non_profit.doctype.donation.donation.capture_razorpay_donations`); + }, __("Donations")); + + frm.add_custom_button(__("Revoke Key"), () => { + frm.call("revoke_key", { + key: "donation_webhook_secret" + }).then(() => { + frm.refresh(); + }); + }, __("Donations")); + + } else { + label = __("Generate Webhook Secret"); } + + frm.add_custom_button(label, () => { + frm.call("generate_webhook_secret", { + field: "donation_webhook_secret" + }).then(() => { + frm.refresh(); + }); + }, __("Donations")); } }); diff --git a/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.json b/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.json new file mode 100644 index 0000000000..25ff0c1bb0 --- /dev/null +++ b/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.json @@ -0,0 +1,273 @@ +{ + "actions": [], + "creation": "2020-03-29 12:57:03.005120", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "enable_razorpay_for_memberships", + "razorpay_settings_section", + "billing_cycle", + "billing_frequency", + "membership_webhook_secret", + "column_break_6", + "allow_invoicing", + "automate_membership_invoicing", + "automate_membership_payment_entries", + "company", + "membership_debit_account", + "membership_payment_account", + "column_break_9", + "send_email", + "send_invoice", + "membership_print_format", + "inv_print_format", + "email_template", + "donation_settings_section", + "donation_company", + "default_donor_type", + "donation_webhook_secret", + "column_break_22", + "automate_donation_payment_entries", + "donation_debit_account", + "donation_payment_account", + "section_break_27", + "creation_user" + ], + "fields": [ + { + "fieldname": "billing_cycle", + "fieldtype": "Select", + "label": "Billing Cycle", + "options": "Monthly\nYearly" + }, + { + "depends_on": "eval:doc.enable_razorpay_for_memberships", + "fieldname": "razorpay_settings_section", + "fieldtype": "Section Break", + "label": "RazorPay Settings for Memberships" + }, + { + "description": "The number of billing cycles for which the customer should be charged. For example, if a customer is buying a 1-year membership that should be billed on a monthly basis, this value should be 12.", + "fieldname": "billing_frequency", + "fieldtype": "Int", + "label": "Billing Frequency" + }, + { + "fieldname": "column_break_6", + "fieldtype": "Section Break", + "label": "Membership Invoicing" + }, + { + "fieldname": "column_break_9", + "fieldtype": "Column Break" + }, + { + "description": "This company will be set for the Memberships created via webhook.", + "fieldname": "company", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Company", + "options": "Company", + "reqd": 1 + }, + { + "default": "0", + "depends_on": "eval:doc.allow_invoicing && doc.send_email", + "fieldname": "send_invoice", + "fieldtype": "Check", + "label": "Send Invoice with Email" + }, + { + "default": "0", + "fieldname": "send_email", + "fieldtype": "Check", + "label": "Send Membership Acknowledgement" + }, + { + "depends_on": "eval: doc.send_invoice", + "fieldname": "inv_print_format", + "fieldtype": "Link", + "label": "Invoice Print Format", + "mandatory_depends_on": "eval: doc.send_invoice", + "options": "Print Format" + }, + { + "depends_on": "eval:doc.send_email", + "fieldname": "membership_print_format", + "fieldtype": "Link", + "label": "Membership Print Format", + "options": "Print Format" + }, + { + "depends_on": "eval:doc.send_email", + "fieldname": "email_template", + "fieldtype": "Link", + "label": "Email Template", + "mandatory_depends_on": "eval:doc.send_email", + "options": "Email Template" + }, + { + "default": "0", + "fieldname": "allow_invoicing", + "fieldtype": "Check", + "label": "Allow Invoicing for Memberships", + "mandatory_depends_on": "eval:doc.send_invoice || doc.make_payment_entry" + }, + { + "default": "0", + "depends_on": "eval:doc.allow_invoicing", + "description": "Automatically create an invoice when payment is authorized from a web form entry", + "fieldname": "automate_membership_invoicing", + "fieldtype": "Check", + "label": "Automate Invoicing for Web Forms" + }, + { + "default": "0", + "depends_on": "eval:doc.allow_invoicing", + "description": "Auto creates Payment Entry for Sales Invoices created for Membership from web forms.", + "fieldname": "automate_membership_payment_entries", + "fieldtype": "Check", + "label": "Automate Payment Entry Creation" + }, + { + "default": "0", + "fieldname": "enable_razorpay_for_memberships", + "fieldtype": "Check", + "label": "Enable RazorPay For Memberships" + }, + { + "depends_on": "eval:doc.automate_membership_payment_entries", + "description": "Account for accepting membership payments", + "fieldname": "membership_payment_account", + "fieldtype": "Link", + "label": "Membership Payment To", + "mandatory_depends_on": "eval:doc.automate_membership_payment_entries", + "options": "Account" + }, + { + "fieldname": "membership_webhook_secret", + "fieldtype": "Password", + "label": "Membership Webhook Secret", + "read_only": 1 + }, + { + "fieldname": "donation_webhook_secret", + "fieldtype": "Password", + "label": "Donation Webhook Secret", + "read_only": 1 + }, + { + "depends_on": "automate_donation_payment_entries", + "description": "Account for accepting donation payments", + "fieldname": "donation_payment_account", + "fieldtype": "Link", + "label": "Donation Payment To", + "mandatory_depends_on": "automate_donation_payment_entries", + "options": "Account" + }, + { + "default": "0", + "description": "Auto creates Payment Entry for Donations created from web forms.", + "fieldname": "automate_donation_payment_entries", + "fieldtype": "Check", + "label": "Automate Donation Payment Entries" + }, + { + "depends_on": "eval:doc.allow_invoicing", + "fieldname": "membership_debit_account", + "fieldtype": "Link", + "label": "Debit Account", + "mandatory_depends_on": "eval:doc.allow_invoicing", + "options": "Account" + }, + { + "depends_on": "automate_donation_payment_entries", + "fieldname": "donation_debit_account", + "fieldtype": "Link", + "label": "Debit Account", + "mandatory_depends_on": "automate_donation_payment_entries", + "options": "Account" + }, + { + "description": "This company will be set for the Donations created via webhook.", + "fieldname": "donation_company", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Company", + "options": "Company", + "reqd": 1 + }, + { + "fieldname": "donation_settings_section", + "fieldtype": "Section Break", + "label": "Donation Settings" + }, + { + "fieldname": "column_break_22", + "fieldtype": "Column Break" + }, + { + "description": "This Donor Type will be set for the Donor created via Donation web form entry.", + "fieldname": "default_donor_type", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Default Donor Type", + "options": "Donor Type", + "reqd": 1 + }, + { + "fieldname": "section_break_27", + "fieldtype": "Section Break" + }, + { + "description": "The user that will be used to create Donations, Memberships, Invoices, and Payment Entries. This user should have the relevant permissions.", + "fieldname": "creation_user", + "fieldtype": "Link", + "label": "Creation User", + "options": "User", + "reqd": 1 + } + ], + "index_web_pages_for_search": 1, + "issingle": 1, + "links": [], + "modified": "2021-03-11 10:43:38.124240", + "modified_by": "Administrator", + "module": "Non Profit", + "name": "Non Profit Settings", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "print": 1, + "read": 1, + "role": "System Manager", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "print": 1, + "read": 1, + "role": "Non Profit Manager", + "share": 1, + "write": 1 + }, + { + "email": 1, + "print": 1, + "read": 1, + "role": "Non Profit Member", + "share": 1 + } + ], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/non_profit/doctype/membership_settings/membership_settings.py b/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.py similarity index 51% rename from erpnext/non_profit/doctype/membership_settings/membership_settings.py rename to erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.py index f3b2eee6f9..108554c6a0 100644 --- a/erpnext/non_profit/doctype/membership_settings/membership_settings.py +++ b/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.py @@ -8,23 +8,26 @@ from frappe import _ from frappe.integrations.utils import get_payment_gateway_controller from frappe.model.document import Document -class MembershipSettings(Document): - def generate_webhook_key(self): +class NonProfitSettings(Document): + def generate_webhook_secret(self, field="membership_webhook_secret"): key = frappe.generate_hash(length=20) - self.webhook_secret = key + self.set(field, key) self.save() + secret_for = "Membership" if field == "membership_webhook_secret" else "Donation" + frappe.msgprint( - _("Here is your webhook secret, this will be shown to you only once.") + "

" + key, + _("Here is your webhook secret for {0} API, this will be shown to you only once.").format(secret_for) + "

" + key, _("Webhook Secret") - ); + ) - def revoke_key(self): - self.webhook_secret = None; + def revoke_key(self, key): + self.set(key, None) self.save() - def get_webhook_secret(self): - return self.get_password(fieldname="webhook_secret", raise_exception=False) + def get_webhook_secret(self, endpoint="Membership"): + fieldname = "membership_webhook_secret" if endpoint == "Membership" else "donation_webhook_secret" + return self.get_password(fieldname=fieldname, raise_exception=False) @frappe.whitelist() def get_plans_for_membership(*args, **kwargs): diff --git a/erpnext/non_profit/doctype/membership_settings/test_membership_settings.py b/erpnext/non_profit/doctype/non_profit_settings/test_non_profit_settings.py similarity index 79% rename from erpnext/non_profit/doctype/membership_settings/test_membership_settings.py rename to erpnext/non_profit/doctype/non_profit_settings/test_non_profit_settings.py index 2ad7984583..3f0ede32e5 100644 --- a/erpnext/non_profit/doctype/membership_settings/test_membership_settings.py +++ b/erpnext/non_profit/doctype/non_profit_settings/test_non_profit_settings.py @@ -6,5 +6,5 @@ from __future__ import unicode_literals # import frappe import unittest -class TestMembershipSettings(unittest.TestCase): +class TestNonProfitSettings(unittest.TestCase): pass diff --git a/erpnext/non_profit/workspace/non_profit/non_profit.json b/erpnext/non_profit/workspace/non_profit/non_profit.json new file mode 100644 index 0000000000..2557d77d88 --- /dev/null +++ b/erpnext/non_profit/workspace/non_profit/non_profit.json @@ -0,0 +1,251 @@ +{ + "category": "Domains", + "charts": [], + "creation": "2020-03-02 17:23:47.811421", + "developer_mode_only": 0, + "disable_user_customization": 0, + "docstatus": 0, + "doctype": "Workspace", + "extends_another_page": 0, + "hide_custom": 0, + "icon": "non-profit", + "idx": 0, + "is_default": 0, + "is_standard": 1, + "label": "Non Profit", + "links": [ + { + "hidden": 0, + "is_query_report": 0, + "label": "Loan Management", + "onboard": 0, + "type": "Card Break" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan Type", + "link_to": "Loan Type", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan Application", + "link_to": "Loan Application", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Loan", + "link_to": "Loan", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Grant Application", + "onboard": 0, + "type": "Card Break" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Grant Application", + "link_to": "Grant Application", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Membership", + "onboard": 0, + "type": "Card Break" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Member", + "link_to": "Member", + "link_type": "DocType", + "onboard": 1, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Membership", + "link_to": "Membership", + "link_type": "DocType", + "onboard": 1, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Membership Type", + "link_to": "Membership Type", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Membership Settings", + "link_to": "Non Profit Settings", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Volunteer", + "onboard": 0, + "type": "Card Break" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Volunteer", + "link_to": "Volunteer", + "link_type": "DocType", + "onboard": 1, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Volunteer Type", + "link_to": "Volunteer Type", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Chapter", + "onboard": 0, + "type": "Card Break" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Chapter", + "link_to": "Chapter", + "link_type": "DocType", + "onboard": 1, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Donation", + "onboard": 0, + "type": "Card Break" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Donor", + "link_to": "Donor", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "dependencies": "", + "hidden": 0, + "is_query_report": 0, + "label": "Donor Type", + "link_to": "Donor Type", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Donation", + "link_to": "Donation", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Tax Exemption Certification (India)", + "link_type": "DocType", + "onboard": 0, + "type": "Card Break" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Tax Exemption 80G Certificate", + "link_to": "Tax Exemption 80G Certificate", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + } + ], + "modified": "2021-03-11 11:38:09.140655", + "modified_by": "Administrator", + "module": "Non Profit", + "name": "Non Profit", + "owner": "Administrator", + "pin_to_bottom": 0, + "pin_to_top": 0, + "restrict_to_domain": "Non Profit", + "shortcuts": [ + { + "label": "Member", + "link_to": "Member", + "type": "DocType" + }, + { + "label": "Non Profit Settings", + "link_to": "Non Profit Settings", + "type": "DocType" + }, + { + "label": "Membership", + "link_to": "Membership", + "type": "DocType" + }, + { + "label": "Chapter", + "link_to": "Chapter", + "type": "DocType" + }, + { + "label": "Chapter Member", + "link_to": "Chapter Member", + "type": "DocType" + } + ] +} \ No newline at end of file diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 80e2f1c01a..20ea5097bf 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -753,3 +753,5 @@ erpnext.patches.v13_0.add_naming_series_to_old_projects # 1-02-2021 erpnext.patches.v13_0.item_reposting_for_incorrect_sl_and_gl erpnext.patches.v12_0.add_state_code_for_ladakh erpnext.patches.v13_0.update_vehicle_no_reqd_condition +erpnext.patches.v13_0.setup_fields_for_80g_certificate_and_donation +erpnext.patches.v13_0.rename_membership_settings_to_non_profit_settings \ No newline at end of file diff --git a/erpnext/patches/v13_0/rename_membership_settings_to_non_profit_settings.py b/erpnext/patches/v13_0/rename_membership_settings_to_non_profit_settings.py new file mode 100644 index 0000000000..3fa09a7baa --- /dev/null +++ b/erpnext/patches/v13_0/rename_membership_settings_to_non_profit_settings.py @@ -0,0 +1,22 @@ +from __future__ import unicode_literals +import frappe +from frappe.model.utils.rename_field import rename_field + +def execute(): + if frappe.db.table_exists("Membership Settings"): + frappe.rename_doc("DocType", "Membership Settings", "Non Profit Settings") + frappe.reload_doctype("Non Profit Settings", force=True) + + if frappe.db.table_exists("Non Profit Settings"): + rename_fields_map = { + "enable_invoicing": "allow_invoicing", + "create_for_web_forms": "automate_membership_invoicing", + "make_payment_entry": "automate_membership_payment_entries", + "enable_razorpay": "enable_razorpay_for_memberships", + "debit_account": "membership_debit_account", + "payment_account": "membership_payment_account", + "webhook_secret": "membership_webhook_secret" + } + + for old_name, new_name in rename_fields_map.items(): + rename_field("Non Profit Settings", old_name, new_name) \ No newline at end of file diff --git a/erpnext/patches/v13_0/setup_fields_for_80g_certificate_and_donation.py b/erpnext/patches/v13_0/setup_fields_for_80g_certificate_and_donation.py new file mode 100644 index 0000000000..aea53f8add --- /dev/null +++ b/erpnext/patches/v13_0/setup_fields_for_80g_certificate_and_donation.py @@ -0,0 +1,16 @@ +import frappe +from erpnext.regional.india.setup import make_custom_fields + +def execute(): + company = frappe.get_all('Company', filters = {'country': 'India'}) + if not company: + return + + make_custom_fields() + + if not frappe.db.exists('Party Type', 'Donor'): + frappe.get_doc({ + 'doctype': 'Party Type', + 'party_type': 'Donor', + 'account_type': 'Receivable' + }).insert(ignore_permissions=True) \ No newline at end of file diff --git a/erpnext/regional/doctype/tax_exemption_80g_certificate/__init__.py b/erpnext/regional/doctype/tax_exemption_80g_certificate/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.js b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.js new file mode 100644 index 0000000000..54cde9c0cf --- /dev/null +++ b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.js @@ -0,0 +1,67 @@ +// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Tax Exemption 80G Certificate', { + refresh: function(frm) { + if (frm.doc.donor) { + frm.set_query('donation', function() { + return { + filters: { + docstatus: 1, + donor: frm.doc.donor + } + }; + }); + } + }, + + recipient: function(frm) { + if (frm.doc.recipient === 'Donor') { + frm.set_value({ + 'member': '', + 'member_name': '', + 'member_email': '', + 'member_pan_number': '', + 'fiscal_year': '', + 'total': 0, + 'payments': [] + }); + } else { + frm.set_value({ + 'donor': '', + 'donor_name': '', + 'donor_email': '', + 'donor_pan_number': '', + 'donation': '', + 'date_of_donation': '', + 'amount': 0, + 'mode_of_payment': '', + 'razorpay_payment_id': '' + }); + } + }, + + get_payments: function(frm) { + frm.call({ + doc: frm.doc, + method: 'get_payments', + freeze: true + }); + }, + + company: function(frm) { + if ((frm.doc.member || frm.doc.donor) && frm.doc.company) { + frm.call({ + doc: frm.doc, + method: 'set_company_address', + freeze: true + }); + } + }, + + donation: function(frm) { + if (frm.doc.recipient === 'Donor' && !frm.doc.donor) { + frappe.msgprint(__('Please select donor first')); + } + } +}); diff --git a/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.json b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.json new file mode 100644 index 0000000000..9eee722f42 --- /dev/null +++ b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.json @@ -0,0 +1,297 @@ +{ + "actions": [], + "autoname": "naming_series:", + "creation": "2021-02-15 12:37:21.577042", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "naming_series", + "recipient", + "member", + "member_name", + "member_email", + "member_pan_number", + "donor", + "donor_name", + "donor_email", + "donor_pan_number", + "column_break_4", + "date", + "fiscal_year", + "section_break_11", + "company", + "company_address", + "company_address_display", + "column_break_14", + "company_pan_number", + "company_80g_number", + "company_80g_wef", + "title", + "section_break_6", + "get_payments", + "payments", + "total", + "donation_details_section", + "donation", + "date_of_donation", + "amount", + "column_break_27", + "mode_of_payment", + "razorpay_payment_id" + ], + "fields": [ + { + "fieldname": "recipient", + "fieldtype": "Select", + "in_list_view": 1, + "label": "Certificate Recipient", + "options": "Member\nDonor", + "reqd": 1 + }, + { + "depends_on": "eval:doc.recipient === \"Member\";", + "fieldname": "member", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Member", + "mandatory_depends_on": "eval:doc.recipient === \"Member\";", + "options": "Member" + }, + { + "depends_on": "eval:doc.recipient === \"Member\";", + "fetch_from": "member.member_name", + "fieldname": "member_name", + "fieldtype": "Data", + "label": "Member Name", + "read_only": 1 + }, + { + "depends_on": "eval:doc.recipient === \"Donor\";", + "fieldname": "donor", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Donor", + "mandatory_depends_on": "eval:doc.recipient === \"Donor\";", + "options": "Donor" + }, + { + "fieldname": "column_break_4", + "fieldtype": "Column Break" + }, + { + "fieldname": "date", + "fieldtype": "Date", + "label": "Date", + "reqd": 1 + }, + { + "depends_on": "eval:doc.recipient === \"Member\";", + "fieldname": "section_break_6", + "fieldtype": "Section Break" + }, + { + "fieldname": "payments", + "fieldtype": "Table", + "label": "Payments", + "options": "Tax Exemption 80G Certificate Detail" + }, + { + "fieldname": "total", + "fieldtype": "Currency", + "in_list_view": 1, + "label": "Total", + "read_only": 1 + }, + { + "depends_on": "eval:doc.recipient === \"Member\";", + "fieldname": "fiscal_year", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Fiscal Year", + "options": "Fiscal Year" + }, + { + "fieldname": "company", + "fieldtype": "Link", + "label": "Company", + "options": "Company", + "reqd": 1 + }, + { + "fieldname": "get_payments", + "fieldtype": "Button", + "label": "Get Memberships" + }, + { + "fieldname": "naming_series", + "fieldtype": "Select", + "label": "Naming Series", + "options": "NPO-80G-.YYYY.-" + }, + { + "fieldname": "section_break_11", + "fieldtype": "Section Break", + "label": "Company Details" + }, + { + "fieldname": "company_address", + "fieldtype": "Link", + "label": "Company Address", + "options": "Address" + }, + { + "fieldname": "column_break_14", + "fieldtype": "Column Break" + }, + { + "fetch_from": "company.pan_details", + "fieldname": "company_pan_number", + "fieldtype": "Data", + "label": "PAN Number", + "read_only": 1 + }, + { + "fieldname": "company_address_display", + "fieldtype": "Small Text", + "hidden": 1, + "label": "Company Address Display", + "print_hide": 1, + "read_only": 1 + }, + { + "fetch_from": "company.company_80g_number", + "fieldname": "company_80g_number", + "fieldtype": "Data", + "label": "80G Number", + "read_only": 1 + }, + { + "fetch_from": "company.with_effect_from", + "fieldname": "company_80g_wef", + "fieldtype": "Date", + "label": "80G With Effect From", + "read_only": 1 + }, + { + "depends_on": "eval:doc.recipient === \"Donor\";", + "fieldname": "donation_details_section", + "fieldtype": "Section Break", + "label": "Donation Details" + }, + { + "fieldname": "donation", + "fieldtype": "Link", + "label": "Donation", + "mandatory_depends_on": "eval:doc.recipient === \"Donor\";", + "options": "Donation" + }, + { + "fetch_from": "donation.amount", + "fieldname": "amount", + "fieldtype": "Currency", + "label": "Amount", + "read_only": 1 + }, + { + "fetch_from": "donation.mode_of_payment", + "fieldname": "mode_of_payment", + "fieldtype": "Link", + "label": "Mode of Payment", + "options": "Mode of Payment", + "read_only": 1 + }, + { + "fetch_from": "donation.razorpay_payment_id", + "fieldname": "razorpay_payment_id", + "fieldtype": "Data", + "label": "RazorPay Payment ID", + "read_only": 1 + }, + { + "fetch_from": "donation.date", + "fieldname": "date_of_donation", + "fieldtype": "Date", + "label": "Date of Donation", + "read_only": 1 + }, + { + "fieldname": "column_break_27", + "fieldtype": "Column Break" + }, + { + "depends_on": "eval:doc.recipient === \"Donor\";", + "fetch_from": "donor.donor_name", + "fieldname": "donor_name", + "fieldtype": "Data", + "label": "Donor Name", + "read_only": 1 + }, + { + "depends_on": "eval:doc.recipient === \"Donor\";", + "fetch_from": "donor.email", + "fieldname": "donor_email", + "fieldtype": "Data", + "label": "Email", + "read_only": 1 + }, + { + "depends_on": "eval:doc.recipient === \"Member\";", + "fetch_from": "member.email_id", + "fieldname": "member_email", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Email", + "read_only": 1 + }, + { + "depends_on": "eval:doc.recipient === \"Member\";", + "fetch_from": "member.pan_number", + "fieldname": "member_pan_number", + "fieldtype": "Data", + "label": "PAN Details", + "read_only": 1 + }, + { + "depends_on": "eval:doc.recipient === \"Donor\";", + "fetch_from": "donor.pan_number", + "fieldname": "donor_pan_number", + "fieldtype": "Data", + "label": "PAN Details", + "read_only": 1 + }, + { + "fieldname": "title", + "fieldtype": "Data", + "hidden": 1, + "label": "Title", + "print_hide": 1 + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2021-02-22 00:03:34.215633", + "modified_by": "Administrator", + "module": "Regional", + "name": "Tax Exemption 80G Certificate", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "search_fields": "member, member_name", + "sort_field": "modified", + "sort_order": "DESC", + "title_field": "title", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py new file mode 100644 index 0000000000..d734a18c3a --- /dev/null +++ b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py @@ -0,0 +1,89 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe import _ +from frappe.model.document import Document +from frappe.utils import getdate, flt, get_link_to_form +from erpnext.accounts.utils import get_fiscal_year +from frappe.contacts.doctype.address.address import get_company_address + +class TaxExemption80GCertificate(Document): + def validate(self): + self.validate_date() + self.validate_duplicates() + self.validate_company_details() + self.set_company_address() + self.set_title() + + def validate_date(self): + if self.recipient == 'Member': + if getdate(self.date): + fiscal_year = get_fiscal_year(fiscal_year=self.fiscal_year, as_dict=True) + + if not (fiscal_year.year_start_date <= getdate(self.date) \ + <= fiscal_year.year_end_date): + frappe.throw(_('The Certificate Date is not in the Fiscal Year {0}').format(frappe.bold(self.fiscal_year))) + + def validate_duplicates(self): + if self.recipient == 'Donor': + certificate = frappe.db.exists(self.doctype, {'donation': self.donation}) + if certificate: + frappe.throw(_('An 80G Certificate {0} already exists for the donation {1}').format( + get_link_to_form(self.doctype, certificate), frappe.bold(self.donation) + ), title=_('Duplicate Certificate')) + + def validate_company_details(self): + fields = ['company_80g_number', 'with_effect_from', 'pan_details'] + company_details = frappe.db.get_value('Company', self.company, fields, as_dict=True) + if not company_details.company_80g_number: + frappe.throw(_('Please set the {0} for company {1}').format(frappe.bold('80G Number'), + get_link_to_form('Company', self.company))) + + if not company_details.pan_details: + frappe.throw(_('Please set the {0} for company {1}').format(frappe.bold('PAN Number'), + get_link_to_form('Company', self.company))) + + def set_company_address(self): + address = get_company_address(self.company) + self.company_address = address.company_address + self.company_address_display = address.company_address_display + + def set_title(self): + if self.recipient == "Member": + self.title = self.member_name + else: + self.title = self.donor_name + + def get_payments(self): + if not self.member: + frappe.throw(_('Please select a Member first.')) + + fiscal_year = get_fiscal_year(fiscal_year=self.fiscal_year, as_dict=True) + + memberships = frappe.db.get_all('Membership', { + 'member': self.member, + 'from_date': ['between', (fiscal_year.year_start_date, fiscal_year.year_end_date)], + 'to_date': ['between', (fiscal_year.year_start_date, fiscal_year.year_end_date)], + 'membership_status': ('!=', 'Cancelled') + }, ['from_date', 'amount', 'name', 'invoice', 'payment_id']) + + if not memberships: + frappe.msgprint(_('No Membership Payments found against the Member {0}').format(self.member)) + + total = 0 + self.payments = [] + + for doc in memberships: + self.append('payments', { + 'date': doc.from_date, + 'amount': doc.amount, + 'invoice_id': doc.invoice, + 'razorpay_payment_id': doc.payment_id, + 'membership': doc.name + }) + total += flt(doc.amount) + + self.total = total diff --git a/erpnext/regional/doctype/tax_exemption_80g_certificate/test_tax_exemption_80g_certificate.py b/erpnext/regional/doctype/tax_exemption_80g_certificate/test_tax_exemption_80g_certificate.py new file mode 100644 index 0000000000..346ebbf679 --- /dev/null +++ b/erpnext/regional/doctype/tax_exemption_80g_certificate/test_tax_exemption_80g_certificate.py @@ -0,0 +1,101 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +import frappe +import unittest +from frappe.utils import getdate +from erpnext.accounts.utils import get_fiscal_year +from erpnext.non_profit.doctype.donation.test_donation import create_donor, create_mode_of_payment, create_donor_type +from erpnext.non_profit.doctype.donation.donation import create_donation +from erpnext.non_profit.doctype.membership.test_membership import setup_membership, make_membership +from erpnext.non_profit.doctype.member.member import create_member + +class TestTaxExemption80GCertificate(unittest.TestCase): + def setUp(self): + frappe.db.sql('delete from `tabTax Exemption 80G Certificate`') + frappe.db.sql('delete from `tabMembership`') + create_donor_type() + settings = frappe.get_doc('Non Profit Settings') + settings.company = '_Test Company' + settings.donation_company = '_Test Company' + settings.default_donor_type = '_Test Donor' + settings.creation_user = 'Administrator' + settings.save() + + company = frappe.get_doc('Company', '_Test Company') + company.pan_details = 'BBBTI3374C' + company.company_80g_number = 'NQ.CIT(E)I2018-19/DEL-IE28615-27062018/10087' + company.with_effect_from = getdate() + company.save() + + def test_duplicate_donation_certificate(self): + donor = create_donor() + create_mode_of_payment() + payment = frappe._dict({ + 'amount': 100, + 'method': 'Debit Card', + 'id': 'pay_MeXAmsgeKOhq7O' + }) + donation = create_donation(donor, payment) + + args = frappe._dict({ + 'recipient': 'Donor', + 'donor': donor.name, + 'donation': donation.name + }) + certificate = create_80g_certificate(args) + certificate.insert() + + # check company details + self.assertEquals(certificate.company_pan_number, 'BBBTI3374C') + self.assertEquals(certificate.company_80g_number, 'NQ.CIT(E)I2018-19/DEL-IE28615-27062018/10087') + + # check donation details + self.assertEquals(certificate.amount, donation.amount) + + duplicate_certificate = create_80g_certificate(args) + # duplicate validation + self.assertRaises(frappe.ValidationError, duplicate_certificate.insert) + + def test_membership_80g_certificate(self): + plan = setup_membership() + + # make test member + member_doc = create_member(frappe._dict({ + 'fullname': "_Test_Member", + 'email': "_test_member_erpnext@example.com", + 'plan_id': plan.name + })) + member_doc.make_customer_and_link() + member = member_doc.name + + membership = make_membership(member, { "from_date": getdate() }) + invoice = membership.generate_invoice(save=True) + + args = frappe._dict({ + 'recipient': 'Member', + 'member': member, + 'fiscal_year': get_fiscal_year(getdate(), as_dict=True).get('name') + }) + certificate = create_80g_certificate(args) + certificate.get_payments() + certificate.insert() + + self.assertEquals(len(certificate.payments), 1) + self.assertEquals(certificate.payments[0].amount, membership.amount) + self.assertEquals(certificate.payments[0].invoice_id, invoice.name) + + +def create_80g_certificate(args): + certificate = frappe.get_doc({ + 'doctype': 'Tax Exemption 80G Certificate', + 'recipient': args.recipient, + 'date': getdate(), + 'company': '_Test Company' + }) + + certificate.update(args) + + return certificate \ No newline at end of file diff --git a/erpnext/regional/doctype/tax_exemption_80g_certificate_detail/__init__.py b/erpnext/regional/doctype/tax_exemption_80g_certificate_detail/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/regional/doctype/tax_exemption_80g_certificate_detail/tax_exemption_80g_certificate_detail.json b/erpnext/regional/doctype/tax_exemption_80g_certificate_detail/tax_exemption_80g_certificate_detail.json new file mode 100644 index 0000000000..dfa817dd27 --- /dev/null +++ b/erpnext/regional/doctype/tax_exemption_80g_certificate_detail/tax_exemption_80g_certificate_detail.json @@ -0,0 +1,66 @@ +{ + "actions": [], + "creation": "2021-02-15 12:43:52.754124", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "date", + "amount", + "invoice_id", + "column_break_4", + "razorpay_payment_id", + "membership" + ], + "fields": [ + { + "fieldname": "date", + "fieldtype": "Date", + "in_list_view": 1, + "label": "Date", + "reqd": 1 + }, + { + "fieldname": "amount", + "fieldtype": "Currency", + "in_list_view": 1, + "label": "Amount", + "reqd": 1 + }, + { + "fieldname": "invoice_id", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Invoice ID", + "options": "Sales Invoice", + "reqd": 1 + }, + { + "fieldname": "razorpay_payment_id", + "fieldtype": "Data", + "label": "Razorpay Payment ID" + }, + { + "fieldname": "membership", + "fieldtype": "Link", + "label": "Membership", + "options": "Membership" + }, + { + "fieldname": "column_break_4", + "fieldtype": "Column Break" + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-02-15 16:35:10.777587", + "modified_by": "Administrator", + "module": "Regional", + "name": "Tax Exemption 80G Certificate Detail", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/regional/doctype/tax_exemption_80g_certificate_detail/tax_exemption_80g_certificate_detail.py b/erpnext/regional/doctype/tax_exemption_80g_certificate_detail/tax_exemption_80g_certificate_detail.py new file mode 100644 index 0000000000..bdad798d98 --- /dev/null +++ b/erpnext/regional/doctype/tax_exemption_80g_certificate_detail/tax_exemption_80g_certificate_detail.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +# import frappe +from frappe.model.document import Document + +class TaxExemption80GCertificateDetail(Document): + pass diff --git a/erpnext/regional/india/setup.py b/erpnext/regional/india/setup.py index 526198424f..40247f7e3d 100644 --- a/erpnext/regional/india/setup.py +++ b/erpnext/regional/india/setup.py @@ -398,9 +398,9 @@ def make_custom_fields(update=True): si_einvoice_fields = [ dict(fieldname='irn', label='IRN', fieldtype='Data', read_only=1, insert_after='customer', no_copy=1, print_hide=1, depends_on='eval:in_list(["Registered Regular", "SEZ", "Overseas", "Deemed Export"], doc.gst_category) && doc.irn_cancelled === 0'), - + dict(fieldname='ack_no', label='Ack. No.', fieldtype='Data', read_only=1, hidden=1, insert_after='irn', no_copy=1, print_hide=1), - + dict(fieldname='ack_date', label='Ack. Date', fieldtype='Data', read_only=1, hidden=1, insert_after='ack_no', no_copy=1, print_hide=1), dict(fieldname='irn_cancelled', label='IRN Cancelled', fieldtype='Check', no_copy=1, print_hide=1, @@ -498,6 +498,14 @@ def make_custom_fields(update=True): fieldtype='Link', options='Salary Component', insert_after='basic_component'), dict(fieldname='arrear_component', label='Arrear Component', fieldtype='Link', options='Salary Component', insert_after='hra_component'), + dict(fieldname='non_profit_section', label='Non Profit Settings', + fieldtype='Section Break', insert_after='asset_received_but_not_billed', collapsible=1), + dict(fieldname='company_80g_number', label='80G Number', + fieldtype='Data', insert_after='non_profit_section'), + dict(fieldname='with_effect_from', label='80G With Effect From', + fieldtype='Date', insert_after='company_80g_number'), + dict(fieldname='pan_details', label='PAN Number', + fieldtype='Data', insert_after='with_effect_from') ], 'Employee Tax Exemption Declaration':[ dict(fieldname='hra_section', label='HRA Exemption', @@ -580,7 +588,15 @@ def make_custom_fields(update=True): 'options': '\nWith Payment of Tax\nWithout Payment of Tax' } ], - "Member": [ + 'Member': [ + { + 'fieldname': 'pan_number', + 'label': 'PAN Details', + 'fieldtype': 'Data', + 'insert_after': 'email_id' + } + ], + 'Donor': [ { 'fieldname': 'pan_number', 'label': 'PAN Details', @@ -642,7 +658,7 @@ def set_tax_withholding_category(company): pass docs = get_tds_details(accounts, fiscal_year) - + for d in docs: try: doc = frappe.get_doc(d) @@ -660,7 +676,7 @@ def set_tax_withholding_category(company): fy_exist = [k for k in doc.get('rates') if k.get('fiscal_year')==fiscal_year] if not fy_exist: doc.append("rates", d.get('rates')[0]) - + doc.flags.ignore_permissions = True doc.flags.ignore_mandatory = True doc.save() diff --git a/erpnext/regional/print_format/80g_certificate_for_donation/80g_certificate_for_donation.json b/erpnext/regional/print_format/80g_certificate_for_donation/80g_certificate_for_donation.json new file mode 100644 index 0000000000..a8da0bd209 --- /dev/null +++ b/erpnext/regional/print_format/80g_certificate_for_donation/80g_certificate_for_donation.json @@ -0,0 +1,26 @@ +{ + "absolute_value": 0, + "align_labels_right": 0, + "creation": "2021-02-22 00:17:33.878581", + "css": ".details {\n font-size: 15px;\n font-family: Tahoma, sans-serif;;\n line-height: 150%;\n}\n\n.certificate-footer {\n font-size: 15px;\n font-family: Tahoma, sans-serif;\n line-height: 140%;\n margin-top: 120px;\n}\n\n.company-address {\n color: #666666;\n font-size: 15px;\n font-family: Tahoma, sans-serif;;\n}", + "custom_format": 1, + "default_print_language": "en", + "disabled": 0, + "doc_type": "Tax Exemption 80G Certificate", + "docstatus": 0, + "doctype": "Print Format", + "font": "Default", + "html": "{% if letter_head and not no_letterhead -%}\n
{{ letter_head }}
\n{%- endif %}\n\n
\n

{{ doc.company }} 80G Donor Certificate

\n
\n

\n\n
\n

{{ _(\"Certificate No. : \") }} {{ doc.name }}

\n

\n \t{{ _(\"Date\") }} : {{ doc.get_formatted(\"date\") }}
\n

\n

\n \n
\n\n This is to confirm that the {{ doc.company }} received an amount of {{doc.get_formatted(\"amount\")}}\n from {{ doc.donor_name }}\n {% if doc.pan_number -%}\n bearing PAN Number {{ doc.member_pan_number }}\n {%- endif %}\n\n via the Mode of Payment {{doc.mode_of_payment}}\n\n {% if doc.razorpay_payment_id -%}\n bearing RazorPay Payment ID {{ doc.razorpay_payment_id }}\n {%- endif %}\n\n on {{ doc.get_formatted(\"date_of_donation\") }}\n

\n \n

\n We thank you for your contribution towards the corpus of the {{ doc.company }} and helping support our work.\n

\n\n
\n
\n\n

\n

{{doc.company_address_display }}

\n\n", + "idx": 0, + "line_breaks": 0, + "modified": "2021-02-22 00:20:08.516600", + "modified_by": "Administrator", + "module": "Regional", + "name": "80G Certificate for Donation", + "owner": "Administrator", + "print_format_builder": 0, + "print_format_type": "Jinja", + "raw_printing": 0, + "show_section_headings": 0, + "standard": "Yes" +} \ No newline at end of file diff --git a/erpnext/regional/print_format/80g_certificate_for_donation/__init__.py b/erpnext/regional/print_format/80g_certificate_for_donation/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/regional/print_format/80g_certificate_for_membership/80g_certificate_for_membership.json b/erpnext/regional/print_format/80g_certificate_for_membership/80g_certificate_for_membership.json new file mode 100644 index 0000000000..f1b15aab29 --- /dev/null +++ b/erpnext/regional/print_format/80g_certificate_for_membership/80g_certificate_for_membership.json @@ -0,0 +1,26 @@ +{ + "absolute_value": 0, + "align_labels_right": 0, + "creation": "2021-02-15 16:53:55.026611", + "css": ".details {\n font-size: 15px;\n font-family: Tahoma, sans-serif;;\n line-height: 150%;\n}\n\n.certificate-footer {\n font-size: 15px;\n font-family: Tahoma, sans-serif;\n line-height: 140%;\n margin-top: 120px;\n}\n\n.company-address {\n color: #666666;\n font-size: 15px;\n font-family: Tahoma, sans-serif;;\n}", + "custom_format": 1, + "default_print_language": "en", + "disabled": 0, + "doc_type": "Tax Exemption 80G Certificate", + "docstatus": 0, + "doctype": "Print Format", + "font": "Default", + "html": "{% if letter_head and not no_letterhead -%}\n
{{ letter_head }}
\n{%- endif %}\n\n
\n

{{ doc.company }} Members 80G Donor Certificate

\n

Financial Cycle {{ doc.fiscal_year }}

\n
\n

\n\n
\n

{{ _(\"Certificate No. : \") }} {{ doc.name }}

\n

\n \t{{ _(\"Date\") }} : {{ doc.get_formatted(\"date\") }}
\n

\n

\n \n
\n This is to confirm that the {{ doc.company }} received a total amount of {{doc.get_formatted(\"total\")}}\n from {{ doc.member_name }}\n {% if doc.pan_number -%}\n bearing PAN Number {{ doc.member_pan_number }}\n {%- endif %}\n as per the payment details given below:\n \n

\n \n \t\n \t\t\n \t\t\t\n \t\t\t\n \t\t\t\n \t\t\n \t\n \t\n \t\t{%- for payment in doc.payments -%}\n \t\t\n \t\t\t\n \t\t\t\n \t\t\t\n \t\t\n \t\t{%- endfor -%}\n \t\n
{{ _(\"Date\") }}{{ _(\"Amount\") }}{{ _(\"Invoice ID\") }}
{{ payment.date }} {{ payment.get_formatted(\"amount\") }}{{ payment.invoice_id }}
\n \n
\n \n

\n We thank you for your contribution towards the corpus of the {{ doc.company }} and helping support our work.\n

\n\n
\n
\n\n

\n

{{doc.company_address_display }}

\n\n", + "idx": 0, + "line_breaks": 0, + "modified": "2021-02-21 23:29:00.778973", + "modified_by": "Administrator", + "module": "Regional", + "name": "80G Certificate for Membership", + "owner": "Administrator", + "print_format_builder": 0, + "print_format_type": "Jinja", + "raw_printing": 0, + "show_section_headings": 0, + "standard": "Yes" +} \ No newline at end of file diff --git a/erpnext/regional/print_format/80g_certificate_for_membership/__init__.py b/erpnext/regional/print_format/80g_certificate_for_membership/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index 72ed00293e..5053c6a512 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -195,6 +195,7 @@ def install(country=None): {'doctype': "Party Type", "party_type": "Member", "account_type": "Receivable"}, {'doctype': "Party Type", "party_type": "Shareholder", "account_type": "Payable"}, {'doctype': "Party Type", "party_type": "Student", "account_type": "Receivable"}, + {'doctype': "Party Type", "party_type": "Donor", "account_type": "Receivable"}, {'doctype': "Opportunity Type", "name": "Hub"}, {'doctype': "Opportunity Type", "name": _("Sales")}, From 2b61491adb3c4de3a3068d5425384409b9b89291 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 11 Mar 2021 16:05:58 +0530 Subject: [PATCH 297/449] fix: use account_name only in consolidated report (#24840) Don't use account_number and only rely on account_name for preparing consolidated financial statement. Related issue: ISS-20-21-10217 --- .../consolidated_financial_statement.py | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py index 76f3c50578..0c4a422440 100644 --- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py +++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py @@ -240,8 +240,7 @@ def get_company_currency(filters=None): def calculate_values(accounts_by_name, gl_entries_by_account, companies, start_date, filters): for entries in gl_entries_by_account.values(): for entry in entries: - key = entry.account_number or entry.account_name - d = accounts_by_name.get(key) + d = accounts_by_name.get(entry.account_name) if d: for company in companies: # check if posting date is within the period @@ -256,7 +255,8 @@ def accumulate_values_into_parents(accounts, accounts_by_name, companies): """accumulate children's values in parent accounts""" for d in reversed(accounts): if d.parent_account: - account = d.parent_account.split(' - ')[0].strip() + account = d.parent_account_name + if not accounts_by_name.get(account): continue @@ -267,16 +267,34 @@ def accumulate_values_into_parents(accounts, accounts_by_name, companies): accounts_by_name[account]["opening_balance"] = \ accounts_by_name[account].get("opening_balance", 0.0) + d.get("opening_balance", 0.0) + def get_account_heads(root_type, companies, filters): accounts = get_accounts(root_type, filters) if not accounts: return None, None + accounts = update_parent_account_names(accounts) + accounts, accounts_by_name, parent_children_map = filter_accounts(accounts) return accounts, accounts_by_name +def update_parent_account_names(accounts): + """Update parent_account_name in accounts list. + + parent_name is `name` of parent account which could have other prefix + of account_number and suffix of company abbr. This function adds key called + `parent_account_name` which does not have such prefix/suffix. + """ + name_to_account_map = { d.name : d.account_name for d in accounts } + + for account in accounts: + if account.parent_account: + account["parent_account_name"] = name_to_account_map[account.parent_account] + + return accounts + def get_companies(filters): companies = {} all_companies = get_subsidiary_companies(filters.get('company')) @@ -381,9 +399,9 @@ def set_gl_entries_by_account(from_date, to_date, root_lft, root_rgt, filters, g convert_to_presentation_currency(gl_entries, currency_info, filters.get('company')) for entry in gl_entries: - key = entry.account_number or entry.account_name - validate_entries(key, entry, accounts_by_name, accounts) - gl_entries_by_account.setdefault(key, []).append(entry) + account_name = entry.account_name + validate_entries(account_name, entry, accounts_by_name, accounts) + gl_entries_by_account.setdefault(account_name, []).append(entry) return gl_entries_by_account @@ -452,8 +470,7 @@ def filter_accounts(accounts, depth=10): parent_children_map = {} accounts_by_name = {} for d in accounts: - key = d.account_number or d.account_name - accounts_by_name[key] = d + accounts_by_name[d.account_name] = d parent_children_map.setdefault(d.parent_account or None, []).append(d) filtered_accounts = [] From 9ab3bedd0ad63a49e8c19eab13a0caa7c4d6cfa5 Mon Sep 17 00:00:00 2001 From: Afshan <33727827+AfshanKhan@users.noreply.github.com> Date: Fri, 12 Mar 2021 15:51:23 +0530 Subject: [PATCH 298/449] fix: added correct path in hooks (#24865) --- erpnext/hooks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 1c20555b82..fe80c6585d 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -357,13 +357,13 @@ scheduler_events = { "erpnext.hr.utils.generate_leave_encashment", "erpnext.hr.utils.allocate_earned_leaves", "erpnext.hr.utils.grant_leaves_automatically", - "erpnext.loan_management.doctype.loan_security_shortfall.loan_security_shortfall.create_process_loan_security_shortfall", - "erpnext.loan_management.doctype.loan_interest_accrual.loan_interest_accrual.process_loan_interest_accrual_for_term_loans", + "erpnext.loan_management.doctype.process_loan_security_shortfall.process_loan_security_shortfall.create_process_loan_security_shortfall", + "erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual.process_loan_interest_accrual_for_term_loans", "erpnext.crm.doctype.lead.lead.daily_open_lead" ], "monthly_long": [ "erpnext.accounts.deferred_revenue.process_deferred_accounting", - "erpnext.loan_management.doctype.loan_interest_accrual.loan_interest_accrual.process_loan_interest_accrual_for_demand_loans" + "erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual.process_loan_interest_accrual_for_demand_loans" ] } From 51c500d446ed1598e63c2702471a7ebd3960a825 Mon Sep 17 00:00:00 2001 From: Marica Date: Fri, 12 Mar 2021 15:51:45 +0530 Subject: [PATCH 299/449] fix: Don't throw exception on invoice lines when there is no item_code (fixes #24640) (#24864) Co-authored-by: casesolved-co-uk --- erpnext/public/js/controllers/transaction.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 123d998838..dce8e5d68b 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1884,7 +1884,6 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ frappe.throw(__("Please enter Item Code to get batch no")); } else if (doc.doctype == "Purchase Receipt" || (doc.doctype == "Purchase Invoice" && doc.update_stock)) { - return { filters: {'item': item.item_code} } @@ -1910,9 +1909,8 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ set_query_for_item_tax_template: function(doc, cdt, cdn) { var item = frappe.get_doc(cdt, cdn); if(!item.item_code) { - frappe.throw(__("Please enter Item Code to get item taxes")); + return doc.company ? {filters: {company: doc.company}} : {}; } else { - let filters = { 'item_code': item.item_code, 'valid_from': ["<=", doc.transaction_date || doc.bill_date || doc.posting_date], @@ -2123,4 +2121,4 @@ erpnext.apply_putaway_rule = (frm, purpose=null) => { } } }); -}; \ No newline at end of file +}; From d8f7a75eae189f4f59124500d76eb6509bf66537 Mon Sep 17 00:00:00 2001 From: Anupam Date: Mon, 15 Mar 2021 10:31:53 +0530 Subject: [PATCH 300/449] feat: add total available stock field --- .../purchase_order_item/purchase_order_item.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json index 75b2954ddd..eba52f2cd2 100644 --- a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json +++ b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json @@ -50,6 +50,7 @@ "base_net_amount", "warehouse_and_reference", "warehouse", + "actual_qty", "material_request", "material_request_item", "sales_order", @@ -735,13 +736,21 @@ "label": "Rate of Stock UOM", "options": "currency", "read_only": 1 + }, + { + "allow_on_submit": 1, + "fieldname": "actual_qty", + "fieldtype": "Float", + "label": "Available Qty at Warehouse", + "print_hide": 1, + "read_only": 1 } ], "idx": 1, "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-01-30 21:44:41.816974", + "modified": "2021-03-15 10:10:16.342693", "modified_by": "Administrator", "module": "Buying", "name": "Purchase Order Item", From 00a0e8da10b0756854ee75a580fe429ca545f8ec Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 11 Feb 2021 18:30:10 +0530 Subject: [PATCH 301/449] fix: validation of job card in stock entry --- .../doctype/job_card/job_card.py | 18 +- .../doctype/job_card_item/job_card_item.json | 455 ++++-------------- .../stock/doctype/stock_entry/stock_entry.py | 3 +- .../stock_entry_detail.json | 14 +- 4 files changed, 136 insertions(+), 354 deletions(-) diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py index ec28eb7795..662a06b1ee 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.py +++ b/erpnext/manufacturing/doctype/job_card/job_card.py @@ -267,6 +267,17 @@ class JobCard(Document): fields = ["sum(total_time_in_mins) as time_in_mins", "sum(total_completed_qty) as completed_qty"], filters = {"docstatus": 1, "work_order": self.work_order, "operation_id": self.operation_id}) + def set_transferred_qty_in_job_card(self, ste_doc): + for row in ste_doc.items: + if not row.job_card_item: continue + + qty = frappe.db.sql(""" SELECT SUM(qty) from `tabStock Entry Detail` sed, `tabStock Entry` se + WHERE sed.job_card_item = %s and se.docstatus = 1 and sed.parent = se.name and + se.purpose = 'Material Transfer for Manufacture' + """, (row.job_card_item))[0][0] + + frappe.db.set_value('Job Card Item', row.job_card_item, 'transferred_qty', flt(qty)) + def set_transferred_qty(self, update_status=False): if not self.items: self.transferred_qty = self.for_quantity if self.docstatus == 1 else 0 @@ -279,7 +290,8 @@ class JobCard(Document): self.transferred_qty = frappe.db.get_value('Stock Entry', { 'job_card': self.name, 'work_order': self.work_order, - 'docstatus': 1 + 'docstatus': 1, + 'purpose': 'Material Transfer for Manufacture' }, 'sum(fg_completed_qty)') or 0 self.db_set("transferred_qty", self.transferred_qty) @@ -420,6 +432,7 @@ def make_stock_entry(source_name, target_doc=None): target.purpose = "Material Transfer for Manufacture" target.from_bom = 1 target.fg_completed_qty = source.get('for_quantity', 0) - source.get('transferred_qty', 0) + target.set_transfer_qty() target.calculate_rate_and_amount() target.set_missing_values() target.set_stock_entry_type() @@ -437,9 +450,10 @@ def make_stock_entry(source_name, target_doc=None): "field_map": { "source_warehouse": "s_warehouse", "required_qty": "qty", - "uom": "stock_uom" + "name": "job_card_item" }, "postprocess": update_item, + "condition": lambda doc: doc.required_qty > 0 } }, target_doc, set_missing_values) diff --git a/erpnext/manufacturing/doctype/job_card_item/job_card_item.json b/erpnext/manufacturing/doctype/job_card_item/job_card_item.json index bc9fe108ca..100ef4ca3a 100644 --- a/erpnext/manufacturing/doctype/job_card_item/job_card_item.json +++ b/erpnext/manufacturing/doctype/job_card_item/job_card_item.json @@ -1,363 +1,120 @@ { - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "beta": 0, - "creation": "2018-07-09 17:20:44.737289", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "", - "editable_grid": 1, - "engine": "InnoDB", + "actions": [], + "creation": "2018-07-09 17:20:44.737289", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "item_code", + "source_warehouse", + "uom", + "item_group", + "column_break_3", + "stock_uom", + "item_name", + "description", + "qty_section", + "required_qty", + "column_break_9", + "transferred_qty", + "allow_alternative_item" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "item_code", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Item Code", - "length": 0, - "no_copy": 0, - "options": "Item", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "item_code", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Item Code", + "options": "Item", + "read_only": 1 + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "source_warehouse", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 1, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Source Warehouse", - "length": 0, - "no_copy": 0, - "options": "Warehouse", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "source_warehouse", + "fieldtype": "Link", + "ignore_user_permissions": 1, + "in_list_view": 1, + "label": "Source Warehouse", + "options": "Warehouse" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "uom", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "UOM", - "length": 0, - "no_copy": 0, - "options": "UOM", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "uom", + "fieldtype": "Link", + "label": "UOM", + "options": "UOM" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "column_break_3", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "item_name", - "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Item Name", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "item_name", + "fieldtype": "Data", + "label": "Item Name", + "read_only": 1 + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "description", - "fieldtype": "Text", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Description", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "description", + "fieldtype": "Text", + "label": "Description", + "read_only": 1 + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "qty_section", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Qty", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "qty_section", + "fieldtype": "Section Break", + "label": "Qty" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "required_qty", - "fieldtype": "Float", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Required Qty", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "required_qty", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Required Qty", + "read_only": 1 + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "column_break_9", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "column_break_9", + "fieldtype": "Column Break" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "allow_alternative_item", - "fieldtype": "Check", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Allow Alternative Item", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "default": "0", + "fieldname": "allow_alternative_item", + "fieldtype": "Check", + "label": "Allow Alternative Item" + }, + { + "fetch_from": "item_code.item_group", + "fieldname": "item_group", + "fieldtype": "Link", + "label": "Item Group", + "options": "Item Group", + "read_only": 1 + }, + { + "fetch_from": "item_code.stock_uom", + "fieldname": "stock_uom", + "fieldtype": "Link", + "label": "Stock UOM", + "options": "UOM" + }, + { + "fieldname": "transferred_qty", + "fieldtype": "Float", + "label": "Transferred Qty", + "no_copy": 1, + "print_hide": 1, + "read_only": 1 } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 1, - "max_attachments": 0, - "modified": "2018-08-28 15:23:48.099459", - "modified_by": "Administrator", - "module": "Manufacturing", - "name": "Job Card Item", - "name_case": "", - "owner": "Administrator", - "permissions": [], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0, - "track_views": 0 + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-02-11 13:50:13.804108", + "modified_by": "Administrator", + "module": "Manufacturing", + "name": "Job Card Item", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 } \ 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 d77b70ff14..9cdc3cfa55 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -163,7 +163,7 @@ class StockEntry(StockController): if self.purpose not in valid_purposes: frappe.throw(_("Purpose must be one of {0}").format(comma_or(valid_purposes))) - if self.job_card and self.purpose != 'Material Transfer for Manufacture': + if self.job_card and self.purpose not in ['Material Transfer for Manufacture', 'Repack']: frappe.throw(_("For job card {0}, you can only make the 'Material Transfer for Manufacture' type stock entry") .format(self.job_card)) @@ -823,6 +823,7 @@ class StockEntry(StockController): if self.job_card: job_doc = frappe.get_doc('Job Card', self.job_card) job_doc.set_transferred_qty(update_status=True) + job_doc.set_transferred_qty_in_job_card(self) if self.work_order: pro_doc = frappe.get_doc("Work Order", self.work_order) diff --git a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json index 988ae92969..864ff488b2 100644 --- a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json +++ b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json @@ -69,7 +69,8 @@ "putaway_rule", "column_break_51", "reference_purchase_receipt", - "quality_inspection" + "quality_inspection", + "job_card_item" ], "fields": [ { @@ -532,13 +533,22 @@ "fieldname": "is_finished_item", "fieldtype": "Check", "label": "Is Finished Item" + }, + { + "fieldname": "job_card_item", + "fieldtype": "Data", + "hidden": 1, + "label": "Job Card Item", + "no_copy": 1, + "print_hide": 1, + "read_only": 1 } ], "idx": 1, "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2020-12-30 15:00:44.489442", + "modified": "2021-02-11 13:47:50.158754", "modified_by": "Administrator", "module": "Stock", "name": "Stock Entry Detail", From 7f2e45e0f4acd9e1abbb1dae6622c85776329b62 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Mon, 15 Mar 2021 18:04:47 +0530 Subject: [PATCH 302/449] fix: Unequal debit and credit issue on RCM Invoice (#24838) * fix: Unequal debit and credit issue on RCM Invoice * fix: Travis --- erpnext/regional/india/utils.py | 41 +++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index d6200c9fd6..fd1d5e8bf9 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -693,25 +693,12 @@ def update_grand_total_for_rcm(doc, method): if country != 'India': return - if not doc.total_taxes_and_charges: + gst_tax, base_gst_tax = get_gst_tax_amount(doc) + + if not base_gst_tax: return if doc.reverse_charge == 'Y': - gst_accounts = get_gst_accounts(doc.company) - gst_account_list = gst_accounts.get('cgst_account') + gst_accounts.get('sgst_account') \ - + gst_accounts.get('igst_account') - - base_gst_tax = 0 - gst_tax = 0 - - for tax in doc.get('taxes'): - if tax.category not in ("Total", "Valuation and Total"): - continue - - if flt(tax.base_tax_amount_after_discount_amount) and tax.account_head in gst_account_list: - base_gst_tax += tax.base_tax_amount_after_discount_amount - gst_tax += tax.tax_amount_after_discount_amount - doc.taxes_and_charges_added -= gst_tax doc.total_taxes_and_charges -= gst_tax doc.base_taxes_and_charges_added -= base_gst_tax @@ -745,7 +732,9 @@ def make_regional_gl_entries(gl_entries, doc): if country != 'India': return gl_entries - if not doc.total_taxes_and_charges: + gst_tax, base_gst_tax = get_gst_tax_amount(doc) + + if not base_gst_tax: return gl_entries if doc.reverse_charge == 'Y': @@ -775,3 +764,21 @@ def make_regional_gl_entries(gl_entries, doc): ) return gl_entries + +def get_gst_tax_amount(doc): + gst_accounts = get_gst_accounts(doc.company) + gst_account_list = gst_accounts.get('cgst_account', []) + gst_accounts.get('sgst_account', []) \ + + gst_accounts.get('igst_account', []) + + base_gst_tax = 0 + gst_tax = 0 + + for tax in doc.get('taxes'): + if tax.category not in ("Total", "Valuation and Total"): + continue + + if flt(tax.base_tax_amount_after_discount_amount) and tax.account_head in gst_account_list: + base_gst_tax += tax.base_tax_amount_after_discount_amount + gst_tax += tax.tax_amount_after_discount_amount + + return gst_tax, base_gst_tax From dd7d71ca2ec07472f1175584d44a4d629c6f873f Mon Sep 17 00:00:00 2001 From: marination Date: Sun, 14 Mar 2021 18:20:23 +0530 Subject: [PATCH 303/449] fix: POS Opening Entry with empty balance detail rows --- .../doctype/pos_opening_entry/pos_opening_entry.py | 13 +++++++------ .../selling/page/point_of_sale/pos_controller.js | 4 ++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py index cb5b3a58fe..0023a84a46 100644 --- a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py +++ b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py @@ -20,15 +20,16 @@ class POSOpeningEntry(StatusUpdater): if not cint(frappe.db.get_value("User", self.user, "enabled")): frappe.throw(_("User {} is disabled. Please select valid user/cashier").format(self.user)) - + def validate_payment_method_account(self): invalid_modes = [] for d in self.balance_details: - account = frappe.db.get_value("Mode of Payment Account", - {"parent": d.mode_of_payment, "company": self.company}, "default_account") - if not account: - invalid_modes.append(get_link_to_form("Mode of Payment", d.mode_of_payment)) - + if d.mode_of_payment: + account = frappe.db.get_value("Mode of Payment Account", + {"parent": d.mode_of_payment, "company": self.company}, "default_account") + if not account: + invalid_modes.append(get_link_to_form("Mode of Payment", d.mode_of_payment)) + if invalid_modes: if invalid_modes == 1: msg = _("Please set default Cash or Bank account in Mode of Payment {}") diff --git a/erpnext/selling/page/point_of_sale/pos_controller.js b/erpnext/selling/page/point_of_sale/pos_controller.js index 45b4e30bf0..89fd9c7d8c 100644 --- a/erpnext/selling/page/point_of_sale/pos_controller.js +++ b/erpnext/selling/page/point_of_sale/pos_controller.js @@ -106,6 +106,10 @@ erpnext.PointOfSale.Controller = class { }) return frappe.utils.play_sound("error"); } + + // filter balance details for empty rows + balance_details = balance_details.filter(d => d.mode_of_payment); + const method = "erpnext.selling.page.point_of_sale.point_of_sale.create_opening_voucher"; const res = await frappe.call({ method, args: { pos_profile, company, balance_details }, freeze:true }); !res.exc && this.prepare_app_defaults(res.message); From 635c480771b67c16381f583a01aca7a1551cd767 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 16 Mar 2021 13:09:59 +0530 Subject: [PATCH 304/449] fix: Add method for regional round off account back --- erpnext/regional/india/utils.py | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index 95ff291516..7f00d1ea0e 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -772,3 +772,42 @@ def make_regional_gl_entries(gl_entries, doc): ) return gl_entries + +def get_gst_tax_amount(doc): + gst_accounts = get_gst_accounts(doc.company) + gst_account_list = gst_accounts.get('cgst_account', []) + gst_accounts.get('sgst_account', []) \ + + gst_accounts.get('igst_account', []) + + base_gst_tax = 0 + gst_tax = 0 + + for tax in doc.get('taxes'): + if tax.category not in ("Total", "Valuation and Total"): + continue + + if flt(tax.base_tax_amount_after_discount_amount) and tax.account_head in gst_account_list: + base_gst_tax += tax.base_tax_amount_after_discount_amount + gst_tax += tax.tax_amount_after_discount_amount + + return gst_tax, base_gst_tax + +@frappe.whitelist() +def get_regional_round_off_accounts(company, account_list): + country = frappe.get_cached_value('Company', company, 'country') + + if country != 'India': + return + + if isinstance(account_list, string_types): + account_list = json.loads(account_list) + + if not frappe.db.get_single_value('GST Settings', 'round_off_gst_values'): + return + + gst_accounts = get_gst_accounts(company) + gst_account_list = gst_accounts.get('cgst_account') + gst_accounts.get('sgst_account') \ + + gst_accounts.get('igst_account') + + account_list.extend(gst_account_list) + + return account_list From 00cce433a5bfce95c19151fdcdf6a7f823706598 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Tue, 16 Mar 2021 20:52:53 +0530 Subject: [PATCH 305/449] fix(Non Profit): Membership and Donation API fixes (#24900) (#24905) * fix: Donation fixes - differentiate between subscription payment and payment - issue with donation amount * fix: existing membership validation * fix: ignore subscription payments while capturing donations --- erpnext/non_profit/doctype/donation/donation.py | 6 +++++- erpnext/non_profit/doctype/membership/membership.py | 4 ++-- .../tax_exemption_80g_certificate.py | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/erpnext/non_profit/doctype/donation/donation.py b/erpnext/non_profit/doctype/donation/donation.py index e947588482..6a2a06dbc8 100644 --- a/erpnext/non_profit/doctype/donation/donation.py +++ b/erpnext/non_profit/doctype/donation/donation.py @@ -91,6 +91,10 @@ def capture_razorpay_donations(*args, **kwargs): if not data.event == 'payment.captured': return + # to avoid capturing subscription payments as donations + if payment.description and 'subscription' in str(payment.description).lower(): + return + donor = get_donor(payment.email) if not donor: donor = create_donor(payment) @@ -119,7 +123,7 @@ def create_donation(donor, payment): 'donor_name': donor.donor_name, 'email': donor.email, 'date': getdate(), - 'amount': flt(payment.amount), + 'amount': flt(payment.amount) / 100, # Convert to rupees from paise 'mode_of_payment': payment.method, 'razorpay_payment_id': payment.id }).insert(ignore_mandatory=True) diff --git a/erpnext/non_profit/doctype/membership/membership.py b/erpnext/non_profit/doctype/membership/membership.py index 191281f4ce..c41a2f5165 100644 --- a/erpnext/non_profit/doctype/membership/membership.py +++ b/erpnext/non_profit/doctype/membership/membership.py @@ -48,7 +48,7 @@ class Membership(Document): last_membership = erpnext.get_last_membership(self.member) # if person applied for offline membership - if last_membership and not frappe.session.user == "Administrator": + if last_membership and last_membership != self.name and not frappe.session.user == "Administrator": # if last membership does not expire in 30 days, then do not allow to renew if getdate(add_days(last_membership.to_date, -30)) > getdate(nowdate()) : frappe.throw(_("You can only renew if your membership expires within 30 days")) @@ -287,7 +287,7 @@ def trigger_razorpay_subscription(*args, **kwargs): membership.generate_invoice(with_payment_entry=settings.automate_membership_payment_entries, save=True) except Exception as e: - message = "{0}\n\n{1}\n\n{2}: {3}".format(e, frappe.get_traceback(), __("Payment ID"), payment.id) + message = "{0}\n\n{1}\n\n{2}: {3}".format(e, frappe.get_traceback(), _("Payment ID"), payment.id) log = frappe.log_error(message, _("Error creating membership entry for {0}").format(member.name)) notify_failure(log) return { "status": "Failed", "reason": e} diff --git a/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py index d734a18c3a..ef384d4602 100644 --- a/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py +++ b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py @@ -29,7 +29,10 @@ class TaxExemption80GCertificate(Document): def validate_duplicates(self): if self.recipient == 'Donor': - certificate = frappe.db.exists(self.doctype, {'donation': self.donation}) + certificate = frappe.db.exists(self.doctype, { + 'donation': self.donation, + 'name': ('!=', self.name) + }) if certificate: frappe.throw(_('An 80G Certificate {0} already exists for the donation {1}').format( get_link_to_form(self.doctype, certificate), frappe.bold(self.donation) From 6117ac5affff70b9042f19ed04774ccd153a61f2 Mon Sep 17 00:00:00 2001 From: Andy Zhu Date: Wed, 17 Mar 2021 13:53:02 +1300 Subject: [PATCH 306/449] fix: copy_parent_value_in_all_row function error --- erpnext/public/js/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index e5b50d86ed..e7c7d11b0d 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -293,7 +293,7 @@ $.extend(erpnext.utils, { }, copy_parent_value_in_all_row: function(doc, dt, dn, table_fieldname, fieldname, parent_fieldname) { var d = locals[dt][dn]; - if(d[fieldname]){ + if(d[parent_fieldname]){ var cl = doc[table_fieldname] || []; for(var i = 0; i < cl.length; i++) { cl[i][fieldname] = doc[parent_fieldname]; From a5987782bdd694132f8b1e6a6e014a8afabfa0dc Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 17 Mar 2021 15:47:03 +0530 Subject: [PATCH 307/449] fix(India): Incorrect Nil Exempt and Non GST amount in GSTR3B report --- erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py index 68c8a0d4d3..0d08a35787 100644 --- a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py +++ b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py @@ -353,7 +353,7 @@ class GSTR3BReport(Document): inward_nil_exempt = frappe.db.sql(""" select p.place_of_supply, sum(i.base_amount) as base_amount, i.is_nil_exempt, i.is_non_gst from `tabPurchase Invoice` p , `tabPurchase Invoice Item` i where p.docstatus = 1 and p.name = i.parent - and i.is_nil_exempt = 1 or i.is_non_gst = 1 and + and (i.is_nil_exempt = 1 or i.is_non_gst = 1) and month(p.posting_date) = %s and year(p.posting_date) = %s and p.company = %s and p.company_gstin = %s group by p.place_of_supply """, (self.month_no, self.year, self.company, self.gst_details.get("gstin")), as_dict=1) From f9519c7e13cc565358b558f0b0998396bf02aa8b Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 17 Mar 2021 18:00:08 +0530 Subject: [PATCH 308/449] fix: Group nil exempted and non gst items separately --- erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py index 0d08a35787..a8e843b61d 100644 --- a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py +++ b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py @@ -349,14 +349,15 @@ class GSTR3BReport(Document): return inter_state_supply_details def get_inward_nil_exempt(self, state): - + print("@@@@@@@@@@@@") inward_nil_exempt = frappe.db.sql(""" select p.place_of_supply, sum(i.base_amount) as base_amount, i.is_nil_exempt, i.is_non_gst from `tabPurchase Invoice` p , `tabPurchase Invoice Item` i where p.docstatus = 1 and p.name = i.parent and (i.is_nil_exempt = 1 or i.is_non_gst = 1) and month(p.posting_date) = %s and year(p.posting_date) = %s and p.company = %s and p.company_gstin = %s - group by p.place_of_supply """, (self.month_no, self.year, self.company, self.gst_details.get("gstin")), as_dict=1) + group by p.place_of_supply, i.is_nil_exempt, i.is_non_gst""", (self.month_no, self.year, self.company, self.gst_details.get("gstin")), as_dict=1) + print(inward_nil_exempt, "$#$#$#$") inward_nil_exempt_details = { "gst": { "intra": 0.0, From 438d9cad900f0fe26244bafaa9a5e736b8458f1b Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 17 Mar 2021 18:03:17 +0530 Subject: [PATCH 309/449] fix: Remove print statement --- erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py index a8e843b61d..a49996d107 100644 --- a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py +++ b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py @@ -349,7 +349,6 @@ class GSTR3BReport(Document): return inter_state_supply_details def get_inward_nil_exempt(self, state): - print("@@@@@@@@@@@@") inward_nil_exempt = frappe.db.sql(""" select p.place_of_supply, sum(i.base_amount) as base_amount, i.is_nil_exempt, i.is_non_gst from `tabPurchase Invoice` p , `tabPurchase Invoice Item` i where p.docstatus = 1 and p.name = i.parent @@ -357,7 +356,6 @@ class GSTR3BReport(Document): month(p.posting_date) = %s and year(p.posting_date) = %s and p.company = %s and p.company_gstin = %s group by p.place_of_supply, i.is_nil_exempt, i.is_non_gst""", (self.month_no, self.year, self.company, self.gst_details.get("gstin")), as_dict=1) - print(inward_nil_exempt, "$#$#$#$") inward_nil_exempt_details = { "gst": { "intra": 0.0, From bacfaa4396b16b0a32e640f9e34b52de1feaf91c Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 17 Mar 2021 19:51:59 +0530 Subject: [PATCH 310/449] fix: calculate 80g certificate amount on validate for memberships (#24925) (#24926) --- .../tax_exemption_80g_certificate.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py index ef384d4602..5bbd5750f9 100644 --- a/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py +++ b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py @@ -16,6 +16,7 @@ class TaxExemption80GCertificate(Document): self.validate_duplicates() self.validate_company_details() self.set_company_address() + self.calculate_total() self.set_title() def validate_date(self): @@ -54,8 +55,17 @@ class TaxExemption80GCertificate(Document): self.company_address = address.company_address self.company_address_display = address.company_address_display + def calculate_total(self): + if self.recipient == 'Donor': + return + + total = 0 + for entry in self.payments: + total += flt(entry.amount) + self.total = total + def set_title(self): - if self.recipient == "Member": + if self.recipient == 'Member': self.title = self.member_name else: self.title = self.donor_name From 95e9b2fd6e4131b149ab6fb5132642fc7b7214c2 Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Wed, 17 Mar 2021 19:58:56 +0530 Subject: [PATCH 311/449] refactor(payroll): simplified logic for additional salary (#24907) --- .../additional_salary/additional_salary.py | 53 +++---- .../doctype/salary_slip/salary_slip.py | 132 ++++++++++-------- .../doctype/salary_slip/test_salary_slip.py | 2 +- 3 files changed, 92 insertions(+), 95 deletions(-) diff --git a/erpnext/payroll/doctype/additional_salary/additional_salary.py b/erpnext/payroll/doctype/additional_salary/additional_salary.py index f5af677fce..029e11ff9b 100644 --- a/erpnext/payroll/doctype/additional_salary/additional_salary.py +++ b/erpnext/payroll/doctype/additional_salary/additional_salary.py @@ -89,10 +89,11 @@ class AdditionalSalary(Document): no_of_days = date_diff(getdate(end_date), getdate(start_date)) + 1 return amount_per_day * no_of_days -@frappe.whitelist() -def get_additional_salary_component(employee, start_date, end_date, component_type): - additional_salaries = frappe.db.sql(""" - select name, salary_component, type, amount, overwrite_salary_structure_amount, deduct_full_tax_on_selected_payroll_date +def get_additional_salaries(employee, start_date, end_date, component_type): + additional_salary_list = frappe.db.sql(""" + select name, salary_component as component, type, amount, + overwrite_salary_structure_amount as overwrite, + deduct_full_tax_on_selected_payroll_date from `tabAdditional Salary` where employee=%(employee)s and docstatus = 1 @@ -102,7 +103,7 @@ def get_additional_salary_component(employee, start_date, end_date, component_ty from_date <= %(to_date)s and to_date >= %(to_date)s ) and type = %(component_type)s - order by salary_component, overwrite_salary_structure_amount DESC + order by salary_component, overwrite ASC """, { 'employee': employee, 'from_date': start_date, @@ -110,38 +111,18 @@ def get_additional_salary_component(employee, start_date, end_date, component_ty 'component_type': "Earning" if component_type == "earnings" else "Deduction" }, as_dict=1) - existing_salary_components= [] - salary_components_details = {} - additional_salary_details = [] + additional_salaries = [] + components_to_overwrite = [] - overwrites_components = [ele.salary_component for ele in additional_salaries if ele.overwrite_salary_structure_amount == 1] + for d in additional_salary_list: + if d.overwrite: + if d.component in components_to_overwrite: + frappe.throw(_("Multiple Additional Salaries with overwrite " + "property exist for Salary Component {0} between {1} and {2}.").format( + frappe.bold(d.component), start_date, end_date), title=_("Error")) - component_fields = ["depends_on_payment_days", "salary_component_abbr", "is_tax_applicable", "variable_based_on_taxable_salary", 'type'] - for d in additional_salaries: + components_to_overwrite.append(d.component) - if d.salary_component not in existing_salary_components: - component = frappe.get_all("Salary Component", filters={'name': d.salary_component}, fields=component_fields) - struct_row = frappe._dict({'salary_component': d.salary_component}) - if component: - struct_row.update(component[0]) + additional_salaries.append(d) - struct_row['deduct_full_tax_on_selected_payroll_date'] = d.deduct_full_tax_on_selected_payroll_date - struct_row['is_additional_component'] = 1 - - salary_components_details[d.salary_component] = struct_row - - - if overwrites_components.count(d.salary_component) > 1: - frappe.throw(_("Multiple Additional Salaries with overwrite property exist for Salary Component: {0} between {1} and {2}.".format(d.salary_component, start_date, end_date)), title=_("Error")) - else: - additional_salary_details.append({ - 'name': d.name, - 'component': d.salary_component, - 'amount': d.amount, - 'type': d.type, - 'overwrite': d.overwrite_salary_structure_amount, - }) - - existing_salary_components.append(d.salary_component) - - return salary_components_details, additional_salary_details + return additional_salaries diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index 5c5eccd7e5..55e1c63a3f 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -13,7 +13,7 @@ from erpnext.payroll.doctype.payroll_entry.payroll_entry import get_start_end_da from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee from erpnext.utilities.transaction_base import TransactionBase from frappe.utils.background_jobs import enqueue -from erpnext.payroll.doctype.additional_salary.additional_salary import get_additional_salary_component +from erpnext.payroll.doctype.additional_salary.additional_salary import get_additional_salaries from erpnext.payroll.doctype.payroll_period.payroll_period import get_period_factor, get_payroll_period from erpnext.payroll.doctype.employee_benefit_application.employee_benefit_application import get_benefit_component_amount from erpnext.payroll.doctype.employee_benefit_claim.employee_benefit_claim import get_benefit_claim_amount, get_last_payroll_period_benefits @@ -540,15 +540,16 @@ class SalarySlip(TransactionBase): self.update_component_row(frappe._dict(last_benefit.struct_row), amount, "earnings") def add_additional_salary_components(self, component_type): - salary_components_details, additional_salary_details = get_additional_salary_component(self.employee, + additional_salaries = get_additional_salaries(self.employee, self.start_date, self.end_date, component_type) - if salary_components_details and additional_salary_details: - for additional_salary in additional_salary_details: - additional_salary =frappe._dict(additional_salary) - amount = additional_salary.amount - overwrite = additional_salary.overwrite - self.update_component_row(frappe._dict(salary_components_details[additional_salary.component]), amount, - component_type, overwrite=overwrite, additional_salary=additional_salary.name) + + for additional_salary in additional_salaries: + self.update_component_row( + get_salary_component_data(additional_salary.component), + additional_salary.amount, + component_type, + additional_salary + ) def add_tax_components(self, payroll_period): # Calculate variable_based_on_taxable_salary after all components updated in salary slip @@ -565,46 +566,59 @@ class SalarySlip(TransactionBase): for d in tax_components: tax_amount = self.calculate_variable_based_on_taxable_salary(d, payroll_period) - tax_row = self.get_salary_slip_row(d) + tax_row = get_salary_component_data(d) self.update_component_row(tax_row, tax_amount, "deductions") - def update_component_row(self, struct_row, amount, key, overwrite=1, additional_salary = ''): + def update_component_row(self, component_data, amount, component_type, additional_salary=None): component_row = None - for d in self.get(key): - if d.salary_component == struct_row.salary_component: + for d in self.get(component_type): + if d.salary_component != component_data.salary_component: + continue + + if ( + not d.additional_salary + and (not additional_salary or additional_salary.overwrite) + or additional_salary + and additional_salary.name == d.additional_salary + ): component_row = d - if not component_row or (struct_row.get("is_additional_component") and not overwrite): - if amount: - self.append(key, { - 'amount': amount, - 'default_amount': amount if not struct_row.get("is_additional_component") else 0, - 'depends_on_payment_days' : struct_row.depends_on_payment_days, - 'salary_component' : struct_row.salary_component, - 'abbr' : struct_row.abbr or struct_row.get("salary_component_abbr"), - 'additional_salary': additional_salary, - 'do_not_include_in_total' : struct_row.do_not_include_in_total, - 'is_tax_applicable': struct_row.is_tax_applicable, - 'is_flexible_benefit': struct_row.is_flexible_benefit, - 'variable_based_on_taxable_salary': struct_row.variable_based_on_taxable_salary, - 'deduct_full_tax_on_selected_payroll_date': struct_row.deduct_full_tax_on_selected_payroll_date, - 'additional_amount': amount if struct_row.get("is_additional_component") else 0, - 'exempted_from_income_tax': struct_row.exempted_from_income_tax - }) + break + + if additional_salary and additional_salary.overwrite: + # Additional Salary with overwrite checked, remove default rows of same component + self.set(component_type, [ + d for d in self.get(component_type) + if d.salary_component != component_data.salary_component + or d.additional_salary and additional_salary.name != d.additional_salary + or d == component_row + ]) + + if not component_row: + if not amount: + return + + component_row = self.append(component_type) + for attr in ( + 'depends_on_payment_days', 'salary_component', 'abbr' + 'do_not_include_in_total', 'is_tax_applicable', + 'is_flexible_benefit', 'variable_based_on_taxable_salary', + 'exempted_from_income_tax' + ): + component_row.set(attr, component_data.get(attr)) + + if additional_salary: + component_row.default_amount = 0 + component_row.additional_amount = amount + component_row.additional_salary = additional_salary.name + component_row.deduct_full_tax_on_selected_payroll_date = \ + additional_salary.deduct_full_tax_on_selected_payroll_date else: - if struct_row.get("is_additional_component"): - if overwrite: - component_row.additional_amount = amount - component_row.get("default_amount", 0) - component_row.additional_salary = additional_salary - else: - component_row.additional_amount = amount + component_row.default_amount = amount + component_row.additional_amount = 0 + component_row.deduct_full_tax_on_selected_payroll_date = \ + component_data.deduct_full_tax_on_selected_payroll_date - if not overwrite and component_row.default_amount: - amount += component_row.default_amount - else: - component_row.default_amount = amount - - component_row.amount = amount - component_row.deduct_full_tax_on_selected_payroll_date = struct_row.deduct_full_tax_on_selected_payroll_date + component_row.amount = amount def calculate_variable_based_on_taxable_salary(self, tax_component, payroll_period): if not payroll_period: @@ -937,19 +951,6 @@ class SalarySlip(TransactionBase): frappe.throw(_("Error in formula or condition: {0}").format(e)) raise - def get_salary_slip_row(self, salary_component): - component = frappe.get_doc("Salary Component", salary_component) - # Data for update_component_row - struct_row = frappe._dict() - struct_row['depends_on_payment_days'] = component.depends_on_payment_days - struct_row['salary_component'] = component.name - struct_row['abbr'] = component.salary_component_abbr - struct_row['do_not_include_in_total'] = component.do_not_include_in_total - struct_row['is_tax_applicable'] = component.is_tax_applicable - struct_row['is_flexible_benefit'] = component.is_flexible_benefit - struct_row['variable_based_on_taxable_salary'] = component.variable_based_on_taxable_salary - return struct_row - def get_component_totals(self, component_type, depends_on_payment_days=0): joining_date, relieving_date = frappe.get_cached_value("Employee", self.employee, ["date_of_joining", "relieving_date"]) @@ -1012,7 +1013,6 @@ class SalarySlip(TransactionBase): self.total_loan_repayment += payment.total_payment def get_loan_details(self): - return frappe.get_all("Loan", fields=["name", "interest_income_account", "loan_account", "loan_type"], filters = { @@ -1241,4 +1241,20 @@ def unlink_ref_doc_from_salary_slip(ref_no): def generate_password_for_pdf(policy_template, employee): employee = frappe.get_doc("Employee", employee) - return policy_template.format(**employee.as_dict()) \ No newline at end of file + return policy_template.format(**employee.as_dict()) + +def get_salary_component_data(component): + return frappe.get_value( + "Salary Component", + component, + [ + "name as salary_component", + "depends_on_payment_days", + "salary_component_abbr as abbr", + "do_not_include_in_total", + "is_tax_applicable", + "is_flexible_benefit", + "variable_based_on_taxable_salary", + ], + as_dict=1, + ) diff --git a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py index f58a8e58c2..1402f3a839 100644 --- a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py @@ -245,7 +245,7 @@ class TestSalarySlip(unittest.TestCase): make_salary_structure("Test Loan Repayment Salary Structure", "Monthly", employee=applicant, currency='INR', payroll_period=payroll_period) - frappe.db.sql("""delete from `tabLoan""") + frappe.db.sql("delete from tabLoan") loan = create_loan(applicant, "Car Loan", 11000, "Repay Over Number of Periods", 20, posting_date=add_months(nowdate(), -1)) loan.repay_from_salary = 1 loan.submit() From b75cbeee4d1f6cc3fc739b146ec4820d6069f568 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 17 Mar 2021 10:56:52 +0530 Subject: [PATCH 312/449] fix: Allow user to update exchange rate in Multi-currency LCV --- erpnext/controllers/taxes_and_totals.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 6c7eb92221..23541c1ba0 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -779,7 +779,7 @@ class init_landed_taxes_and_totals(object): for d in self.doc.get(self.tax_field): if d.account_currency == company_currency: d.exchange_rate = 1 - elif not d.exchange_rate or d.exchange_rate == 1 or self.doc.posting_date: + elif not d.exchange_rate: d.exchange_rate = get_exchange_rate(self.doc.posting_date, account=d.expense_account, account_currency=d.account_currency, company=self.doc.company) From 67d94ac0cc070edac49d41357ff2c6d85ae61d15 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Sat, 13 Mar 2021 12:48:14 +0530 Subject: [PATCH 313/449] fix: revert stock balance value calculation --- erpnext/stock/report/stock_balance/stock_balance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/report/stock_balance/stock_balance.py b/erpnext/stock/report/stock_balance/stock_balance.py index e5d4d626c4..6dfede4590 100644 --- a/erpnext/stock/report/stock_balance/stock_balance.py +++ b/erpnext/stock/report/stock_balance/stock_balance.py @@ -198,7 +198,7 @@ def get_item_warehouse_map(filters, sle): else: qty_diff = flt(d.actual_qty) - value_diff = flt(d.stock_value) - flt(qty_dict.bal_val) + value_diff = flt(d.stock_value_difference) if d.posting_date < from_date: qty_dict.opening_qty += qty_diff From dffa647071564fb3815f34cb9aeec3fc3ed62713 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Sat, 20 Mar 2021 22:24:55 +0530 Subject: [PATCH 314/449] fix: membership renewal validation (#24963) (#24964) --- erpnext/non_profit/doctype/membership/membership.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/non_profit/doctype/membership/membership.py b/erpnext/non_profit/doctype/membership/membership.py index c41a2f5165..52447e4386 100644 --- a/erpnext/non_profit/doctype/membership/membership.py +++ b/erpnext/non_profit/doctype/membership/membership.py @@ -48,7 +48,7 @@ class Membership(Document): last_membership = erpnext.get_last_membership(self.member) # if person applied for offline membership - if last_membership and last_membership != self.name and not frappe.session.user == "Administrator": + if last_membership and last_membership.name != self.name and not frappe.session.user == "Administrator": # if last membership does not expire in 30 days, then do not allow to renew if getdate(add_days(last_membership.to_date, -30)) > getdate(nowdate()) : frappe.throw(_("You can only renew if your membership expires within 30 days")) @@ -90,6 +90,7 @@ class Membership(Document): self.validate_membership_type_and_settings(plan, settings) invoice = make_invoice(self, member, plan, settings) + self.reload() self.invoice = invoice.name if with_payment_entry: @@ -284,6 +285,7 @@ def trigger_razorpay_subscription(*args, **kwargs): settings = frappe.get_doc("Non Profit Settings") if settings.allow_invoicing and settings.automate_membership_invoicing: + membership.reload() membership.generate_invoice(with_payment_entry=settings.automate_membership_payment_entries, save=True) except Exception as e: From c7c921495bc17fe39a3a0ae5b49d29b03c374d25 Mon Sep 17 00:00:00 2001 From: Anuja Pawar <60467153+Anuja-pawar@users.noreply.github.com> Date: Mon, 22 Mar 2021 11:21:15 +0530 Subject: [PATCH 315/449] fix: payment reference on adding cost center in PE and Issue Summary Report error fixes (#24951) --- .../doctype/payment_entry/payment_entry.js | 15 ++++++++++----- .../support/report/issue_summary/issue_summary.py | 6 ++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index 6412772073..b5f6a401df 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -605,12 +605,22 @@ frappe.ui.form.on('Payment Entry', { {fieldtype:"Column Break"}, {fieldtype:"Float", label: __("Less Than Amount"), fieldname:"outstanding_amt_less_than"}, {fieldtype:"Section Break"}, + {fieldtype:"Link", label:__("Cost Center"), fieldname:"cost_center", options:"Cost Center", + "get_query": function() { + return { + "filters": {"company": frm.doc.company} + } + } + }, + {fieldtype:"Column Break"}, + {fieldtype:"Section Break"}, {fieldtype:"Check", label: __("Allocate Payment Amount"), fieldname:"allocate_payment_amount", default:1}, ]; frappe.prompt(fields, function(filters){ frappe.flags.allocate_payment_amount = true; frm.events.validate_filters_data(frm, filters); + frm.doc.cost_center = filters.cost_center; frm.events.get_outstanding_documents(frm, filters); }, __("Filters"), __("Get Outstanding Documents")); }, @@ -1066,11 +1076,6 @@ frappe.ui.form.on('Payment Entry', { frm.set_value("paid_from_account_balance", r.message.paid_from_account_balance); frm.set_value("paid_to_account_balance", r.message.paid_to_account_balance); frm.set_value("party_balance", r.message.party_balance); - }, - () => { - if(frm.doc.payment_type != "Internal") { - frm.clear_table("references"); - } } ]); diff --git a/erpnext/support/report/issue_summary/issue_summary.py b/erpnext/support/report/issue_summary/issue_summary.py index 3d735314f4..7861e30d25 100644 --- a/erpnext/support/report/issue_summary/issue_summary.py +++ b/erpnext/support/report/issue_summary/issue_summary.py @@ -260,8 +260,7 @@ class IssueSummary(object): self.issue_summary_data[value]['avg_user_resolution_time'] = entry.get('avg_user_resolution_time') or 0.0 def get_chart_data(self): - if not self.data: - return None + self.chart = [] labels = [] open_issues = [] @@ -310,8 +309,7 @@ class IssueSummary(object): } def get_report_summary(self): - if not self.data: - return None + self.report_summary = [] open_issues = 0 replied = 0 From d1f15b2a88ba312c7b985c13cd9491b32544acc8 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Tue, 23 Mar 2021 10:45:06 +0530 Subject: [PATCH 316/449] fix: TDS check getting checked after reload (#24973) --- erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js index 06aa20bfc5..66a8e206a8 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -524,7 +524,7 @@ frappe.ui.form.on("Purchase Invoice", { }, onload: function(frm) { - if(frm.doc.__onload) { + if(frm.doc.__onload && frm.is_new()) { if(frm.doc.supplier) { frm.doc.apply_tds = frm.doc.__onload.supplier_tds ? 1 : 0; } From 4ccda9f799f2128d17b187996c019e2adc39921a Mon Sep 17 00:00:00 2001 From: Marica Date: Tue, 23 Mar 2021 10:45:57 +0530 Subject: [PATCH 317/449] chore: Allow changing Work Stations in WO. (#24898) --- erpnext/manufacturing/doctype/job_card/job_card.py | 3 +++ erpnext/manufacturing/doctype/work_order/work_order.json | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py index 662a06b1ee..7aaf2a08ec 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.py +++ b/erpnext/manufacturing/doctype/job_card/job_card.py @@ -255,6 +255,9 @@ class JobCard(Document): data.actual_operation_time = time_in_mins data.actual_start_time = time_data[0].start_time if time_data else None data.actual_end_time = time_data[0].end_time if time_data else None + if data.get("workstation") != self.workstation: + # workstations can change in a job card + data.workstation = self.workstation wo.flags.ignore_validate_update_after_submit = True wo.update_operation_status() diff --git a/erpnext/manufacturing/doctype/work_order/work_order.json b/erpnext/manufacturing/doctype/work_order/work_order.json index 585a09db2b..cd9edeeea8 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.json +++ b/erpnext/manufacturing/doctype/work_order/work_order.json @@ -333,8 +333,7 @@ "fieldname": "operations", "fieldtype": "Table", "label": "Operations", - "options": "Work Order Operation", - "read_only": 1 + "options": "Work Order Operation" }, { "depends_on": "operations", @@ -496,7 +495,7 @@ "image_field": "image", "is_submittable": 1, "links": [], - "modified": "2020-05-05 19:32:43.323054", + "modified": "2021-03-16 13:27:51.116484", "modified_by": "Administrator", "module": "Manufacturing", "name": "Work Order", From 6a534ea82b857adaac74a1f6038aac0a76f4e401 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 15 Mar 2021 19:10:54 +0530 Subject: [PATCH 318/449] fix: Allow zero valuation in stock reconciliation Stock reconciliation can not be done for customer provided item as they have zero valuation. This change adds a checkbox in item table to allow such items. Related issue: ISS-20-21-10248 --- .../stock_reconciliation/stock_reconciliation.py | 5 +++-- .../stock_reconciliation_item.json | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index f0a90f9754..4d9a01de4c 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -31,6 +31,7 @@ class StockReconciliation(StockController): self.validate_expense_account() self.set_total_qty_and_amount() self.validate_putaway_capacity() + self.validate_customer_provided_item() if self._action=="submit": self.make_batches('warehouse') @@ -217,7 +218,7 @@ class StockReconciliation(StockController): if row.valuation_rate in ("", None): row.valuation_rate = previous_sle.get("valuation_rate", 0) - if row.qty and not row.valuation_rate: + if row.qty and not row.valuation_rate and not row.allow_zero_valuation_rate: frappe.throw(_("Valuation Rate required for Item {0} at row {1}").format(row.item_code, row.idx)) if ((previous_sle and row.qty == previous_sle.get("qty_after_transaction") @@ -531,4 +532,4 @@ def get_difference_account(purpose, company): account = frappe.db.get_value('Account', {'is_group': 0, 'company': company, 'account_type': 'Temporary'}, 'name') - return account \ No newline at end of file + return account diff --git a/erpnext/stock/doctype/stock_reconciliation_item/stock_reconciliation_item.json b/erpnext/stock/doctype/stock_reconciliation_item/stock_reconciliation_item.json index e53db0772b..85c7ebe263 100644 --- a/erpnext/stock/doctype/stock_reconciliation_item/stock_reconciliation_item.json +++ b/erpnext/stock/doctype/stock_reconciliation_item/stock_reconciliation_item.json @@ -13,6 +13,7 @@ "qty", "valuation_rate", "amount", + "allow_zero_valuation_rate", "serial_no_and_batch_section", "serial_no", "column_break_11", @@ -166,10 +167,19 @@ "fieldtype": "Link", "label": "Batch No", "options": "Batch" + }, + { + "default": "0", + "fieldname": "allow_zero_valuation_rate", + "fieldtype": "Check", + "label": "Allow Zero Valuation Rate", + "print_hide": 1, + "read_only": 1 } ], "istable": 1, - "modified": "2019-06-14 17:10:53.188305", + "links": [], + "modified": "2021-03-23 11:09:44.407157", "modified_by": "Administrator", "module": "Stock", "name": "Stock Reconciliation Item", @@ -179,4 +189,4 @@ "sort_field": "modified", "sort_order": "DESC", "track_changes": 1 -} \ No newline at end of file +} From 2a391298a7ac567544889ab962fde69db75d7096 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 23 Mar 2021 12:41:19 +0530 Subject: [PATCH 319/449] test: customer item in stock reconciliation --- .../stock_reconciliation/test_stock_reconciliation.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index 088456f865..6690c6a606 100644 --- a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -193,6 +193,16 @@ class TestStockReconciliation(unittest.TestCase): stock_doc = frappe.get_doc("Stock Reconciliation", d) stock_doc.cancel() + def test_customer_provided_items(self): + item_code = 'Stock-Reco-customer-Item-100' + create_item(item_code, is_customer_provided_item = 1, + customer = '_Test Customer', is_purchase_item = 0) + + sr = create_stock_reconciliation(item_code = item_code, qty = 10, rate = 420) + + self.assertEqual(sr.get("items")[0].allow_zero_valuation_rate, 1) + self.assertEqual(sr.get("items")[0].valuation_rate, 0) + self.assertEqual(sr.get("items")[0].amount, 0) def insert_existing_sle(warehouse): from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry From 2ba198576c68c503cd7fb3da26341df8744f5275 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 23 Mar 2021 12:16:58 +0530 Subject: [PATCH 320/449] fix: set valuation rate for customer items to zero - In stock reconciliation always set valuation rate of customer provided items to zero during validation. - Let user know the valuation has been changed. --- .../stock_reconciliation.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index 4d9a01de4c..b452e96c5e 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -29,9 +29,10 @@ class StockReconciliation(StockController): self.remove_items_with_no_change() self.validate_data() self.validate_expense_account() + self.validate_customer_provided_item() + self.set_zero_value_for_customer_provided_items() self.set_total_qty_and_amount() self.validate_putaway_capacity() - self.validate_customer_provided_item() if self._action=="submit": self.make_batches('warehouse') @@ -437,6 +438,20 @@ class StockReconciliation(StockController): if frappe.db.get_value("Account", self.expense_account, "report_type") == "Profit and Loss": frappe.throw(_("Difference Account must be a Asset/Liability type account, since this Stock Reconciliation is an Opening Entry"), OpeningEntryAccountError) + def set_zero_value_for_customer_provided_items(self): + changed_any_values = False + + for d in self.get('items'): + is_customer_item = frappe.db.get_value('Item', d.item_code, 'is_customer_provided_item') + if is_customer_item and d.valuation_rate: + d.valuation_rate = 0.0 + changed_any_values = True + + if changed_any_values: + msgprint(_("Valuation rate for customer provided items has been set to zero."), + title=_("Note"), indicator="blue") + + def set_total_qty_and_amount(self): for d in self.get("items"): d.amount = flt(d.qty, d.precision("qty")) * flt(d.valuation_rate, d.precision("valuation_rate")) From 940c75f8ac6ea265e25f9a9a63baa22d7a07b7d3 Mon Sep 17 00:00:00 2001 From: Anupam Date: Tue, 23 Mar 2021 16:54:54 +0530 Subject: [PATCH 321/449] fix: validate_series --- erpnext/setup/doctype/naming_series/naming_series.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/setup/doctype/naming_series/naming_series.py b/erpnext/setup/doctype/naming_series/naming_series.py index abff97364c..2ea0bc08ca 100644 --- a/erpnext/setup/doctype/naming_series/naming_series.py +++ b/erpnext/setup/doctype/naming_series/naming_series.py @@ -10,6 +10,7 @@ from frappe import msgprint, throw, _ from frappe.model.document import Document from frappe.model.naming import parse_naming_series from frappe.permissions import get_doctypes_with_read +from frappe.core.doctype.doctype.doctype import validate_series class NamingSeriesNotSetError(frappe.ValidationError): pass @@ -126,7 +127,7 @@ class NamingSeries(Document): dt = frappe.get_doc("DocType", self.select_doc_for_series) options = self.scrub_options_list(self.set_options.split("\n")) for series in options: - dt.validate_series(series) + validate_series(dt, series) for i in sr: if i[0]: existing_series = [d.split('.')[0] for d in i[0].split("\n")] From d7b139182bb2c5ec998b89ee44b93a72d5103c51 Mon Sep 17 00:00:00 2001 From: Jannat Patel <31363128+pateljannat@users.noreply.github.com> Date: Tue, 23 Mar 2021 21:09:54 +0530 Subject: [PATCH 322/449] fix: serial no trim issue (#24981) * fix: serial no trim issue * fix: sider --- erpnext/public/js/controllers/transaction.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index dce8e5d68b..7d90d2662e 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -703,21 +703,15 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ } else { var valid_serial_nos = []; - + var serialnos = []; // Replacing all occurences of comma with carriage return - var serial_nos = item.serial_no.trim().replace(/,/g, '\n'); - - serial_nos = serial_nos.trim().split('\n'); - - // Trim each string and push unique string to new list - for (var x=0; x<=serial_nos.length - 1; x++) { - if (serial_nos[x].trim() != "" && valid_serial_nos.indexOf(serial_nos[x].trim()) == -1) { - valid_serial_nos.push(serial_nos[x].trim()); + item.serial_no = item.serial_no.replace(/,/g, '\n'); + serialnos = item.serial_no.split("\n"); + for (var i = 0; i < serialnos.length; i++) { + if (serialnos[i] != "") { + valid_serial_nos.push(serialnos[i]); } } - - // Add the new list to the serial no. field in grid with each in new line - item.serial_no = valid_serial_nos.join('\n'); item.conversion_factor = item.conversion_factor || 1; refresh_field("serial_no", item.name, item.parentfield); From d26ed25c3eb2471c2934f77487757f5030a80521 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Tue, 23 Mar 2021 21:11:06 +0530 Subject: [PATCH 323/449] fix: Period list for exponential smoothing forecasting report (#24983) --- erpnext/accounts/report/financial_statements.py | 6 +++++- .../exponential_smoothing_forecasting.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 7dfce85629..14efa1f8fc 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -51,7 +51,11 @@ def get_period_list(from_fiscal_year, to_fiscal_year, period_start_date, period_ "from_date": start_date }) - to_date = add_months(start_date, months_to_add) + if i==0 and filter_based_on == 'Date Range': + to_date = add_months(get_first_day(start_date), months_to_add) + else: + to_date = add_months(start_date, months_to_add) + start_date = to_date # Subtract one day from to_date, as it may be first day in next fiscal year or month diff --git a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py index 2ca9f1694b..fc27d35598 100644 --- a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py +++ b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py @@ -61,7 +61,7 @@ class ForecastingReport(ExponentialSmoothingForecast): from_date = add_years(self.filters.from_date, cint(self.filters.no_of_years) * -1) self.period_list = get_period_list(from_date, self.filters.to_date, - from_date, self.filters.to_date, None, self.filters.periodicity, ignore_fiscal_year=True) + from_date, self.filters.to_date, "Date Range", self.filters.periodicity, ignore_fiscal_year=True) order_data = self.get_data_for_forecast() or [] From 5c172044d7495f4a6ae0a2700e51a4b665e8681b Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Tue, 23 Mar 2021 21:13:06 +0530 Subject: [PATCH 324/449] fix: validate_series (#24987) --- erpnext/setup/doctype/naming_series/naming_series.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/setup/doctype/naming_series/naming_series.py b/erpnext/setup/doctype/naming_series/naming_series.py index abff97364c..2ea0bc08ca 100644 --- a/erpnext/setup/doctype/naming_series/naming_series.py +++ b/erpnext/setup/doctype/naming_series/naming_series.py @@ -10,6 +10,7 @@ from frappe import msgprint, throw, _ from frappe.model.document import Document from frappe.model.naming import parse_naming_series from frappe.permissions import get_doctypes_with_read +from frappe.core.doctype.doctype.doctype import validate_series class NamingSeriesNotSetError(frappe.ValidationError): pass @@ -126,7 +127,7 @@ class NamingSeries(Document): dt = frappe.get_doc("DocType", self.select_doc_for_series) options = self.scrub_options_list(self.set_options.split("\n")) for series in options: - dt.validate_series(series) + validate_series(dt, series) for i in sr: if i[0]: existing_series = [d.split('.')[0] for d in i[0].split("\n")] From 9165327cf6ed5997240d39457c3b8a7e705bbb4f Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 23 Mar 2021 11:37:27 +0530 Subject: [PATCH 325/449] fix: repost not completed backdated transactions --- erpnext/hooks.py | 1 + .../repost_item_valuation.py | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/erpnext/hooks.py b/erpnext/hooks.py index fe80c6585d..0401be47b2 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -320,6 +320,7 @@ scheduler_events = { "erpnext.hr.doctype.shift_type.shift_type.process_auto_attendance_for_all_shifts", "erpnext.support.doctype.issue.issue.set_service_level_agreement_variance", "erpnext.erpnext_integrations.connectors.shopify_connection.sync_old_orders", + "erpnext.stock.doctype.repost_item_valuation.repost_item_valuation.repost_entries" ], "daily": [ "erpnext.stock.reorder_item.reorder_item", diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py index 8436acbed2..559f9a5ed9 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe, erpnext from frappe.model.document import Document -from frappe.utils import cint, get_link_to_form +from frappe.utils import cint, get_link_to_form, add_to_date, today from erpnext.stock.stock_ledger import repost_future_sle from erpnext.accounts.utils import update_gl_entries_after, check_if_stock_and_account_balance_synced from frappe.utils.user import get_users_with_role @@ -29,7 +29,7 @@ class RepostItemValuation(Document): self.company = frappe.get_cached_value(self.voucher_type, self.voucher_no, "company") elif self.warehouse: self.company = frappe.get_cached_value("Warehouse", self.warehouse, "company") - + def set_status(self, status=None): if not status: status = 'Queued' @@ -54,7 +54,6 @@ def repost(doc): repost_sl_entries(doc) repost_gl_entries(doc) - check_if_stock_and_account_balance_synced(doc.posting_date, doc.company) doc.set_status('Completed') except Exception: @@ -103,7 +102,7 @@ def notify_error_to_stock_managers(doc, traceback): recipients = get_users_with_role("Stock Manager") if not recipients: get_users_with_role("System Manager") - + subject = _("Error while reposting item valuation") message = (_("Hi,") + "
" + _("An error has been appeared while reposting item valuation via {0}") @@ -112,4 +111,24 @@ def notify_error_to_stock_managers(doc, traceback): ) frappe.sendmail(recipients=recipients, subject=subject, message=message) +def repost_entries(): + riv_entries = get_repost_item_valuation_entries() + for row in riv_entries: + doc = frappe.get_cached_doc('Repost Item Valuation', row.name) + repost(doc) + + riv_entries = get_repost_item_valuation_entries() + if riv_entries: + return + + for d in frappe.get_all('Company', filters= {'enable_perpetual_inventory': 1}): + check_if_stock_and_account_balance_synced(today(), d.company) + +def get_repost_item_valuation_entries(): + date = add_to_date(today(), hours=-12) + + return frappe.db.sql(""" SELECT name from `tabRepost Item Valuation` + WHERE status != 'Completed' and creation <= %s and docstatus = 1 + ORDER BY timestamp(posting_date, posting_time) asc, creation asc + """, date, as_dict=1) \ No newline at end of file From 244f3eeedcbc5633d632883578875e59231f864c Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 24 Mar 2021 16:42:22 +0530 Subject: [PATCH 326/449] fix: incorrect fieldname --- .../doctype/repost_item_valuation/repost_item_valuation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py index 559f9a5ed9..a75db1ac86 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -123,7 +123,7 @@ def repost_entries(): return for d in frappe.get_all('Company', filters= {'enable_perpetual_inventory': 1}): - check_if_stock_and_account_balance_synced(today(), d.company) + check_if_stock_and_account_balance_synced(today(), d.name) def get_repost_item_valuation_entries(): date = add_to_date(today(), hours=-12) From 91026e026fe3c549f383d9dca08d5e4b9724e159 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 25 Mar 2021 11:53:07 +0530 Subject: [PATCH 327/449] chore: Added change log --- erpnext/change_log/v13/v13_0_0-beta_14.md | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 erpnext/change_log/v13/v13_0_0-beta_14.md diff --git a/erpnext/change_log/v13/v13_0_0-beta_14.md b/erpnext/change_log/v13/v13_0_0-beta_14.md new file mode 100644 index 0000000000..8ef3c92e31 --- /dev/null +++ b/erpnext/change_log/v13/v13_0_0-beta_14.md @@ -0,0 +1,24 @@ +### Fixes and Enhancements + +- Repost incompleted backdated transactions ([#24991](https://github.com/frappe/erpnext/pull/24991)) +- Revert stock balance value calculation ([#24957](https://github.com/frappe/erpnext/pull/24957)) +- Allow user to update exchange rate in Multi-currency LCV ([#24947](https://github.com/frappe/erpnext/pull/24947)) +- Added correct path in hooks ([#24865](https://github.com/frappe/erpnext/pull/24865)) +- Unequal debit and credit issue on RCM Invoice ([#24838](https://github.com/frappe/erpnext/pull/24838)) +- Period list for exponential smoothing forecasting report ([#24983](https://github.com/frappe/erpnext/pull/24983)) +- POS Opening Entry with empty balance detail rows ([#24891](https://github.com/frappe/erpnext/pull/24891)) +- Use account_name only in consolidated report ([#24840](https://github.com/frappe/erpnext/pull/24840)) +- Validation of job card in stock entry ([#24882](https://github.com/frappe/erpnext/pull/24882)) +- Added supplier warehouse field back again ([#24827](https://github.com/frappe/erpnext/pull/24827)) +- Don't throw exception on invoice lines when there is no item_cod… ([#24864](https://github.com/frappe/erpnext/pull/24864)) +- Incorrect Nil Exempt and Non GST amount in GSTR3B report ([#24918](https://github.com/frappe/erpnext/pull/24918)) +- Payment References on adding Cost Center in PE and Report Issue Summary fix for V13 beta pre-release ([#24951](https://github.com/frappe/erpnext/pull/24951)) +- TDS check getting checked after reload ([#24973](https://github.com/frappe/erpnext/pull/24973)) +- Membership and Donation API fixes ([#24900](https://github.com/frappe/erpnext/pull/24900)) +- Serial no trim issue ([#24981](https://github.com/frappe/erpnext/pull/24981)) +- Add method for regional round off account back ([#24894](https://github.com/frappe/erpnext/pull/24894)) +- Allow zero valuation in stock reconciliation ([#24985](https://github.com/frappe/erpnext/pull/24985)) +- Simplified logic for additional salary ([#24907](https://github.com/frappe/erpnext/pull/24907)) +- Allow to select item code in batch naming ([#24825](https://github.com/frappe/erpnext/pull/24825)) +- 80G Certificates and Donations ([#24848](https://github.com/frappe/erpnext/pull/24848)) +- Membership renewal validation (#24963) ([#24964](https://github.com/frappe/erpnext/pull/24964)) \ No newline at end of file From d4499277b4da8bae40a65f18adc0243e47e91e88 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 25 Mar 2021 12:18:22 +0530 Subject: [PATCH 328/449] chore: Added change log --- erpnext/change_log/v13/v13_0_0-beta_14.md | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/change_log/v13/v13_0_0-beta_14.md b/erpnext/change_log/v13/v13_0_0-beta_14.md index 8ef3c92e31..1fa4376a72 100644 --- a/erpnext/change_log/v13/v13_0_0-beta_14.md +++ b/erpnext/change_log/v13/v13_0_0-beta_14.md @@ -1,3 +1,4 @@ +## Version 13.0.0 Beta 14 Release Notes ### Fixes and Enhancements - Repost incompleted backdated transactions ([#24991](https://github.com/frappe/erpnext/pull/24991)) From f29c075bc3e9c1b2081c4d6621b715a7a9b08332 Mon Sep 17 00:00:00 2001 From: Mohammad Hasnain Mohsin Rajan Date: Thu, 25 Mar 2021 12:56:13 +0530 Subject: [PATCH 329/449] fix: patch regional fields for old companies (#24999) * fix: patch regional fields for old companies * chore: fix sider --- erpnext/patches.txt | 1 + erpnext/patches/v13_0/setup_uae_vat_fields.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 erpnext/patches/v13_0/setup_uae_vat_fields.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 59b12f319e..c686635b6c 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -759,3 +759,4 @@ erpnext.patches.v13_0.update_vehicle_no_reqd_condition erpnext.patches.v13_0.setup_fields_for_80g_certificate_and_donation erpnext.patches.v13_0.rename_membership_settings_to_non_profit_settings erpnext.patches.v13_0.setup_gratuity_rule_for_india_and_uae +erpnext.patches.v13_0.setup_uae_vat_fields diff --git a/erpnext/patches/v13_0/setup_uae_vat_fields.py b/erpnext/patches/v13_0/setup_uae_vat_fields.py new file mode 100644 index 0000000000..ee55bb8996 --- /dev/null +++ b/erpnext/patches/v13_0/setup_uae_vat_fields.py @@ -0,0 +1,12 @@ +# Copyright (c) 2019, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +import frappe +from erpnext.regional.united_arab_emirates.setup import setup + +def execute(): + company = frappe.get_all('Company', filters = {'country': 'United Arab Emirates'}) + if not company: + return + + setup() From 2a39b74ad24facc417c10ff7cadb60ea86116345 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 26 Mar 2021 10:49:39 +0530 Subject: [PATCH 330/449] fix: Fixes on job card and salary slip (#25011) * fix: map conversion factor while making stock entry from job card * fix: fetch additional salary in salary slip --- erpnext/manufacturing/doctype/job_card/job_card.py | 1 + erpnext/payroll/doctype/salary_slip/salary_slip.py | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py index 7aaf2a08ec..d2ac71223d 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.py +++ b/erpnext/manufacturing/doctype/job_card/job_card.py @@ -430,6 +430,7 @@ def make_material_request(source_name, target_doc=None): def make_stock_entry(source_name, target_doc=None): def update_item(obj, target, source_parent): target.t_warehouse = source_parent.wip_warehouse + target.conversion_factor = 1 def set_missing_values(source, target): target.purpose = "Material Transfer for Manufacture" diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index 55e1c63a3f..0053c0cd93 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -576,10 +576,10 @@ class SalarySlip(TransactionBase): continue if ( - not d.additional_salary - and (not additional_salary or additional_salary.overwrite) - or additional_salary - and additional_salary.name == d.additional_salary + (not d.additional_salary + and (not additional_salary or additional_salary.overwrite)) + or (additional_salary + and additional_salary.name == d.additional_salary) ): component_row = d break @@ -589,7 +589,7 @@ class SalarySlip(TransactionBase): self.set(component_type, [ d for d in self.get(component_type) if d.salary_component != component_data.salary_component - or d.additional_salary and additional_salary.name != d.additional_salary + or (d.additional_salary and additional_salary.name != d.additional_salary) or d == component_row ]) From e9c801e4bd5c2692de28aab8dfc5168b560c5798 Mon Sep 17 00:00:00 2001 From: "hasnain2808@gmail.com" Date: Fri, 15 Jan 2021 18:56:06 +0530 Subject: [PATCH 331/449] fix: ams integration breaks when error raised --- .../doctype/amazon_mws_settings/amazon_methods.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py b/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py index cc75a0afbe..148c1a6a16 100644 --- a/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py +++ b/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py @@ -117,7 +117,7 @@ def call_mws_method(mws_method, *args, **kwargs): return response except Exception as e: delay = math.pow(4, x) * 125 - frappe.log_error(message=e, title=str(mws_method)) + frappe.log_error(message=e, title=f'Method "{mws_method.__name__}" failed') time.sleep(delay) continue From eeb3121622211efe25326b95e0ec94d36b521251 Mon Sep 17 00:00:00 2001 From: prssanna Date: Wed, 24 Mar 2021 16:44:49 +0530 Subject: [PATCH 332/449] fix: missing help links in navbar help dropdown --- erpnext/public/js/help_links.js | 244 ++++++++++++++++++++------------ 1 file changed, 152 insertions(+), 92 deletions(-) diff --git a/erpnext/public/js/help_links.js b/erpnext/public/js/help_links.js index 472c5374f5..66ff46405d 100644 --- a/erpnext/public/js/help_links.js +++ b/erpnext/public/js/help_links.js @@ -2,13 +2,13 @@ frappe.provide('frappe.help.help_links'); const docsUrl = 'https://erpnext.com/docs/'; -frappe.help.help_links['rename tool'] = [ +frappe.help.help_links['Form/Rename Tool'] = [ { label: 'Bulk Rename', url: docsUrl + 'user/manual/en/setting-up/data/bulk-rename' }, ] //Setup -frappe.help.help_links['user'] = [ +frappe.help.help_links['List/User'] = [ { label: 'New User', url: docsUrl + 'user/manual/en/setting-up/users-and-permissions/adding-users' }, { label: 'Rename User', url: docsUrl + 'user/manual/en/setting-up/articles/rename-user' }, ] @@ -21,7 +21,7 @@ frappe.help.help_links['permission-manager'] = [ { label: 'Password', url: docsUrl + 'user/manual/en/setting-up/articles/change-password' }, ] -frappe.help.help_links['system-settings'] = [ +frappe.help.help_links['Form/System Settings'] = [ { label: 'Naming Series', url: docsUrl + 'user/manual/en/setting-up/settings/system-settings' }, ] @@ -30,60 +30,64 @@ frappe.help.help_links['data-import-tool'] = [ { label: 'Overwriting Data from Data Import Tool', url: docsUrl + 'user/manual/en/setting-up/articles/overwriting-data-from-data-import-tool' }, ] -frappe.help.help_links['naming-series'] = [ +frappe.help.help_links['module_setup'] = [ + { label: 'Role Permissions Manager', url: docsUrl + 'user/manual/en/setting-up/users-and-permissions/role-based-permissions' }, +] + +frappe.help.help_links['Form/Naming Series'] = [ { label: 'Naming Series', url: docsUrl + 'user/manual/en/setting-up/settings/naming-series' }, { label: 'Setting the Current Value for Naming Series', url: docsUrl + 'user/manual/en/setting-up/articles/naming-series-current-value' }, ] -frappe.help.help_links['global-defaults'] = [ +frappe.help.help_links['Form/Global Defaults'] = [ { label: 'Global Settings', url: docsUrl + 'user/manual/en/setting-up/settings/global-defaults' }, ] -frappe.help.help_links['email-digest'] = [ +frappe.help.help_links['Form/Email Digest'] = [ { label: 'Email Digest', url: docsUrl + 'user/manual/en/setting-up/email/email-digest' }, ] -frappe.help.help_links['print-heading'] = [ +frappe.help.help_links['List/Print Heading'] = [ { label: 'Print Heading', url: docsUrl + 'user/manual/en/setting-up/print/print-headings' }, ] -frappe.help.help_links['letter-head'] = [ +frappe.help.help_links['List/Letter Head'] = [ { label: 'Letter Head', url: docsUrl + 'user/manual/en/setting-up/print/letter-head' }, ] -frappe.help.help_links['address-template'] = [ +frappe.help.help_links['List/Address Template'] = [ { label: 'Address Template', url: docsUrl + 'user/manual/en/setting-up/print/address-template' }, ] -frappe.help.help_links['terms-and-conditions'] = [ +frappe.help.help_links['List/Terms and Conditions'] = [ { label: 'Terms and Conditions', url: docsUrl + 'user/manual/en/setting-up/print/terms-and-conditions' }, ] -frappe.help.help_links['cheque-print-template'] = [ +frappe.help.help_links['List/Cheque Print Template'] = [ { label: 'Cheque Print Template', url: docsUrl + 'user/manual/en/setting-up/print/cheque-print-template' }, ] -frappe.help.help_links['email-account'] = [ +frappe.help.help_links['List/Email Account'] = [ { label: 'Email Account', url: docsUrl + 'user/manual/en/setting-up/email/email-account' }, ] -frappe.help.help_links['notification'] = [ +frappe.help.help_links['List/Notification'] = [ { label: 'Notification', url: docsUrl + 'user/manual/en/setting-up/email/notifications' }, ] -frappe.help.help_links['notification'] = [ +frappe.help.help_links['Form/Notification'] = [ { label: 'Notification', url: docsUrl + 'user/manual/en/setting-up/email/notifications' }, ] -frappe.help.help_links['email-digest'] = [ +frappe.help.help_links['List/Email Digest'] = [ { label: 'Email Digest', url: docsUrl + 'user/manual/en/setting-up/email/email-digest' }, ] -frappe.help.help_links['auto-email-report'] = [ +frappe.help.help_links['List/Auto Email Report'] = [ { label: 'Auto Email Reports', url: docsUrl + 'user/manual/en/setting-up/email/email-reports' }, ] -frappe.help.help_links['print-settings'] = [ +frappe.help.help_links['Form/Print Settings'] = [ { label: 'Print Settings', url: docsUrl + 'user/manual/en/setting-up/print/print-settings' }, ] @@ -91,60 +95,66 @@ frappe.help.help_links['print-format-builder'] = [ { label: 'Print Format Builder', url: docsUrl + 'user/manual/en/setting-up/print/print-settings' }, ] -frappe.help.help_links['print-heading'] = [ +frappe.help.help_links['List/Print Heading'] = [ { label: 'Print Heading', url: docsUrl + 'user/manual/en/setting-up/print/print-headings' }, ] //setup-integrations -frappe.help.help_links['paypal-settings'] = [ +frappe.help.help_links['Form/PayPal Settings'] = [ { label: 'PayPal Settings', url: docsUrl + 'user/manual/en/setting-up/integrations/paypal-integration' }, ] -frappe.help.help_links['razorpay-settings'] = [ +frappe.help.help_links['Form/Razorpay Settings'] = [ { label: 'Razorpay Settings', url: docsUrl + 'user/manual/en/setting-up/integrations/razorpay-integration' }, ] -frappe.help.help_links['dropbox-settings'] = [ +frappe.help.help_links['Form/Dropbox Settings'] = [ { label: 'Dropbox Settings', url: docsUrl + 'user/manual/en/setting-up/integrations/dropbox-backup' }, ] -frappe.help.help_links['ldap-settings'] = [ +frappe.help.help_links['Form/LDAP Settings'] = [ { label: 'LDAP Settings', url: docsUrl + 'user/manual/en/setting-up/integrations/ldap-integration' }, ] -frappe.help.help_links['stripe-settings'] = [ +frappe.help.help_links['Form/Stripe Settings'] = [ { label: 'Stripe Settings', url: docsUrl + 'user/manual/en/setting-up/integrations/stripe-integration' }, ] //Sales -frappe.help.help_links['quotation'] = [ +frappe.help.help_links['Form/Quotation'] = [ { label: 'Quotation', url: docsUrl + 'user/manual/en/selling/quotation' }, { label: 'Applying Discount', url: docsUrl + 'user/manual/en/selling/articles/applying-discount' }, { label: 'Sales Person', url: docsUrl + 'user/manual/en/selling/articles/sales-persons-in-the-sales-transactions' }, { label: 'Applying Margin', url: docsUrl + 'user/manual/en/selling/articles/adding-margin' }, ] -frappe.help.help_links['customer'] = [ +frappe.help.help_links['List/Customer'] = [ { label: 'Customer', url: docsUrl + 'user/manual/en/CRM/customer' }, { label: 'Credit Limit', url: docsUrl + 'user/manual/en/accounts/credit-limit' }, ] -frappe.help.help_links['customer'] = [ +frappe.help.help_links['Form/Customer'] = [ { label: 'Customer', url: docsUrl + 'user/manual/en/CRM/customer' }, { label: 'Credit Limit', url: docsUrl + 'user/manual/en/accounts/credit-limit' }, ] -frappe.help.help_links['sales-taxes-and-charges-template'] = [ +frappe.help.help_links['List/Sales Taxes and Charges Template'] = [ { label: 'Setting Up Taxes', url: docsUrl + 'user/manual/en/setting-up/setting-up-taxes' }, ] -frappe.help.help_links['sales-taxes-and-charges-template'] = [ +frappe.help.help_links['Form/Sales Taxes and Charges Template'] = [ { label: 'Setting Up Taxes', url: docsUrl + 'user/manual/en/setting-up/setting-up-taxes' }, ] -frappe.help.help_links['sales-order'] = [ +frappe.help.help_links['List/Sales Order'] = [ + { label: 'Sales Order', url: docsUrl + 'user/manual/en/selling/sales-order' }, + { label: 'Recurring Sales Order', url: docsUrl + 'user/manual/en/accounts/recurring-orders-and-invoices' }, + { label: 'Applying Discount', url: docsUrl + 'user/manual/en/selling/articles/applying-discount' }, +] + +frappe.help.help_links['Form/Sales Order'] = [ { label: 'Sales Order', url: docsUrl + 'user/manual/en/selling/sales-order' }, { label: 'Recurring Sales Order', url: docsUrl + 'user/manual/en/accounts/recurring-orders-and-invoices' }, { label: 'Applying Discount', url: docsUrl + 'user/manual/en/selling/articles/applying-discount' }, @@ -154,34 +164,43 @@ frappe.help.help_links['sales-order'] = [ { label: 'Applying Margin', url: docsUrl + 'user/manual/en/selling/articles/adding-margin' }, ] -frappe.help.help_links['product-bundle'] = [ +frappe.help.help_links['Form/Product Bundle'] = [ { label: 'Product Bundle', url: docsUrl + 'user/manual/en/selling/setup/product-bundle' }, ] -frappe.help.help_links['selling-settings'] = [ +frappe.help.help_links['Form/Selling Settings'] = [ { label: 'Selling Settings', url: docsUrl + 'user/manual/en/selling/setup/selling-settings' }, ] //Buying -frappe.help.help_links['supplier'] = [ +frappe.help.help_links['List/Supplier'] = [ { label: 'Supplier', url: docsUrl + 'user/manual/en/buying/supplier' }, ] -frappe.help.help_links['request-for-quotation'] = [ +frappe.help.help_links['Form/Supplier'] = [ + { label: 'Supplier', url: docsUrl + 'user/manual/en/buying/supplier' }, +] + +frappe.help.help_links['Form/Request for Quotation'] = [ { label: 'Request for Quotation', url: docsUrl + 'user/manual/en/buying/request-for-quotation' }, { label: 'RFQ Video', url: docsUrl + 'user/videos/learn/request-for-quotation.html' }, ] -frappe.help.help_links['supplier-quotation'] = [ +frappe.help.help_links['Form/Supplier Quotation'] = [ { label: 'Supplier Quotation', url: docsUrl + 'user/manual/en/buying/supplier-quotation' }, ] -frappe.help.help_links['buying-settings'] = [ +frappe.help.help_links['Form/Buying Settings'] = [ { label: 'Buying Settings', url: docsUrl + 'user/manual/en/buying/setup/buying-settings' }, ] -frappe.help.help_links['purchase-order'] = [ +frappe.help.help_links['List/Purchase Order'] = [ + { label: 'Purchase Order', url: docsUrl + 'user/manual/en/buying/purchase-order' }, + { label: 'Recurring Purchase Order', url: docsUrl + 'user/manual/en/accounts/recurring-orders-and-invoices' }, +] + +frappe.help.help_links['Form/Purchase Order'] = [ { label: 'Purchase Order', url: docsUrl + 'user/manual/en/buying/purchase-order' }, { label: 'Item UoM', url: docsUrl + 'user/manual/en/buying/articles/purchasing-in-different-unit' }, { label: 'Supplier Item Code', url: docsUrl + 'user/manual/en/buying/articles/maintaining-suppliers-part-no-in-item' }, @@ -189,44 +208,44 @@ frappe.help.help_links['purchase-order'] = [ { label: 'Subcontracting', url: docsUrl + 'user/manual/en/manufacturing/subcontracting' }, ] -frappe.help.help_links['purchase-taxes-and-charges-template'] = [ +frappe.help.help_links['List/Purchase Taxes and Charges Template'] = [ { label: 'Setting Up Taxes', url: docsUrl + 'user/manual/en/setting-up/setting-up-taxes' }, ] -frappe.help.help_links['pos-profile'] = [ +frappe.help.help_links['List/POS Profile'] = [ { label: 'POS Profile', url: docsUrl + 'user/manual/en/setting-up/pos-setting' }, ] -frappe.help.help_links['price-list'] = [ +frappe.help.help_links['List/Price List'] = [ { label: 'Price List', url: docsUrl + 'user/manual/en/setting-up/price-lists' }, ] -frappe.help.help_links['authorization-rule'] = [ +frappe.help.help_links['List/Authorization Rule'] = [ { label: 'Authorization Rule', url: docsUrl + 'user/manual/en/setting-up/authorization-rule' }, ] -frappe.help.help_links['sms-settings'] = [ +frappe.help.help_links['Form/SMS Settings'] = [ { label: 'SMS Settings', url: docsUrl + 'user/manual/en/setting-up/sms-setting' }, ] -frappe.help.help_links['stock-reconciliation'] = [ +frappe.help.help_links['List/Stock Reconciliation'] = [ { label: 'Stock Reconciliation', url: docsUrl + 'user/manual/en/setting-up/stock-reconciliation-for-non-serialized-item' }, ] -frappe.help.help_links['territory/view/tree'] = [ +frappe.help.help_links['Tree/Territory'] = [ { label: 'Territory', url: docsUrl + 'user/manual/en/setting-up/territory' }, ] -frappe.help.help_links['dropbox-backup'] = [ +frappe.help.help_links['Form/Dropbox Backup'] = [ { label: 'Dropbox Backup', url: docsUrl + 'user/manual/en/setting-up/third-party-backups' }, { label: 'Setting Up Dropbox Backup', url: docsUrl + 'user/manual/en/setting-up/articles/setting-up-dropbox-backups' }, ] -frappe.help.help_links['workflow'] = [ +frappe.help.help_links['List/Workflow'] = [ { label: 'Workflow', url: docsUrl + 'user/manual/en/setting-up/workflows' }, ] -frappe.help.help_links['company'] = [ +frappe.help.help_links['List/Company'] = [ { label: 'Company', url: docsUrl + 'user/manual/en/setting-up/company-setup' }, { label: 'Managing Multiple Companies', url: docsUrl + 'user/manual/en/setting-up/articles/managing-multiple-companies' }, { label: 'Delete All Related Transactions for a Company', url: docsUrl + 'user/manual/en/setting-up/articles/delete-a-company-and-all-related-transactions' }, @@ -234,25 +253,25 @@ frappe.help.help_links['company'] = [ //Accounts -frappe.help.help_links['accounts'] = [ +frappe.help.help_links['modules/Accounts'] = [ { label: 'Introduction to Accounts', url: docsUrl + 'user/manual/en/accounts/' }, { label: 'Chart of Accounts', url: docsUrl + 'user/manual/en/accounts/chart-of-accounts.html' }, { label: 'Multi Currency Accounting', url: docsUrl + 'user/manual/en/accounts/multi-currency-accounting' }, ] -frappe.help.help_links['account/view/tree'] = [ +frappe.help.help_links['Tree/Account'] = [ { label: 'Chart of Accounts', url: docsUrl + 'user/manual/en/accounts/chart-of-accounts' }, { label: 'Managing Tree Mastes', url: docsUrl + 'user/manual/en/setting-up/articles/managing-tree-structure-masters' }, ] -frappe.help.help_links['sales-invoice'] = [ +frappe.help.help_links['Form/Sales Invoice'] = [ { label: 'Sales Invoice', url: docsUrl + 'user/manual/en/accounts/sales-invoice' }, { label: 'Accounts Opening Balance', url: docsUrl + 'user/manual/en/accounts/opening-accounts' }, { label: 'Sales Return', url: docsUrl + 'user/manual/en/stock/sales-return' }, { label: 'Recurring Sales Invoice', url: docsUrl + 'user/manual/en/accounts/recurring-orders-and-invoices' }, ] -frappe.help.help_links['sales-invoice'] = [ +frappe.help.help_links['List/Sales Invoice'] = [ { label: 'Sales Invoice', url: docsUrl + 'user/manual/en/accounts/sales-invoice' }, { label: 'Accounts Opening Balance', url: docsUrl + 'user/manual/en/accounts/opening-accounts' }, { label: 'Sales Return', url: docsUrl + 'user/manual/en/stock/sales-return' }, @@ -263,43 +282,43 @@ frappe.help.help_links['pos'] = [ { label: 'Point of Sale Invoice', url: docsUrl + 'user/manual/en/accounts/point-of-sale-pos-invoice' }, ] -frappe.help.help_links['pos-profile'] = [ +frappe.help.help_links['List/POS Profile'] = [ { label: 'Point of Sale Profile', url: docsUrl + 'user/manual/en/setting-up/pos-setting' }, ] -frappe.help.help_links['purchase-invoice'] = [ +frappe.help.help_links['List/Purchase Invoice'] = [ { label: 'Purchase Invoice', url: docsUrl + 'user/manual/en/accounts/purchase-invoice' }, { label: 'Accounts Opening Balance', url: docsUrl + 'user/manual/en/accounts/opening-accounts' }, { label: 'Recurring Purchase Invoice', url: docsUrl + 'user/manual/en/accounts/recurring-orders-and-invoices' }, ] -frappe.help.help_links['journal-entry'] = [ +frappe.help.help_links['List/Journal Entry'] = [ { label: 'Journal Entry', url: docsUrl + 'user/manual/en/accounts/journal-entry' }, { label: 'Advance Payment Entry', url: docsUrl + 'user/manual/en/accounts/advance-payment-entry' }, { label: 'Accounts Opening Balance', url: docsUrl + 'user/manual/en/accounts/opening-accounts' }, ] -frappe.help.help_links['payment-entry'] = [ +frappe.help.help_links['List/Payment Entry'] = [ { label: 'Payment Entry', url: docsUrl + 'user/manual/en/accounts/payment-entry' }, ] -frappe.help.help_links['payment-request'] = [ +frappe.help.help_links['List/Payment Request'] = [ { label: 'Payment Request', url: docsUrl + 'user/manual/en/accounts/payment-request' }, ] -frappe.help.help_links['asset'] = [ +frappe.help.help_links['List/Asset'] = [ { label: 'Managing Fixed Assets', url: docsUrl + 'user/manual/en/accounts/managing-fixed-assets' }, ] -frappe.help.help_links['asset-category'] = [ +frappe.help.help_links['List/Asset Category'] = [ { label: 'Asset Category', url: docsUrl + 'user/manual/en/accounts/managing-fixed-assets' }, ] -frappe.help.help_links['cost-center/view/tree'] = [ +frappe.help.help_links['Tree/Cost Center'] = [ { label: 'Budgeting', url: docsUrl + 'user/manual/en/accounts/budgeting' }, ] -frappe.help.help_links['item'] = [ +frappe.help.help_links['List/Item'] = [ { label: 'Item', url: docsUrl + 'user/manual/en/stock/item' }, { label: 'Item Price', url: docsUrl + 'user/manual/en/stock/item/item-price' }, { label: 'Barcode', url: docsUrl + 'user/manual/en/stock/articles/track-items-using-barcode' }, @@ -310,42 +329,61 @@ frappe.help.help_links['item'] = [ { label: 'Item Valuation', url: docsUrl + 'user/manual/en/stock/item/item-valuation-fifo-and-moving-average' }, ] -frappe.help.help_links['purchase-receipt'] = [ +frappe.help.help_links['Form/Item'] = [ + { label: 'Item', url: docsUrl + 'user/manual/en/stock/item' }, + { label: 'Item Price', url: docsUrl + 'user/manual/en/stock/item/item-price' }, + { label: 'Barcode', url: docsUrl + 'user/manual/en/stock/articles/track-items-using-barcode' }, + { label: 'Item Wise Taxation', url: docsUrl + 'user/manual/en/accounts/item-wise-taxation' }, + { label: 'Managing Fixed Assets', url: docsUrl + 'user/manual/en/accounts/managing-fixed-assets' }, + { label: 'Item Codification', url: docsUrl + 'user/manual/en/stock/item/item-codification' }, + { label: 'Item Variants', url: docsUrl + 'user/manual/en/stock/item/item-variants' }, + { label: 'Item Valuation', url: docsUrl + 'user/manual/en/stock/item/item-valuation-fifo-and-moving-average' }, +] + +frappe.help.help_links['List/Purchase Receipt'] = [ { label: 'Purchase Receipt', url: docsUrl + 'user/manual/en/stock/purchase-receipt' }, { label: 'Barcode', url: docsUrl + 'user/manual/en/stock/articles/track-items-using-barcode' }, ] -frappe.help.help_links['delivery-note'] = [ +frappe.help.help_links['List/Delivery Note'] = [ { label: 'Delivery Note', url: docsUrl + 'user/manual/en/stock/delivery-note' }, { label: 'Barcode', url: docsUrl + 'user/manual/en/stock/articles/track-items-using-barcode' }, { label: 'Sales Return', url: docsUrl + 'user/manual/en/stock/sales-return' }, ] -frappe.help.help_links['delivery-note'] = [ +frappe.help.help_links['Form/Delivery Note'] = [ { label: 'Delivery Note', url: docsUrl + 'user/manual/en/stock/delivery-note' }, { label: 'Sales Return', url: docsUrl + 'user/manual/en/stock/sales-return' }, { label: 'Barcode', url: docsUrl + 'user/manual/en/stock/articles/track-items-using-barcode' }, { label: 'Subcontracting', url: docsUrl + 'user/manual/en/manufacturing/subcontracting' }, ] -frappe.help.help_links['installation-note'] = [ +frappe.help.help_links['List/Installation Note'] = [ { label: 'Installation Note', url: docsUrl + 'user/manual/en/stock/installation-note' }, ] +frappe.help.help_links['Tree'] = [ + { label: 'Managing Tree Structure Masters', url: docsUrl + 'user/manual/en/setting-up/articles/managing-tree-structure-masters' }, +] -frappe.help.help_links['budget'] = [ +frappe.help.help_links['List/Budget'] = [ { label: 'Budgeting', url: docsUrl + 'user/manual/en/accounts/budgeting' }, ] //Stock -frappe.help.help_links['material-request'] = [ +frappe.help.help_links['List/Material Request'] = [ { label: 'Material Request', url: docsUrl + 'user/manual/en/stock/material-request' }, { label: 'Auto-creation of Material Request', url: docsUrl + 'user/manual/en/stock/articles/auto-creation-of-material-request' }, ] -frappe.help.help_links['stock-entry'] = [ +frappe.help.help_links['Form/Material Request'] = [ + { label: 'Material Request', url: docsUrl + 'user/manual/en/stock/material-request' }, + { label: 'Auto-creation of Material Request', url: docsUrl + 'user/manual/en/stock/articles/auto-creation-of-material-request' }, +] + +frappe.help.help_links['Form/Stock Entry'] = [ { label: 'Stock Entry', url: docsUrl + 'user/manual/en/stock/stock-entry' }, { label: 'Stock Entry Types', url: docsUrl + 'user/manual/en/stock/articles/stock-entry-purpose' }, { label: 'Repack Entry', url: docsUrl + 'user/manual/en/stock/articles/repack-entry' }, @@ -353,114 +391,136 @@ frappe.help.help_links['stock-entry'] = [ { label: 'Subcontracting', url: docsUrl + 'user/manual/en/manufacturing/subcontracting' }, ] -frappe.help.help_links['warehouse/view/tree'] = [ +frappe.help.help_links['List/Stock Entry'] = [ + { label: 'Stock Entry', url: docsUrl + 'user/manual/en/stock/stock-entry' }, +] + +frappe.help.help_links['Tree/Warehouse'] = [ { label: 'Warehouse', url: docsUrl + 'user/manual/en/stock/warehouse' }, ] -frappe.help.help_links['serial-no'] = [ +frappe.help.help_links['List/Serial No'] = [ { label: 'Serial No', url: docsUrl + 'user/manual/en/stock/serial-no' }, ] -frappe.help.help_links['batch'] = [ +frappe.help.help_links['Form/Serial No'] = [ + { label: 'Serial No', url: docsUrl + 'user/manual/en/stock/serial-no' }, +] + +frappe.help.help_links['Form/Batch'] = [ { label: 'Batch', url: docsUrl + 'user/manual/en/stock/batch' }, ] -frappe.help.help_links['packing-slip'] = [ +frappe.help.help_links['Form/Packing Slip'] = [ { label: 'Packing Slip', url: docsUrl + 'user/manual/en/stock/tools/packing-slip' }, ] -frappe.help.help_links['quality-inspection'] = [ +frappe.help.help_links['Form/Quality Inspection'] = [ { label: 'Quality Inspection', url: docsUrl + 'user/manual/en/stock/tools/quality-inspection' }, ] -frappe.help.help_links['landed-cost-voucher'] = [ +frappe.help.help_links['Form/Landed Cost Voucher'] = [ { label: 'Landed Cost Voucher', url: docsUrl + 'user/manual/en/stock/tools/landed-cost-voucher' }, ] -frappe.help.help_links['item-group/view/tree'] = [ +frappe.help.help_links['Tree/Item Group'] = [ { label: 'Item Group', url: docsUrl + 'user/manual/en/stock/setup/item-group' }, ] -frappe.help.help_links['item-attribute'] = [ +frappe.help.help_links['Form/Item Attribute'] = [ { label: 'Item Attribute', url: docsUrl + 'user/manual/en/stock/setup/item-attribute' }, ] -frappe.help.help_links['uom'] = [ +frappe.help.help_links['Form/UOM'] = [ { label: 'Fractions in UOM', url: docsUrl + 'user/manual/en/stock/articles/managing-fractions-in-uom' }, ] -frappe.help.help_links['stock-reconciliation'] = [ +frappe.help.help_links['Form/Stock Reconciliation'] = [ { label: 'Opening Stock Entry', url: docsUrl + 'user/manual/en/stock/opening-stock' }, ] //CRM -frappe.help.help_links['lead'] = [ +frappe.help.help_links['Form/Lead'] = [ { label: 'Lead', url: docsUrl + 'user/manual/en/CRM/lead' }, ] -frappe.help.help_links['opportunity'] = [ +frappe.help.help_links['Form/Opportunity'] = [ { label: 'Opportunity', url: docsUrl + 'user/manual/en/CRM/opportunity' }, ] -frappe.help.help_links['address'] = [ +frappe.help.help_links['Form/Address'] = [ { label: 'Address', url: docsUrl + 'user/manual/en/CRM/address' }, ] -frappe.help.help_links['contact'] = [ +frappe.help.help_links['Form/Contact'] = [ { label: 'Contact', url: docsUrl + 'user/manual/en/CRM/contact' }, ] -frappe.help.help_links['newsletter'] = [ +frappe.help.help_links['Form/Newsletter'] = [ { label: 'Newsletter', url: docsUrl + 'user/manual/en/CRM/newsletter' }, ] -frappe.help.help_links['campaign'] = [ +frappe.help.help_links['Form/Campaign'] = [ { label: 'Campaign', url: docsUrl + 'user/manual/en/CRM/setup/campaign' }, ] -frappe.help.help_links['sales-person/view/tree'] = [ +frappe.help.help_links['Tree/Sales Person'] = [ { label: 'Sales Person', url: docsUrl + 'user/manual/en/CRM/setup/sales-person' }, ] -frappe.help.help_links['sales-person'] = [ +frappe.help.help_links['Form/Sales Person'] = [ { label: 'Sales Person Target', url: docsUrl + 'user/manual/en/selling/setup/sales-person-target-allocation' }, ] +//Support + +frappe.help.help_links['List/Feedback Trigger'] = [ + { label: 'Feedback Trigger', url: docsUrl + 'user/manual/en/setting-up/feedback/setting-up-feedback' }, +] + +frappe.help.help_links['List/Feedback Request'] = [ + { label: 'Feedback Request', url: docsUrl + 'user/manual/en/setting-up/feedback/submit-feedback' }, +] + +frappe.help.help_links['List/Feedback Request'] = [ + { label: 'Feedback Request', url: docsUrl + 'user/manual/en/setting-up/feedback/submit-feedback' }, +] + //Manufacturing -frappe.help.help_links['bom'] = [ +frappe.help.help_links['Form/BOM'] = [ { label: 'Bill of Material', url: docsUrl + 'user/manual/en/manufacturing/bill-of-materials' }, { label: 'Nested BOM Structure', url: docsUrl + 'user/manual/en/manufacturing/articles/nested-bom-structure' }, ] -frappe.help.help_links['work-order'] = [ +frappe.help.help_links['Form/Work Order'] = [ { label: 'Work Order', url: docsUrl + 'user/manual/en/manufacturing/work-order' }, ] -frappe.help.help_links['workstation'] = [ +frappe.help.help_links['Form/Workstation'] = [ { label: 'Workstation', url: docsUrl + 'user/manual/en/manufacturing/workstation' }, ] -frappe.help.help_links['operation'] = [ +frappe.help.help_links['Form/Operation'] = [ { label: 'Operation', url: docsUrl + 'user/manual/en/manufacturing/operation' }, ] -frappe.help.help_links['bom-update-tool'] = [ +frappe.help.help_links['Form/BOM Update Tool'] = [ { label: 'BOM Update Tool', url: docsUrl + 'user/manual/en/manufacturing/tools/bom-update-tool' }, ] //Customize -frappe.help.help_links['customize-form'] = [ +frappe.help.help_links['Form/Customize Form'] = [ { label: 'Custom Field', url: docsUrl + 'user/manual/en/customize-erpnext/custom-field' }, { label: 'Customize Field', url: docsUrl + 'user/manual/en/customize-erpnext/customize-form' }, ] -frappe.help.help_links['custom-field'] = [ +frappe.help.help_links['Form/Custom Field'] = [ { label: 'Custom Field', url: docsUrl + 'user/manual/en/customize-erpnext/custom-field' }, ] -frappe.help.help_links['custom-field'] = [ +frappe.help.help_links['Form/Custom Field'] = [ { label: 'Custom Field', url: docsUrl + 'user/manual/en/customize-erpnext/custom-field' }, ] From 0ae0368d34cd252a803cc1c7d616674bae9d8816 Mon Sep 17 00:00:00 2001 From: prssanna Date: Wed, 24 Mar 2021 16:45:32 +0530 Subject: [PATCH 333/449] fix: re-execute add_standard_navbar_items patch - check that same items aren't appended again --- erpnext/patches.txt | 2 +- erpnext/setup/install.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index c686635b6c..ff9433a7ef 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -720,7 +720,7 @@ erpnext.patches.v13_0.delete_report_requested_items_to_order erpnext.patches.v12_0.update_item_tax_template_company erpnext.patches.v13_0.move_branch_code_to_bank_account erpnext.patches.v13_0.healthcare_lab_module_rename_doctypes -erpnext.patches.v13_0.add_standard_navbar_items #4 +erpnext.patches.v13_0.add_standard_navbar_items #2021-03-24 erpnext.patches.v13_0.stock_entry_enhancements erpnext.patches.v12_0.update_state_code_for_daman_and_diu erpnext.patches.v12_0.rename_lost_reason_detail diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py index 0bb480bd4b..29fd0e659b 100644 --- a/erpnext/setup/install.py +++ b/erpnext/setup/install.py @@ -142,13 +142,15 @@ def add_standard_navbar_items(): } ] - current_nabvar_items = navbar_settings.help_dropdown + current_navbar_items = navbar_settings.help_dropdown navbar_settings.set('help_dropdown', []) for item in erpnext_navbar_items: - navbar_settings.append('help_dropdown', item) + current_labels = [item.get('item_label') for item in current_navbar_items] + if not item.get('item_label') in current_labels: + navbar_settings.append('help_dropdown', item) - for item in current_nabvar_items: + for item in current_navbar_items: navbar_settings.append('help_dropdown', { 'item_label': item.item_label, 'item_type': item.item_type, From 5243eea5320bbdd02ec913667a1ee864cc1a6938 Mon Sep 17 00:00:00 2001 From: prssanna Date: Fri, 26 Mar 2021 14:35:47 +0530 Subject: [PATCH 334/449] style: fix formatting --- erpnext/public/js/help_links.js | 1319 +++++++++++++++++++++---------- 1 file changed, 922 insertions(+), 397 deletions(-) diff --git a/erpnext/public/js/help_links.js b/erpnext/public/js/help_links.js index 66ff46405d..e78992302f 100644 --- a/erpnext/public/js/help_links.js +++ b/erpnext/public/js/help_links.js @@ -1,526 +1,1051 @@ -frappe.provide('frappe.help.help_links'); +frappe.provide("frappe.help.help_links"); -const docsUrl = 'https://erpnext.com/docs/'; +const docsUrl = "https://erpnext.com/docs/"; -frappe.help.help_links['Form/Rename Tool'] = [ - { label: 'Bulk Rename', url: docsUrl + 'user/manual/en/setting-up/data/bulk-rename' }, -] +frappe.help.help_links["Form/Rename Tool"] = [ + { + label: "Bulk Rename", + url: docsUrl + "user/manual/en/setting-up/data/bulk-rename", + }, +]; //Setup -frappe.help.help_links['List/User'] = [ - { label: 'New User', url: docsUrl + 'user/manual/en/setting-up/users-and-permissions/adding-users' }, - { label: 'Rename User', url: docsUrl + 'user/manual/en/setting-up/articles/rename-user' }, -] +frappe.help.help_links["List/User"] = [ + { + label: "New User", + url: + docsUrl + + "user/manual/en/setting-up/users-and-permissions/adding-users", + }, + { + label: "Rename User", + url: docsUrl + "user/manual/en/setting-up/articles/rename-user", + }, +]; -frappe.help.help_links['permission-manager'] = [ - { label: 'Role Permissions Manager', url: docsUrl + 'user/manual/en/setting-up/users-and-permissions/role-based-permissions' }, - { label: 'Managing Perm Level in Permissions Manager', url: docsUrl + 'user/manual/en/setting-up/articles/managing-perm-level' }, - { label: 'User Permissions', url: docsUrl + 'user/manual/en/setting-up/users-and-permissions/user-permissions' }, - { label: 'Sharing', url: docsUrl + 'user/manual/en/setting-up/users-and-permissions/sharing' }, - { label: 'Password', url: docsUrl + 'user/manual/en/setting-up/articles/change-password' }, -] +frappe.help.help_links["permission-manager"] = [ + { + label: "Role Permissions Manager", + url: + docsUrl + + "user/manual/en/setting-up/users-and-permissions/role-based-permissions", + }, + { + label: "Managing Perm Level in Permissions Manager", + url: docsUrl + "user/manual/en/setting-up/articles/managing-perm-level", + }, + { + label: "User Permissions", + url: + docsUrl + + "user/manual/en/setting-up/users-and-permissions/user-permissions", + }, + { + label: "Sharing", + url: + docsUrl + "user/manual/en/setting-up/users-and-permissions/sharing", + }, + { + label: "Password", + url: docsUrl + "user/manual/en/setting-up/articles/change-password", + }, +]; -frappe.help.help_links['Form/System Settings'] = [ - { label: 'Naming Series', url: docsUrl + 'user/manual/en/setting-up/settings/system-settings' }, -] +frappe.help.help_links["Form/System Settings"] = [ + { + label: "Naming Series", + url: docsUrl + "user/manual/en/setting-up/settings/system-settings", + }, +]; -frappe.help.help_links['data-import-tool'] = [ - { label: 'Importing and Exporting Data', url: docsUrl + 'user/manual/en/setting-up/data/data-import-tool' }, - { label: 'Overwriting Data from Data Import Tool', url: docsUrl + 'user/manual/en/setting-up/articles/overwriting-data-from-data-import-tool' }, -] +frappe.help.help_links["data-import-tool"] = [ + { + label: "Importing and Exporting Data", + url: docsUrl + "user/manual/en/setting-up/data/data-import-tool", + }, + { + label: "Overwriting Data from Data Import Tool", + url: + docsUrl + + "user/manual/en/setting-up/articles/overwriting-data-from-data-import-tool", + }, +]; -frappe.help.help_links['module_setup'] = [ - { label: 'Role Permissions Manager', url: docsUrl + 'user/manual/en/setting-up/users-and-permissions/role-based-permissions' }, -] +frappe.help.help_links["module_setup"] = [ + { + label: "Role Permissions Manager", + url: + docsUrl + + "user/manual/en/setting-up/users-and-permissions/role-based-permissions", + }, +]; -frappe.help.help_links['Form/Naming Series'] = [ - { label: 'Naming Series', url: docsUrl + 'user/manual/en/setting-up/settings/naming-series' }, - { label: 'Setting the Current Value for Naming Series', url: docsUrl + 'user/manual/en/setting-up/articles/naming-series-current-value' }, -] +frappe.help.help_links["Form/Naming Series"] = [ + { + label: "Naming Series", + url: docsUrl + "user/manual/en/setting-up/settings/naming-series", + }, + { + label: "Setting the Current Value for Naming Series", + url: + docsUrl + + "user/manual/en/setting-up/articles/naming-series-current-value", + }, +]; -frappe.help.help_links['Form/Global Defaults'] = [ - { label: 'Global Settings', url: docsUrl + 'user/manual/en/setting-up/settings/global-defaults' }, -] +frappe.help.help_links["Form/Global Defaults"] = [ + { + label: "Global Settings", + url: docsUrl + "user/manual/en/setting-up/settings/global-defaults", + }, +]; -frappe.help.help_links['Form/Email Digest'] = [ - { label: 'Email Digest', url: docsUrl + 'user/manual/en/setting-up/email/email-digest' }, -] +frappe.help.help_links["Form/Email Digest"] = [ + { + label: "Email Digest", + url: docsUrl + "user/manual/en/setting-up/email/email-digest", + }, +]; -frappe.help.help_links['List/Print Heading'] = [ - { label: 'Print Heading', url: docsUrl + 'user/manual/en/setting-up/print/print-headings' }, -] +frappe.help.help_links["List/Print Heading"] = [ + { + label: "Print Heading", + url: docsUrl + "user/manual/en/setting-up/print/print-headings", + }, +]; -frappe.help.help_links['List/Letter Head'] = [ - { label: 'Letter Head', url: docsUrl + 'user/manual/en/setting-up/print/letter-head' }, -] +frappe.help.help_links["List/Letter Head"] = [ + { + label: "Letter Head", + url: docsUrl + "user/manual/en/setting-up/print/letter-head", + }, +]; -frappe.help.help_links['List/Address Template'] = [ - { label: 'Address Template', url: docsUrl + 'user/manual/en/setting-up/print/address-template' }, -] +frappe.help.help_links["List/Address Template"] = [ + { + label: "Address Template", + url: docsUrl + "user/manual/en/setting-up/print/address-template", + }, +]; -frappe.help.help_links['List/Terms and Conditions'] = [ - { label: 'Terms and Conditions', url: docsUrl + 'user/manual/en/setting-up/print/terms-and-conditions' }, -] +frappe.help.help_links["List/Terms and Conditions"] = [ + { + label: "Terms and Conditions", + url: docsUrl + "user/manual/en/setting-up/print/terms-and-conditions", + }, +]; -frappe.help.help_links['List/Cheque Print Template'] = [ - { label: 'Cheque Print Template', url: docsUrl + 'user/manual/en/setting-up/print/cheque-print-template' }, -] +frappe.help.help_links["List/Cheque Print Template"] = [ + { + label: "Cheque Print Template", + url: docsUrl + "user/manual/en/setting-up/print/cheque-print-template", + }, +]; -frappe.help.help_links['List/Email Account'] = [ - { label: 'Email Account', url: docsUrl + 'user/manual/en/setting-up/email/email-account' }, -] +frappe.help.help_links["List/Email Account"] = [ + { + label: "Email Account", + url: docsUrl + "user/manual/en/setting-up/email/email-account", + }, +]; -frappe.help.help_links['List/Notification'] = [ - { label: 'Notification', url: docsUrl + 'user/manual/en/setting-up/email/notifications' }, -] +frappe.help.help_links["List/Notification"] = [ + { + label: "Notification", + url: docsUrl + "user/manual/en/setting-up/email/notifications", + }, +]; -frappe.help.help_links['Form/Notification'] = [ - { label: 'Notification', url: docsUrl + 'user/manual/en/setting-up/email/notifications' }, -] +frappe.help.help_links["Form/Notification"] = [ + { + label: "Notification", + url: docsUrl + "user/manual/en/setting-up/email/notifications", + }, +]; -frappe.help.help_links['List/Email Digest'] = [ - { label: 'Email Digest', url: docsUrl + 'user/manual/en/setting-up/email/email-digest' }, -] +frappe.help.help_links["List/Email Digest"] = [ + { + label: "Email Digest", + url: docsUrl + "user/manual/en/setting-up/email/email-digest", + }, +]; -frappe.help.help_links['List/Auto Email Report'] = [ - { label: 'Auto Email Reports', url: docsUrl + 'user/manual/en/setting-up/email/email-reports' }, -] +frappe.help.help_links["List/Auto Email Report"] = [ + { + label: "Auto Email Reports", + url: docsUrl + "user/manual/en/setting-up/email/email-reports", + }, +]; -frappe.help.help_links['Form/Print Settings'] = [ - { label: 'Print Settings', url: docsUrl + 'user/manual/en/setting-up/print/print-settings' }, -] +frappe.help.help_links["Form/Print Settings"] = [ + { + label: "Print Settings", + url: docsUrl + "user/manual/en/setting-up/print/print-settings", + }, +]; -frappe.help.help_links['print-format-builder'] = [ - { label: 'Print Format Builder', url: docsUrl + 'user/manual/en/setting-up/print/print-settings' }, -] +frappe.help.help_links["print-format-builder"] = [ + { + label: "Print Format Builder", + url: docsUrl + "user/manual/en/setting-up/print/print-settings", + }, +]; -frappe.help.help_links['List/Print Heading'] = [ - { label: 'Print Heading', url: docsUrl + 'user/manual/en/setting-up/print/print-headings' }, -] +frappe.help.help_links["List/Print Heading"] = [ + { + label: "Print Heading", + url: docsUrl + "user/manual/en/setting-up/print/print-headings", + }, +]; //setup-integrations -frappe.help.help_links['Form/PayPal Settings'] = [ - { label: 'PayPal Settings', url: docsUrl + 'user/manual/en/setting-up/integrations/paypal-integration' }, -] +frappe.help.help_links["Form/PayPal Settings"] = [ + { + label: "PayPal Settings", + url: + docsUrl + + "user/manual/en/setting-up/integrations/paypal-integration", + }, +]; -frappe.help.help_links['Form/Razorpay Settings'] = [ - { label: 'Razorpay Settings', url: docsUrl + 'user/manual/en/setting-up/integrations/razorpay-integration' }, -] +frappe.help.help_links["Form/Razorpay Settings"] = [ + { + label: "Razorpay Settings", + url: + docsUrl + + "user/manual/en/setting-up/integrations/razorpay-integration", + }, +]; -frappe.help.help_links['Form/Dropbox Settings'] = [ - { label: 'Dropbox Settings', url: docsUrl + 'user/manual/en/setting-up/integrations/dropbox-backup' }, -] +frappe.help.help_links["Form/Dropbox Settings"] = [ + { + label: "Dropbox Settings", + url: docsUrl + "user/manual/en/setting-up/integrations/dropbox-backup", + }, +]; -frappe.help.help_links['Form/LDAP Settings'] = [ - { label: 'LDAP Settings', url: docsUrl + 'user/manual/en/setting-up/integrations/ldap-integration' }, -] +frappe.help.help_links["Form/LDAP Settings"] = [ + { + label: "LDAP Settings", + url: + docsUrl + "user/manual/en/setting-up/integrations/ldap-integration", + }, +]; -frappe.help.help_links['Form/Stripe Settings'] = [ - { label: 'Stripe Settings', url: docsUrl + 'user/manual/en/setting-up/integrations/stripe-integration' }, -] +frappe.help.help_links["Form/Stripe Settings"] = [ + { + label: "Stripe Settings", + url: + docsUrl + + "user/manual/en/setting-up/integrations/stripe-integration", + }, +]; //Sales -frappe.help.help_links['Form/Quotation'] = [ - { label: 'Quotation', url: docsUrl + 'user/manual/en/selling/quotation' }, - { label: 'Applying Discount', url: docsUrl + 'user/manual/en/selling/articles/applying-discount' }, - { label: 'Sales Person', url: docsUrl + 'user/manual/en/selling/articles/sales-persons-in-the-sales-transactions' }, - { label: 'Applying Margin', url: docsUrl + 'user/manual/en/selling/articles/adding-margin' }, -] +frappe.help.help_links["Form/Quotation"] = [ + { label: "Quotation", url: docsUrl + "user/manual/en/selling/quotation" }, + { + label: "Applying Discount", + url: docsUrl + "user/manual/en/selling/articles/applying-discount", + }, + { + label: "Sales Person", + url: + docsUrl + + "user/manual/en/selling/articles/sales-persons-in-the-sales-transactions", + }, + { + label: "Applying Margin", + url: docsUrl + "user/manual/en/selling/articles/adding-margin", + }, +]; -frappe.help.help_links['List/Customer'] = [ - { label: 'Customer', url: docsUrl + 'user/manual/en/CRM/customer' }, - { label: 'Credit Limit', url: docsUrl + 'user/manual/en/accounts/credit-limit' }, -] +frappe.help.help_links["List/Customer"] = [ + { label: "Customer", url: docsUrl + "user/manual/en/CRM/customer" }, + { + label: "Credit Limit", + url: docsUrl + "user/manual/en/accounts/credit-limit", + }, +]; -frappe.help.help_links['Form/Customer'] = [ - { label: 'Customer', url: docsUrl + 'user/manual/en/CRM/customer' }, - { label: 'Credit Limit', url: docsUrl + 'user/manual/en/accounts/credit-limit' }, -] +frappe.help.help_links["Form/Customer"] = [ + { label: "Customer", url: docsUrl + "user/manual/en/CRM/customer" }, + { + label: "Credit Limit", + url: docsUrl + "user/manual/en/accounts/credit-limit", + }, +]; -frappe.help.help_links['List/Sales Taxes and Charges Template'] = [ - { label: 'Setting Up Taxes', url: docsUrl + 'user/manual/en/setting-up/setting-up-taxes' }, -] +frappe.help.help_links["List/Sales Taxes and Charges Template"] = [ + { + label: "Setting Up Taxes", + url: docsUrl + "user/manual/en/setting-up/setting-up-taxes", + }, +]; -frappe.help.help_links['Form/Sales Taxes and Charges Template'] = [ - { label: 'Setting Up Taxes', url: docsUrl + 'user/manual/en/setting-up/setting-up-taxes' }, -] +frappe.help.help_links["Form/Sales Taxes and Charges Template"] = [ + { + label: "Setting Up Taxes", + url: docsUrl + "user/manual/en/setting-up/setting-up-taxes", + }, +]; -frappe.help.help_links['List/Sales Order'] = [ - { label: 'Sales Order', url: docsUrl + 'user/manual/en/selling/sales-order' }, - { label: 'Recurring Sales Order', url: docsUrl + 'user/manual/en/accounts/recurring-orders-and-invoices' }, - { label: 'Applying Discount', url: docsUrl + 'user/manual/en/selling/articles/applying-discount' }, -] +frappe.help.help_links["List/Sales Order"] = [ + { + label: "Sales Order", + url: docsUrl + "user/manual/en/selling/sales-order", + }, + { + label: "Recurring Sales Order", + url: docsUrl + "user/manual/en/accounts/recurring-orders-and-invoices", + }, + { + label: "Applying Discount", + url: docsUrl + "user/manual/en/selling/articles/applying-discount", + }, +]; -frappe.help.help_links['Form/Sales Order'] = [ - { label: 'Sales Order', url: docsUrl + 'user/manual/en/selling/sales-order' }, - { label: 'Recurring Sales Order', url: docsUrl + 'user/manual/en/accounts/recurring-orders-and-invoices' }, - { label: 'Applying Discount', url: docsUrl + 'user/manual/en/selling/articles/applying-discount' }, - { label: 'Drop Shipping', url: docsUrl + 'user/manual/en/selling/articles/drop-shipping' }, - { label: 'Sales Person', url: docsUrl + 'user/manual/en/selling/articles/sales-persons-in-the-sales-transactions' }, - { label: 'Close Sales Order', url: docsUrl + 'user/manual/en/selling/articles/close-sales-order' }, - { label: 'Applying Margin', url: docsUrl + 'user/manual/en/selling/articles/adding-margin' }, -] +frappe.help.help_links["Form/Sales Order"] = [ + { + label: "Sales Order", + url: docsUrl + "user/manual/en/selling/sales-order", + }, + { + label: "Recurring Sales Order", + url: docsUrl + "user/manual/en/accounts/recurring-orders-and-invoices", + }, + { + label: "Applying Discount", + url: docsUrl + "user/manual/en/selling/articles/applying-discount", + }, + { + label: "Drop Shipping", + url: docsUrl + "user/manual/en/selling/articles/drop-shipping", + }, + { + label: "Sales Person", + url: + docsUrl + + "user/manual/en/selling/articles/sales-persons-in-the-sales-transactions", + }, + { + label: "Close Sales Order", + url: docsUrl + "user/manual/en/selling/articles/close-sales-order", + }, + { + label: "Applying Margin", + url: docsUrl + "user/manual/en/selling/articles/adding-margin", + }, +]; -frappe.help.help_links['Form/Product Bundle'] = [ - { label: 'Product Bundle', url: docsUrl + 'user/manual/en/selling/setup/product-bundle' }, -] +frappe.help.help_links["Form/Product Bundle"] = [ + { + label: "Product Bundle", + url: docsUrl + "user/manual/en/selling/setup/product-bundle", + }, +]; -frappe.help.help_links['Form/Selling Settings'] = [ - { label: 'Selling Settings', url: docsUrl + 'user/manual/en/selling/setup/selling-settings' }, -] +frappe.help.help_links["Form/Selling Settings"] = [ + { + label: "Selling Settings", + url: docsUrl + "user/manual/en/selling/setup/selling-settings", + }, +]; //Buying -frappe.help.help_links['List/Supplier'] = [ - { label: 'Supplier', url: docsUrl + 'user/manual/en/buying/supplier' }, -] +frappe.help.help_links["List/Supplier"] = [ + { label: "Supplier", url: docsUrl + "user/manual/en/buying/supplier" }, +]; -frappe.help.help_links['Form/Supplier'] = [ - { label: 'Supplier', url: docsUrl + 'user/manual/en/buying/supplier' }, -] +frappe.help.help_links["Form/Supplier"] = [ + { label: "Supplier", url: docsUrl + "user/manual/en/buying/supplier" }, +]; -frappe.help.help_links['Form/Request for Quotation'] = [ - { label: 'Request for Quotation', url: docsUrl + 'user/manual/en/buying/request-for-quotation' }, - { label: 'RFQ Video', url: docsUrl + 'user/videos/learn/request-for-quotation.html' }, -] +frappe.help.help_links["Form/Request for Quotation"] = [ + { + label: "Request for Quotation", + url: docsUrl + "user/manual/en/buying/request-for-quotation", + }, + { + label: "RFQ Video", + url: docsUrl + "user/videos/learn/request-for-quotation.html", + }, +]; -frappe.help.help_links['Form/Supplier Quotation'] = [ - { label: 'Supplier Quotation', url: docsUrl + 'user/manual/en/buying/supplier-quotation' }, -] +frappe.help.help_links["Form/Supplier Quotation"] = [ + { + label: "Supplier Quotation", + url: docsUrl + "user/manual/en/buying/supplier-quotation", + }, +]; -frappe.help.help_links['Form/Buying Settings'] = [ - { label: 'Buying Settings', url: docsUrl + 'user/manual/en/buying/setup/buying-settings' }, -] +frappe.help.help_links["Form/Buying Settings"] = [ + { + label: "Buying Settings", + url: docsUrl + "user/manual/en/buying/setup/buying-settings", + }, +]; -frappe.help.help_links['List/Purchase Order'] = [ - { label: 'Purchase Order', url: docsUrl + 'user/manual/en/buying/purchase-order' }, - { label: 'Recurring Purchase Order', url: docsUrl + 'user/manual/en/accounts/recurring-orders-and-invoices' }, -] +frappe.help.help_links["List/Purchase Order"] = [ + { + label: "Purchase Order", + url: docsUrl + "user/manual/en/buying/purchase-order", + }, + { + label: "Recurring Purchase Order", + url: docsUrl + "user/manual/en/accounts/recurring-orders-and-invoices", + }, +]; -frappe.help.help_links['Form/Purchase Order'] = [ - { label: 'Purchase Order', url: docsUrl + 'user/manual/en/buying/purchase-order' }, - { label: 'Item UoM', url: docsUrl + 'user/manual/en/buying/articles/purchasing-in-different-unit' }, - { label: 'Supplier Item Code', url: docsUrl + 'user/manual/en/buying/articles/maintaining-suppliers-part-no-in-item' }, - { label: 'Recurring Purchase Order', url: docsUrl + 'user/manual/en/accounts/recurring-orders-and-invoices' }, - { label: 'Subcontracting', url: docsUrl + 'user/manual/en/manufacturing/subcontracting' }, -] +frappe.help.help_links["Form/Purchase Order"] = [ + { + label: "Purchase Order", + url: docsUrl + "user/manual/en/buying/purchase-order", + }, + { + label: "Item UoM", + url: + docsUrl + + "user/manual/en/buying/articles/purchasing-in-different-unit", + }, + { + label: "Supplier Item Code", + url: + docsUrl + + "user/manual/en/buying/articles/maintaining-suppliers-part-no-in-item", + }, + { + label: "Recurring Purchase Order", + url: docsUrl + "user/manual/en/accounts/recurring-orders-and-invoices", + }, + { + label: "Subcontracting", + url: docsUrl + "user/manual/en/manufacturing/subcontracting", + }, +]; -frappe.help.help_links['List/Purchase Taxes and Charges Template'] = [ - { label: 'Setting Up Taxes', url: docsUrl + 'user/manual/en/setting-up/setting-up-taxes' }, -] +frappe.help.help_links["List/Purchase Taxes and Charges Template"] = [ + { + label: "Setting Up Taxes", + url: docsUrl + "user/manual/en/setting-up/setting-up-taxes", + }, +]; -frappe.help.help_links['List/POS Profile'] = [ - { label: 'POS Profile', url: docsUrl + 'user/manual/en/setting-up/pos-setting' }, -] +frappe.help.help_links["List/POS Profile"] = [ + { + label: "POS Profile", + url: docsUrl + "user/manual/en/setting-up/pos-setting", + }, +]; -frappe.help.help_links['List/Price List'] = [ - { label: 'Price List', url: docsUrl + 'user/manual/en/setting-up/price-lists' }, -] +frappe.help.help_links["List/Price List"] = [ + { + label: "Price List", + url: docsUrl + "user/manual/en/setting-up/price-lists", + }, +]; -frappe.help.help_links['List/Authorization Rule'] = [ - { label: 'Authorization Rule', url: docsUrl + 'user/manual/en/setting-up/authorization-rule' }, -] +frappe.help.help_links["List/Authorization Rule"] = [ + { + label: "Authorization Rule", + url: docsUrl + "user/manual/en/setting-up/authorization-rule", + }, +]; -frappe.help.help_links['Form/SMS Settings'] = [ - { label: 'SMS Settings', url: docsUrl + 'user/manual/en/setting-up/sms-setting' }, -] +frappe.help.help_links["Form/SMS Settings"] = [ + { + label: "SMS Settings", + url: docsUrl + "user/manual/en/setting-up/sms-setting", + }, +]; -frappe.help.help_links['List/Stock Reconciliation'] = [ - { label: 'Stock Reconciliation', url: docsUrl + 'user/manual/en/setting-up/stock-reconciliation-for-non-serialized-item' }, -] +frappe.help.help_links["List/Stock Reconciliation"] = [ + { + label: "Stock Reconciliation", + url: + docsUrl + + "user/manual/en/setting-up/stock-reconciliation-for-non-serialized-item", + }, +]; -frappe.help.help_links['Tree/Territory'] = [ - { label: 'Territory', url: docsUrl + 'user/manual/en/setting-up/territory' }, -] +frappe.help.help_links["Tree/Territory"] = [ + { + label: "Territory", + url: docsUrl + "user/manual/en/setting-up/territory", + }, +]; -frappe.help.help_links['Form/Dropbox Backup'] = [ - { label: 'Dropbox Backup', url: docsUrl + 'user/manual/en/setting-up/third-party-backups' }, - { label: 'Setting Up Dropbox Backup', url: docsUrl + 'user/manual/en/setting-up/articles/setting-up-dropbox-backups' }, -] +frappe.help.help_links["Form/Dropbox Backup"] = [ + { + label: "Dropbox Backup", + url: docsUrl + "user/manual/en/setting-up/third-party-backups", + }, + { + label: "Setting Up Dropbox Backup", + url: + docsUrl + + "user/manual/en/setting-up/articles/setting-up-dropbox-backups", + }, +]; -frappe.help.help_links['List/Workflow'] = [ - { label: 'Workflow', url: docsUrl + 'user/manual/en/setting-up/workflows' }, -] +frappe.help.help_links["List/Workflow"] = [ + { label: "Workflow", url: docsUrl + "user/manual/en/setting-up/workflows" }, +]; -frappe.help.help_links['List/Company'] = [ - { label: 'Company', url: docsUrl + 'user/manual/en/setting-up/company-setup' }, - { label: 'Managing Multiple Companies', url: docsUrl + 'user/manual/en/setting-up/articles/managing-multiple-companies' }, - { label: 'Delete All Related Transactions for a Company', url: docsUrl + 'user/manual/en/setting-up/articles/delete-a-company-and-all-related-transactions' }, -] +frappe.help.help_links["List/Company"] = [ + { + label: "Company", + url: docsUrl + "user/manual/en/setting-up/company-setup", + }, + { + label: "Managing Multiple Companies", + url: + docsUrl + + "user/manual/en/setting-up/articles/managing-multiple-companies", + }, + { + label: "Delete All Related Transactions for a Company", + url: + docsUrl + + "user/manual/en/setting-up/articles/delete-a-company-and-all-related-transactions", + }, +]; //Accounts -frappe.help.help_links['modules/Accounts'] = [ - { label: 'Introduction to Accounts', url: docsUrl + 'user/manual/en/accounts/' }, - { label: 'Chart of Accounts', url: docsUrl + 'user/manual/en/accounts/chart-of-accounts.html' }, - { label: 'Multi Currency Accounting', url: docsUrl + 'user/manual/en/accounts/multi-currency-accounting' }, -] +frappe.help.help_links["modules/Accounts"] = [ + { + label: "Introduction to Accounts", + url: docsUrl + "user/manual/en/accounts/", + }, + { + label: "Chart of Accounts", + url: docsUrl + "user/manual/en/accounts/chart-of-accounts.html", + }, + { + label: "Multi Currency Accounting", + url: docsUrl + "user/manual/en/accounts/multi-currency-accounting", + }, +]; -frappe.help.help_links['Tree/Account'] = [ - { label: 'Chart of Accounts', url: docsUrl + 'user/manual/en/accounts/chart-of-accounts' }, - { label: 'Managing Tree Mastes', url: docsUrl + 'user/manual/en/setting-up/articles/managing-tree-structure-masters' }, -] +frappe.help.help_links["Tree/Account"] = [ + { + label: "Chart of Accounts", + url: docsUrl + "user/manual/en/accounts/chart-of-accounts", + }, + { + label: "Managing Tree Mastes", + url: + docsUrl + + "user/manual/en/setting-up/articles/managing-tree-structure-masters", + }, +]; -frappe.help.help_links['Form/Sales Invoice'] = [ - { label: 'Sales Invoice', url: docsUrl + 'user/manual/en/accounts/sales-invoice' }, - { label: 'Accounts Opening Balance', url: docsUrl + 'user/manual/en/accounts/opening-accounts' }, - { label: 'Sales Return', url: docsUrl + 'user/manual/en/stock/sales-return' }, - { label: 'Recurring Sales Invoice', url: docsUrl + 'user/manual/en/accounts/recurring-orders-and-invoices' }, -] +frappe.help.help_links["Form/Sales Invoice"] = [ + { + label: "Sales Invoice", + url: docsUrl + "user/manual/en/accounts/sales-invoice", + }, + { + label: "Accounts Opening Balance", + url: docsUrl + "user/manual/en/accounts/opening-accounts", + }, + { + label: "Sales Return", + url: docsUrl + "user/manual/en/stock/sales-return", + }, + { + label: "Recurring Sales Invoice", + url: docsUrl + "user/manual/en/accounts/recurring-orders-and-invoices", + }, +]; -frappe.help.help_links['List/Sales Invoice'] = [ - { label: 'Sales Invoice', url: docsUrl + 'user/manual/en/accounts/sales-invoice' }, - { label: 'Accounts Opening Balance', url: docsUrl + 'user/manual/en/accounts/opening-accounts' }, - { label: 'Sales Return', url: docsUrl + 'user/manual/en/stock/sales-return' }, - { label: 'Recurring Sales Invoice', url: docsUrl + 'user/manual/en/accounts/recurring-orders-and-invoices' }, -] +frappe.help.help_links["List/Sales Invoice"] = [ + { + label: "Sales Invoice", + url: docsUrl + "user/manual/en/accounts/sales-invoice", + }, + { + label: "Accounts Opening Balance", + url: docsUrl + "user/manual/en/accounts/opening-accounts", + }, + { + label: "Sales Return", + url: docsUrl + "user/manual/en/stock/sales-return", + }, + { + label: "Recurring Sales Invoice", + url: docsUrl + "user/manual/en/accounts/recurring-orders-and-invoices", + }, +]; -frappe.help.help_links['pos'] = [ - { label: 'Point of Sale Invoice', url: docsUrl + 'user/manual/en/accounts/point-of-sale-pos-invoice' }, -] +frappe.help.help_links["pos"] = [ + { + label: "Point of Sale Invoice", + url: docsUrl + "user/manual/en/accounts/point-of-sale-pos-invoice", + }, +]; -frappe.help.help_links['List/POS Profile'] = [ - { label: 'Point of Sale Profile', url: docsUrl + 'user/manual/en/setting-up/pos-setting' }, -] +frappe.help.help_links["List/POS Profile"] = [ + { + label: "Point of Sale Profile", + url: docsUrl + "user/manual/en/setting-up/pos-setting", + }, +]; -frappe.help.help_links['List/Purchase Invoice'] = [ - { label: 'Purchase Invoice', url: docsUrl + 'user/manual/en/accounts/purchase-invoice' }, - { label: 'Accounts Opening Balance', url: docsUrl + 'user/manual/en/accounts/opening-accounts' }, - { label: 'Recurring Purchase Invoice', url: docsUrl + 'user/manual/en/accounts/recurring-orders-and-invoices' }, -] +frappe.help.help_links["List/Purchase Invoice"] = [ + { + label: "Purchase Invoice", + url: docsUrl + "user/manual/en/accounts/purchase-invoice", + }, + { + label: "Accounts Opening Balance", + url: docsUrl + "user/manual/en/accounts/opening-accounts", + }, + { + label: "Recurring Purchase Invoice", + url: docsUrl + "user/manual/en/accounts/recurring-orders-and-invoices", + }, +]; -frappe.help.help_links['List/Journal Entry'] = [ - { label: 'Journal Entry', url: docsUrl + 'user/manual/en/accounts/journal-entry' }, - { label: 'Advance Payment Entry', url: docsUrl + 'user/manual/en/accounts/advance-payment-entry' }, - { label: 'Accounts Opening Balance', url: docsUrl + 'user/manual/en/accounts/opening-accounts' }, -] +frappe.help.help_links["List/Journal Entry"] = [ + { + label: "Journal Entry", + url: docsUrl + "user/manual/en/accounts/journal-entry", + }, + { + label: "Advance Payment Entry", + url: docsUrl + "user/manual/en/accounts/advance-payment-entry", + }, + { + label: "Accounts Opening Balance", + url: docsUrl + "user/manual/en/accounts/opening-accounts", + }, +]; -frappe.help.help_links['List/Payment Entry'] = [ - { label: 'Payment Entry', url: docsUrl + 'user/manual/en/accounts/payment-entry' }, -] +frappe.help.help_links["List/Payment Entry"] = [ + { + label: "Payment Entry", + url: docsUrl + "user/manual/en/accounts/payment-entry", + }, +]; -frappe.help.help_links['List/Payment Request'] = [ - { label: 'Payment Request', url: docsUrl + 'user/manual/en/accounts/payment-request' }, -] +frappe.help.help_links["List/Payment Request"] = [ + { + label: "Payment Request", + url: docsUrl + "user/manual/en/accounts/payment-request", + }, +]; -frappe.help.help_links['List/Asset'] = [ - { label: 'Managing Fixed Assets', url: docsUrl + 'user/manual/en/accounts/managing-fixed-assets' }, -] +frappe.help.help_links["List/Asset"] = [ + { + label: "Managing Fixed Assets", + url: docsUrl + "user/manual/en/accounts/managing-fixed-assets", + }, +]; -frappe.help.help_links['List/Asset Category'] = [ - { label: 'Asset Category', url: docsUrl + 'user/manual/en/accounts/managing-fixed-assets' }, -] +frappe.help.help_links["List/Asset Category"] = [ + { + label: "Asset Category", + url: docsUrl + "user/manual/en/accounts/managing-fixed-assets", + }, +]; -frappe.help.help_links['Tree/Cost Center'] = [ - { label: 'Budgeting', url: docsUrl + 'user/manual/en/accounts/budgeting' }, -] +frappe.help.help_links["Tree/Cost Center"] = [ + { label: "Budgeting", url: docsUrl + "user/manual/en/accounts/budgeting" }, +]; -frappe.help.help_links['List/Item'] = [ - { label: 'Item', url: docsUrl + 'user/manual/en/stock/item' }, - { label: 'Item Price', url: docsUrl + 'user/manual/en/stock/item/item-price' }, - { label: 'Barcode', url: docsUrl + 'user/manual/en/stock/articles/track-items-using-barcode' }, - { label: 'Item Wise Taxation', url: docsUrl + 'user/manual/en/accounts/item-wise-taxation' }, - { label: 'Managing Fixed Assets', url: docsUrl + 'user/manual/en/accounts/managing-fixed-assets' }, - { label: 'Item Codification', url: docsUrl + 'user/manual/en/stock/item/item-codification' }, - { label: 'Item Variants', url: docsUrl + 'user/manual/en/stock/item/item-variants' }, - { label: 'Item Valuation', url: docsUrl + 'user/manual/en/stock/item/item-valuation-fifo-and-moving-average' }, -] +frappe.help.help_links["List/Item"] = [ + { label: "Item", url: docsUrl + "user/manual/en/stock/item" }, + { + label: "Item Price", + url: docsUrl + "user/manual/en/stock/item/item-price", + }, + { + label: "Barcode", + url: + docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", + }, + { + label: "Item Wise Taxation", + url: docsUrl + "user/manual/en/accounts/item-wise-taxation", + }, + { + label: "Managing Fixed Assets", + url: docsUrl + "user/manual/en/accounts/managing-fixed-assets", + }, + { + label: "Item Codification", + url: docsUrl + "user/manual/en/stock/item/item-codification", + }, + { + label: "Item Variants", + url: docsUrl + "user/manual/en/stock/item/item-variants", + }, + { + label: "Item Valuation", + url: + docsUrl + + "user/manual/en/stock/item/item-valuation-fifo-and-moving-average", + }, +]; -frappe.help.help_links['Form/Item'] = [ - { label: 'Item', url: docsUrl + 'user/manual/en/stock/item' }, - { label: 'Item Price', url: docsUrl + 'user/manual/en/stock/item/item-price' }, - { label: 'Barcode', url: docsUrl + 'user/manual/en/stock/articles/track-items-using-barcode' }, - { label: 'Item Wise Taxation', url: docsUrl + 'user/manual/en/accounts/item-wise-taxation' }, - { label: 'Managing Fixed Assets', url: docsUrl + 'user/manual/en/accounts/managing-fixed-assets' }, - { label: 'Item Codification', url: docsUrl + 'user/manual/en/stock/item/item-codification' }, - { label: 'Item Variants', url: docsUrl + 'user/manual/en/stock/item/item-variants' }, - { label: 'Item Valuation', url: docsUrl + 'user/manual/en/stock/item/item-valuation-fifo-and-moving-average' }, -] +frappe.help.help_links["Form/Item"] = [ + { label: "Item", url: docsUrl + "user/manual/en/stock/item" }, + { + label: "Item Price", + url: docsUrl + "user/manual/en/stock/item/item-price", + }, + { + label: "Barcode", + url: + docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", + }, + { + label: "Item Wise Taxation", + url: docsUrl + "user/manual/en/accounts/item-wise-taxation", + }, + { + label: "Managing Fixed Assets", + url: docsUrl + "user/manual/en/accounts/managing-fixed-assets", + }, + { + label: "Item Codification", + url: docsUrl + "user/manual/en/stock/item/item-codification", + }, + { + label: "Item Variants", + url: docsUrl + "user/manual/en/stock/item/item-variants", + }, + { + label: "Item Valuation", + url: + docsUrl + + "user/manual/en/stock/item/item-valuation-fifo-and-moving-average", + }, +]; -frappe.help.help_links['List/Purchase Receipt'] = [ - { label: 'Purchase Receipt', url: docsUrl + 'user/manual/en/stock/purchase-receipt' }, - { label: 'Barcode', url: docsUrl + 'user/manual/en/stock/articles/track-items-using-barcode' }, -] +frappe.help.help_links["List/Purchase Receipt"] = [ + { + label: "Purchase Receipt", + url: docsUrl + "user/manual/en/stock/purchase-receipt", + }, + { + label: "Barcode", + url: + docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", + }, +]; -frappe.help.help_links['List/Delivery Note'] = [ - { label: 'Delivery Note', url: docsUrl + 'user/manual/en/stock/delivery-note' }, - { label: 'Barcode', url: docsUrl + 'user/manual/en/stock/articles/track-items-using-barcode' }, - { label: 'Sales Return', url: docsUrl + 'user/manual/en/stock/sales-return' }, -] +frappe.help.help_links["List/Delivery Note"] = [ + { + label: "Delivery Note", + url: docsUrl + "user/manual/en/stock/delivery-note", + }, + { + label: "Barcode", + url: + docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", + }, + { + label: "Sales Return", + url: docsUrl + "user/manual/en/stock/sales-return", + }, +]; -frappe.help.help_links['Form/Delivery Note'] = [ - { label: 'Delivery Note', url: docsUrl + 'user/manual/en/stock/delivery-note' }, - { label: 'Sales Return', url: docsUrl + 'user/manual/en/stock/sales-return' }, - { label: 'Barcode', url: docsUrl + 'user/manual/en/stock/articles/track-items-using-barcode' }, - { label: 'Subcontracting', url: docsUrl + 'user/manual/en/manufacturing/subcontracting' }, -] +frappe.help.help_links["Form/Delivery Note"] = [ + { + label: "Delivery Note", + url: docsUrl + "user/manual/en/stock/delivery-note", + }, + { + label: "Sales Return", + url: docsUrl + "user/manual/en/stock/sales-return", + }, + { + label: "Barcode", + url: + docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", + }, + { + label: "Subcontracting", + url: docsUrl + "user/manual/en/manufacturing/subcontracting", + }, +]; -frappe.help.help_links['List/Installation Note'] = [ - { label: 'Installation Note', url: docsUrl + 'user/manual/en/stock/installation-note' }, -] +frappe.help.help_links["List/Installation Note"] = [ + { + label: "Installation Note", + url: docsUrl + "user/manual/en/stock/installation-note", + }, +]; +frappe.help.help_links["Tree"] = [ + { + label: "Managing Tree Structure Masters", + url: + docsUrl + + "user/manual/en/setting-up/articles/managing-tree-structure-masters", + }, +]; -frappe.help.help_links['Tree'] = [ - { label: 'Managing Tree Structure Masters', url: docsUrl + 'user/manual/en/setting-up/articles/managing-tree-structure-masters' }, -] - -frappe.help.help_links['List/Budget'] = [ - { label: 'Budgeting', url: docsUrl + 'user/manual/en/accounts/budgeting' }, -] +frappe.help.help_links["List/Budget"] = [ + { label: "Budgeting", url: docsUrl + "user/manual/en/accounts/budgeting" }, +]; //Stock -frappe.help.help_links['List/Material Request'] = [ - { label: 'Material Request', url: docsUrl + 'user/manual/en/stock/material-request' }, - { label: 'Auto-creation of Material Request', url: docsUrl + 'user/manual/en/stock/articles/auto-creation-of-material-request' }, -] +frappe.help.help_links["List/Material Request"] = [ + { + label: "Material Request", + url: docsUrl + "user/manual/en/stock/material-request", + }, + { + label: "Auto-creation of Material Request", + url: + docsUrl + + "user/manual/en/stock/articles/auto-creation-of-material-request", + }, +]; -frappe.help.help_links['Form/Material Request'] = [ - { label: 'Material Request', url: docsUrl + 'user/manual/en/stock/material-request' }, - { label: 'Auto-creation of Material Request', url: docsUrl + 'user/manual/en/stock/articles/auto-creation-of-material-request' }, -] +frappe.help.help_links["Form/Material Request"] = [ + { + label: "Material Request", + url: docsUrl + "user/manual/en/stock/material-request", + }, + { + label: "Auto-creation of Material Request", + url: + docsUrl + + "user/manual/en/stock/articles/auto-creation-of-material-request", + }, +]; -frappe.help.help_links['Form/Stock Entry'] = [ - { label: 'Stock Entry', url: docsUrl + 'user/manual/en/stock/stock-entry' }, - { label: 'Stock Entry Types', url: docsUrl + 'user/manual/en/stock/articles/stock-entry-purpose' }, - { label: 'Repack Entry', url: docsUrl + 'user/manual/en/stock/articles/repack-entry' }, - { label: 'Opening Stock', url: docsUrl + 'user/manual/en/stock/opening-stock' }, - { label: 'Subcontracting', url: docsUrl + 'user/manual/en/manufacturing/subcontracting' }, -] +frappe.help.help_links["Form/Stock Entry"] = [ + { label: "Stock Entry", url: docsUrl + "user/manual/en/stock/stock-entry" }, + { + label: "Stock Entry Types", + url: docsUrl + "user/manual/en/stock/articles/stock-entry-purpose", + }, + { + label: "Repack Entry", + url: docsUrl + "user/manual/en/stock/articles/repack-entry", + }, + { + label: "Opening Stock", + url: docsUrl + "user/manual/en/stock/opening-stock", + }, + { + label: "Subcontracting", + url: docsUrl + "user/manual/en/manufacturing/subcontracting", + }, +]; -frappe.help.help_links['List/Stock Entry'] = [ - { label: 'Stock Entry', url: docsUrl + 'user/manual/en/stock/stock-entry' }, -] +frappe.help.help_links["List/Stock Entry"] = [ + { label: "Stock Entry", url: docsUrl + "user/manual/en/stock/stock-entry" }, +]; -frappe.help.help_links['Tree/Warehouse'] = [ - { label: 'Warehouse', url: docsUrl + 'user/manual/en/stock/warehouse' }, -] +frappe.help.help_links["Tree/Warehouse"] = [ + { label: "Warehouse", url: docsUrl + "user/manual/en/stock/warehouse" }, +]; -frappe.help.help_links['List/Serial No'] = [ - { label: 'Serial No', url: docsUrl + 'user/manual/en/stock/serial-no' }, -] +frappe.help.help_links["List/Serial No"] = [ + { label: "Serial No", url: docsUrl + "user/manual/en/stock/serial-no" }, +]; -frappe.help.help_links['Form/Serial No'] = [ - { label: 'Serial No', url: docsUrl + 'user/manual/en/stock/serial-no' }, -] +frappe.help.help_links["Form/Serial No"] = [ + { label: "Serial No", url: docsUrl + "user/manual/en/stock/serial-no" }, +]; -frappe.help.help_links['Form/Batch'] = [ - { label: 'Batch', url: docsUrl + 'user/manual/en/stock/batch' }, -] +frappe.help.help_links["Form/Batch"] = [ + { label: "Batch", url: docsUrl + "user/manual/en/stock/batch" }, +]; -frappe.help.help_links['Form/Packing Slip'] = [ - { label: 'Packing Slip', url: docsUrl + 'user/manual/en/stock/tools/packing-slip' }, -] +frappe.help.help_links["Form/Packing Slip"] = [ + { + label: "Packing Slip", + url: docsUrl + "user/manual/en/stock/tools/packing-slip", + }, +]; -frappe.help.help_links['Form/Quality Inspection'] = [ - { label: 'Quality Inspection', url: docsUrl + 'user/manual/en/stock/tools/quality-inspection' }, -] +frappe.help.help_links["Form/Quality Inspection"] = [ + { + label: "Quality Inspection", + url: docsUrl + "user/manual/en/stock/tools/quality-inspection", + }, +]; -frappe.help.help_links['Form/Landed Cost Voucher'] = [ - { label: 'Landed Cost Voucher', url: docsUrl + 'user/manual/en/stock/tools/landed-cost-voucher' }, -] +frappe.help.help_links["Form/Landed Cost Voucher"] = [ + { + label: "Landed Cost Voucher", + url: docsUrl + "user/manual/en/stock/tools/landed-cost-voucher", + }, +]; -frappe.help.help_links['Tree/Item Group'] = [ - { label: 'Item Group', url: docsUrl + 'user/manual/en/stock/setup/item-group' }, -] +frappe.help.help_links["Tree/Item Group"] = [ + { + label: "Item Group", + url: docsUrl + "user/manual/en/stock/setup/item-group", + }, +]; -frappe.help.help_links['Form/Item Attribute'] = [ - { label: 'Item Attribute', url: docsUrl + 'user/manual/en/stock/setup/item-attribute' }, -] +frappe.help.help_links["Form/Item Attribute"] = [ + { + label: "Item Attribute", + url: docsUrl + "user/manual/en/stock/setup/item-attribute", + }, +]; -frappe.help.help_links['Form/UOM'] = [ - { label: 'Fractions in UOM', url: docsUrl + 'user/manual/en/stock/articles/managing-fractions-in-uom' }, -] +frappe.help.help_links["Form/UOM"] = [ + { + label: "Fractions in UOM", + url: + docsUrl + "user/manual/en/stock/articles/managing-fractions-in-uom", + }, +]; -frappe.help.help_links['Form/Stock Reconciliation'] = [ - { label: 'Opening Stock Entry', url: docsUrl + 'user/manual/en/stock/opening-stock' }, -] +frappe.help.help_links["Form/Stock Reconciliation"] = [ + { + label: "Opening Stock Entry", + url: docsUrl + "user/manual/en/stock/opening-stock", + }, +]; //CRM -frappe.help.help_links['Form/Lead'] = [ - { label: 'Lead', url: docsUrl + 'user/manual/en/CRM/lead' }, -] +frappe.help.help_links["Form/Lead"] = [ + { label: "Lead", url: docsUrl + "user/manual/en/CRM/lead" }, +]; -frappe.help.help_links['Form/Opportunity'] = [ - { label: 'Opportunity', url: docsUrl + 'user/manual/en/CRM/opportunity' }, -] +frappe.help.help_links["Form/Opportunity"] = [ + { label: "Opportunity", url: docsUrl + "user/manual/en/CRM/opportunity" }, +]; -frappe.help.help_links['Form/Address'] = [ - { label: 'Address', url: docsUrl + 'user/manual/en/CRM/address' }, -] +frappe.help.help_links["Form/Address"] = [ + { label: "Address", url: docsUrl + "user/manual/en/CRM/address" }, +]; -frappe.help.help_links['Form/Contact'] = [ - { label: 'Contact', url: docsUrl + 'user/manual/en/CRM/contact' }, -] +frappe.help.help_links["Form/Contact"] = [ + { label: "Contact", url: docsUrl + "user/manual/en/CRM/contact" }, +]; -frappe.help.help_links['Form/Newsletter'] = [ - { label: 'Newsletter', url: docsUrl + 'user/manual/en/CRM/newsletter' }, -] +frappe.help.help_links["Form/Newsletter"] = [ + { label: "Newsletter", url: docsUrl + "user/manual/en/CRM/newsletter" }, +]; -frappe.help.help_links['Form/Campaign'] = [ - { label: 'Campaign', url: docsUrl + 'user/manual/en/CRM/setup/campaign' }, -] +frappe.help.help_links["Form/Campaign"] = [ + { label: "Campaign", url: docsUrl + "user/manual/en/CRM/setup/campaign" }, +]; -frappe.help.help_links['Tree/Sales Person'] = [ - { label: 'Sales Person', url: docsUrl + 'user/manual/en/CRM/setup/sales-person' }, -] +frappe.help.help_links["Tree/Sales Person"] = [ + { + label: "Sales Person", + url: docsUrl + "user/manual/en/CRM/setup/sales-person", + }, +]; -frappe.help.help_links['Form/Sales Person'] = [ - { label: 'Sales Person Target', url: docsUrl + 'user/manual/en/selling/setup/sales-person-target-allocation' }, -] +frappe.help.help_links["Form/Sales Person"] = [ + { + label: "Sales Person Target", + url: + docsUrl + + "user/manual/en/selling/setup/sales-person-target-allocation", + }, +]; //Support -frappe.help.help_links['List/Feedback Trigger'] = [ - { label: 'Feedback Trigger', url: docsUrl + 'user/manual/en/setting-up/feedback/setting-up-feedback' }, -] +frappe.help.help_links["List/Feedback Trigger"] = [ + { + label: "Feedback Trigger", + url: docsUrl + "user/manual/en/setting-up/feedback/setting-up-feedback", + }, +]; -frappe.help.help_links['List/Feedback Request'] = [ - { label: 'Feedback Request', url: docsUrl + 'user/manual/en/setting-up/feedback/submit-feedback' }, -] +frappe.help.help_links["List/Feedback Request"] = [ + { + label: "Feedback Request", + url: docsUrl + "user/manual/en/setting-up/feedback/submit-feedback", + }, +]; -frappe.help.help_links['List/Feedback Request'] = [ - { label: 'Feedback Request', url: docsUrl + 'user/manual/en/setting-up/feedback/submit-feedback' }, -] +frappe.help.help_links["List/Feedback Request"] = [ + { + label: "Feedback Request", + url: docsUrl + "user/manual/en/setting-up/feedback/submit-feedback", + }, +]; //Manufacturing -frappe.help.help_links['Form/BOM'] = [ - { label: 'Bill of Material', url: docsUrl + 'user/manual/en/manufacturing/bill-of-materials' }, - { label: 'Nested BOM Structure', url: docsUrl + 'user/manual/en/manufacturing/articles/nested-bom-structure' }, -] +frappe.help.help_links["Form/BOM"] = [ + { + label: "Bill of Material", + url: docsUrl + "user/manual/en/manufacturing/bill-of-materials", + }, + { + label: "Nested BOM Structure", + url: + docsUrl + + "user/manual/en/manufacturing/articles/nested-bom-structure", + }, +]; -frappe.help.help_links['Form/Work Order'] = [ - { label: 'Work Order', url: docsUrl + 'user/manual/en/manufacturing/work-order' }, -] +frappe.help.help_links["Form/Work Order"] = [ + { + label: "Work Order", + url: docsUrl + "user/manual/en/manufacturing/work-order", + }, +]; -frappe.help.help_links['Form/Workstation'] = [ - { label: 'Workstation', url: docsUrl + 'user/manual/en/manufacturing/workstation' }, -] +frappe.help.help_links["Form/Workstation"] = [ + { + label: "Workstation", + url: docsUrl + "user/manual/en/manufacturing/workstation", + }, +]; -frappe.help.help_links['Form/Operation'] = [ - { label: 'Operation', url: docsUrl + 'user/manual/en/manufacturing/operation' }, -] +frappe.help.help_links["Form/Operation"] = [ + { + label: "Operation", + url: docsUrl + "user/manual/en/manufacturing/operation", + }, +]; -frappe.help.help_links['Form/BOM Update Tool'] = [ - { label: 'BOM Update Tool', url: docsUrl + 'user/manual/en/manufacturing/tools/bom-update-tool' }, -] +frappe.help.help_links["Form/BOM Update Tool"] = [ + { + label: "BOM Update Tool", + url: docsUrl + "user/manual/en/manufacturing/tools/bom-update-tool", + }, +]; //Customize -frappe.help.help_links['Form/Customize Form'] = [ - { label: 'Custom Field', url: docsUrl + 'user/manual/en/customize-erpnext/custom-field' }, - { label: 'Customize Field', url: docsUrl + 'user/manual/en/customize-erpnext/customize-form' }, -] +frappe.help.help_links["Form/Customize Form"] = [ + { + label: "Custom Field", + url: docsUrl + "user/manual/en/customize-erpnext/custom-field", + }, + { + label: "Customize Field", + url: docsUrl + "user/manual/en/customize-erpnext/customize-form", + }, +]; -frappe.help.help_links['Form/Custom Field'] = [ - { label: 'Custom Field', url: docsUrl + 'user/manual/en/customize-erpnext/custom-field' }, -] +frappe.help.help_links["Form/Custom Field"] = [ + { + label: "Custom Field", + url: docsUrl + "user/manual/en/customize-erpnext/custom-field", + }, +]; -frappe.help.help_links['Form/Custom Field'] = [ - { label: 'Custom Field', url: docsUrl + 'user/manual/en/customize-erpnext/custom-field' }, -] +frappe.help.help_links["Form/Custom Field"] = [ + { + label: "Custom Field", + url: docsUrl + "user/manual/en/customize-erpnext/custom-field", + }, +]; From f66aab6d98b7922b2327eaad1150348baa06aca7 Mon Sep 17 00:00:00 2001 From: Saqib Date: Fri, 26 Mar 2021 16:40:51 +0530 Subject: [PATCH 335/449] fix: e-invoicing option visible even if settings disabled (#25021) --- erpnext/regional/india/e_invoice/einvoice.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/regional/india/e_invoice/einvoice.js b/erpnext/regional/india/e_invoice/einvoice.js index e8a7c30e19..cad2acd80e 100644 --- a/erpnext/regional/india/e_invoice/einvoice.js +++ b/erpnext/regional/india/e_invoice/einvoice.js @@ -1,7 +1,8 @@ erpnext.setup_einvoice_actions = (doctype) => { frappe.ui.form.on(doctype, { - refresh(frm) { - const einvoicing_enabled = frappe.db.get_value("E Invoice Settings", "E Invoice Settings", "enable"); + async refresh(frm) { + const { message } = await frappe.db.get_value("E Invoice Settings", "E Invoice Settings", "enable"); + const einvoicing_enabled = cint(message.enable); const supply_type = frm.doc.gst_category; const valid_supply_type = ['Registered Regular', 'SEZ', 'Overseas', 'Deemed Export'].includes(supply_type); const company_transaction = frm.doc.billing_address_gstin == frm.doc.company_gstin; From efe2b425b15a36ca33b966fdcf2a232f2841a470 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Mon, 8 Mar 2021 20:58:57 +0530 Subject: [PATCH 336/449] feat(Production Plan): Consider Safety Stock in Required Qty Calculation --- .../material_request_plan_item.json | 9 ++++++++- .../doctype/production_plan/production_plan.json | 9 ++++++++- .../doctype/production_plan/production_plan.py | 13 +++++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json b/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json index f93b244a50..88f8d6075d 100644 --- a/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json +++ b/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json @@ -15,6 +15,7 @@ "uom", "projected_qty", "actual_qty", + "safety_stock", "item_details", "description", "min_order_qty", @@ -129,11 +130,17 @@ "fieldtype": "Link", "label": "From Warehouse", "options": "Warehouse" + }, + { + "fetch_from": "item_code.safety_stock", + "fieldname": "safety_stock", + "fieldtype": "Float", + "label": "Safety Stock" } ], "istable": 1, "links": [], - "modified": "2020-02-03 12:22:29.913302", + "modified": "2021-03-08 18:39:17.553611", "modified_by": "Administrator", "module": "Manufacturing", "name": "Material Request Plan Item", diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.json b/erpnext/manufacturing/doctype/production_plan/production_plan.json index 7daf7069f3..f11470086a 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.json +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.json @@ -32,6 +32,7 @@ "material_request_planning", "include_non_stock_items", "include_subcontracted_items", + "include_safety_stock", "ignore_existing_ordered_qty", "column_break_25", "for_warehouse", @@ -309,13 +310,19 @@ "fieldtype": "Select", "label": "Sales Order Status", "options": "\nTo Deliver and Bill\nTo Bill\nTo Deliver" + }, + { + "default": "0", + "fieldname": "include_safety_stock", + "fieldtype": "Check", + "label": "Include Safety Stock in Required Qty Calculation" } ], "icon": "fa fa-calendar", "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2020-11-10 18:01:54.991970", + "modified": "2021-03-08 11:17:25.470147", "modified_by": "Administrator", "module": "Manufacturing", "name": "Production Plan", diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index 3833e86d27..730288be59 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -482,7 +482,7 @@ def get_subitems(doc, data, item_details, bom_no, company, include_non_stock_ite ifnull(%(parent_qty)s * sum(bom_item.stock_qty/ifnull(bom.quantity, 1)) * %(planned_qty)s, 0) as qty, item.is_sub_contracted_item as is_sub_contracted, bom_item.source_warehouse, item.default_bom as default_bom, bom_item.description as description, - bom_item.stock_uom as stock_uom, item.min_order_qty as min_order_qty, + bom_item.stock_uom as stock_uom, item.min_order_qty as min_order_qty, item.safety_stock as safety_stock, item_default.default_warehouse, item.purchase_uom, item_uom.conversion_factor FROM `tabBOM Item` bom_item @@ -518,8 +518,8 @@ def get_subitems(doc, data, item_details, bom_no, company, include_non_stock_ite include_non_stock_items, include_subcontracted_items, d.qty) return item_details -def get_material_request_items(row, sales_order, - company, ignore_existing_ordered_qty, warehouse, bin_dict): +def get_material_request_items(row, sales_order, company, + ignore_existing_ordered_qty, include_safety_stock, warehouse, bin_dict): total_qty = row['qty'] required_qty = 0 @@ -543,6 +543,9 @@ def get_material_request_items(row, sales_order, if frappe.db.get_value("UOM", row['purchase_uom'], "must_be_whole_number"): required_qty = ceil(required_qty) + if include_safety_stock: + required_qty += flt(row['safety_stock']) + if required_qty > 0: return { 'item_code': row.item_code, @@ -660,6 +663,7 @@ def get_items_for_material_requests(doc, warehouses=None): company = doc.get('company') ignore_existing_ordered_qty = doc.get('ignore_existing_ordered_qty') + include_safety_stock = doc.get('include_safety_stock') so_item_details = frappe._dict() for data in po_items: @@ -711,6 +715,7 @@ def get_items_for_material_requests(doc, warehouses=None): 'description' : item_master.description, 'stock_uom' : item_master.stock_uom, 'conversion_factor' : conversion_factor, + 'safety_stock': item_master.safety_stock } ) @@ -732,7 +737,7 @@ def get_items_for_material_requests(doc, warehouses=None): if details.qty > 0: items = get_material_request_items(details, sales_order, company, - ignore_existing_ordered_qty, warehouse, bin_dict) + ignore_existing_ordered_qty, include_safety_stock, warehouse, bin_dict) if items: mr_items.append(items) From 28a885a3a9e63f36311fcac252a4e4cc1b4608e0 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Mon, 22 Mar 2021 12:21:23 +0530 Subject: [PATCH 337/449] feat: show ordered and reserved qty in Material Request Plan Item table --- .../material_request_plan_item.json | 18 +++++++++++++++++- .../doctype/production_plan/production_plan.py | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json b/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json index 88f8d6075d..8d67827c81 100644 --- a/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json +++ b/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json @@ -15,6 +15,8 @@ "uom", "projected_qty", "actual_qty", + "ordered_qty", + "reserved_qty_for_production", "safety_stock", "item_details", "description", @@ -136,11 +138,25 @@ "fieldname": "safety_stock", "fieldtype": "Float", "label": "Safety Stock" + }, + { + "fieldname": "ordered_qty", + "fieldtype": "Float", + "label": "Ordered Qty", + "no_copy": 1, + "read_only": 1 + }, + { + "fieldname": "reserved_qty_for_production", + "fieldtype": "Float", + "label": "Reserved Qty for Production", + "no_copy": 1, + "read_only": 1 } ], "istable": 1, "links": [], - "modified": "2021-03-08 18:39:17.553611", + "modified": "2021-03-22 12:11:10.993737", "modified_by": "Administrator", "module": "Manufacturing", "name": "Material Request Plan Item", diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index 730288be59..a15a806187 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -557,6 +557,8 @@ def get_material_request_items(row, sales_order, company, or row.get('default_warehouse') or item_group_defaults.get("default_warehouse"), 'actual_qty': bin_dict.get("actual_qty", 0), 'projected_qty': bin_dict.get("projected_qty", 0), + 'ordered_qty': bin_dict.get("ordered_qty", 0), + 'reserved_qty_for_production': bin_dict.get("reserved_qty_for_production", 0), 'min_order_qty': row['min_order_qty'], 'material_request_type': row.get("default_material_request_type"), 'sales_order': sales_order, From d74ff72527c842de603c879039ee9f6db51ec12c Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 26 Mar 2021 11:50:54 +0530 Subject: [PATCH 338/449] fix: Ordered and Reserved Qty for Production not getting fetched in Items --- .../manufacturing/doctype/production_plan/production_plan.js | 3 ++- .../manufacturing/doctype/production_plan/production_plan.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js index b723387a09..cf892650c6 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.js +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js @@ -251,7 +251,8 @@ frappe.ui.form.on('Production Plan', { get_items_for_material_requests: function(frm, warehouses) { const set_fields = ['actual_qty', 'item_code','item_name', 'description', 'uom', 'from_warehouse', - 'min_order_qty', 'quantity', 'sales_order', 'warehouse', 'projected_qty', 'material_request_type']; + 'min_order_qty', 'quantity', 'sales_order', 'warehouse', 'projected_qty', 'ordered_qty', + 'reserved_qty_for_production', 'material_request_type']; frappe.call({ method: "erpnext.manufacturing.doctype.production_plan.production_plan.get_items_for_material_requests", diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index a15a806187..dde7325a06 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -625,7 +625,8 @@ def get_bin_details(row, company, for_warehouse=None, all_warehouse=False): """.format(lft, rgt, company) return frappe.db.sql(""" select ifnull(sum(projected_qty),0) as projected_qty, - ifnull(sum(actual_qty),0) as actual_qty, warehouse from `tabBin` + ifnull(sum(actual_qty),0) as actual_qty, ifnull(sum(ordered_qty),0) as ordered_qty, + ifnull(sum(reserved_qty_for_production),0) as reserved_qty_for_production, warehouse from `tabBin` where item_code = %(item_code)s {conditions} group by item_code, warehouse """.format(conditions=conditions), { "item_code": row['item_code'] }, as_dict=1) From 4cd68cdecbf6c3e7d7f34ba570ef64f587606816 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 26 Mar 2021 12:33:21 +0530 Subject: [PATCH 339/449] feat: Add more fields to raw material download --- .../doctype/production_plan/production_plan.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index dde7325a06..60e4d88949 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -435,11 +435,13 @@ def download_raw_materials(doc): doc = frappe._dict(json.loads(doc)) item_list = [['Item Code', 'Description', 'Stock UOM', 'Required Qty', 'Warehouse', - 'projected Qty', 'Actual Qty']] + 'Projected Qty', 'Actual Qty', 'Ordered Qty', 'Reserved Qty for Production', + 'Safety Stock']] for d in get_items_for_material_requests(doc): item_list.append([d.get('item_code'), d.get('description'), d.get('stock_uom'), d.get('quantity'), - d.get('warehouse'), d.get('projected_qty'), d.get('actual_qty')]) + d.get('warehouse'), d.get('projected_qty'), d.get('actual_qty'), d.get('ordered_qty'), + d.get('reserved_qty_for_production'), d.get('safety_stock')]) if not doc.get('for_warehouse'): row = {'item_code': d.get('item_code')} @@ -448,7 +450,8 @@ def download_raw_materials(doc): continue item_list.append(['', '', '', '', bin_dict.get('warehouse'), - bin_dict.get('projected_qty', 0), bin_dict.get('actual_qty', 0)]) + bin_dict.get('projected_qty', 0), bin_dict.get('actual_qty', 0)], + bin_dict.get('ordered_qty', 0), bin_dict.get('reserved_qty_for_production', 0)) build_csv_response(item_list, doc.name) @@ -555,6 +558,7 @@ def get_material_request_items(row, sales_order, company, 'stock_uom': row.get("stock_uom"), 'warehouse': warehouse or row.get('source_warehouse') \ or row.get('default_warehouse') or item_group_defaults.get("default_warehouse"), + 'safety_stock': row.safety_stock, 'actual_qty': bin_dict.get("actual_qty", 0), 'projected_qty': bin_dict.get("projected_qty", 0), 'ordered_qty': bin_dict.get("ordered_qty", 0), From 44853da7c2b081e0700f958059869352929a7387 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 26 Mar 2021 13:39:35 +0530 Subject: [PATCH 340/449] feat: Show Required Qty as per BOM in Material Request Items --- .../material_request_plan_item.json | 14 ++++++++++++-- .../doctype/production_plan/production_plan.js | 2 +- .../doctype/production_plan/production_plan.py | 17 +++++++++-------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json b/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json index 8d67827c81..6c60bbde86 100644 --- a/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json +++ b/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json @@ -11,6 +11,7 @@ "from_warehouse", "warehouse", "column_break_4", + "required_bom_qty", "quantity", "uom", "projected_qty", @@ -137,7 +138,9 @@ "fetch_from": "item_code.safety_stock", "fieldname": "safety_stock", "fieldtype": "Float", - "label": "Safety Stock" + "label": "Safety Stock", + "no_copy": 1, + "read_only": 1 }, { "fieldname": "ordered_qty", @@ -152,11 +155,18 @@ "label": "Reserved Qty for Production", "no_copy": 1, "read_only": 1 + }, + { + "fieldname": "required_bom_qty", + "fieldtype": "Float", + "label": "Required Qty as per BOM", + "no_copy": 1, + "read_only": 1 } ], "istable": 1, "links": [], - "modified": "2021-03-22 12:11:10.993737", + "modified": "2021-03-26 12:41:13.013149", "modified_by": "Administrator", "module": "Manufacturing", "name": "Material Request Plan Item", diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js index cf892650c6..15ec6209c1 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.js +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js @@ -251,7 +251,7 @@ frappe.ui.form.on('Production Plan', { get_items_for_material_requests: function(frm, warehouses) { const set_fields = ['actual_qty', 'item_code','item_name', 'description', 'uom', 'from_warehouse', - 'min_order_qty', 'quantity', 'sales_order', 'warehouse', 'projected_qty', 'ordered_qty', + 'min_order_qty', 'required_bom_qty', 'quantity', 'sales_order', 'warehouse', 'projected_qty', 'ordered_qty', 'reserved_qty_for_production', 'material_request_type']; frappe.call({ diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index 60e4d88949..2e6569faa1 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -434,14 +434,14 @@ def download_raw_materials(doc): if isinstance(doc, string_types): doc = frappe._dict(json.loads(doc)) - item_list = [['Item Code', 'Description', 'Stock UOM', 'Required Qty', 'Warehouse', + item_list = [['Item Code', 'Description', 'Stock UOM', 'Warehouse', 'Required Qty as per BOM', 'Projected Qty', 'Actual Qty', 'Ordered Qty', 'Reserved Qty for Production', - 'Safety Stock']] + 'Safety Stock', 'Required Qty']] for d in get_items_for_material_requests(doc): - item_list.append([d.get('item_code'), d.get('description'), d.get('stock_uom'), d.get('quantity'), - d.get('warehouse'), d.get('projected_qty'), d.get('actual_qty'), d.get('ordered_qty'), - d.get('reserved_qty_for_production'), d.get('safety_stock')]) + item_list.append([d.get('item_code'), d.get('description'), d.get('stock_uom'), d.get('warehouse'), + d.get('required_bom_qty'), d.get('projected_qty'), d.get('actual_qty'), d.get('ordered_qty'), + d.get('reserved_qty_for_production'), d.get('safety_stock'), d.get('quantity')]) if not doc.get('for_warehouse'): row = {'item_code': d.get('item_code')} @@ -449,9 +449,9 @@ def download_raw_materials(doc): if d.get("warehouse") == bin_dict.get('warehouse'): continue - item_list.append(['', '', '', '', bin_dict.get('warehouse'), - bin_dict.get('projected_qty', 0), bin_dict.get('actual_qty', 0)], - bin_dict.get('ordered_qty', 0), bin_dict.get('reserved_qty_for_production', 0)) + item_list.append(['', '', '', bin_dict.get('warehouse'), '', + bin_dict.get('projected_qty', 0), bin_dict.get('actual_qty', 0), + bin_dict.get('ordered_qty', 0), bin_dict.get('reserved_qty_for_production', 0)]) build_csv_response(item_list, doc.name) @@ -554,6 +554,7 @@ def get_material_request_items(row, sales_order, company, 'item_code': row.item_code, 'item_name': row.item_name, 'quantity': required_qty, + 'required_bom_qty': total_qty, 'description': row.description, 'stock_uom': row.get("stock_uom"), 'warehouse': warehouse or row.get('source_warehouse') \ From cd8422a840d97d748b0e1656f0da49ba6ea5647c Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Sat, 6 Mar 2021 22:08:08 +0530 Subject: [PATCH 341/449] feat: recursive product discount --- .../doctype/pricing_rule/pricing_rule.json | 37 +++++++++++------- .../doctype/pricing_rule/pricing_rule.py | 1 + .../accounts/doctype/pricing_rule/utils.py | 38 +++++++++++-------- .../promotional_scheme/promotional_scheme.py | 2 +- .../promotional_scheme_product_discount.json | 15 +++++++- erpnext/controllers/taxes_and_totals.py | 5 ++- erpnext/public/js/controllers/transaction.js | 38 ++++++++++++------- 7 files changed, 90 insertions(+), 46 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.json b/erpnext/accounts/doctype/pricing_rule/pricing_rule.json index d08a854142..81890d50b9 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.json +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.json @@ -44,6 +44,14 @@ "column_break_21", "min_amt", "max_amt", + "product_discount_scheme_section", + "same_item", + "free_item", + "free_qty", + "free_item_rate", + "column_break_42", + "free_item_uom", + "is_recursive", "section_break_23", "valid_from", "valid_upto", @@ -62,13 +70,6 @@ "discount_amount", "discount_percentage", "for_price_list", - "product_discount_scheme_section", - "same_item", - "free_item", - "free_qty", - "column_break_51", - "free_item_uom", - "free_item_rate", "section_break_13", "threshold_percentage", "priority", @@ -459,10 +460,6 @@ "fieldtype": "Float", "label": "Qty" }, - { - "fieldname": "column_break_51", - "fieldtype": "Column Break" - }, { "fieldname": "free_item_uom", "fieldtype": "Link", @@ -553,19 +550,33 @@ "fieldname": "promotional_scheme", "fieldtype": "Link", "label": "Promotional Scheme", - "options": "Promotional Scheme" + "no_copy": 1, + "options": "Promotional Scheme", + "print_hide": 1, + "read_only": 1 }, { "description": "Simple Python Expression, Example: territory != 'All Territories'", "fieldname": "condition", "fieldtype": "Code", "label": "Condition" + }, + { + "fieldname": "column_break_42", + "fieldtype": "Column Break" + }, + { + "default": "0", + "description": "Discounts to be applied in sequential ranges like buy 1 get 1, buy 2 get 2, buy 3 get 3 and so on", + "fieldname": "is_recursive", + "fieldtype": "Check", + "label": "Is Recursive" } ], "icon": "fa fa-gift", "idx": 1, "links": [], - "modified": "2020-12-04 00:36:24.698219", + "modified": "2021-03-06 22:01:24.840422", "modified_by": "Administrator", "module": "Accounts", "name": "Pricing Rule", diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index 05652642eb..9a3ea27621 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -237,6 +237,7 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa "doctype": args.doctype, "has_margin": False, "name": args.name, + "free_item_data": [], "parent": args.parent, "parenttype": args.parenttype, "child_docname": args.get('child_docname') diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index d163335996..210cd16009 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -367,7 +367,7 @@ def get_qty_and_rate_for_mixed_conditions(doc, pr_doc, args): if items and doc.get("items"): for row in doc.get('items'): - if row.get(apply_on) not in items: continue + if (row.get(apply_on) or args.get(apply_on)) not in items: continue if pr_doc.mixed_conditions: amt = args.get('qty') * args.get("price_list_rate") @@ -479,7 +479,7 @@ def apply_pricing_rule_on_transaction(doc): doc.calculate_taxes_and_totals() elif d.price_or_product_discount == 'Product': - item_details = frappe._dict({'parenttype': doc.doctype}) + item_details = frappe._dict({'parenttype': doc.doctype, 'free_item_data': []}) get_product_discount_rule(d, item_details, doc=doc) apply_pricing_rule_for_free_items(doc, item_details.free_item_data) doc.set_missing_values() @@ -508,9 +508,15 @@ def get_product_discount_rule(pricing_rule, item_details, args=None, doc=None): frappe.throw(_("Free item not set in the pricing rule {0}") .format(get_link_to_form("Pricing Rule", pricing_rule.name))) - item_details.free_item_data = { + qty = pricing_rule.free_qty or 1 + if pricing_rule.is_recursive: + transaction_qty = args.get('qty') if args else doc.total_qty + if transaction_qty: + qty = flt(transaction_qty) * qty + + free_item_data_args = { 'item_code': free_item, - 'qty': pricing_rule.free_qty or 1, + 'qty': qty, 'rate': pricing_rule.free_item_rate or 0, 'price_list_rate': pricing_rule.free_item_rate or 0, 'is_free_item': 1 @@ -519,24 +525,26 @@ def get_product_discount_rule(pricing_rule, item_details, args=None, doc=None): item_data = frappe.get_cached_value('Item', free_item, ['item_name', 'description', 'stock_uom'], as_dict=1) - item_details.free_item_data.update(item_data) - item_details.free_item_data['uom'] = pricing_rule.free_item_uom or item_data.stock_uom - item_details.free_item_data['conversion_factor'] = get_conversion_factor(free_item, - item_details.free_item_data['uom']).get("conversion_factor", 1) + free_item_data_args.update(item_data) + free_item_data_args['uom'] = pricing_rule.free_item_uom or item_data.stock_uom + free_item_data_args['conversion_factor'] = get_conversion_factor(free_item, + free_item_data_args['uom']).get("conversion_factor", 1) if item_details.get("parenttype") == 'Purchase Order': - item_details.free_item_data['schedule_date'] = doc.schedule_date if doc else today() + free_item_data_args['schedule_date'] = doc.schedule_date if doc else today() if item_details.get("parenttype") == 'Sales Order': - item_details.free_item_data['delivery_date'] = doc.delivery_date if doc else today() + free_item_data_args['delivery_date'] = doc.delivery_date if doc else today() + + item_details.free_item_data.append(free_item_data_args) def apply_pricing_rule_for_free_items(doc, pricing_rule_args, set_missing_values=False): - if pricing_rule_args.get('item_code'): - items = [d.item_code for d in doc.items - if d.item_code == (pricing_rule_args.get("item_code")) and d.is_free_item] + if pricing_rule_args: + items = tuple([d.item_code for d in doc.items if d.is_free_item]) - if not items: - doc.append('items', pricing_rule_args) + for args in pricing_rule_args: + if not items or args.get('item_code') not in items: + doc.append('items', args) def get_pricing_rule_items(pr_doc): apply_on_data = [] diff --git a/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py b/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py index 89f7238a06..6e13f0694c 100644 --- a/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py +++ b/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py @@ -21,7 +21,7 @@ price_discount_fields = ['rate_or_discount', 'apply_discount_on', 'apply_discoun 'rate', 'discount_amount', 'discount_percentage', 'validate_applied_rule'] product_discount_fields = ['free_item', 'free_qty', 'free_item_uom', - 'free_item_rate', 'same_item'] + 'free_item_rate', 'same_item', 'is_recursive'] class PromotionalScheme(Document): def validate(self): diff --git a/erpnext/accounts/doctype/promotional_scheme_product_discount/promotional_scheme_product_discount.json b/erpnext/accounts/doctype/promotional_scheme_product_discount/promotional_scheme_product_discount.json index 72d53bfa01..3eab51510d 100644 --- a/erpnext/accounts/doctype/promotional_scheme_product_discount/promotional_scheme_product_discount.json +++ b/erpnext/accounts/doctype/promotional_scheme_product_discount/promotional_scheme_product_discount.json @@ -1,10 +1,12 @@ { + "actions": [], "creation": "2019-03-24 14:48:59.649168", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", "field_order": [ "disable", + "apply_multiple_pricing_rules", "column_break_2", "rule_description", "section_break_1", @@ -25,7 +27,7 @@ "threshold_percentage", "column_break_15", "priority", - "apply_multiple_pricing_rules" + "is_recursive" ], "fields": [ { @@ -152,10 +154,19 @@ "fieldname": "apply_multiple_pricing_rules", "fieldtype": "Check", "label": "Apply Multiple Pricing Rules" + }, + { + "default": "0", + "description": "Discounts to be applied in sequential ranges like buy 1 get 1, buy 2 get 2, buy 3 get 3 and so on", + "fieldname": "is_recursive", + "fieldtype": "Check", + "label": "Is Recursive" } ], + "index_web_pages_for_search": 1, "istable": 1, - "modified": "2019-07-21 00:00:56.674284", + "links": [], + "modified": "2021-03-06 21:58:18.162346", "modified_by": "Administrator", "module": "Accounts", "name": "Promotional Scheme Product Discount", diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 23541c1ba0..220c876cc2 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -111,7 +111,10 @@ class calculate_taxes_and_totals(object): item.rate_with_margin, item.base_rate_with_margin = self.calculate_margin(item) if flt(item.rate_with_margin) > 0: item.rate = flt(item.rate_with_margin * (1.0 - (item.discount_percentage / 100.0)), item.precision("rate")) - item.discount_amount = item.rate_with_margin - item.rate + if not item.discount_amount: + item.discount_amount = item.rate_with_margin - item.rate + elif not item.discount_percentage: + item.rate -= item.discount_amount elif flt(item.price_list_rate) > 0: item.discount_amount = item.price_list_rate - item.rate elif flt(item.price_list_rate) > 0 and not item.discount_amount: diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 7d90d2662e..6f577936f2 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -576,7 +576,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ var d = locals[cdt][cdn]; me.add_taxes_from_item_tax_template(d.item_tax_rate); if (d.free_item_data) { - me.apply_product_discount(d.free_item_data); + me.apply_product_discount(d); } }, () => { @@ -1163,7 +1163,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ calculate_stock_uom_rate: function(doc, cdt, cdn) { let item = frappe.get_doc(cdt, cdn); - item.stock_uom_rate = flt(item.rate)/flt(item.conversion_factor); + item.stock_uom_rate = flt(item.rate)/flt(item.conversion_factor); refresh_field("stock_uom_rate", item.name, item.parentfield); }, service_stop_date: function(frm, cdt, cdn) { @@ -1504,7 +1504,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ } if (d.free_item_data) { - me.apply_product_discount(d.free_item_data); + me.apply_product_discount(d); } if (d.apply_rule_on_other_items) { @@ -1538,20 +1538,30 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ } }, - apply_product_discount: function(free_item_data) { - const items = this.frm.doc.items.filter(d => (d.item_code == free_item_data.item_code - && d.is_free_item)) || []; + apply_product_discount: function(args) { + const items = this.frm.doc.items.filter(d => (d.is_free_item)) || []; - if (!items.length) { - let row_to_modify = frappe.model.add_child(this.frm.doc, - this.frm.doc.doctype + ' Item', 'items'); + const exist_items = items.map(row => row.item_code); - for (let key in free_item_data) { - row_to_modify[key] = free_item_data[key]; + args.free_item_data.forEach(pr_row => { + let row_to_modify = {}; + if (!items || !in_list(exist_items, pr_row.item_code)) { + + row_to_modify = frappe.model.add_child(this.frm.doc, + this.frm.doc.doctype + ' Item', 'items'); + + } else if(items) { + row_to_modify = items.filter(d => d.item_code === pr_row.item_code)[0]; } - } if (items && items.length && free_item_data) { - items[0].qty = free_item_data.qty - } + + for (let key in pr_row) { + row_to_modify[key] = pr_row[key]; + } + }); + + // free_item_data is a temporary variable + args.free_item_data = ''; + refresh_field('items'); }, apply_price_list: function(item, reset_plc_conversion) { From fce552b811983869358d2a8d1658853ee9889199 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Sun, 7 Mar 2021 11:43:22 +0530 Subject: [PATCH 342/449] fix: nonetype object has no attribute options --- .../promotional_scheme/promotional_scheme.py | 4 +- .../promotional_scheme_price_discount.json | 721 ++---------------- erpnext/public/js/controllers/transaction.js | 5 +- 3 files changed, 61 insertions(+), 669 deletions(-) diff --git a/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py b/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py index 6e13f0694c..e1725bc89e 100644 --- a/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py +++ b/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py @@ -18,10 +18,10 @@ other_fields = ['min_qty', 'max_qty', 'min_amt', 'max_amt', 'priority','warehouse', 'threshold_percentage', 'rule_description'] price_discount_fields = ['rate_or_discount', 'apply_discount_on', 'apply_discount_on_rate', - 'rate', 'discount_amount', 'discount_percentage', 'validate_applied_rule'] + 'rate', 'discount_amount', 'discount_percentage', 'validate_applied_rule', 'apply_multiple_pricing_rules'] product_discount_fields = ['free_item', 'free_qty', 'free_item_uom', - 'free_item_rate', 'same_item', 'is_recursive'] + 'free_item_rate', 'same_item', 'is_recursive', 'apply_multiple_pricing_rules'] class PromotionalScheme(Document): def validate(self): diff --git a/erpnext/accounts/doctype/promotional_scheme_price_discount/promotional_scheme_price_discount.json b/erpnext/accounts/doctype/promotional_scheme_price_discount/promotional_scheme_price_discount.json index 224b8de779..795fb1c6f4 100644 --- a/erpnext/accounts/doctype/promotional_scheme_price_discount/promotional_scheme_price_discount.json +++ b/erpnext/accounts/doctype/promotional_scheme_price_discount/promotional_scheme_price_discount.json @@ -1,792 +1,181 @@ { - "allow_copy": 0, - "allow_events_in_timeline": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "beta": 0, + "actions": [], "creation": "2019-03-24 14:48:59.649168", - "custom": 0, - "docstatus": 0, "doctype": "DocType", - "document_type": "", "editable_grid": 1, "engine": "InnoDB", + "field_order": [ + "disable", + "apply_multiple_pricing_rules", + "column_break_2", + "rule_description", + "section_break_2", + "min_qty", + "max_qty", + "column_break_3", + "min_amount", + "max_amount", + "section_break_6", + "rate_or_discount", + "column_break_10", + "rate", + "discount_amount", + "discount_percentage", + "section_break_11", + "warehouse", + "threshold_percentage", + "validate_applied_rule", + "column_break_14", + "priority", + "apply_discount_on_rate" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, + "default": "0", "fieldname": "disable", "fieldtype": "Check", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Disable", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Disable" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "column_break_2", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Column Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "rule_description", "fieldtype": "Small Text", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Rule Description", - "length": 0, "no_copy": 1, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "reqd": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "section_break_2", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Section Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, "columns": 1, "default": "0", "fieldname": "min_qty", "fieldtype": "Float", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, - "label": "Min Qty", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Min Qty" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, "columns": 1, "default": "0", "fieldname": "max_qty", "fieldtype": "Float", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, - "label": "Max Qty", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Max Qty" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "column_break_3", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Column Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "default": "0", "fieldname": "min_amount", "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, - "label": "Min Amount", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Min Amount" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "default": "0", - "depends_on": "", "fieldname": "max_amount", "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, - "label": "Max Amount", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Max Amount" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "depends_on": "", "fieldname": "section_break_6", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Section Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "default": "Discount Percentage", - "depends_on": "", "fieldname": "rate_or_discount", "fieldtype": "Select", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, "label": "Discount Type", - "length": 0, - "no_copy": 0, - "options": "\nRate\nDiscount Percentage\nDiscount Amount", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "options": "\nRate\nDiscount Percentage\nDiscount Amount" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "depends_on": "", "fieldname": "column_break_10", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Column Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, "columns": 2, "depends_on": "eval:doc.rate_or_discount==\"Rate\"", "fieldname": "rate", "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, - "label": "Rate", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Rate" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "depends_on": "eval:doc.rate_or_discount==\"Discount Amount\"", "fieldname": "discount_amount", "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Discount Amount", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Discount Amount" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "depends_on": "eval:doc.rate_or_discount==\"Discount Percentage\"", "fieldname": "discount_percentage", "fieldtype": "Float", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Discount Percentage", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Discount Percentage" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "section_break_11", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Section Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "warehouse", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Warehouse", - "length": 0, - "no_copy": 0, - "options": "Warehouse", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "options": "Warehouse" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "threshold_percentage", "fieldtype": "Percent", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Threshold for Suggestion", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Threshold for Suggestion" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "default": "1", "fieldname": "validate_applied_rule", "fieldtype": "Check", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Validate Applied Rule", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Validate Applied Rule" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "column_break_14", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Column Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "priority", "fieldtype": "Select", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Priority", - "length": 0, - "no_copy": 0, - "options": "\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "options": "\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, + "default": "0", "depends_on": "priority", "fieldname": "apply_multiple_pricing_rules", "fieldtype": "Check", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Apply Multiple Pricing Rules", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Apply Multiple Pricing Rules" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "default": "0", "depends_on": "eval:in_list(['Discount Percentage', 'Discount Amount'], doc.rate_or_discount) && doc.apply_multiple_pricing_rules", "fieldname": "apply_discount_on_rate", "fieldtype": "Check", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Apply Discount on Rate", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Apply Discount on Rate" } ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, + "index_web_pages_for_search": 1, "istable": 1, - "max_attachments": 0, - "modified": "2019-03-24 14:48:59.649168", + "links": [], + "modified": "2021-03-07 11:56:23.424137", "modified_by": "Administrator", "module": "Accounts", "name": "Promotional Scheme Price Discount", - "name_case": "", "owner": "Administrator", "permissions": [], - "quick_entry": 0, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 0, - "track_seen": 0, - "track_views": 0 + "sort_order": "DESC" } \ No newline at end of file diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 6f577936f2..d6d1e6f025 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1492,7 +1492,10 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ if(k=="price_list_rate") { if(flt(v) != flt(d.price_list_rate)) price_list_rate_changed = true; } - frappe.model.set_value(d.doctype, d.name, k, v); + + if (k !== 'free_item_data') { + frappe.model.set_value(d.doctype, d.name, k, v); + } } } From 0486276789eb517fbd20d70aa482798ca27e4803 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 17 Mar 2021 18:49:54 +0530 Subject: [PATCH 343/449] fix: don't club same free item --- erpnext/accounts/doctype/pricing_rule/utils.py | 5 +++-- .../doctype/promotional_scheme/promotional_scheme.py | 2 +- erpnext/public/js/controllers/transaction.js | 7 ++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index 210cd16009..c676abd4c6 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -517,6 +517,7 @@ def get_product_discount_rule(pricing_rule, item_details, args=None, doc=None): free_item_data_args = { 'item_code': free_item, 'qty': qty, + 'pricing_rules': pricing_rule.name, 'rate': pricing_rule.free_item_rate or 0, 'price_list_rate': pricing_rule.free_item_rate or 0, 'is_free_item': 1 @@ -540,10 +541,10 @@ def get_product_discount_rule(pricing_rule, item_details, args=None, doc=None): def apply_pricing_rule_for_free_items(doc, pricing_rule_args, set_missing_values=False): if pricing_rule_args: - items = tuple([d.item_code for d in doc.items if d.is_free_item]) + items = tuple([(d.item_code, d.pricing_rules) for d in doc.items if d.is_free_item]) for args in pricing_rule_args: - if not items or args.get('item_code') not in items: + if not items or (args.get('item_code'), args.get('pricing_rules')) not in items: doc.append('items', args) def get_pricing_rule_items(pr_doc): diff --git a/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py b/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py index e1725bc89e..523e9ee08a 100644 --- a/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py +++ b/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py @@ -12,7 +12,7 @@ from frappe.model.document import Document pricing_rule_fields = ['apply_on', 'mixed_conditions', 'is_cumulative', 'other_item_code', 'other_item_group' 'apply_rule_on_other', 'other_brand', 'selling', 'buying', 'applicable_for', 'valid_from', 'valid_upto', 'customer', 'customer_group', 'territory', 'sales_partner', 'campaign', 'supplier', - 'supplier_group', 'company', 'currency'] + 'supplier_group', 'company', 'currency', 'apply_multiple_pricing_rules'] other_fields = ['min_qty', 'max_qty', 'min_amt', 'max_amt', 'priority','warehouse', 'threshold_percentage', 'rule_description'] diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index d6d1e6f025..4173beb576 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1544,17 +1544,18 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ apply_product_discount: function(args) { const items = this.frm.doc.items.filter(d => (d.is_free_item)) || []; - const exist_items = items.map(row => row.item_code); + const exist_items = items.map(row => (row.item_code, row.pricing_rules)); args.free_item_data.forEach(pr_row => { let row_to_modify = {}; - if (!items || !in_list(exist_items, pr_row.item_code)) { + if (!items || !in_list(exist_items, (pr_row.item_code, pr_row.pricing_rules))) { row_to_modify = frappe.model.add_child(this.frm.doc, this.frm.doc.doctype + ' Item', 'items'); } else if(items) { - row_to_modify = items.filter(d => d.item_code === pr_row.item_code)[0]; + row_to_modify = items.filter(d => (d.item_code === pr_row.item_code + && d.pricing_rules === pr_row.pricing_rules))[0]; } for (let key in pr_row) { From 256b9c7bf9b92efc1426605d3e1f71a5f4340a17 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 22 Mar 2021 23:36:48 +0530 Subject: [PATCH 344/449] fix: total weight not set for free items --- erpnext/controllers/accounts_controller.py | 3 ++- erpnext/stock/get_item_details.py | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index e6b14c2e40..256437966b 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -25,7 +25,8 @@ from erpnext.stock.doctype.packed_item.packed_item import make_packing_list class AccountMissingError(frappe.ValidationError): pass -force_item_fields = ("item_group", "brand", "stock_uom", "is_fixed_asset", "item_tax_rate", "pricing_rules") +force_item_fields = ("item_group", "brand", "stock_uom", "is_fixed_asset", "item_tax_rate", + "pricing_rules", "weight_per_unit", "weight_uom", "total_weight") class AccountsController(TransactionBase): def __init__(self, *args, **kwargs): diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 873cfec85e..70e4c2c40e 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -314,7 +314,9 @@ def get_basic_details(args, item, overwrite_warehouse=True): "last_purchase_rate": item.last_purchase_rate if args.get("doctype") in ["Purchase Order"] else 0, "transaction_date": args.get("transaction_date"), "against_blanket_order": args.get("against_blanket_order"), - "bom_no": item.get("default_bom") + "bom_no": item.get("default_bom"), + "weight_per_unit": args.get("weight_per_unit") or item.get("weight_per_unit"), + "weight_uom": args.get("weight_uom") or item.get("weight_uom") }) if item.get("enable_deferred_revenue") or item.get("enable_deferred_expense"): @@ -369,6 +371,9 @@ def get_basic_details(args, item, overwrite_warehouse=True): if meta.get_field("barcode"): update_barcode_value(out) + if out.get("weight_per_unit"): + out['total_weight'] = out.weight_per_unit * out.stock_qty + return out def get_item_warehouse(item, args, overwrite_warehouse, defaults={}): From 5d994d8aa1f6c281212f9d37ada256eb6555421f Mon Sep 17 00:00:00 2001 From: Anupam Date: Sat, 27 Mar 2021 00:54:19 +0530 Subject: [PATCH 345/449] fix: unable to submit stock entry --- erpnext/stock/doctype/stock_entry/stock_entry.js | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 274bbc28b1..4d1a71be8f 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -817,7 +817,6 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ } erpnext.hide_company(); erpnext.utils.add_item(this.frm); - this.frm.trigger('add_to_transit'); }, scan_barcode: function() { From d429138dcc0600d2a2b9b72c1922c00999463391 Mon Sep 17 00:00:00 2001 From: Anupam Date: Sat, 27 Mar 2021 17:09:39 +0530 Subject: [PATCH 346/449] fix: added flag for dont_fetch_price_list_rate in transaction --- erpnext/public/js/controllers/transaction.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 4173beb576..e0b0b272f3 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1132,6 +1132,11 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ this.calculate_net_weight(); } + // for handling customization not to fetch price list rate + if(frappe.flags.dont_fetch_price_list_rate) { + return + } + if (!dont_fetch_price_list_rate && frappe.meta.has_field(doc.doctype, "price_list_currency")) { this.apply_price_list(item, true); From b38ea0cc8be3ee2d4693e2a5bd10c5c863a5ca04 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Sun, 28 Mar 2021 15:51:32 +0530 Subject: [PATCH 347/449] fix: patch (#25014) * fix: patch * fix: pricing_rule test cases --- .../doctype/pricing_rule/test_pricing_rule.py | 16 ++++++++++++++++ .../doctype/sales_invoice/test_sales_invoice.py | 4 +++- erpnext/controllers/stock_controller.py | 2 +- erpnext/controllers/taxes_and_totals.py | 8 +++++--- .../item_reposting_for_incorrect_sl_and_gl.py | 13 ++++++++++--- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py index f28cee7c5a..ef9aad562d 100644 --- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py @@ -328,6 +328,21 @@ class TestPricingRule(unittest.TestCase): self.assertEquals(item.discount_amount, 110) self.assertEquals(item.rate, 990) + def test_pricing_rule_with_margin_and_discount_amount(self): + frappe.delete_doc_if_exists('Pricing Rule', '_Test Pricing Rule') + make_pricing_rule(selling=1, margin_type="Percentage", margin_rate_or_amount=10, + rate_or_discount="Discount Amount", discount_amount=110) + si = create_sales_invoice(do_not_save=True) + si.items[0].price_list_rate = 1000 + si.payment_schedule = [] + si.insert(ignore_permissions=True) + + item = si.items[0] + self.assertEquals(item.margin_rate_or_amount, 10) + self.assertEquals(item.rate_with_margin, 1100) + self.assertEquals(item.discount_amount, 110) + self.assertEquals(item.rate, 990) + def test_pricing_rule_for_product_discount_on_same_item(self): frappe.delete_doc_if_exists('Pricing Rule', '_Test Pricing Rule') test_record = { @@ -560,6 +575,7 @@ def make_pricing_rule(**args): "margin_rate_or_amount": args.margin_rate_or_amount or 0.0, "condition": args.condition or '', "priority": 1, + "discount_amount": args.discount_amount or 0.0, "apply_multiple_pricing_rules": args.apply_multiple_pricing_rules or 0 }) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 7cd1828343..979231a101 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -1166,10 +1166,12 @@ class TestSalesInvoice(unittest.TestCase): def test_create_so_with_margin(self): si = create_sales_invoice(item_code="_Test Item", qty=1, do_not_submit=True) - price_list_rate = 100 + price_list_rate = flt(100) * flt(si.plc_conversion_rate) si.items[0].price_list_rate = price_list_rate si.items[0].margin_type = 'Percentage' si.items[0].margin_rate_or_amount = 25 + si.items[0].discount_amount = 0.0 + si.items[0].discount_percentage = 0.0 si.save() self.assertEqual(si.get("items")[0].rate, flt((price_list_rate*25)/100 + price_list_rate)) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index cb44b73caf..f92e8849f6 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -405,7 +405,7 @@ class StockController(AccountsController): def set_rate_of_stock_uom(self): if self.doctype in ["Purchase Receipt", "Purchase Invoice", "Purchase Order", "Sales Invoice", "Sales Order", "Delivery Note", "Quotation"]: for d in self.get("items"): - d.stock_uom_rate = d.rate / d.conversion_factor + d.stock_uom_rate = d.rate / (d.conversion_factor or 1) def validate_internal_transfer(self): if self.doctype in ('Sales Invoice', 'Delivery Note', 'Purchase Invoice', 'Purchase Receipt') \ diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 220c876cc2..f976b17ae6 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -111,10 +111,12 @@ class calculate_taxes_and_totals(object): item.rate_with_margin, item.base_rate_with_margin = self.calculate_margin(item) if flt(item.rate_with_margin) > 0: item.rate = flt(item.rate_with_margin * (1.0 - (item.discount_percentage / 100.0)), item.precision("rate")) - if not item.discount_amount: + + if item.discount_amount and not item.discount_percentage: + item.rate = item.rate_with_margin - item.discount_amount + else: item.discount_amount = item.rate_with_margin - item.rate - elif not item.discount_percentage: - item.rate -= item.discount_amount + elif flt(item.price_list_rate) > 0: item.discount_amount = item.price_list_rate - item.rate elif flt(item.price_list_rate) > 0 and not item.discount_amount: diff --git a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py index d968e1fb76..021bb72cae 100644 --- a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py +++ b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py @@ -20,9 +20,11 @@ def execute(): frappe.clear_cache() frappe.flags.warehouse_account_map = {} + company_list = [] + data = frappe.db.sql(''' SELECT - name, item_code, warehouse, voucher_type, voucher_no, posting_date, posting_time + name, item_code, warehouse, voucher_type, voucher_no, posting_date, posting_time, company FROM `tabStock Ledger Entry` WHERE @@ -36,6 +38,9 @@ def execute(): total_sle = len(data) i = 0 for d in data: + if d.company not in company_list: + company_list.append(d.company) + update_entries_after({ "item_code": d.item_code, "warehouse": d.warehouse, @@ -53,8 +58,10 @@ def execute(): print("Reposting General Ledger Entries...") - for row in frappe.get_all('Company', filters= {'enable_perpetual_inventory': 1}): - update_gl_entries_after(posting_date, posting_time, company=row.name) + if data: + for row in frappe.get_all('Company', filters= {'enable_perpetual_inventory': 1}): + if row.name in company_list: + update_gl_entries_after(posting_date, posting_time, company=row.name) frappe.db.auto_commit_on_many_writes = 0 From ceb026c5abf9509aad211154eeb05dd8689bd6ec Mon Sep 17 00:00:00 2001 From: Saurabh Date: Sun, 28 Mar 2021 16:14:56 +0550 Subject: [PATCH 348/449] bumped to version 13.0.0-beta.14 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index b122e5fa11..78e87c8869 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0-beta.13' +__version__ = '13.0.0-beta.14' def get_default_company(user=None): '''Get default company for user''' From c2548ddc75b067714e71cab30bc2639cfc8949bc Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 28 Jan 2021 21:23:16 +0530 Subject: [PATCH 349/449] feat: Normal rounding for GST Taxes --- erpnext/controllers/taxes_and_totals.py | 19 ++ erpnext/hooks.py | 1 + .../public/js/controllers/taxes_and_totals.js | 30 +- .../doctype/gst_settings/gst_settings.json | 290 +++++------------- erpnext/regional/india/utils.py | 21 ++ 5 files changed, 147 insertions(+), 214 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 6c7eb92221..0ab4bf0e23 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -15,6 +15,8 @@ from erpnext.accounts.doctype.journal_entry.journal_entry import get_exchange_ra class calculate_taxes_and_totals(object): def __init__(self, doc): self.doc = doc + frappe.flags.round_off_applicable_accounts = [] + get_round_off_applicable_accounts(self.doc.company, frappe.flags.round_off_applicable_accounts) self.calculate() def calculate(self): @@ -335,10 +337,18 @@ class calculate_taxes_and_totals(object): elif tax.charge_type == "On Item Quantity": current_tax_amount = tax_rate * item.qty + current_tax_amount = self.get_final_current_tax_amount(tax, current_tax_amount) self.set_item_wise_tax(item, tax, tax_rate, current_tax_amount) return current_tax_amount + def get_final_current_tax_amount(self, tax, current_tax_amount): + # Some countries need individual tax components to be rounded + # Handeled via regional doctypess + if tax.account_head in frappe.flags.round_off_applicable_accounts: + current_tax_amount = round(current_tax_amount, 0) + return current_tax_amount + def set_item_wise_tax(self, item, tax, tax_rate, current_tax_amount): # store tax breakup for each item key = item.item_code or item.item_name @@ -696,6 +706,15 @@ def get_itemised_tax_breakup_html(doc): ) ) +@frappe.whitelist() +def get_round_off_applicable_accounts(company, account_list): + account_list = get_regional_round_off_accounts(company, account_list) + + return account_list + +@erpnext.allow_regional +def get_regional_round_off_accounts(company, account_list): + pass @erpnext.allow_regional def update_itemised_tax_data(doc): diff --git a/erpnext/hooks.py b/erpnext/hooks.py index fe80c6585d..88734cf317 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -401,6 +401,7 @@ regional_overrides = { 'erpnext.controllers.taxes_and_totals.get_itemised_tax_breakup_header': 'erpnext.regional.india.utils.get_itemised_tax_breakup_header', 'erpnext.controllers.taxes_and_totals.get_itemised_tax_breakup_data': 'erpnext.regional.india.utils.get_itemised_tax_breakup_data', 'erpnext.accounts.party.get_regional_address_details': 'erpnext.regional.india.utils.get_regional_address_details', + 'erpnext.controllers.taxes_and_totals.get_regional_round_off_accounts': 'erpnext.regional.india.utils.get_regional_round_off_accounts', 'erpnext.hr.utils.calculate_annual_eligible_hra_exemption': 'erpnext.regional.india.utils.calculate_annual_eligible_hra_exemption', 'erpnext.hr.utils.calculate_hra_exemption_for_period': 'erpnext.regional.india.utils.calculate_hra_exemption_for_period', 'erpnext.accounts.doctype.purchase_invoice.purchase_invoice.make_regional_gl_entries': 'erpnext.regional.india.utils.make_regional_gl_entries', diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 22e75780b8..ad19e6f91a 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -2,7 +2,9 @@ // License: GNU General Public License v3. See license.txt erpnext.taxes_and_totals = erpnext.payments.extend({ - setup: function() {}, + setup: function() { + this.fetch_round_off_accounts(); + }, apply_pricing_rule_on_item: function(item){ let effective_item_rate = item.price_list_rate; @@ -151,6 +153,22 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ }); }, + fetch_round_off_accounts: function() { + let me = this; + frappe.flags.round_off_applicable_accounts = []; + + return frappe.call({ + "method": "erpnext.controllers.taxes_and_totals.get_round_off_applicable_accounts", + "args": { + "company": me.frm.doc.company, + "account_list": frappe.flags.round_off_applicable_accounts + }, + callback: function(r) { + frappe.flags.round_off_applicable_accounts.push(...r.message); + } + }); + }, + determine_exclusive_rate: function() { var me = this; @@ -371,11 +389,21 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ } else if (tax.charge_type == "On Item Quantity") { current_tax_amount = tax_rate * item.qty; } + + current_tax_amount = this.get_final_tax_amount(tax, current_tax_amount); this.set_item_wise_tax(item, tax, tax_rate, current_tax_amount); return current_tax_amount; }, + get_final_tax_amount: function(tax, current_tax_amount) { + if (frappe.flags.round_off_applicable_accounts.includes(tax.account_head)) { + current_tax_amount = Math.round(current_tax_amount); + } + + return current_tax_amount + }, + set_item_wise_tax: function(item, tax, tax_rate, current_tax_amount) { // store tax breakup for each item let tax_detail = tax.item_wise_tax_detail; diff --git a/erpnext/regional/doctype/gst_settings/gst_settings.json b/erpnext/regional/doctype/gst_settings/gst_settings.json index 98c33ad33b..95b930c4c8 100644 --- a/erpnext/regional/doctype/gst_settings/gst_settings.json +++ b/erpnext/regional/doctype/gst_settings/gst_settings.json @@ -1,222 +1,86 @@ { - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "beta": 0, - "creation": "2017-06-27 15:09:01.318003", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "", - "editable_grid": 1, - "engine": "InnoDB", + "actions": [], + "creation": "2017-06-27 15:09:01.318003", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "gst_summary", + "column_break_2", + "round_off_gst_values", + "gstin_email_sent_on", + "section_break_4", + "gst_accounts", + "b2c_limit" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "gst_summary", - "fieldtype": "HTML", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "GST Summary", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, + "fieldname": "gst_summary", + "fieldtype": "HTML", + "label": "GST Summary", + "show_days": 1, + "show_seconds": 1 + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "column_break_2", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, + "fieldname": "column_break_2", + "fieldtype": "Column Break", + "show_days": 1, + "show_seconds": 1 + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "gstin_email_sent_on", - "fieldtype": "Date", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "GSTIN Email Sent On", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, + "fieldname": "gstin_email_sent_on", + "fieldtype": "Date", + "label": "GSTIN Email Sent On", + "read_only": 1, + "show_days": 1, + "show_seconds": 1 + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "section_break_4", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, + "fieldname": "section_break_4", + "fieldtype": "Section Break", + "show_days": 1, + "show_seconds": 1 + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "gst_accounts", - "fieldtype": "Table", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "GST Accounts", - "length": 0, - "no_copy": 0, - "options": "GST Account", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, + "fieldname": "gst_accounts", + "fieldtype": "Table", + "label": "GST Accounts", + "options": "GST Account", + "show_days": 1, + "show_seconds": 1 + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "default": "250000", - "description": "Set Invoice Value for B2C. B2CL and B2CS calculated based on this invoice value.", - "fieldname": "b2c_limit", - "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "B2C Limit", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 + "default": "250000", + "description": "Set Invoice Value for B2C. B2CL and B2CS calculated based on this invoice value.", + "fieldname": "b2c_limit", + "fieldtype": "Data", + "in_list_view": 1, + "label": "B2C Limit", + "reqd": 1, + "show_days": 1, + "show_seconds": 1 + }, + { + "default": "0", + "description": "Enabling this option will round off individual GST components in all the Invoices", + "fieldname": "round_off_gst_values", + "fieldtype": "Check", + "label": "Round Off GST Values", + "show_days": 1, + "show_seconds": 1 } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 1, - "istable": 0, - "max_attachments": 0, - "modified": "2018-02-14 08:14:15.375181", - "modified_by": "Administrator", - "module": "Regional", - "name": "GST Settings", - "name_case": "", - "owner": "Administrator", - "permissions": [], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0 -} \ No newline at end of file + ], + "index_web_pages_for_search": 1, + "issingle": 1, + "links": [], + "modified": "2021-01-28 17:19:47.969260", + "modified_by": "Administrator", + "module": "Regional", + "name": "GST Settings", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 + } \ No newline at end of file diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index fd1d5e8bf9..3757f6384f 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -782,3 +782,24 @@ def get_gst_tax_amount(doc): gst_tax += tax.tax_amount_after_discount_amount return gst_tax, base_gst_tax + +@frappe.whitelist() +def get_regional_round_off_accounts(company, account_list): + country = frappe.get_cached_value('Company', company, 'country') + + if country != 'India': + return + + if isinstance(account_list, string_types): + account_list = json.loads(account_list) + + if not frappe.db.get_single_value('GST Settings', 'round_off_gst_values'): + return + + gst_accounts = get_gst_accounts(company) + gst_account_list = gst_accounts.get('cgst_account') + gst_accounts.get('sgst_account') \ + + gst_accounts.get('igst_account') + + account_list.extend(gst_account_list) + + return account_list From 237033704f2c903908a9a6b633a4974ded8f35f3 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sat, 30 Jan 2021 17:08:52 +0530 Subject: [PATCH 350/449] fix: Add test case --- erpnext/__init__.py | 2 +- .../public/js/controllers/taxes_and_totals.js | 2 +- .../gstr_3b_report/test_gstr_3b_report.py | 67 ++++++++++++++----- 3 files changed, 52 insertions(+), 19 deletions(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index b122e5fa11..5ad34ea72a 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -109,7 +109,7 @@ def get_region(company=None): ''' if company or frappe.flags.company: return frappe.get_cached_value('Company', - company or frappe.flags.company, 'country') + company or frappe.flags.company, 'country') elif frappe.flags.country: return frappe.flags.country else: diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index ad19e6f91a..9f9ec04342 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -401,7 +401,7 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ current_tax_amount = Math.round(current_tax_amount); } - return current_tax_amount + return current_tax_amount; }, set_item_wise_tax: function(item, tax, tax_rate, current_tax_amount) { diff --git a/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py b/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py index 8174da20cb..023b4ed22b 100644 --- a/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py +++ b/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py @@ -14,8 +14,20 @@ import json test_dependencies = ["Territory", "Customer Group", "Supplier Group", "Item"] class TestGSTR3BReport(unittest.TestCase): - def test_gstr_3b_report(self): + def setUp(self): + frappe.set_user("Administrator") + frappe.db.sql("delete from `tabSales Invoice` where company='_Test Company GST'") + frappe.db.sql("delete from `tabPurchase Invoice` where company='_Test Company GST'") + frappe.db.sql("delete from `tabGSTR 3B Report` where company='_Test Company GST'") + + make_company() + make_item("Milk", properties = {"is_nil_exempt": 1, "standard_rate": 0.000000}) + set_account_heads() + make_customers() + make_suppliers() + + def test_gstr_3b_report(self): month_number_mapping = { 1: "January", 2: "February", @@ -31,17 +43,6 @@ class TestGSTR3BReport(unittest.TestCase): 12: "December" } - frappe.set_user("Administrator") - - frappe.db.sql("delete from `tabSales Invoice` where company='_Test Company GST'") - frappe.db.sql("delete from `tabPurchase Invoice` where company='_Test Company GST'") - frappe.db.sql("delete from `tabGSTR 3B Report` where company='_Test Company GST'") - - make_company() - make_item("Milk", properties = {"is_nil_exempt": 1, "standard_rate": 0.000000}) - set_account_heads() - make_customers() - make_suppliers() make_sales_invoice() create_purchase_invoices() @@ -67,6 +68,42 @@ class TestGSTR3BReport(unittest.TestCase): self.assertEqual(output["itc_elg"]["itc_avl"][4]["samt"], 22.50) self.assertEqual(output["itc_elg"]["itc_avl"][4]["camt"], 22.50) + def test_gst_rounding(self): + gst_settings = frappe.get_doc('GST Settings') + gst_settings.round_off_gst_values = 1 + gst_settings.save() + + current_country = frappe.flags.country + frappe.flags.country = 'India' + + si = create_sales_invoice(company="_Test Company GST", + customer = '_Test GST Customer', + currency = 'INR', + warehouse = 'Finished Goods - _GST', + debit_to = 'Debtors - _GST', + income_account = 'Sales - _GST', + expense_account = 'Cost of Goods Sold - _GST', + cost_center = 'Main - _GST', + rate=216, + do_not_save=1 + ) + + si.append("taxes", { + "charge_type": "On Net Total", + "account_head": "IGST - _GST", + "cost_center": "Main - _GST", + "description": "IGST @ 18.0", + "rate": 18 + }) + + si.save() + # Check for 39 instead of 38.88 + self.assertEqual(si.taxes[0].base_tax_amount_after_discount_amount, 39) + + frappe.flags.country = current_country + gst_settings.round_off_gst_values = 1 + gst_settings.save() + def make_sales_invoice(): si = create_sales_invoice(company="_Test Company GST", customer = '_Test GST Customer', @@ -145,7 +182,6 @@ def make_sales_invoice(): si3.submit() def create_purchase_invoices(): - pi = make_purchase_invoice( company="_Test Company GST", supplier = '_Test Registered Supplier', @@ -193,7 +229,6 @@ def create_purchase_invoices(): pi1.submit() def make_suppliers(): - if not frappe.db.exists("Supplier", "_Test Registered Supplier"): frappe.get_doc({ "supplier_group": "_Test Supplier Group", @@ -257,7 +292,6 @@ def make_suppliers(): address.save() def make_customers(): - if not frappe.db.exists("Customer", "_Test GST Customer"): frappe.get_doc({ "customer_group": "_Test Customer Group", @@ -354,9 +388,9 @@ def make_customers(): address.save() def make_company(): - if frappe.db.exists("Company", "_Test Company GST"): return + company = frappe.new_doc("Company") company.company_name = "_Test Company GST" company.abbr = "_GST" @@ -388,7 +422,6 @@ def make_company(): address.save() def set_account_heads(): - gst_settings = frappe.get_doc("GST Settings") gst_account = frappe.get_all( From 7f43c051df43f29e537e2157081b53985846d107 Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Mon, 29 Mar 2021 21:18:26 +0530 Subject: [PATCH 351/449] fix(Italy): setup, validations, optimisations --- erpnext/regional/italy/sales_invoice.js | 13 +--- erpnext/regional/italy/setup.py | 7 +- erpnext/regional/italy/utils.py | 98 ++++++++++++++----------- 3 files changed, 62 insertions(+), 56 deletions(-) diff --git a/erpnext/regional/italy/sales_invoice.js b/erpnext/regional/italy/sales_invoice.js index 586a52937b..b54ac53812 100644 --- a/erpnext/regional/italy/sales_invoice.js +++ b/erpnext/regional/italy/sales_invoice.js @@ -11,15 +11,10 @@ erpnext.setup_e_invoice_button = (doctype) => { callback: function(r) { frm.reload_doc(); if(r.message) { - var w = window.open( - frappe.urllib.get_full_url( - "/api/method/erpnext.regional.italy.utils.download_e_invoice_file?" - + "file_name=" + r.message - ) - ) - if (!w) { - frappe.msgprint(__("Please enable pop-ups")); return; - } + open_url_post(frappe.request.url, { + cmd: 'frappe.core.doctype.file.file.download_file', + file_url: r.message + }); } } }); diff --git a/erpnext/regional/italy/setup.py b/erpnext/regional/italy/setup.py index 6ab73413df..309aedfb0d 100644 --- a/erpnext/regional/italy/setup.py +++ b/erpnext/regional/italy/setup.py @@ -128,11 +128,8 @@ def make_custom_fields(update=True): fetch_from="company.vat_collectability"), dict(fieldname='sb_e_invoicing_reference', label='E-Invoicing', fieldtype='Section Break', insert_after='pos_total_qty', print_hide=1), - dict(fieldname='company_tax_id', label='Company Tax ID', - fieldtype='Data', insert_after='sb_e_invoicing_reference', print_hide=1, read_only=1, - fetch_from="company.tax_id"), dict(fieldname='company_fiscal_code', label='Company Fiscal Code', - fieldtype='Data', insert_after='company_tax_id', print_hide=1, read_only=1, + fieldtype='Data', insert_after='sb_e_invoicing_reference', print_hide=1, read_only=1, fetch_from="company.fiscal_code"), dict(fieldname='company_fiscal_regime', label='Company Fiscal Regime', fieldtype='Data', insert_after='company_fiscal_code', print_hide=1, read_only=1, @@ -219,4 +216,4 @@ def add_permissions(): update_permission_property(doctype, 'Accounts Manager', 0, 'delete', 1) add_permission(doctype, 'Accounts Manager', 1) update_permission_property(doctype, 'Accounts Manager', 1, 'write', 1) - update_permission_property(doctype, 'Accounts Manager', 1, 'create', 1) \ No newline at end of file + update_permission_property(doctype, 'Accounts Manager', 1, 'create', 1) diff --git a/erpnext/regional/italy/utils.py b/erpnext/regional/italy/utils.py index 6842fb2a61..08573cddcd 100644 --- a/erpnext/regional/italy/utils.py +++ b/erpnext/regional/italy/utils.py @@ -1,6 +1,8 @@ from __future__ import unicode_literals -import frappe, json, os +import io +import json +import frappe from frappe.utils import flt, cstr from erpnext.controllers.taxes_and_totals import get_itemised_tax from frappe import _ @@ -28,20 +30,22 @@ def update_itemised_tax_data(doc): @frappe.whitelist() def export_invoices(filters=None): - saved_xmls = [] + frappe.has_permission('Sales Invoice', throw=True) - invoices = frappe.get_all("Sales Invoice", filters=get_conditions(filters), fields=["*"]) + invoices = frappe.get_all( + "Sales Invoice", + filters=get_conditions(filters), + fields=["name", "company_tax_id"] + ) - for invoice in invoices: - attachments = get_e_invoice_attachments(invoice) - saved_xmls += [attachment.file_name for attachment in attachments] + attachments = get_e_invoice_attachments(invoices) - zip_filename = "{0}-einvoices.zip".format(frappe.utils.get_datetime().strftime("%Y%m%d_%H%M%S")) + zip_filename = "{0}-einvoices.zip".format( + frappe.utils.get_datetime().strftime("%Y%m%d_%H%M%S")) - download_zip(saved_xmls, zip_filename) + download_zip(attachments, zip_filename) -@frappe.whitelist() def prepare_invoice(invoice, progressive_number): #set company information company = frappe.get_doc("Company", invoice.company) @@ -98,7 +102,7 @@ def prepare_invoice(invoice, progressive_number): def get_conditions(filters): filters = json.loads(filters) - conditions = {"docstatus": 1} + conditions = {"docstatus": 1, "company_tax_id": ("!=", "")} if filters.get("company"): conditions["company"] = filters["company"] if filters.get("customer"): conditions["customer"] = filters["customer"] @@ -111,23 +115,22 @@ def get_conditions(filters): return conditions -#TODO: Use function from frappe once PR #6853 is merged. + def download_zip(files, output_filename): - from zipfile import ZipFile + import zipfile - input_files = [frappe.get_site_path('private', 'files', filename) for filename in files] - output_path = frappe.get_site_path('private', 'files', output_filename) + zip_stream = io.BytesIO() + with zipfile.ZipFile(zip_stream, 'w', zipfile.ZIP_DEFLATED) as zip_file: + for file in files: + file_path = frappe.utils.get_files_path( + file.file_name, is_private=file.is_private) - with ZipFile(output_path, 'w') as output_zip: - for input_file in input_files: - output_zip.write(input_file, arcname=os.path.basename(input_file)) - - with open(output_path, 'rb') as fileobj: - filedata = fileobj.read() + zip_file.write(file_path, arcname=file.file_name) frappe.local.response.filename = output_filename - frappe.local.response.filecontent = filedata + frappe.local.response.filecontent = zip_stream.getvalue() frappe.local.response.type = "download" + zip_stream.close() def get_invoice_summary(items, taxes): summary_data = frappe._dict() @@ -307,23 +310,12 @@ def prepare_and_attach_invoice(doc, replace=False): @frappe.whitelist() def generate_single_invoice(docname): doc = frappe.get_doc("Sales Invoice", docname) - + frappe.has_permission("Sales Invoice", doc=doc, throw=True) e_invoice = prepare_and_attach_invoice(doc, True) + return e_invoice.file_url - return e_invoice.file_name - -@frappe.whitelist() -def download_e_invoice_file(file_name): - content = None - with open(frappe.get_site_path('private', 'files', file_name), "r") as f: - content = f.read() - - frappe.local.response.filename = file_name - frappe.local.response.filecontent = content - frappe.local.response.type = "download" - -#Delete e-invoice attachment on cancel. +# Delete e-invoice attachment on cancel. def sales_invoice_on_cancel(doc, method): if get_company_country(doc.company) not in ['Italy', 'Italia', 'Italian Republic', 'Repubblica Italiana']: @@ -335,16 +327,38 @@ def sales_invoice_on_cancel(doc, method): def get_company_country(company): return frappe.get_cached_value('Company', company, 'country') -def get_e_invoice_attachments(invoice): - if not invoice.company_tax_id: - return [] +def get_e_invoice_attachments(invoices): + if not isinstance(invoices, list): + if not invoices.company_tax_id: + return + + invoices = [invoices] + + tax_id_map = { + invoice.name: ( + invoice.company_tax_id + if invoice.company_tax_id.startswith("IT") + else "IT" + invoice.company_tax_id + ) for invoice in invoices + } + + attachments = frappe.get_all( + "File", + fields=("name", "file_name", "attached_to_name", "is_private"), + filters= { + "attached_to_name": ('in', tax_id_map), + "attached_to_doctype": 'Sales Invoice' + } + ) out = [] - attachments = get_attachments(invoice.doctype, invoice.name) - company_tax_id = invoice.company_tax_id if invoice.company_tax_id.startswith("IT") else "IT" + invoice.company_tax_id - for attachment in attachments: - if attachment.file_name and attachment.file_name.startswith(company_tax_id) and attachment.file_name.endswith(".xml"): + if ( + attachment.file_name + and attachment.file_name.endswith(".xml") + and attachment.file_name.startswith( + tax_id_map.get(attachment.attached_to_name)) + ): out.append(attachment) return out From 170d2efd3575b273be9dba26639650bb58d598f2 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Tue, 30 Mar 2021 11:02:46 +0530 Subject: [PATCH 352/449] fix(Payroll): Exchange Rate not getting set in Salary Slip (#25013) --- .../doctype/salary_slip/salary_slip.js | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.js b/erpnext/payroll/doctype/salary_slip/salary_slip.js index 7460c75227..d5278393a1 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.js +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.js @@ -74,43 +74,46 @@ frappe.ui.form.on("Salary Slip", { if (!frm.doc.letter_head && company.default_letter_head) { frm.set_value('letter_head', company.default_letter_head); } + }, + + currency: function(frm) { frm.trigger("set_dynamic_labels"); }, set_dynamic_labels: function(frm) { var company_currency = frm.doc.company? erpnext.get_currency(frm.doc.company): frappe.defaults.get_default("currency"); - frappe.run_serially([ - () => frm.events.set_exchange_rate(frm, company_currency), - () => frm.events.change_form_labels(frm, company_currency), - () => frm.events.change_grid_labels(frm), - () => frm.refresh_fields() - ]); + if (frm.doc.employee && frm.doc.currency) { + frappe.run_serially([ + () => frm.events.set_exchange_rate(frm, company_currency), + () => frm.events.change_form_labels(frm, company_currency), + () => frm.events.change_grid_labels(frm), + () => frm.refresh_fields() + ]); + } }, set_exchange_rate: function(frm, company_currency) { - if (frm.doc.docstatus === 0) { - if (frm.doc.currency) { - var from_currency = frm.doc.currency; - if (from_currency != company_currency) { - frm.events.hide_loan_section(frm); - frappe.call({ - method: "erpnext.setup.utils.get_exchange_rate", - args: { - from_currency: from_currency, - to_currency: company_currency, - }, - callback: function(r) { - frm.set_value("exchange_rate", flt(r.message)); - frm.set_df_property('exchange_rate', 'hidden', 0); - frm.set_df_property("exchange_rate", "description", "1 " + frm.doc.currency - + " = [?] " + company_currency); - } - }); - } else { - frm.set_value("exchange_rate", 1.0); - frm.set_df_property('exchange_rate', 'hidden', 1); - frm.set_df_property("exchange_rate", "description", "" ); - } + if (frm.doc.currency) { + var from_currency = frm.doc.currency; + if (from_currency != company_currency) { + frm.events.hide_loan_section(frm); + frappe.call({ + method: "erpnext.setup.utils.get_exchange_rate", + args: { + from_currency: from_currency, + to_currency: company_currency, + }, + callback: function(r) { + frm.set_value("exchange_rate", flt(r.message)); + frm.set_df_property("exchange_rate", "hidden", 0); + frm.set_df_property("exchange_rate", "description", "1 " + frm.doc.currency + + " = [?] " + company_currency); + } + }); + } else { + frm.set_value("exchange_rate", 1.0); + frm.set_df_property("exchange_rate", "hidden", 1); + frm.set_df_property("exchange_rate", "description", ""); } } }, From 5f4a2bfc61b8f2151f7ecd7f0ddd1ca5d1495392 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Tue, 16 Mar 2021 20:08:51 +0530 Subject: [PATCH 353/449] fix(Non Profit): Membership and Donation API fixes (#24900) * fix: Donation fixes - differentiate between subscription payment and payment - issue with donation amount * fix: existing membership validation * fix: ignore subscription payments while capturing donations --- erpnext/non_profit/doctype/donation/donation.py | 6 +++++- erpnext/non_profit/doctype/membership/membership.py | 4 ++-- .../tax_exemption_80g_certificate.py | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/erpnext/non_profit/doctype/donation/donation.py b/erpnext/non_profit/doctype/donation/donation.py index e947588482..6a2a06dbc8 100644 --- a/erpnext/non_profit/doctype/donation/donation.py +++ b/erpnext/non_profit/doctype/donation/donation.py @@ -91,6 +91,10 @@ def capture_razorpay_donations(*args, **kwargs): if not data.event == 'payment.captured': return + # to avoid capturing subscription payments as donations + if payment.description and 'subscription' in str(payment.description).lower(): + return + donor = get_donor(payment.email) if not donor: donor = create_donor(payment) @@ -119,7 +123,7 @@ def create_donation(donor, payment): 'donor_name': donor.donor_name, 'email': donor.email, 'date': getdate(), - 'amount': flt(payment.amount), + 'amount': flt(payment.amount) / 100, # Convert to rupees from paise 'mode_of_payment': payment.method, 'razorpay_payment_id': payment.id }).insert(ignore_mandatory=True) diff --git a/erpnext/non_profit/doctype/membership/membership.py b/erpnext/non_profit/doctype/membership/membership.py index 191281f4ce..c41a2f5165 100644 --- a/erpnext/non_profit/doctype/membership/membership.py +++ b/erpnext/non_profit/doctype/membership/membership.py @@ -48,7 +48,7 @@ class Membership(Document): last_membership = erpnext.get_last_membership(self.member) # if person applied for offline membership - if last_membership and not frappe.session.user == "Administrator": + if last_membership and last_membership != self.name and not frappe.session.user == "Administrator": # if last membership does not expire in 30 days, then do not allow to renew if getdate(add_days(last_membership.to_date, -30)) > getdate(nowdate()) : frappe.throw(_("You can only renew if your membership expires within 30 days")) @@ -287,7 +287,7 @@ def trigger_razorpay_subscription(*args, **kwargs): membership.generate_invoice(with_payment_entry=settings.automate_membership_payment_entries, save=True) except Exception as e: - message = "{0}\n\n{1}\n\n{2}: {3}".format(e, frappe.get_traceback(), __("Payment ID"), payment.id) + message = "{0}\n\n{1}\n\n{2}: {3}".format(e, frappe.get_traceback(), _("Payment ID"), payment.id) log = frappe.log_error(message, _("Error creating membership entry for {0}").format(member.name)) notify_failure(log) return { "status": "Failed", "reason": e} diff --git a/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py index d734a18c3a..ef384d4602 100644 --- a/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py +++ b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py @@ -29,7 +29,10 @@ class TaxExemption80GCertificate(Document): def validate_duplicates(self): if self.recipient == 'Donor': - certificate = frappe.db.exists(self.doctype, {'donation': self.donation}) + certificate = frappe.db.exists(self.doctype, { + 'donation': self.donation, + 'name': ('!=', self.name) + }) if certificate: frappe.throw(_('An 80G Certificate {0} already exists for the donation {1}').format( get_link_to_form(self.doctype, certificate), frappe.bold(self.donation) From 146cbb10f8f1e033c78d91e71da5b1b803882e73 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 17 Mar 2021 19:49:27 +0530 Subject: [PATCH 354/449] fix: calculate 80g certificate amount on validate for memberships (#24925) --- .../tax_exemption_80g_certificate.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py index ef384d4602..5bbd5750f9 100644 --- a/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py +++ b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py @@ -16,6 +16,7 @@ class TaxExemption80GCertificate(Document): self.validate_duplicates() self.validate_company_details() self.set_company_address() + self.calculate_total() self.set_title() def validate_date(self): @@ -54,8 +55,17 @@ class TaxExemption80GCertificate(Document): self.company_address = address.company_address self.company_address_display = address.company_address_display + def calculate_total(self): + if self.recipient == 'Donor': + return + + total = 0 + for entry in self.payments: + total += flt(entry.amount) + self.total = total + def set_title(self): - if self.recipient == "Member": + if self.recipient == 'Member': self.title = self.member_name else: self.title = self.donor_name From a54eecb230748b4541f02b71b7a5f9a5d086d219 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Sat, 20 Mar 2021 22:22:01 +0530 Subject: [PATCH 355/449] fix: membership renewal validation (#24963) --- erpnext/non_profit/doctype/membership/membership.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/non_profit/doctype/membership/membership.py b/erpnext/non_profit/doctype/membership/membership.py index c41a2f5165..52447e4386 100644 --- a/erpnext/non_profit/doctype/membership/membership.py +++ b/erpnext/non_profit/doctype/membership/membership.py @@ -48,7 +48,7 @@ class Membership(Document): last_membership = erpnext.get_last_membership(self.member) # if person applied for offline membership - if last_membership and last_membership != self.name and not frappe.session.user == "Administrator": + if last_membership and last_membership.name != self.name and not frappe.session.user == "Administrator": # if last membership does not expire in 30 days, then do not allow to renew if getdate(add_days(last_membership.to_date, -30)) > getdate(nowdate()) : frappe.throw(_("You can only renew if your membership expires within 30 days")) @@ -90,6 +90,7 @@ class Membership(Document): self.validate_membership_type_and_settings(plan, settings) invoice = make_invoice(self, member, plan, settings) + self.reload() self.invoice = invoice.name if with_payment_entry: @@ -284,6 +285,7 @@ def trigger_razorpay_subscription(*args, **kwargs): settings = frappe.get_doc("Non Profit Settings") if settings.allow_invoicing and settings.automate_membership_invoicing: + membership.reload() membership.generate_invoice(with_payment_entry=settings.automate_membership_payment_entries, save=True) except Exception as e: From 9be11afbdee128e422efd20e55460ab4755ff631 Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Tue, 30 Mar 2021 12:09:46 +0530 Subject: [PATCH 356/449] feat: price margin in buying (#25058) --- .../doctype/pricing_rule/pricing_rule.json | 1 - .../purchase_invoice_item.json | 55 +++++++++++++++++- .../sales_invoice_item.json | 3 +- .../purchase_order_item.json | 58 +++++++++++++++++-- erpnext/controllers/taxes_and_totals.py | 2 +- erpnext/public/js/controllers/buying.js | 23 -------- erpnext/public/js/controllers/transaction.js | 44 ++++++++++++-- .../quotation_item/quotation_item.json | 3 +- .../sales_order_item/sales_order_item.json | 3 +- erpnext/selling/sales_common.js | 34 ----------- .../delivery_note_item.json | 3 +- .../purchase_receipt_item.json | 56 +++++++++++++++++- 12 files changed, 207 insertions(+), 78 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.json b/erpnext/accounts/doctype/pricing_rule/pricing_rule.json index 81890d50b9..428989aa96 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.json +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.json @@ -358,7 +358,6 @@ "reqd": 1 }, { - "depends_on": "eval: doc.selling == 1", "fieldname": "margin", "fieldtype": "Section Break", "label": "Margin" diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json index 07e75acb41..96ad0fd785 100644 --- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json +++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json @@ -28,10 +28,16 @@ "stock_qty", "sec_break1", "price_list_rate", - "discount_percentage", - "discount_amount", "col_break3", "base_price_list_rate", + "section_break_26", + "margin_type", + "margin_rate_or_amount", + "rate_with_margin", + "column_break_30", + "discount_percentage", + "discount_amount", + "base_rate_with_margin", "sec_break2", "rate", "amount", @@ -789,6 +795,7 @@ "fieldname": "stock_uom_rate", "fieldtype": "Currency", "label": "Rate of Stock UOM", + "no_copy": 1, "options": "currency", "read_only": 1 }, @@ -799,12 +806,54 @@ "no_copy": 1, "print_hide": 1, "read_only": 1 + }, + { + "collapsible": 1, + "fieldname": "section_break_26", + "fieldtype": "Section Break", + "label": "Discount and Margin" + }, + { + "depends_on": "price_list_rate", + "fieldname": "margin_type", + "fieldtype": "Select", + "label": "Margin Type", + "options": "\nPercentage\nAmount", + "print_hide": 1 + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate", + "fieldname": "margin_rate_or_amount", + "fieldtype": "Float", + "label": "Margin Rate or Amount", + "print_hide": 1 + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate && doc.margin_rate_or_amount", + "fieldname": "rate_with_margin", + "fieldtype": "Currency", + "label": "Rate With Margin", + "options": "currency", + "read_only": 1 + }, + { + "fieldname": "column_break_30", + "fieldtype": "Column Break" + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate && doc.margin_rate_or_amount", + "fieldname": "base_rate_with_margin", + "fieldtype": "Currency", + "label": "Rate With Margin (Company Currency)", + "options": "Company:company:default_currency", + "print_hide": 1, + "read_only": 1 } ], "idx": 1, "istable": 1, "links": [], - "modified": "2021-01-30 21:43:21.488258", + "modified": "2021-02-23 00:59:52.614805", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice Item", diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json index b403c7b237..8e6952a93c 100644 --- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json +++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json @@ -818,6 +818,7 @@ "fieldname": "stock_uom_rate", "fieldtype": "Currency", "label": "Rate of Stock UOM", + "no_copy": 1, "options": "currency", "read_only": 1 } @@ -825,7 +826,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2021-01-30 21:42:37.796771", + "modified": "2021-02-23 01:05:22.123527", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice Item", diff --git a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json index 75b2954ddd..5baf6939cd 100644 --- a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json +++ b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json @@ -27,11 +27,17 @@ "stock_qty", "sec_break1", "price_list_rate", + "last_purchase_rate", + "col_break3", + "base_price_list_rate", + "discount_and_margin_section", + "margin_type", + "margin_rate_or_amount", + "rate_with_margin", + "column_break_28", "discount_percentage", "discount_amount", - "col_break3", - "last_purchase_rate", - "base_price_list_rate", + "base_rate_with_margin", "sec_break2", "rate", "amount", @@ -733,15 +739,59 @@ "fieldname": "stock_uom_rate", "fieldtype": "Currency", "label": "Rate of Stock UOM", + "no_copy": 1, "options": "currency", "read_only": 1 + }, + { + "collapsible": 1, + "fieldname": "discount_and_margin_section", + "fieldtype": "Section Break", + "label": "Discount and Margin" + }, + { + "depends_on": "price_list_rate", + "fieldname": "margin_type", + "fieldtype": "Select", + "label": "Margin Type", + "options": "\nPercentage\nAmount", + "print_hide": 1 + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate", + "fieldname": "margin_rate_or_amount", + "fieldtype": "Float", + "label": "Margin Rate or Amount", + "print_hide": 1 + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate && doc.margin_rate_or_amount", + "fieldname": "rate_with_margin", + "fieldtype": "Currency", + "label": "Rate With Margin", + "options": "currency", + "print_hide": 1, + "read_only": 1 + }, + { + "fieldname": "column_break_28", + "fieldtype": "Column Break" + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate && doc.margin_rate_or_amount", + "fieldname": "base_rate_with_margin", + "fieldtype": "Currency", + "label": "Rate With Margin (Company Currency)", + "options": "Company:company:default_currency", + "print_hide": 1, + "read_only": 1 } ], "idx": 1, "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-01-30 21:44:41.816974", + "modified": "2021-02-23 01:00:27.132705", "modified_by": "Administrator", "module": "Buying", "name": "Purchase Order Item", diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index f976b17ae6..eb33a47873 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -107,7 +107,7 @@ class calculate_taxes_and_totals(object): elif item.discount_amount and item.pricing_rules: item.rate = item.price_list_rate - item.discount_amount - if item.doctype in ['Quotation Item', 'Sales Order Item', 'Delivery Note Item', 'Sales Invoice Item', 'POS Invoice Item']: + if item.doctype in ['Quotation Item', 'Sales Order Item', 'Delivery Note Item', 'Sales Invoice Item', 'POS Invoice Item', 'Purchase Invoice Item', 'Purchase Order Item', 'Purchase Receipt Item']: item.rate_with_margin, item.base_rate_with_margin = self.calculate_margin(item) if flt(item.rate_with_margin) > 0: item.rate = flt(item.rate_with_margin * (1.0 - (item.discount_percentage / 100.0)), item.precision("rate")) diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index c96386611b..67b12fbca4 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -141,29 +141,6 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ this.apply_price_list(); }, - price_list_rate: function(doc, cdt, cdn) { - var item = frappe.get_doc(cdt, cdn); - - frappe.model.round_floats_in(item, ["price_list_rate", "discount_percentage"]); - - let item_rate = item.price_list_rate; - if (doc.doctype == "Purchase Order" && item.blanket_order_rate) { - item_rate = item.blanket_order_rate; - } - - if (item.discount_percentage) { - item.discount_amount = flt(item_rate) * flt(item.discount_percentage) / 100; - } - - if (item.discount_amount) { - item.rate = flt((item.price_list_rate) - (item.discount_amount), precision('rate', item)); - } else { - item.rate = item_rate; - } - - this.calculate_taxes_and_totals(); - }, - discount_percentage: function(doc, cdt, cdn) { var item = frappe.get_doc(cdt, cdn); item.discount_amount = 0.0; diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index e0b0b272f3..51e4905a93 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -648,6 +648,40 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ } }, + price_list_rate: function(doc, cdt, cdn) { + var item = frappe.get_doc(cdt, cdn); + frappe.model.round_floats_in(item, ["price_list_rate", "discount_percentage"]); + + // check if child doctype is Sales Order Item/Qutation Item and calculate the rate + if (in_list(["Quotation Item", "Sales Order Item", "Delivery Note Item", "Sales Invoice Item", "POS Invoice Item", "Purchase Invoice Item", "Purchase Order Item", "Purchase Receipt Item"]), cdt) + this.apply_pricing_rule_on_item(item); + else + item.rate = flt(item.price_list_rate * (1 - item.discount_percentage / 100.0), + precision("rate", item)); + + this.calculate_taxes_and_totals(); + }, + + margin_rate_or_amount: function(doc, cdt, cdn) { + // calculated the revised total margin and rate on margin rate changes + let item = frappe.get_doc(cdt, cdn); + this.apply_pricing_rule_on_item(item); + this.calculate_taxes_and_totals(); + cur_frm.refresh_fields(); + }, + + margin_type: function(doc, cdt, cdn) { + // calculate the revised total margin and rate on margin type changes + let item = frappe.get_doc(cdt, cdn); + if (!item.margin_type) { + frappe.model.set_value(cdt, cdn, "margin_rate_or_amount", 0); + } else { + this.apply_pricing_rule_on_item(item, doc, cdt, cdn); + this.calculate_taxes_and_totals(); + cur_frm.refresh_fields(); + } + }, + get_incoming_rate: function(item, posting_date, posting_time, voucher_type, company) { let item_args = { @@ -1023,7 +1057,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ }, set_margin_amount_based_on_currency: function(exchange_rate) { - if (in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]), this.frm.doc.doctype) { + if (in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice", "Purchase Invoice", "Purchase Order", "Purchase Receipt"]), this.frm.doc.doctype) { var me = this; $.each(this.frm.doc.items || [], function(i, d) { if(d.margin_type == "Amount") { @@ -1278,10 +1312,10 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ change_grid_labels: function(company_currency) { var me = this; - this.frm.set_currency_labels(["base_rate", "base_net_rate", "base_price_list_rate", "base_amount", "base_net_amount"], + this.frm.set_currency_labels(["base_rate", "base_net_rate", "base_price_list_rate", "base_amount", "base_net_amount", "base_rate_with_margin"], company_currency, "items"); - this.frm.set_currency_labels(["rate", "net_rate", "price_list_rate", "amount", "net_amount", "stock_uom_rate"], + this.frm.set_currency_labels(["rate", "net_rate", "price_list_rate", "amount", "net_amount", "stock_uom_rate", "rate_with_margin"], this.frm.doc.currency, "items"); if(this.frm.fields_dict["operations"]) { @@ -1319,7 +1353,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ // toggle columns var item_grid = this.frm.fields_dict["items"].grid; - $.each(["base_rate", "base_price_list_rate", "base_amount"], function(i, fname) { + $.each(["base_rate", "base_price_list_rate", "base_amount", "base_rate_with_margin"], function(i, fname) { if(frappe.meta.get_docfield(item_grid.doctype, fname)) item_grid.set_column_disp(fname, me.frm.doc.currency != company_currency); }); @@ -1466,7 +1500,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ }); // if doctype is Quotation Item / Sales Order Iten then add Margin Type and rate in item_list - if (in_list(["Quotation Item", "Sales Order Item", "Delivery Note Item", "Sales Invoice Item"]), d.doctype){ + if (in_list(["Quotation Item", "Sales Order Item", "Delivery Note Item", "Sales Invoice Item", "Purchase Invoice Item", "Purchase Order Item", "Purchase Receipt Item"]), d.doctype) { item_list[0]["margin_type"] = d.margin_type; item_list[0]["margin_rate_or_amount"] = d.margin_rate_or_amount; } diff --git a/erpnext/selling/doctype/quotation_item/quotation_item.json b/erpnext/selling/doctype/quotation_item/quotation_item.json index a6785f709a..8b53902d32 100644 --- a/erpnext/selling/doctype/quotation_item/quotation_item.json +++ b/erpnext/selling/doctype/quotation_item/quotation_item.json @@ -641,6 +641,7 @@ "fieldname": "stock_uom_rate", "fieldtype": "Currency", "label": "Rate of Stock UOM", + "no_copy": 1, "options": "currency", "read_only": 1 } @@ -648,7 +649,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2021-01-30 21:39:40.174551", + "modified": "2021-02-23 01:13:54.670763", "modified_by": "Administrator", "module": "Selling", "name": "Quotation Item", diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.json b/erpnext/selling/doctype/sales_order_item/sales_order_item.json index 37e47a9d41..1e5590e748 100644 --- a/erpnext/selling/doctype/sales_order_item/sales_order_item.json +++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.json @@ -786,6 +786,7 @@ "fieldname": "stock_uom_rate", "fieldtype": "Currency", "label": "Rate of Stock UOM", + "no_copy": 1, "options": "currency", "read_only": 1 } @@ -793,7 +794,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2021-01-30 21:35:07.617320", + "modified": "2021-02-23 01:15:05.803091", "modified_by": "Administrator", "module": "Selling", "name": "Sales Order Item", diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index ce084646e1..04285735ab 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -127,20 +127,6 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ this.set_dynamic_labels(); }, - price_list_rate: function(doc, cdt, cdn) { - var item = frappe.get_doc(cdt, cdn); - frappe.model.round_floats_in(item, ["price_list_rate", "discount_percentage"]); - - // check if child doctype is Sales Order Item/Qutation Item and calculate the rate - if(in_list(["Quotation Item", "Sales Order Item", "Delivery Note Item", "Sales Invoice Item", "POS Invoice Item"]), cdt) - this.apply_pricing_rule_on_item(item); - else - item.rate = flt(item.price_list_rate * (1 - item.discount_percentage / 100.0), - precision("rate", item)); - - this.calculate_taxes_and_totals(); - }, - discount_percentage: function(doc, cdt, cdn) { var item = frappe.get_doc(cdt, cdn); item.discount_amount = 0.0; @@ -353,26 +339,6 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ refresh_field('product_bundle_help'); }, - margin_rate_or_amount: function(doc, cdt, cdn) { - // calculated the revised total margin and rate on margin rate changes - var item = locals[cdt][cdn]; - this.apply_pricing_rule_on_item(item) - this.calculate_taxes_and_totals(); - cur_frm.refresh_fields(); - }, - - margin_type: function(doc, cdt, cdn){ - // calculate the revised total margin and rate on margin type changes - var item = locals[cdt][cdn]; - if(!item.margin_type) { - frappe.model.set_value(cdt, cdn, "margin_rate_or_amount", 0); - } else { - this.apply_pricing_rule_on_item(item, doc,cdt, cdn) - this.calculate_taxes_and_totals(); - cur_frm.refresh_fields(); - } - }, - company_address: function() { var me = this; if(this.frm.doc.company_address) { diff --git a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json index 17996247c5..b05090a237 100644 --- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json +++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json @@ -750,6 +750,7 @@ "fieldname": "stock_uom_rate", "fieldtype": "Currency", "label": "Rate of Stock UOM", + "no_copy": 1, "options": "currency", "read_only": 1 } @@ -758,7 +759,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-01-30 21:42:03.767968", + "modified": "2021-02-23 01:04:08.588104", "modified_by": "Administrator", "module": "Stock", "name": "Delivery Note Item", diff --git a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json index 8974ad9318..efe3642d23 100644 --- a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json +++ b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json @@ -37,10 +37,16 @@ "returned_qty", "rate_and_amount", "price_list_rate", - "discount_percentage", - "discount_amount", "col_break3", "base_price_list_rate", + "discount_and_margin_section", + "margin_type", + "margin_rate_or_amount", + "rate_with_margin", + "column_break_37", + "discount_percentage", + "discount_amount", + "base_rate_with_margin", "sec_break1", "rate", "amount", @@ -880,6 +886,7 @@ "fieldname": "stock_uom_rate", "fieldtype": "Currency", "label": "Rate of Stock UOM", + "no_copy": 1, "options": "currency", "read_only": 1 }, @@ -890,12 +897,55 @@ "no_copy": 1, "print_hide": 1, "read_only": 1 + }, + { + "collapsible": 1, + "fieldname": "discount_and_margin_section", + "fieldtype": "Section Break", + "label": "Discount and Margin" + }, + { + "depends_on": "price_list_rate", + "fieldname": "margin_type", + "fieldtype": "Select", + "label": "Margin Type", + "options": "\nPercentage\nAmount", + "print_hide": 1 + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate", + "fieldname": "margin_rate_or_amount", + "fieldtype": "Float", + "label": "Margin Rate or Amount", + "print_hide": 1 + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate && doc.margin_rate_or_amount", + "fieldname": "rate_with_margin", + "fieldtype": "Currency", + "label": "Rate With Margin", + "options": "currency", + "print_hide": 1, + "read_only": 1 + }, + { + "fieldname": "column_break_37", + "fieldtype": "Column Break" + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate && doc.margin_rate_or_amount", + "fieldname": "base_rate_with_margin", + "fieldtype": "Currency", + "label": "Rate With Margin (Company Currency)", + "options": "Company:company:default_currency", + "print_hide": 1, + "read_only": 1 } ], "idx": 1, "istable": 1, "links": [], - "modified": "2021-01-30 21:44:06.918515", + "modified": "2021-02-23 00:59:14.360847", "modified_by": "Administrator", "module": "Stock", "name": "Purchase Receipt Item", From 04c02965584f55d08756e3694c8bbbd7436f28c8 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Tue, 30 Mar 2021 12:30:40 +0530 Subject: [PATCH 357/449] fix: add filters to account link fields in Non Profit Settings - fetch memberships ordered by date in certificate --- .../non_profit/doctype/donation/donation.py | 5 ++-- .../non_profit_settings.js | 23 ++++++++++++++++++- .../tax_exemption_80g_certificate.py | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/erpnext/non_profit/doctype/donation/donation.py b/erpnext/non_profit/doctype/donation/donation.py index 6a2a06dbc8..4fd1a30ab9 100644 --- a/erpnext/non_profit/doctype/donation/donation.py +++ b/erpnext/non_profit/doctype/donation/donation.py @@ -42,7 +42,7 @@ class Donation(Document): self.load_from_db() self.create_payment_entry() - def create_payment_entry(self): + def create_payment_entry(self, date=None): settings = frappe.get_doc('Non Profit Settings') if not settings.automate_donation_payment_entries: return @@ -58,8 +58,9 @@ class Donation(Document): frappe.flags.ignore_account_permission = False pe.paid_from = settings.donation_debit_account pe.paid_to = settings.donation_payment_account + pe.posting_date = date or getdate() pe.reference_no = self.name - pe.reference_date = getdate() + pe.reference_date = date or getdate() pe.flags.ignore_mandatory = True pe.insert() pe.submit() diff --git a/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.js b/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.js index cff92b42ab..4c4ca9834b 100644 --- a/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.js +++ b/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.js @@ -19,7 +19,7 @@ frappe.ui.form.on("Non Profit Settings", { }; }); - frm.set_query("debit_account", function() { + frm.set_query("membership_debit_account", function() { return { filters: { "account_type": "Receivable", @@ -29,6 +29,16 @@ frappe.ui.form.on("Non Profit Settings", { }; }); + frm.set_query("donation_debit_account", function() { + return { + filters: { + "account_type": "Receivable", + "is_group": 0, + "company": frm.doc.donation_company + } + }; + }); + frm.set_query("membership_payment_account", function () { var account_types = ["Bank", "Cash"]; return { @@ -40,6 +50,17 @@ frappe.ui.form.on("Non Profit Settings", { }; }); + frm.set_query("donation_payment_account", function () { + var account_types = ["Bank", "Cash"]; + return { + filters: { + "account_type": ["in", account_types], + "is_group": 0, + "company": frm.doc.donation_company + } + }; + }); + let docs_url = "https://docs.erpnext.com/docs/user/manual/en/non_profit/membership"; frm.set_intro(__("You can learn more about memberships in the manual. ") + `${__('ERPNext Docs')}`, true); diff --git a/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py index 5bbd5750f9..41c7b23146 100644 --- a/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py +++ b/erpnext/regional/doctype/tax_exemption_80g_certificate/tax_exemption_80g_certificate.py @@ -81,7 +81,7 @@ class TaxExemption80GCertificate(Document): 'from_date': ['between', (fiscal_year.year_start_date, fiscal_year.year_end_date)], 'to_date': ['between', (fiscal_year.year_start_date, fiscal_year.year_end_date)], 'membership_status': ('!=', 'Cancelled') - }, ['from_date', 'amount', 'name', 'invoice', 'payment_id']) + }, ['from_date', 'amount', 'name', 'invoice', 'payment_id'], order_by='from_date') if not memberships: frappe.msgprint(_('No Membership Payments found against the Member {0}').format(self.member)) From a21e347bf167bd01c6c3743fb9d5e0ac0a4a3b62 Mon Sep 17 00:00:00 2001 From: Andy Zhu Date: Mon, 5 Oct 2020 12:16:48 +1300 Subject: [PATCH 358/449] fix: Update Items on Purchase Order If user add rows or remove rows to update items on purchase order, the quantity in bin won't get updated. This fix is not mature yet but to give an tempopary solution for fixing this issue. --- erpnext/controllers/accounts_controller.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 12a81c7887..69e5e1ddec 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1321,6 +1321,7 @@ def set_order_defaults(parent_doctype, parent_doctype_name, child_doctype, child date_fieldname = "delivery_date" if child_doctype == "Sales Order Item" else "schedule_date" child_item.update({date_fieldname: trans_item.get(date_fieldname) or p_doc.get(date_fieldname)}) child_item.uom = trans_item.get("uom") or item.stock_uom + child_item.warehouse = p_doc.set_warehouse conversion_factor = flt(get_conversion_factor(item.item_code, child_item.uom).get("conversion_factor")) child_item.conversion_factor = flt(trans_item.get('conversion_factor')) or conversion_factor if child_doctype == "Purchase Order Item": @@ -1359,6 +1360,12 @@ def validate_and_delete_children(parent, data): d.cancel() d.delete() + + from erpnext.stock.stock_balance import update_bin_qty, get_ordered_qty + frappe.errprint(f"Item Code: {d.item_code}, Warehouse: {d.warehouse}") + update_bin_qty(d.item_code, d.warehouse, { + "ordered_qty": get_ordered_qty(d.item_code, d.warehouse) + }) @frappe.whitelist() def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name, child_docname="items"): From c0ba6eafd543b52bd36d1747415ac5e34404de74 Mon Sep 17 00:00:00 2001 From: Andy Zhu Date: Tue, 6 Oct 2020 10:51:42 +1300 Subject: [PATCH 359/449] fix: Update Items on Purchase Order 1. set warehouse using `get_item_warehouse` 2. update "reserved_qty" for sales order --- erpnext/controllers/accounts_controller.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 69e5e1ddec..ba9f87f3a3 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1321,7 +1321,7 @@ def set_order_defaults(parent_doctype, parent_doctype_name, child_doctype, child date_fieldname = "delivery_date" if child_doctype == "Sales Order Item" else "schedule_date" child_item.update({date_fieldname: trans_item.get(date_fieldname) or p_doc.get(date_fieldname)}) child_item.uom = trans_item.get("uom") or item.stock_uom - child_item.warehouse = p_doc.set_warehouse + child_item.warehouse = get_item_warehouse(item, p_doc, overwrite_warehouse=True) conversion_factor = flt(get_conversion_factor(item.item_code, child_item.uom).get("conversion_factor")) child_item.conversion_factor = flt(trans_item.get('conversion_factor')) or conversion_factor if child_doctype == "Purchase Order Item": @@ -1361,9 +1361,9 @@ def validate_and_delete_children(parent, data): d.cancel() d.delete() - from erpnext.stock.stock_balance import update_bin_qty, get_ordered_qty - frappe.errprint(f"Item Code: {d.item_code}, Warehouse: {d.warehouse}") + from erpnext.stock.stock_balance import update_bin_qty, get_reserved_qty, get_ordered_qty update_bin_qty(d.item_code, d.warehouse, { + "reserved_qty": get_reserved_qty(d.item_code, d.warehouse), "ordered_qty": get_ordered_qty(d.item_code, d.warehouse) }) From ba3578929eea16c83ea879381964f7374cab117a Mon Sep 17 00:00:00 2001 From: Andy Zhu Date: Tue, 27 Oct 2020 14:57:59 +1300 Subject: [PATCH 360/449] Update accounts_controller.py Updating Bin quantity based on doctype to optimize running efficiency. --- erpnext/controllers/accounts_controller.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index ba9f87f3a3..8d53914f6c 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1362,10 +1362,15 @@ def validate_and_delete_children(parent, data): d.delete() from erpnext.stock.stock_balance import update_bin_qty, get_reserved_qty, get_ordered_qty - update_bin_qty(d.item_code, d.warehouse, { - "reserved_qty": get_reserved_qty(d.item_code, d.warehouse), - "ordered_qty": get_ordered_qty(d.item_code, d.warehouse) - }) + # updating both will be time consuming, update it based on the doctype. reserved qty if sales order, otherwise ordered qty + if parent.doctype == "Sales Order": + update_bin_qty(d.item_code, d.warehouse, { + "reserved_qty": get_reserved_qty(d.item_code, d.warehouse) + }) + else: + update_bin_qty(d.item_code, d.warehouse, { + "ordered_qty": get_ordered_qty(d.item_code, d.warehouse) + }) @frappe.whitelist() def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name, child_docname="items"): From a5de6c779bdbf9d87f32c5f58819883011f3afa1 Mon Sep 17 00:00:00 2001 From: marination Date: Wed, 31 Mar 2021 01:38:22 +0530 Subject: [PATCH 361/449] fix: Cleaned up and fixed validation and bin updation on deletion - Created separate smaller functions for validation and bin updation of deleted row - Made sure previous doc (linked doc) was also updated after deletion of row - Tests to check bin updation on add/update/delete - Made reserved qty for subcontrating read only in bin --- .../doctype/purchase_order/purchase_order.py | 1 + .../purchase_order/test_purchase_order.py | 69 +++++++++++++++-- erpnext/controllers/accounts_controller.py | 76 ++++++++++++------- .../doctype/sales_order/sales_order.py | 2 +- .../doctype/sales_order/test_sales_order.py | 26 +++++++ erpnext/stock/doctype/bin/bin.json | 8 +- 6 files changed, 144 insertions(+), 38 deletions(-) diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py index d32e98e8d9..29a8d59cb0 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -252,6 +252,7 @@ class PurchaseOrder(BuyingController): self.update_prevdoc_status() # Must be called after updating ordered qty in Material Request + # bin uses Material Request Items to recalculate & update self.update_requested_qty() self.update_ordered_qty() diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index 02d4865320..1b231b3acb 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -90,6 +90,50 @@ class TestPurchaseOrder(unittest.TestCase): frappe.db.set_value('Item', '_Test Item', 'over_billing_allowance', 0) frappe.db.set_value("Accounts Settings", None, "over_billing_allowance", 0) + def test_update_remove_child_linked_to_mr(self): + """Test impact on linked PO and MR on deleting/updating row.""" + mr = make_material_request(qty=10) + po = make_purchase_order(mr.name) + po.supplier = "_Test Supplier" + po.save() + po.submit() + + first_item_of_po = po.get("items")[0] + existing_ordered_qty = get_ordered_qty() # 10 + existing_requested_qty = get_requested_qty() # 0 + + # decrease ordered qty by 3 (10 -> 7) and add item + trans_item = json.dumps([ + { + 'item_code': first_item_of_po.item_code, + 'rate': first_item_of_po.rate, + 'qty': 7, + 'docname': first_item_of_po.name + }, + {'item_code' : '_Test Item 2', 'rate' : 200, 'qty' : 2} + ]) + update_child_qty_rate('Purchase Order', trans_item, po.name) + mr.reload() + + # requested qty increases as ordered qty decreases + self.assertEqual(get_requested_qty(), existing_requested_qty + 3) # 3 + self.assertEqual(mr.items[0].ordered_qty, 7) + + self.assertEqual(get_ordered_qty(), existing_ordered_qty - 3) # 7 + + # delete first item linked to Material Request + trans_item = json.dumps([ + {'item_code' : '_Test Item 2', 'rate' : 200, 'qty' : 2} + ]) + update_child_qty_rate('Purchase Order', trans_item, po.name) + mr.reload() + + # requested qty increases as ordered qty is 0 (deleted row) + self.assertEqual(get_requested_qty(), existing_requested_qty + 10) # 10 + self.assertEqual(mr.items[0].ordered_qty, 0) + + # ordered qty decreases as ordered qty is 0 (deleted row) + self.assertEqual(get_ordered_qty(), existing_ordered_qty - 10) # 0 def test_update_child(self): mr = make_material_request(qty=10) @@ -120,7 +164,6 @@ class TestPurchaseOrder(unittest.TestCase): self.assertEqual(po.get("items")[0].amount, 1400) self.assertEqual(get_ordered_qty(), existing_ordered_qty + 3) - def test_update_child_adding_new_item(self): po = create_purchase_order(do_not_save=1) po.items[0].qty = 4 @@ -129,6 +172,7 @@ class TestPurchaseOrder(unittest.TestCase): pr = make_pr_against_po(po.name, 2) po.load_from_db() + existing_ordered_qty = get_ordered_qty() first_item_of_po = po.get("items")[0] trans_item = json.dumps([ @@ -145,7 +189,8 @@ class TestPurchaseOrder(unittest.TestCase): po.reload() self.assertEquals(len(po.get('items')), 2) self.assertEqual(po.status, 'To Receive and Bill') - + # ordered qty should increase on row addition + self.assertEqual(get_ordered_qty(), existing_ordered_qty + 7) def test_update_child_removing_item(self): po = create_purchase_order(do_not_save=1) @@ -156,6 +201,7 @@ class TestPurchaseOrder(unittest.TestCase): po.reload() first_item_of_po = po.get("items")[0] + existing_ordered_qty = get_ordered_qty() # add an item trans_item = json.dumps([ { @@ -168,6 +214,10 @@ class TestPurchaseOrder(unittest.TestCase): update_child_qty_rate('Purchase Order', trans_item, po.name) po.reload() + + # ordered qty should increase on row addition + self.assertEqual(get_ordered_qty(), existing_ordered_qty + 7) + # check if can remove received item trans_item = json.dumps([{'item_code' : '_Test Item', 'rate' : 200, 'qty' : 7, 'docname': po.get("items")[1].name}]) self.assertRaises(frappe.ValidationError, update_child_qty_rate, 'Purchase Order', trans_item, po.name) @@ -187,6 +237,9 @@ class TestPurchaseOrder(unittest.TestCase): self.assertEquals(len(po.get('items')), 1) self.assertEqual(po.status, 'To Receive and Bill') + # ordered qty should decrease (back to initial) on row deletion + self.assertEqual(get_ordered_qty(), existing_ordered_qty) + def test_update_child_perm(self): po = create_purchase_order(item_code= "_Test Item", qty=4) @@ -230,11 +283,13 @@ class TestPurchaseOrder(unittest.TestCase): new_item_with_tax = frappe.get_doc("Item", "Test Item with Tax") - new_item_with_tax.append("taxes", { - "item_tax_template": "Test Update Items Template - _TC", - "valid_from": nowdate() - }) - new_item_with_tax.save() + if not frappe.db.exists("Item Tax", + {"item_tax_template": "Test Update Items Template - _TC", "parent": "Test Item with Tax"}): + new_item_with_tax.append("taxes", { + "item_tax_template": "Test Update Items Template - _TC", + "valid_from": nowdate() + }) + new_item_with_tax.save() tax_template = "_Test Account Excise Duty @ 10 - _TC" item = "_Test Item Home Desktop 100" diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 8d53914f6c..a73de44606 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1316,26 +1316,63 @@ def set_order_defaults(parent_doctype, parent_doctype_name, child_doctype, child p_doc = frappe.get_doc(parent_doctype, parent_doctype_name) child_item = frappe.new_doc(child_doctype, p_doc, child_docname) item = frappe.get_doc("Item", trans_item.get('item_code')) + for field in ("item_code", "item_name", "description", "item_group"): - child_item.update({field: item.get(field)}) + child_item.update({field: item.get(field)}) + date_fieldname = "delivery_date" if child_doctype == "Sales Order Item" else "schedule_date" child_item.update({date_fieldname: trans_item.get(date_fieldname) or p_doc.get(date_fieldname)}) + child_item.stock_uom = item.stock_uom child_item.uom = trans_item.get("uom") or item.stock_uom child_item.warehouse = get_item_warehouse(item, p_doc, overwrite_warehouse=True) conversion_factor = flt(get_conversion_factor(item.item_code, child_item.uom).get("conversion_factor")) child_item.conversion_factor = flt(trans_item.get('conversion_factor')) or conversion_factor + if child_doctype == "Purchase Order Item": - child_item.base_rate = 1 # Initiallize value will update in parent validation - child_item.base_amount = 1 # Initiallize value will update in parent validation + # Initialized value will update in parent validation + child_item.base_rate = 1 + child_item.base_amount = 1 if child_doctype == "Sales Order Item": child_item.warehouse = get_item_warehouse(item, p_doc, overwrite_warehouse=True) if not child_item.warehouse: frappe.throw(_("Cannot find {} for item {}. Please set the same in Item Master or Stock Settings.") .format(frappe.bold("default warehouse"), frappe.bold(item.item_code))) + set_child_tax_template_and_map(item, child_item, p_doc) add_taxes_from_tax_template(child_item, p_doc) return child_item +def validate_child_on_delete(row, parent): + """Check if partially transacted item (row) is being deleted.""" + if parent.doctype == "Sales Order": + if flt(row.delivered_qty): + frappe.throw(_("Row #{0}: Cannot delete item {1} which has already been delivered").format(row.idx, row.item_code)) + if flt(row.work_order_qty): + frappe.throw(_("Row #{0}: Cannot delete item {1} which has work order assigned to it.").format(row.idx, row.item_code)) + if flt(row.ordered_qty): + frappe.throw(_("Row #{0}: Cannot delete item {1} which is assigned to customer's purchase order.").format(row.idx, row.item_code)) + + if parent.doctype == "Purchase Order" and flt(row.received_qty): + frappe.throw(_("Row #{0}: Cannot delete item {1} which has already been received").format(row.idx, row.item_code)) + + if flt(row.billed_amt): + frappe.throw(_("Row #{0}: Cannot delete item {1} which has already been billed.").format(row.idx, row.item_code)) + +def update_bin_on_delete(row, doctype): + """Update bin for deleted item (row).""" + from erpnext.stock.stock_balance import update_bin_qty, get_reserved_qty, get_ordered_qty, get_indented_qty + qty_dict = {} + + if doctype == "Sales Order": + qty_dict["reserved_qty"] = get_reserved_qty(row.item_code, row.warehouse) + else: + if row.material_request_item: + qty_dict["indented_qty"] = get_indented_qty(row.item_code, row.warehouse) + + qty_dict["ordered_qty"] = get_ordered_qty(row.item_code, row.warehouse) + + update_bin_qty(row.item_code, row.warehouse, qty_dict) + def validate_and_delete_children(parent, data): deleted_children = [] updated_item_names = [d.get("docname") for d in data] @@ -1344,33 +1381,16 @@ def validate_and_delete_children(parent, data): deleted_children.append(item) for d in deleted_children: - if parent.doctype == "Sales Order": - if flt(d.delivered_qty): - frappe.throw(_("Row #{0}: Cannot delete item {1} which has already been delivered").format(d.idx, d.item_code)) - if flt(d.work_order_qty): - frappe.throw(_("Row #{0}: Cannot delete item {1} which has work order assigned to it.").format(d.idx, d.item_code)) - if flt(d.ordered_qty): - frappe.throw(_("Row #{0}: Cannot delete item {1} which is assigned to customer's purchase order.").format(d.idx, d.item_code)) - - if parent.doctype == "Purchase Order" and flt(d.received_qty): - frappe.throw(_("Row #{0}: Cannot delete item {1} which has already been received").format(d.idx, d.item_code)) - - if flt(d.billed_amt): - frappe.throw(_("Row #{0}: Cannot delete item {1} which has already been billed.").format(d.idx, d.item_code)) - + validate_child_on_delete(d, parent) d.cancel() d.delete() - - from erpnext.stock.stock_balance import update_bin_qty, get_reserved_qty, get_ordered_qty - # updating both will be time consuming, update it based on the doctype. reserved qty if sales order, otherwise ordered qty - if parent.doctype == "Sales Order": - update_bin_qty(d.item_code, d.warehouse, { - "reserved_qty": get_reserved_qty(d.item_code, d.warehouse) - }) - else: - update_bin_qty(d.item_code, d.warehouse, { - "ordered_qty": get_ordered_qty(d.item_code, d.warehouse) - }) + + # need to update ordered qty in Material Request first + # bin uses Material Request Items to recalculate & update + parent.update_prevdoc_status() + + for d in deleted_children: + update_bin_on_delete(d, parent.doctype) @frappe.whitelist() def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name, child_docname="items"): diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index e56129170c..fd9ddd8463 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -150,7 +150,7 @@ class SalesOrder(SellingController): if enq: frappe.db.sql("update `tabOpportunity` set status = %s where name=%s",(flag,enq[0][0])) - def update_prevdoc_status(self, flag): + def update_prevdoc_status(self, flag=None): for quotation in list(set([d.prevdoc_docname for d in self.get("items")])): if quotation: doc = frappe.get_doc("Quotation", quotation) diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py index ee16f44171..7752b7bb08 100644 --- a/erpnext/selling/doctype/sales_order/test_sales_order.py +++ b/erpnext/selling/doctype/sales_order/test_sales_order.py @@ -340,6 +340,9 @@ class TestSalesOrder(unittest.TestCase): prev_total = so.get("base_total") prev_total_in_words = so.get("base_in_words") + # get reserved qty before update items + reserved_qty_for_second_item = get_reserved_qty("_Test Item 2") + first_item_of_so = so.get("items")[0] trans_item = json.dumps([ {'item_code' : first_item_of_so.item_code, 'rate' : first_item_of_so.rate, \ @@ -353,6 +356,10 @@ class TestSalesOrder(unittest.TestCase): self.assertEqual(so.get("items")[-1].rate, 200) self.assertEqual(so.get("items")[-1].qty, 7) self.assertEqual(so.get("items")[-1].amount, 1400) + + # reserved qty should increase after adding row + self.assertEqual(get_reserved_qty('_Test Item 2'), reserved_qty_for_second_item + 7) + self.assertEqual(so.status, 'To Deliver and Bill') updated_total = so.get("base_total") @@ -372,6 +379,9 @@ class TestSalesOrder(unittest.TestCase): create_dn_against_so(so.name, 2) make_sales_invoice(so.name) + # get reserved qty before update items + reserved_qty_for_second_item = get_reserved_qty("_Test Item 2") + # add an item so as to try removing items trans_item = json.dumps([ {"item_code": '_Test Item', "qty": 5, "rate":1000, "docname": so.get("items")[0].name}, @@ -381,6 +391,9 @@ class TestSalesOrder(unittest.TestCase): so.reload() self.assertEqual(len(so.get("items")), 2) + # reserved qty should increase after adding row + self.assertEqual(get_reserved_qty('_Test Item 2'), reserved_qty_for_second_item + 2) + # check if delivered items can be removed trans_item = json.dumps([{ "item_code": '_Test Item 2', @@ -401,6 +414,10 @@ class TestSalesOrder(unittest.TestCase): so.reload() self.assertEqual(len(so.get("items")), 1) + + # reserved qty should decrease (back to initial) after deleting row + self.assertEqual(get_reserved_qty('_Test Item 2'), reserved_qty_for_second_item) + self.assertEqual(so.status, 'To Deliver and Bill') @@ -508,12 +525,18 @@ class TestSalesOrder(unittest.TestCase): so = make_sales_order(item_code = "_Test Item", warehouse=None) + # get reserved qty of packed item + existing_reserved_qty = get_reserved_qty("_Packed Item") + added_item = json.dumps([{"item_code" : "_Product Bundle Item", "rate" : 200, 'qty' : 2}]) update_child_qty_rate('Sales Order', added_item, so.name) so.reload() self.assertEqual(so.packed_items[0].qty, 4) + # reserved qty in packed item should increase after adding bundle item + self.assertEqual(get_reserved_qty("_Packed Item"), existing_reserved_qty + 4) + # test uom and conversion factor change update_uom_conv_factor = json.dumps([{ 'item_code': so.get("items")[0].item_code, @@ -528,6 +551,9 @@ class TestSalesOrder(unittest.TestCase): so.reload() self.assertEqual(so.packed_items[0].qty, 8) + # reserved qty in packed item should increase after changing bundle item uom + self.assertEqual(get_reserved_qty("_Packed Item"), existing_reserved_qty + 8) + def test_update_child_with_tax_template(self): """ Test Action: Create a SO with one item having its tax account head already in the SO. diff --git a/erpnext/stock/doctype/bin/bin.json b/erpnext/stock/doctype/bin/bin.json index 04d624ec0b..8e79f0e555 100644 --- a/erpnext/stock/doctype/bin/bin.json +++ b/erpnext/stock/doctype/bin/bin.json @@ -1,4 +1,5 @@ { + "actions": [], "autoname": "MAT-BIN-.YYYY.-.#####", "creation": "2013-01-10 16:34:25", "doctype": "DocType", @@ -112,7 +113,8 @@ { "fieldname": "reserved_qty_for_sub_contract", "fieldtype": "Float", - "label": "Reserved Qty for sub contract" + "label": "Reserved Qty for sub contract", + "read_only": 1 }, { "fieldname": "ma_rate", @@ -166,7 +168,8 @@ "hide_toolbar": 1, "idx": 1, "in_create": 1, - "modified": "2019-11-18 18:34:59.456882", + "links": [], + "modified": "2021-03-30 23:09:39.572776", "modified_by": "Administrator", "module": "Stock", "name": "Bin", @@ -196,5 +199,6 @@ ], "quick_entry": 1, "search_fields": "item_code,warehouse", + "sort_field": "modified", "sort_order": "ASC" } \ No newline at end of file From 41229ba705db86b43ce8d9a9bc146639b968655c Mon Sep 17 00:00:00 2001 From: Anupam Date: Wed, 31 Mar 2021 02:32:25 +0530 Subject: [PATCH 362/449] fix: unable to submit stock entry --- erpnext/stock/doctype/stock_entry/stock_entry.js | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 4979234caf..af3c4e5aa0 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -848,7 +848,6 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ } erpnext.hide_company(); erpnext.utils.add_item(this.frm); - this.frm.trigger('add_to_transit'); }, scan_barcode: function() { From 91a8a74d54e5fe7a52ae2dd23b8b733332869cdb Mon Sep 17 00:00:00 2001 From: Afshan <33727827+AfshanKhan@users.noreply.github.com> Date: Wed, 31 Mar 2021 11:30:04 +0530 Subject: [PATCH 363/449] fix: column width in Recruitment Analytics report (#25074) --- .../report/recruitment_analytics/recruitment_analytics.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/hr/report/recruitment_analytics/recruitment_analytics.py b/erpnext/hr/report/recruitment_analytics/recruitment_analytics.py index e961114ac2..303c829eb6 100644 --- a/erpnext/hr/report/recruitment_analytics/recruitment_analytics.py +++ b/erpnext/hr/report/recruitment_analytics/recruitment_analytics.py @@ -31,7 +31,7 @@ def get_columns(): "fieldtype": "Link", "fieldname": "job_opening", "options": "Job Opening", - "width": 100 + "width": 105 }, { "label": _("Job Applicant"), @@ -44,13 +44,13 @@ def get_columns(): "label": _("Applicant name"), "fieldtype": "data", "fieldname": "applicant_name", - "width": 120 + "width": 130 }, { "label": _("Application Status"), "fieldtype": "Data", "fieldname": "application_status", - "width": 100 + "width": 150 }, { "label": _("Job Offer"), @@ -187,4 +187,4 @@ def get_job_offer(ja_list): else: ja_joff_map[offer.job_applicant].append(offer) - return ja_joff_map \ No newline at end of file + return ja_joff_map From 410d36beca66f4fba4769dd647c016ae988237c6 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 31 Mar 2021 12:11:00 +0530 Subject: [PATCH 364/449] fix: bom stock calculated report --- .../report/bom_stock_calculated/bom_stock_calculated.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/manufacturing/report/bom_stock_calculated/bom_stock_calculated.py b/erpnext/manufacturing/report/bom_stock_calculated/bom_stock_calculated.py index f7b407b792..f7cae025d5 100644 --- a/erpnext/manufacturing/report/bom_stock_calculated/bom_stock_calculated.py +++ b/erpnext/manufacturing/report/bom_stock_calculated/bom_stock_calculated.py @@ -88,7 +88,7 @@ def get_bom_stock(filters): GROUP BY bom_item.item_code""".format(qty_field=qty_field, table=table, conditions=conditions, bom=bom), as_dict=1) def get_manufacturer_records(): - details = frappe.get_list('Item Manufacturer', fields = ["manufacturer", "manufacturer_part_no, parent"]) + details = frappe.get_list('Item Manufacturer', fields = ["manufacturer", "manufacturer_part_no", "parent"]) manufacture_details = frappe._dict() for detail in details: dic = manufacture_details.setdefault(detail.get('parent'), {}) From 368cb451475c1acb8d6818fad1548926fe84ae25 Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Wed, 31 Mar 2021 12:43:33 +0530 Subject: [PATCH 365/449] fix(Italy): setup, validations, optimisations (#25065) --- erpnext/regional/italy/sales_invoice.js | 13 +--- erpnext/regional/italy/setup.py | 7 +- erpnext/regional/italy/utils.py | 98 ++++++++++++++----------- 3 files changed, 62 insertions(+), 56 deletions(-) diff --git a/erpnext/regional/italy/sales_invoice.js b/erpnext/regional/italy/sales_invoice.js index 586a52937b..b54ac53812 100644 --- a/erpnext/regional/italy/sales_invoice.js +++ b/erpnext/regional/italy/sales_invoice.js @@ -11,15 +11,10 @@ erpnext.setup_e_invoice_button = (doctype) => { callback: function(r) { frm.reload_doc(); if(r.message) { - var w = window.open( - frappe.urllib.get_full_url( - "/api/method/erpnext.regional.italy.utils.download_e_invoice_file?" - + "file_name=" + r.message - ) - ) - if (!w) { - frappe.msgprint(__("Please enable pop-ups")); return; - } + open_url_post(frappe.request.url, { + cmd: 'frappe.core.doctype.file.file.download_file', + file_url: r.message + }); } } }); diff --git a/erpnext/regional/italy/setup.py b/erpnext/regional/italy/setup.py index 95b92e76a6..a1f5bb9836 100644 --- a/erpnext/regional/italy/setup.py +++ b/erpnext/regional/italy/setup.py @@ -128,11 +128,8 @@ def make_custom_fields(update=True): fetch_from="company.vat_collectability"), dict(fieldname='sb_e_invoicing_reference', label='E-Invoicing', fieldtype='Section Break', insert_after='against_income_account', print_hide=1), - dict(fieldname='company_tax_id', label='Company Tax ID', - fieldtype='Data', insert_after='sb_e_invoicing_reference', print_hide=1, read_only=1, - fetch_from="company.tax_id"), dict(fieldname='company_fiscal_code', label='Company Fiscal Code', - fieldtype='Data', insert_after='company_tax_id', print_hide=1, read_only=1, + fieldtype='Data', insert_after='sb_e_invoicing_reference', print_hide=1, read_only=1, fetch_from="company.fiscal_code"), dict(fieldname='company_fiscal_regime', label='Company Fiscal Regime', fieldtype='Data', insert_after='company_fiscal_code', print_hide=1, read_only=1, @@ -217,4 +214,4 @@ def add_permissions(): update_permission_property(doctype, 'Accounts Manager', 0, 'delete', 1) add_permission(doctype, 'Accounts Manager', 1) update_permission_property(doctype, 'Accounts Manager', 1, 'write', 1) - update_permission_property(doctype, 'Accounts Manager', 1, 'create', 1) \ No newline at end of file + update_permission_property(doctype, 'Accounts Manager', 1, 'create', 1) diff --git a/erpnext/regional/italy/utils.py b/erpnext/regional/italy/utils.py index 6842fb2a61..08573cddcd 100644 --- a/erpnext/regional/italy/utils.py +++ b/erpnext/regional/italy/utils.py @@ -1,6 +1,8 @@ from __future__ import unicode_literals -import frappe, json, os +import io +import json +import frappe from frappe.utils import flt, cstr from erpnext.controllers.taxes_and_totals import get_itemised_tax from frappe import _ @@ -28,20 +30,22 @@ def update_itemised_tax_data(doc): @frappe.whitelist() def export_invoices(filters=None): - saved_xmls = [] + frappe.has_permission('Sales Invoice', throw=True) - invoices = frappe.get_all("Sales Invoice", filters=get_conditions(filters), fields=["*"]) + invoices = frappe.get_all( + "Sales Invoice", + filters=get_conditions(filters), + fields=["name", "company_tax_id"] + ) - for invoice in invoices: - attachments = get_e_invoice_attachments(invoice) - saved_xmls += [attachment.file_name for attachment in attachments] + attachments = get_e_invoice_attachments(invoices) - zip_filename = "{0}-einvoices.zip".format(frappe.utils.get_datetime().strftime("%Y%m%d_%H%M%S")) + zip_filename = "{0}-einvoices.zip".format( + frappe.utils.get_datetime().strftime("%Y%m%d_%H%M%S")) - download_zip(saved_xmls, zip_filename) + download_zip(attachments, zip_filename) -@frappe.whitelist() def prepare_invoice(invoice, progressive_number): #set company information company = frappe.get_doc("Company", invoice.company) @@ -98,7 +102,7 @@ def prepare_invoice(invoice, progressive_number): def get_conditions(filters): filters = json.loads(filters) - conditions = {"docstatus": 1} + conditions = {"docstatus": 1, "company_tax_id": ("!=", "")} if filters.get("company"): conditions["company"] = filters["company"] if filters.get("customer"): conditions["customer"] = filters["customer"] @@ -111,23 +115,22 @@ def get_conditions(filters): return conditions -#TODO: Use function from frappe once PR #6853 is merged. + def download_zip(files, output_filename): - from zipfile import ZipFile + import zipfile - input_files = [frappe.get_site_path('private', 'files', filename) for filename in files] - output_path = frappe.get_site_path('private', 'files', output_filename) + zip_stream = io.BytesIO() + with zipfile.ZipFile(zip_stream, 'w', zipfile.ZIP_DEFLATED) as zip_file: + for file in files: + file_path = frappe.utils.get_files_path( + file.file_name, is_private=file.is_private) - with ZipFile(output_path, 'w') as output_zip: - for input_file in input_files: - output_zip.write(input_file, arcname=os.path.basename(input_file)) - - with open(output_path, 'rb') as fileobj: - filedata = fileobj.read() + zip_file.write(file_path, arcname=file.file_name) frappe.local.response.filename = output_filename - frappe.local.response.filecontent = filedata + frappe.local.response.filecontent = zip_stream.getvalue() frappe.local.response.type = "download" + zip_stream.close() def get_invoice_summary(items, taxes): summary_data = frappe._dict() @@ -307,23 +310,12 @@ def prepare_and_attach_invoice(doc, replace=False): @frappe.whitelist() def generate_single_invoice(docname): doc = frappe.get_doc("Sales Invoice", docname) - + frappe.has_permission("Sales Invoice", doc=doc, throw=True) e_invoice = prepare_and_attach_invoice(doc, True) + return e_invoice.file_url - return e_invoice.file_name - -@frappe.whitelist() -def download_e_invoice_file(file_name): - content = None - with open(frappe.get_site_path('private', 'files', file_name), "r") as f: - content = f.read() - - frappe.local.response.filename = file_name - frappe.local.response.filecontent = content - frappe.local.response.type = "download" - -#Delete e-invoice attachment on cancel. +# Delete e-invoice attachment on cancel. def sales_invoice_on_cancel(doc, method): if get_company_country(doc.company) not in ['Italy', 'Italia', 'Italian Republic', 'Repubblica Italiana']: @@ -335,16 +327,38 @@ def sales_invoice_on_cancel(doc, method): def get_company_country(company): return frappe.get_cached_value('Company', company, 'country') -def get_e_invoice_attachments(invoice): - if not invoice.company_tax_id: - return [] +def get_e_invoice_attachments(invoices): + if not isinstance(invoices, list): + if not invoices.company_tax_id: + return + + invoices = [invoices] + + tax_id_map = { + invoice.name: ( + invoice.company_tax_id + if invoice.company_tax_id.startswith("IT") + else "IT" + invoice.company_tax_id + ) for invoice in invoices + } + + attachments = frappe.get_all( + "File", + fields=("name", "file_name", "attached_to_name", "is_private"), + filters= { + "attached_to_name": ('in', tax_id_map), + "attached_to_doctype": 'Sales Invoice' + } + ) out = [] - attachments = get_attachments(invoice.doctype, invoice.name) - company_tax_id = invoice.company_tax_id if invoice.company_tax_id.startswith("IT") else "IT" + invoice.company_tax_id - for attachment in attachments: - if attachment.file_name and attachment.file_name.startswith(company_tax_id) and attachment.file_name.endswith(".xml"): + if ( + attachment.file_name + and attachment.file_name.endswith(".xml") + and attachment.file_name.startswith( + tax_id_map.get(attachment.attached_to_name)) + ): out.append(attachment) return out From e50324aed7fe64d4a22043876ea933dcfb5119db Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Wed, 31 Mar 2021 12:44:03 +0530 Subject: [PATCH 366/449] perf: reduce number of queries for checking if future SL entry exists (#25064) --- erpnext/controllers/stock_controller.py | 45 ++++++++++++++----------- erpnext/stock/stock_ledger.py | 6 ++-- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 11ac703311..f352bae30e 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -495,7 +495,7 @@ class StockController(AccountsController): "voucher_no": self.name, "company": self.company }) - if check_if_future_sle_exists(args): + if future_sle_exists(args): create_repost_item_valuation_entry(args) elif not is_reposting_pending(): check_if_stock_and_account_balance_synced(self.posting_date, @@ -506,37 +506,42 @@ def is_reposting_pending(): {'docstatus': 1, 'status': ['in', ['Queued','In Progress']]}) -def check_if_future_sle_exists(args): - sl_entries = frappe.db.get_all("Stock Ledger Entry", +def future_sle_exists(args): + sl_entries = frappe.get_all("Stock Ledger Entry", filters={"voucher_type": args.voucher_type, "voucher_no": args.voucher_no}, fields=["item_code", "warehouse"], order_by="creation asc") - distinct_item_warehouses = list(set([(d.item_code, d.warehouse) for d in sl_entries])) + if not sl_entries: + return - sle_exists = False - for item_code, warehouse in distinct_item_warehouses: - args.update({ - "item_code": item_code, - "warehouse": warehouse - }) - if get_sle(args): - sle_exists = True - break - return sle_exists + warehouse_items_map = {} + for entry in sl_entries: + if entry.warehouse not in warehouse_items_map: + warehouse_items_map[entry.warehouse] = set() + + warehouse_items_map[entry.warehouse].add(entry.item_code) + + or_conditions = [] + for warehouse, items in warehouse_items_map.items(): + or_conditions.append( + "warehouse = '{}' and item_code in ({})".format( + warehouse, + ", ".join(frappe.db.escape(item) for item in items) + ) + ) -def get_sle(args): return frappe.db.sql(""" select name from `tabStock Ledger Entry` where - item_code=%(item_code)s - and warehouse=%(warehouse)s - and timestamp(posting_date, posting_time) >= timestamp(%(posting_date)s, %(posting_time)s) + ({}) + and timestamp(posting_date, posting_time) + >= timestamp(%(posting_date)s, %(posting_time)s) and voucher_no != %(voucher_no)s and is_cancelled = 0 limit 1 - """, args) + """.format(" or ".join(or_conditions)), args) def create_repost_item_valuation_entry(args): args = frappe._dict(args) @@ -554,4 +559,4 @@ def create_repost_item_valuation_entry(args): repost_entry.allow_zero_rate = args.allow_zero_rate repost_entry.flags.ignore_links = True repost_entry.save() - repost_entry.submit() \ No newline at end of file + repost_entry.submit() diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index f54b3c1bb2..121c51cf6a 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -207,11 +207,11 @@ class update_entries_after(object): def build(self): - from erpnext.controllers.stock_controller import check_if_future_sle_exists + from erpnext.controllers.stock_controller import future_sle_exists if self.args.get("sle_id"): self.process_sle_against_current_timestamp() - if not check_if_future_sle_exists(self.args): + if not future_sle_exists(self.args): self.update_bin() else: entries_to_fix = self.get_future_entries_to_fix() @@ -856,4 +856,4 @@ def get_future_sle_with_negative_qty(args): and qty_after_transaction < 0 order by timestamp(posting_date, posting_time) asc limit 1 - """, args, as_dict=1) \ No newline at end of file + """, args, as_dict=1) From 1999ae0a91d7b9a44e1c8db448aec64706923c24 Mon Sep 17 00:00:00 2001 From: marination Date: Fri, 12 Mar 2021 14:12:46 +0530 Subject: [PATCH 367/449] fix: PO not created against all selected suppliers (drop shipping) - Return list of created POs instead of first doc - test case added --- .../doctype/sales_order/sales_order.py | 6 ++- .../doctype/sales_order/test_sales_order.py | 45 +++++++++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index e56129170c..b5c5e1bc2f 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -778,6 +778,7 @@ def get_events(start, end, filters=None): @frappe.whitelist() def make_purchase_order_for_default_supplier(source_name, selected_items=None, target_doc=None): + """Creates Purchase Order for each Supplier. Returns a list of doc objects.""" if not selected_items: return if isinstance(selected_items, string_types): @@ -829,6 +830,7 @@ def make_purchase_order_for_default_supplier(source_name, selected_items=None, t if not suppliers: frappe.throw(_("Please set a Supplier against the Items to be considered in the Purchase Order.")) + purchase_orders = [] for supplier in suppliers: doc = get_mapped_doc("Sales Order", source_name, { "Sales Order": { @@ -872,7 +874,9 @@ def make_purchase_order_for_default_supplier(source_name, selected_items=None, t doc.insert() frappe.db.commit() - return doc + purchase_orders.append(doc) + + return purchase_orders @frappe.whitelist() def make_purchase_order(source_name, selected_items=None, target_doc=None): diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py index ee16f44171..e10e5d0706 100644 --- a/erpnext/selling/doctype/sales_order/test_sales_order.py +++ b/erpnext/selling/doctype/sales_order/test_sales_order.py @@ -743,7 +743,7 @@ class TestSalesOrder(unittest.TestCase): so = make_sales_order(item_list=so_items, do_not_submit=True) so.submit() - po = make_purchase_order_for_default_supplier(so.name, selected_items=[so_items[0]]) + po = make_purchase_order_for_default_supplier(so.name, selected_items=[so_items[0]])[0] po.submit() dn = create_dn_against_so(so.name, delivered_qty=2) @@ -825,7 +825,7 @@ class TestSalesOrder(unittest.TestCase): so.submit() # create po for only one item - po1 = make_purchase_order_for_default_supplier(so.name, selected_items=[so_items[0]]) + po1 = make_purchase_order_for_default_supplier(so.name, selected_items=[so_items[0]])[0] po1.submit() self.assertEqual(so.customer, po1.customer) @@ -835,7 +835,7 @@ class TestSalesOrder(unittest.TestCase): self.assertEqual(len(po1.items), 1) # create po for remaining item - po2 = make_purchase_order_for_default_supplier(so.name, selected_items=[so_items[1]]) + po2 = make_purchase_order_for_default_supplier(so.name, selected_items=[so_items[1]])[0] po2.submit() # teardown @@ -846,6 +846,45 @@ class TestSalesOrder(unittest.TestCase): so.load_from_db() so.cancel() + def test_drop_shipping_full_for_default_suppliers(self): + """Test if multiple POs are generated in one go against different default suppliers.""" + from erpnext.selling.doctype.sales_order.sales_order import make_purchase_order_for_default_supplier + + if not frappe.db.exists("Item", "_Test Item for Drop Shipping 1"): + po_item1 = make_item("_Test Item for Drop Shipping 1", {"is_stock_item": 1, "delivered_by_supplier": 1}) + + if not frappe.db.exists("Item", "_Test Item for Drop Shipping 2"): + po_item2 = make_item("_Test Item for Drop Shipping 2", {"is_stock_item": 1, "delivered_by_supplier": 1}) + + so_items = [ + { + "item_code": "_Test Item for Drop Shipping 1", + "warehouse": "", + "qty": 2, + "rate": 400, + "delivered_by_supplier": 1, + "supplier": '_Test Supplier' + }, + { + "item_code": "_Test Item for Drop Shipping 2", + "warehouse": "", + "qty": 2, + "rate": 400, + "delivered_by_supplier": 1, + "supplier": '_Test Supplier 1' + } + ] + + # create so and po + so = make_sales_order(item_list=so_items, do_not_submit=True) + so.submit() + + purchase_orders = make_purchase_order_for_default_supplier(so.name, selected_items=so_items) + + self.assertEqual(len(purchase_orders), 2) + self.assertEqual(purchase_orders[0].supplier, '_Test Supplier') + self.assertEqual(purchase_orders[1].supplier, '_Test Supplier 1') + def test_reserved_qty_for_closing_so(self): bin = frappe.get_all("Bin", filters={"item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC"}, fields=["reserved_qty"]) From 1b903e39c8a9bf57ed07c55ab9f64df743a3495a Mon Sep 17 00:00:00 2001 From: marination Date: Fri, 12 Mar 2021 14:24:09 +0530 Subject: [PATCH 368/449] fix: Sider (unused variables) --- erpnext/selling/doctype/sales_order/test_sales_order.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py index e10e5d0706..b636a944d1 100644 --- a/erpnext/selling/doctype/sales_order/test_sales_order.py +++ b/erpnext/selling/doctype/sales_order/test_sales_order.py @@ -851,10 +851,10 @@ class TestSalesOrder(unittest.TestCase): from erpnext.selling.doctype.sales_order.sales_order import make_purchase_order_for_default_supplier if not frappe.db.exists("Item", "_Test Item for Drop Shipping 1"): - po_item1 = make_item("_Test Item for Drop Shipping 1", {"is_stock_item": 1, "delivered_by_supplier": 1}) + make_item("_Test Item for Drop Shipping 1", {"is_stock_item": 1, "delivered_by_supplier": 1}) if not frappe.db.exists("Item", "_Test Item for Drop Shipping 2"): - po_item2 = make_item("_Test Item for Drop Shipping 2", {"is_stock_item": 1, "delivered_by_supplier": 1}) + make_item("_Test Item for Drop Shipping 2", {"is_stock_item": 1, "delivered_by_supplier": 1}) so_items = [ { From 59bff8a2f1a8e85def579772e1575070c9d34db6 Mon Sep 17 00:00:00 2001 From: marination Date: Wed, 31 Mar 2021 12:27:57 +0530 Subject: [PATCH 369/449] fix: Test - Preserve order of supplier list while removing duplicates - Dont use list of set, but list of dict with unique keys --- erpnext/selling/doctype/sales_order/sales_order.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index b5c5e1bc2f..af3d461960 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -821,10 +821,10 @@ def make_purchase_order_for_default_supplier(source_name, selected_items=None, t target.stock_qty = (flt(source.stock_qty) - flt(source.ordered_qty)) target.project = source_parent.project - suppliers = [item.get('supplier') for item in selected_items if item.get('supplier') and item.get('supplier')] - suppliers = list(set(suppliers)) + suppliers = [item.get('supplier') for item in selected_items if item.get('supplier')] + suppliers = list(dict.fromkeys(suppliers)) # remove duplicates while preserving order - items_to_map = [item.get('item_code') for item in selected_items if item.get('item_code') and item.get('item_code')] + items_to_map = [item.get('item_code') for item in selected_items if item.get('item_code')] items_to_map = list(set(items_to_map)) if not suppliers: From df1ef6f8e5d8efd5da31bb2979877592f80f8d34 Mon Sep 17 00:00:00 2001 From: Saqib Date: Wed, 31 Mar 2021 14:23:09 +0530 Subject: [PATCH 370/449] fix: make round off GLE always non-opening (#25087) --- erpnext/accounts/general_ledger.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index b42c0c61d9..dac0c216c8 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -196,7 +196,7 @@ def make_round_off_gle(gl_map, debit_credit_diff, precision): if not round_off_gle: for k in ["voucher_type", "voucher_no", "company", - "posting_date", "remarks", "is_opening"]: + "posting_date", "remarks"]: round_off_gle[k] = gl_map[0][k] round_off_gle.update({ @@ -208,6 +208,7 @@ def make_round_off_gle(gl_map, debit_credit_diff, precision): "cost_center": round_off_cost_center, "party_type": None, "party": None, + "is_opening": "No", "against_voucher_type": None, "against_voucher": None }) From f239dbdd030f83f9b0781be138d1ca15c6db6c72 Mon Sep 17 00:00:00 2001 From: Saqib Date: Wed, 31 Mar 2021 15:15:29 +0530 Subject: [PATCH 371/449] feat: tax collected at source using tax withholding category (#25090) * refactor: tax withholding category against customer * feat: pan and tax withholding category fields for customer * fix: test * feat: charging tcs on sales invoice * fix: tcs chargable amount * fix: tcs amount calculation * fix: sider --- .../doctype/sales_invoice/sales_invoice.py | 29 ++ .../tax_withholding_category.py | 400 ++++++++++++------ .../test_tax_withholding_category.py | 137 +++++- .../selling/doctype/customer/customer.json | 19 +- 4 files changed, 444 insertions(+), 141 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 903a2ef5f7..1893c71dfc 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -23,6 +23,7 @@ from erpnext.accounts.doctype.loyalty_program.loyalty_program import \ from erpnext.accounts.deferred_revenue import validate_service_stop_date from frappe.model.utils import get_fetch_values from frappe.contacts.doctype.address.address import get_address_display +from erpnext.accounts.doctype.tax_withholding_category.tax_withholding_category import get_party_tax_withholding_details from erpnext.healthcare.utils import manage_invoice_submit_cancel @@ -75,6 +76,8 @@ class SalesInvoice(SellingController): if not self.is_pos: self.so_dn_required() + + self.set_tax_withholding() self.validate_proj_cust() self.validate_pos_return() @@ -153,6 +156,32 @@ class SalesInvoice(SellingController): if cost_center_company != self.company: frappe.throw(_("Row #{0}: Cost Center {1} does not belong to company {2}").format(frappe.bold(item.idx), frappe.bold(item.cost_center), frappe.bold(self.company))) + def set_tax_withholding(self): + tax_withholding_details = get_party_tax_withholding_details(self) + + if not tax_withholding_details: + return + + accounts = [] + tax_withholding_account = tax_withholding_details.get("account_head") + + for d in self.taxes: + if d.account_head == tax_withholding_account: + d.update(tax_withholding_details) + accounts.append(d.account_head) + + if not accounts or tax_withholding_account not in accounts: + self.append("taxes", tax_withholding_details) + + to_remove = [d for d in self.taxes + if not d.tax_amount and d.charge_type == "Actual" and d.account_head == tax_withholding_account] + + for d in to_remove: + self.remove(d) + + # calculate totals again after applying TDS + self.calculate_taxes_and_totals() + def before_save(self): set_account_for_mode_of_payment(self) diff --git a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py index 32ad4cb03a..961bdb147f 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py @@ -12,37 +12,62 @@ from erpnext.accounts.utils import get_fiscal_year class TaxWithholdingCategory(Document): pass -def get_party_tax_withholding_details(ref_doc, tax_withholding_category=None): +def get_party_details(inv): + party_type, party = '', '' + if inv.doctype == 'Sales Invoice': + party_type = 'Customer' + party = inv.customer + else: + party_type = 'Supplier' + party = inv.supplier + + return party_type, party + +def get_party_tax_withholding_details(inv, tax_withholding_category=None): pan_no = '' - suppliers = [] + parties = [] + party_type, party = get_party_details(inv) if not tax_withholding_category: - tax_withholding_category, pan_no = frappe.db.get_value('Supplier', ref_doc.supplier, ['tax_withholding_category', 'pan']) + tax_withholding_category, pan_no = frappe.db.get_value(party_type, party, ['tax_withholding_category', 'pan']) if not tax_withholding_category: return + # if tax_withholding_category passed as an argument but not pan_no if not pan_no: - pan_no = frappe.db.get_value('Supplier', ref_doc.supplier, 'pan') + pan_no = frappe.db.get_value(party_type, party, 'pan') # Get others suppliers with the same PAN No if pan_no: - suppliers = [d.name for d in frappe.get_all('Supplier', fields=['name'], filters={'pan': pan_no})] + parties = frappe.get_all(party_type, filters={ 'pan': pan_no }, pluck='name') - if not suppliers: - suppliers.append(ref_doc.supplier) + if not parties: + parties.append(party) + + fiscal_year = get_fiscal_year(inv.posting_date, company=inv.company) + tax_details = get_tax_withholding_details(tax_withholding_category, fiscal_year[0], inv.company) - fy = get_fiscal_year(ref_doc.posting_date, company=ref_doc.company) - tax_details = get_tax_withholding_details(tax_withholding_category, fy[0], ref_doc.company) if not tax_details: frappe.throw(_('Please set associated account in Tax Withholding Category {0} against Company {1}') - .format(tax_withholding_category, ref_doc.company)) + .format(tax_withholding_category, inv.company)) - tds_amount = get_tds_amount(suppliers, ref_doc.net_total, ref_doc.company, - tax_details, fy, ref_doc.posting_date, pan_no) + if party_type == 'Customer' and not tax_details.cumulative_threshold: + # TCS is only chargeable on sum of invoiced value + frappe.throw(_('Tax Withholding Category {} against Company {} for Customer {} should have Cumulative Threshold value.') + .format(tax_withholding_category, inv.company, party)) - tax_row = get_tax_row(tax_details, tds_amount) + tax_amount, tax_deducted = get_tax_amount( + party_type, parties, + inv, tax_details, + fiscal_year, pan_no + ) + + if party_type == 'Supplier': + tax_row = get_tax_row_for_tds(tax_details, tax_amount) + else: + tax_row = get_tax_row_for_tcs(inv, tax_details, tax_amount, tax_deducted) return tax_row @@ -69,147 +94,254 @@ def get_tax_withholding_rates(tax_withholding, fiscal_year): frappe.throw(_("No Tax Withholding data found for the current Fiscal Year.")) -def get_tax_row(tax_details, tds_amount): - - return { +def get_tax_row_for_tcs(inv, tax_details, tax_amount, tax_deducted): + row = { "category": "Total", - "add_deduct_tax": "Deduct", "charge_type": "Actual", - "account_head": tax_details.account_head, + "tax_amount": tax_amount, "description": tax_details.description, - "tax_amount": tds_amount + "account_head": tax_details.account_head } -def get_tds_amount(suppliers, net_total, company, tax_details, fiscal_year_details, posting_date, pan_no=None): - fiscal_year, year_start_date, year_end_date = fiscal_year_details - tds_amount = 0 - tds_deducted = 0 + if tax_deducted: + # TCS already deducted on previous invoices + # So, TCS will be calculated by 'Previous Row Total' - def _get_tds(amount, rate): - if amount <= 0: - return 0 - - return amount * rate / 100 - - ldc_name = frappe.db.get_value('Lower Deduction Certificate', - { - 'pan_no': pan_no, - 'fiscal_year': fiscal_year - }, 'name') - ldc = '' - - if ldc_name: - ldc = frappe.get_doc('Lower Deduction Certificate', ldc_name) - - entries = frappe.db.sql(""" - select voucher_no, credit - from `tabGL Entry` - where company = %s and - party in %s and fiscal_year=%s and credit > 0 - and is_opening = 'No' - """, (company, tuple(suppliers), fiscal_year), as_dict=1) - - vouchers = [d.voucher_no for d in entries] - advance_vouchers = get_advance_vouchers(suppliers, fiscal_year=fiscal_year, company=company) - - tds_vouchers = vouchers + advance_vouchers - - if tds_vouchers: - tds_deducted = frappe.db.sql(""" - SELECT sum(credit) FROM `tabGL Entry` - WHERE - account=%s and fiscal_year=%s and credit > 0 - and voucher_no in ({0})""". format(','.join(['%s'] * len(tds_vouchers))), - ((tax_details.account_head, fiscal_year) + tuple(tds_vouchers))) - - tds_deducted = tds_deducted[0][0] if tds_deducted and tds_deducted[0][0] else 0 - - if tds_deducted: - if ldc: - limit_consumed = frappe.db.get_value('Purchase Invoice', - { - 'supplier': ('in', suppliers), - 'apply_tds': 1, - 'docstatus': 1 - }, 'sum(net_total)') - - if ldc and is_valid_certificate(ldc.valid_from, ldc.valid_upto, posting_date, limit_consumed, net_total, - ldc.certificate_limit): - - tds_amount = get_ltds_amount(net_total, limit_consumed, ldc.certificate_limit, ldc.rate, tax_details) + taxes_excluding_tcs = [d for d in inv.taxes if d.account_head != tax_details.account_head] + if taxes_excluding_tcs: + # chargeable amount is the total amount after other charges are applied + row.update({ + "charge_type": "On Previous Row Total", + "row_id": len(taxes_excluding_tcs), + "rate": tax_details.rate + }) else: - tds_amount = _get_tds(net_total, tax_details.rate) - else: - supplier_credit_amount = frappe.get_all('Purchase Invoice', - fields = ['sum(net_total)'], - filters = {'name': ('in', vouchers), 'docstatus': 1, "apply_tds": 1}, as_list=1) + # if only TCS is to be charged, then net total is chargeable amount + row.update({ + "charge_type": "On Net Total", + "rate": tax_details.rate + }) - supplier_credit_amount = (supplier_credit_amount[0][0] - if supplier_credit_amount and supplier_credit_amount[0][0] else 0) + return row - jv_supplier_credit_amt = frappe.get_all('Journal Entry Account', - fields = ['sum(credit_in_account_currency)'], - filters = { - 'parent': ('in', vouchers), 'docstatus': 1, - 'party': ('in', suppliers), - 'reference_type': ('not in', ['Purchase Invoice']) - }, as_list=1) +def get_tax_row_for_tds(tax_details, tax_amount): + return { + "category": "Total", + "charge_type": "Actual", + "tax_amount": tax_amount, + "add_deduct_tax": "Deduct", + "description": tax_details.description, + "account_head": tax_details.account_head + } - supplier_credit_amount += (jv_supplier_credit_amt[0][0] - if jv_supplier_credit_amt and jv_supplier_credit_amt[0][0] else 0) +def get_lower_deduction_certificate(fiscal_year, pan_no): + ldc_name = frappe.db.get_value('Lower Deduction Certificate', { 'pan_no': pan_no, 'fiscal_year': fiscal_year }, 'name') + if ldc_name: + return frappe.get_doc('Lower Deduction Certificate', ldc_name) - supplier_credit_amount += net_total +def get_tax_amount(party_type, parties, inv, tax_details, fiscal_year_details, pan_no=None): + fiscal_year = fiscal_year_details[0] - debit_note_amount = get_debit_note_amount(suppliers, year_start_date, year_end_date) - supplier_credit_amount -= debit_note_amount + vouchers = get_invoice_vouchers(parties, fiscal_year, inv.company, party_type=party_type) + advance_vouchers = get_advance_vouchers(parties, fiscal_year, inv.company, party_type=party_type) + taxable_vouchers = vouchers + advance_vouchers - if ((tax_details.get('threshold', 0) and supplier_credit_amount >= tax_details.threshold) - or (tax_details.get('cumulative_threshold', 0) and supplier_credit_amount >= tax_details.cumulative_threshold)): + tax_deducted = 0 + if taxable_vouchers: + tax_deducted = get_deducted_tax(taxable_vouchers, fiscal_year, tax_details) - if ldc and is_valid_certificate(ldc.valid_from, ldc.valid_upto, posting_date, tds_deducted, net_total, - ldc.certificate_limit): - tds_amount = get_ltds_amount(supplier_credit_amount, 0, ldc.certificate_limit, ldc.rate, - tax_details) + tax_amount = 0 + posting_date = inv.posting_date + if party_type == 'Supplier': + ldc = get_lower_deduction_certificate(fiscal_year, pan_no) + if tax_deducted: + net_total = inv.net_total + if ldc: + tax_amount = get_tds_amount_from_ldc(ldc, parties, fiscal_year, pan_no, tax_details, posting_date, net_total) else: - tds_amount = _get_tds(supplier_credit_amount, tax_details.rate) + tax_amount = net_total * tax_details.rate / 100 if net_total > 0 else 0 + else: + tax_amount = get_tds_amount( + ldc, parties, inv, tax_details, + fiscal_year_details, tax_deducted, vouchers + ) + + elif party_type == 'Customer': + if tax_deducted: + # if already TCS is charged, then amount will be calculated based on 'Previous Row Total' + tax_amount = 0 + else: + # if no TCS has been charged in FY, + # then chargeable value is "prev invoices + advances" value which cross the threshold + tax_amount = get_tcs_amount( + parties, inv, tax_details, + fiscal_year_details, vouchers, advance_vouchers + ) + + return tax_amount, tax_deducted + +def get_invoice_vouchers(parties, fiscal_year, company, party_type='Supplier'): + dr_or_cr = 'credit' if party_type == 'Supplier' else 'debit' + + filters = { + dr_or_cr: ['>', 0], + 'company': company, + 'party_type': party_type, + 'party': ['in', parties], + 'fiscal_year': fiscal_year, + 'is_opening': 'No', + 'is_cancelled': 0 + } + + return frappe.get_all('GL Entry', filters=filters, distinct=1, pluck="voucher_no") or [""] + +def get_advance_vouchers(parties, fiscal_year=None, company=None, from_date=None, to_date=None, party_type='Supplier'): + # for advance vouchers, debit and credit is reversed + dr_or_cr = 'debit' if party_type == 'Supplier' else 'credit' + + filters = { + dr_or_cr: ['>', 0], + 'is_opening': 'No', + 'is_cancelled': 0, + 'party_type': party_type, + 'party': ['in', parties], + 'against_voucher': ['is', 'not set'] + } + + if fiscal_year: + filters['fiscal_year'] = fiscal_year + if company: + filters['company'] = company + if from_date and to_date: + filters['posting_date'] = ['between', (from_date, to_date)] + + return frappe.get_all('GL Entry', filters=filters, distinct=1, pluck='voucher_no') or [""] + +def get_deducted_tax(taxable_vouchers, fiscal_year, tax_details): + # check if TDS / TCS account is already charged on taxable vouchers + filters = { + 'is_cancelled': 0, + 'credit': ['>', 0], + 'fiscal_year': fiscal_year, + 'account': tax_details.account_head, + 'voucher_no': ['in', taxable_vouchers], + } + field = "sum(credit)" + + return frappe.db.get_value('GL Entry', filters, field) or 0.0 + +def get_tds_amount(ldc, parties, inv, tax_details, fiscal_year_details, tax_deducted, vouchers): + tds_amount = 0 + + supp_credit_amt = frappe.db.get_value('Purchase Invoice', { + 'name': ('in', vouchers), 'docstatus': 1, 'apply_tds': 1 + }, 'sum(net_total)') or 0.0 + + supp_jv_credit_amt = frappe.db.get_value('Journal Entry Account', { + 'parent': ('in', vouchers), 'docstatus': 1, + 'party': ('in', parties), 'reference_type': ('!=', 'Purchase Invoice') + }, 'sum(credit_in_account_currency)') or 0.0 + + supp_credit_amt += supp_jv_credit_amt + supp_credit_amt += inv.net_total + + debit_note_amount = get_debit_note_amount(parties, fiscal_year_details, inv.company) + supp_credit_amt -= debit_note_amount + + threshold = tax_details.get('threshold', 0) + cumulative_threshold = tax_details.get('cumulative_threshold', 0) + + if ((threshold and supp_credit_amt >= threshold) or (cumulative_threshold and supp_credit_amt >= cumulative_threshold)): + if ldc and is_valid_certificate( + ldc.valid_from, ldc.valid_upto, + inv.posting_date, tax_deducted, + inv.net_total, ldc.certificate_limit + ): + tds_amount = get_ltds_amount(supp_credit_amt, 0, ldc.certificate_limit, ldc.rate, tax_details) + else: + tds_amount = supp_credit_amt * tax_details.rate / 100 if supp_credit_amt > 0 else 0 return tds_amount -def get_advance_vouchers(suppliers, fiscal_year=None, company=None, from_date=None, to_date=None): - condition = "fiscal_year=%s" % fiscal_year +def get_tcs_amount(parties, inv, tax_details, fiscal_year_details, vouchers, adv_vouchers): + tcs_amount = 0 + fiscal_year, _, _ = fiscal_year_details + + # sum of debit entries made from sales invoices + invoiced_amt = frappe.db.get_value('GL Entry', { + 'is_cancelled': 0, + 'party': ['in', parties], + 'company': inv.company, + 'voucher_no': ['in', vouchers], + }, 'sum(debit)') or 0.0 + + # sum of credit entries made from PE / JV with unset 'against voucher' + advance_amt = frappe.db.get_value('GL Entry', { + 'is_cancelled': 0, + 'party': ['in', parties], + 'company': inv.company, + 'voucher_no': ['in', adv_vouchers], + }, 'sum(credit)') or 0.0 + + # sum of credit entries made from sales invoice + credit_note_amt = frappe.db.get_value('GL Entry', { + 'is_cancelled': 0, + 'credit': ['>', 0], + 'party': ['in', parties], + 'fiscal_year': fiscal_year, + 'company': inv.company, + 'voucher_type': 'Sales Invoice', + }, 'sum(credit)') or 0.0 + + cumulative_threshold = tax_details.get('cumulative_threshold', 0) + + current_invoice_total = get_invoice_total_without_tcs(inv, tax_details) + total_invoiced_amt = current_invoice_total + invoiced_amt + advance_amt - credit_note_amt + + if ((cumulative_threshold and total_invoiced_amt >= cumulative_threshold)): + chargeable_amt = total_invoiced_amt - cumulative_threshold + tcs_amount = chargeable_amt * tax_details.rate / 100 if chargeable_amt > 0 else 0 + + return tcs_amount + +def get_invoice_total_without_tcs(inv, tax_details): + tcs_tax_row = [d for d in inv.taxes if d.account_head == tax_details.account_head] + tcs_tax_row_amount = tcs_tax_row[0].base_tax_amount if tcs_tax_row else 0 + + return inv.grand_total - tcs_tax_row_amount + +def get_tds_amount_from_ldc(ldc, parties, fiscal_year, pan_no, tax_details, posting_date, net_total): + tds_amount = 0 + limit_consumed = frappe.db.get_value('Purchase Invoice', { + 'supplier': ('in', parties), + 'apply_tds': 1, + 'docstatus': 1 + }, 'sum(net_total)') + + if is_valid_certificate( + ldc.valid_from, ldc.valid_upto, + posting_date, limit_consumed, + net_total, ldc.certificate_limit + ): + tds_amount = get_ltds_amount(net_total, limit_consumed, ldc.certificate_limit, ldc.rate, tax_details) + + return tds_amount + +def get_debit_note_amount(suppliers, fiscal_year_details, company=None): + _, year_start_date, year_end_date = fiscal_year_details + + filters = { + 'supplier': ['in', suppliers], + 'is_return': 1, + 'docstatus': 1, + 'posting_date': ['between', (year_start_date, year_end_date)] + } + fields = ['abs(sum(net_total)) as net_total'] if company: - condition += "and company =%s" % (company) - if from_date and to_date: - condition += "and posting_date between %s and %s" % (from_date, to_date) + filters['company'] = company - ## Appending the same supplier again if length of suppliers list is 1 - ## since tuple of single element list contains None, For example ('Test Supplier 1', ) - ## and the below query fails - if len(suppliers) == 1: - suppliers.append(suppliers[0]) - - return frappe.db.sql_list(""" - select distinct voucher_no - from `tabGL Entry` - where party in %s and %s and debit > 0 - and is_opening = 'No' - """, (tuple(suppliers), condition)) or [] - -def get_debit_note_amount(suppliers, year_start_date, year_end_date, company=None): - condition = "and 1=1" - if company: - condition = " and company=%s " % company - - if len(suppliers) == 1: - suppliers.append(suppliers[0]) - - return flt(frappe.db.sql(""" - select abs(sum(net_total)) - from `tabPurchase Invoice` - where supplier in %s and is_return=1 and docstatus=1 - and posting_date between %s and %s %s - """, (tuple(suppliers), year_start_date, year_end_date, condition))) + return frappe.get_all('Purchase Invoice', filters, fields)[0].get('net_total') or 0.0 def get_ltds_amount(current_amount, deducted_amount, certificate_limit, rate, tax_details): if current_amount < (certificate_limit - deducted_amount): @@ -227,4 +359,4 @@ def is_valid_certificate(valid_from, valid_upto, posting_date, deducted_amount, certificate_limit > deducted_amount): valid = True - return valid \ No newline at end of file + return valid diff --git a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py index ef77674372..9ce8e3fe83 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py @@ -9,7 +9,7 @@ from frappe.utils import today from erpnext.accounts.utils import get_fiscal_year from erpnext.buying.doctype.supplier.test_supplier import create_supplier -test_dependencies = ["Supplier Group"] +test_dependencies = ["Supplier Group", "Customer Group"] class TestTaxWithholdingCategory(unittest.TestCase): @classmethod @@ -18,6 +18,9 @@ class TestTaxWithholdingCategory(unittest.TestCase): create_records() create_tax_with_holding_category() + def tearDown(self): + cancel_invoices() + def test_cumulative_threshold_tds(self): frappe.db.set_value("Supplier", "Test TDS Supplier", "tax_withholding_category", "Cumulative Threshold TDS") invoices = [] @@ -128,9 +131,59 @@ class TestTaxWithholdingCategory(unittest.TestCase): for d in invoices: d.cancel() + def test_cumulative_threshold_tcs(self): + frappe.db.set_value("Customer", "Test TCS Customer", "tax_withholding_category", "Cumulative Threshold TCS") + invoices = [] + + # create invoices for lower than single threshold tax rate + for _ in range(2): + si = create_sales_invoice(customer = "Test TCS Customer") + si.submit() + invoices.append(si) + + # create another invoice whose total when added to previously created invoice, + # surpasses cumulative threshhold + si = create_sales_invoice(customer = "Test TCS Customer", rate=12000) + si.submit() + + # assert tax collection on total invoice amount created until now + tcs_charged = sum([d.base_tax_amount for d in si.taxes if d.account_head == 'TCS - _TC']) + self.assertEqual(tcs_charged, 200) + self.assertEqual(si.grand_total, 12200) + invoices.append(si) + + # TCS is already collected once, so going forward system will collect TCS on every invoice + si = create_sales_invoice(customer = "Test TCS Customer", rate=5000) + si.submit() + + tcs_charged = sum([d.base_tax_amount for d in si.taxes if d.account_head == 'TCS - _TC']) + self.assertEqual(tcs_charged, 500) + invoices.append(si) + + #delete invoices to avoid clashing + for d in invoices: + d.cancel() + +def cancel_invoices(): + purchase_invoices = frappe.get_all("Purchase Invoice", { + 'supplier': ['in', ['Test TDS Supplier', 'Test TDS Supplier1', 'Test TDS Supplier2']], + 'docstatus': 1 + }, pluck="name") + + sales_invoices = frappe.get_all("Sales Invoice", { + 'customer': 'Test TCS Customer', + 'docstatus': 1 + }, pluck="name") + + for d in purchase_invoices: + frappe.get_doc('Purchase Invoice', d).cancel() + + for d in sales_invoices: + frappe.get_doc('Sales Invoice', d).cancel() + def create_purchase_invoice(**args): # return sales invoice doc object - item = frappe.get_doc('Item', {'item_name': 'TDS Item'}) + item = frappe.db.get_value('Item', {'item_name': 'TDS Item'}, "name") args = frappe._dict(args) pi = frappe.get_doc({ @@ -145,7 +198,7 @@ def create_purchase_invoice(**args): "taxes": [], "items": [{ 'doctype': 'Purchase Invoice Item', - 'item_code': item.name, + 'item_code': item, 'qty': args.qty or 1, 'rate': args.rate or 10000, 'cost_center': 'Main - _TC', @@ -156,6 +209,33 @@ def create_purchase_invoice(**args): pi.save() return pi +def create_sales_invoice(**args): + # return sales invoice doc object + item = frappe.db.get_value('Item', {'item_name': 'TCS Item'}, "name") + + args = frappe._dict(args) + si = frappe.get_doc({ + "doctype": "Sales Invoice", + "posting_date": today(), + "customer": args.customer, + "company": '_Test Company', + "taxes_and_charges": "", + "currency": "INR", + "debit_to": "Debtors - _TC", + "taxes": [], + "items": [{ + 'doctype': 'Sales Invoice Item', + 'item_code': item, + 'qty': args.qty or 1, + 'rate': args.rate or 10000, + 'cost_center': 'Main - _TC', + 'expense_account': 'Cost of Goods Sold - _TC' + }] + }) + + si.save() + return si + def create_records(): # create a new suppliers for name in ['Test TDS Supplier', 'Test TDS Supplier1', 'Test TDS Supplier2']: @@ -168,7 +248,17 @@ def create_records(): "doctype": "Supplier", }).insert() - # create an item + for name in ['Test TCS Customer']: + if frappe.db.exists('Customer', name): + continue + + frappe.get_doc({ + "customer_group": "_Test Customer Group", + "customer_name": name, + "doctype": "Customer" + }).insert() + + # create item if not frappe.db.exists('Item', "TDS Item"): frappe.get_doc({ "doctype": "Item", @@ -178,7 +268,16 @@ def create_records(): "is_stock_item": 0, }).insert() - # create an account + if not frappe.db.exists('Item', "TCS Item"): + frappe.get_doc({ + "doctype": "Item", + "item_code": "TCS Item", + "item_name": "TCS Item", + "item_group": "All Item Groups", + "is_stock_item": 1 + }).insert() + + # create tds account if not frappe.db.exists("Account", "TDS - _TC"): frappe.get_doc({ 'doctype': 'Account', @@ -189,6 +288,17 @@ def create_records(): 'root_type': 'Asset' }).insert() + # create tcs account + if not frappe.db.exists("Account", "TCS - _TC"): + frappe.get_doc({ + 'doctype': 'Account', + 'company': '_Test Company', + 'account_name': 'TCS', + 'parent_account': 'Duties and Taxes - _TC', + 'report_type': 'Balance Sheet', + 'root_type': 'Liability' + }).insert() + def create_tax_with_holding_category(): fiscal_year = get_fiscal_year(today(), company="_Test Company")[0] @@ -210,6 +320,23 @@ def create_tax_with_holding_category(): }] }).insert() + if not frappe.db.exists("Tax Withholding Category", "Cumulative Threshold TCS"): + frappe.get_doc({ + "doctype": "Tax Withholding Category", + "name": "Cumulative Threshold TCS", + "category_name": "10% TCS", + "rates": [{ + 'fiscal_year': fiscal_year, + 'tax_withholding_rate': 10, + 'single_threshold': 0, + 'cumulative_threshold': 30000.00 + }], + "accounts": [{ + 'company': '_Test Company', + 'account': 'TCS - _TC' + }] + }).insert() + # Single thresold if not frappe.db.exists("Tax Withholding Category", "Single Threshold TDS"): frappe.get_doc({ diff --git a/erpnext/selling/doctype/customer/customer.json b/erpnext/selling/doctype/customer/customer.json index 557c7151d9..8fb3580747 100644 --- a/erpnext/selling/doctype/customer/customer.json +++ b/erpnext/selling/doctype/customer/customer.json @@ -16,6 +16,8 @@ "customer_name", "gender", "customer_type", + "pan", + "tax_withholding_category", "default_bank_account", "lead_name", "image", @@ -210,7 +212,8 @@ "fieldtype": "Link", "ignore_user_permissions": 1, "label": "Represents Company", - "options": "Company" + "options": "Company", + "unique": 1 }, { "depends_on": "represents_company", @@ -479,13 +482,25 @@ "fieldname": "dn_required", "fieldtype": "Check", "label": "Allow Sales Invoice Creation Without Delivery Note" + }, + { + "fieldname": "pan", + "fieldtype": "Data", + "label": "PAN" + }, + { + "fieldname": "tax_withholding_category", + "fieldtype": "Link", + "label": "Tax Withholding Category", + "options": "Tax Withholding Category" } ], "icon": "fa fa-user", "idx": 363, "image_field": "image", + "index_web_pages_for_search": 1, "links": [], - "modified": "2020-03-17 11:03:42.706907", + "modified": "2021-01-27 12:54:57.258959", "modified_by": "Administrator", "module": "Selling", "name": "Customer", From 94c145f3c3789a2648347930e5f885e13568ed17 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 31 Mar 2021 15:28:26 +0530 Subject: [PATCH 372/449] fix: can't multiply sequence by non-int of type 'float' --- erpnext/stock/get_item_details.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 70e4c2c40e..e23f7d43d9 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -110,7 +110,7 @@ def get_item_details(args, doc=None, for_validate=False, overwrite_warehouse=Tru get_gross_profit(out) if args.doctype == 'Material Request': out.rate = args.rate or out.price_list_rate - out.amount = flt(args.qty * out.rate) + out.amount = flt(args.qty) * flt(out.rate) return out From 4d0939de8d7a576e2188617c3362cf7b1d521c3b Mon Sep 17 00:00:00 2001 From: Saqib Date: Wed, 31 Mar 2021 15:51:48 +0530 Subject: [PATCH 373/449] feat: introduce parameter group in quality inspection (#25094) * feat: introduce parameter group in quality inspection * chore: make parameter group optional --- .../item_quality_inspection_parameter.json | 11 ++- .../quality_inspection_parameter.json | 12 ++- .../__init__.py | 0 .../quality_inspection_parameter_group.js | 8 ++ .../quality_inspection_parameter_group.json | 82 +++++++++++++++++++ .../quality_inspection_parameter_group.py | 10 +++ ...test_quality_inspection_parameter_group.py | 10 +++ .../quality_inspection_reading.json | 11 ++- 8 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 erpnext/stock/doctype/quality_inspection_parameter_group/__init__.py create mode 100644 erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.js create mode 100644 erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.json create mode 100644 erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.py create mode 100644 erpnext/stock/doctype/quality_inspection_parameter_group/test_quality_inspection_parameter_group.py diff --git a/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json b/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json index 471e6853b5..9b1a47eed6 100644 --- a/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json +++ b/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json @@ -7,6 +7,7 @@ "engine": "InnoDB", "field_order": [ "specification", + "parameter_group", "value", "numeric", "column_break_3", @@ -75,12 +76,20 @@ "in_list_view": 1, "label": "Numeric", "width": "80px" + }, + { + "fetch_from": "specification.parameter_group", + "fieldname": "parameter_group", + "fieldtype": "Link", + "label": "Parameter Group", + "options": "Quality Inspection Parameter Group", + "read_only": 1 } ], "idx": 1, "istable": 1, "links": [], - "modified": "2021-02-01 19:18:46.924399", + "modified": "2021-02-04 18:50:02.056173", "modified_by": "Administrator", "module": "Stock", "name": "Item Quality Inspection Parameter", diff --git a/erpnext/stock/doctype/quality_inspection_parameter/quality_inspection_parameter.json b/erpnext/stock/doctype/quality_inspection_parameter/quality_inspection_parameter.json index 0b5a9b5b3c..418b4825f2 100644 --- a/erpnext/stock/doctype/quality_inspection_parameter/quality_inspection_parameter.json +++ b/erpnext/stock/doctype/quality_inspection_parameter/quality_inspection_parameter.json @@ -7,24 +7,34 @@ "engine": "InnoDB", "field_order": [ "parameter", + "parameter_group", "description" ], "fields": [ { "fieldname": "parameter", "fieldtype": "Data", + "in_list_view": 1, "label": "Parameter", + "reqd": 1, "unique": 1 }, { "fieldname": "description", "fieldtype": "Text Editor", "label": "Description" + }, + { + "fieldname": "parameter_group", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Parameter Group", + "options": "Quality Inspection Parameter Group" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2020-12-28 18:06:54.897317", + "modified": "2021-02-19 20:33:30.657406", "modified_by": "Administrator", "module": "Stock", "name": "Quality Inspection Parameter", diff --git a/erpnext/stock/doctype/quality_inspection_parameter_group/__init__.py b/erpnext/stock/doctype/quality_inspection_parameter_group/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.js b/erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.js new file mode 100644 index 0000000000..8716a29871 --- /dev/null +++ b/erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.js @@ -0,0 +1,8 @@ +// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Quality Inspection Parameter Group', { + // refresh: function(frm) { + + // } +}); diff --git a/erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.json b/erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.json new file mode 100644 index 0000000000..57264741a6 --- /dev/null +++ b/erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.json @@ -0,0 +1,82 @@ +{ + "actions": [], + "autoname": "field:group_name", + "creation": "2021-02-04 18:44:12.223295", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "group_name" + ], + "fields": [ + { + "fieldname": "group_name", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Parameter Group Name", + "reqd": 1, + "unique": 1 + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2021-02-04 18:44:12.223295", + "modified_by": "Administrator", + "module": "Stock", + "name": "Quality Inspection Parameter Group", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Stock User", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Quality Manager", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Manufacturing User", + "share": 1, + "write": 1 + } + ], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.py b/erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.py new file mode 100644 index 0000000000..1a3b1a0463 --- /dev/null +++ b/erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +# import frappe +from frappe.model.document import Document + +class QualityInspectionParameterGroup(Document): + pass diff --git a/erpnext/stock/doctype/quality_inspection_parameter_group/test_quality_inspection_parameter_group.py b/erpnext/stock/doctype/quality_inspection_parameter_group/test_quality_inspection_parameter_group.py new file mode 100644 index 0000000000..212d4b8c21 --- /dev/null +++ b/erpnext/stock/doctype/quality_inspection_parameter_group/test_quality_inspection_parameter_group.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +# import frappe +import unittest + +class TestQualityInspectionParameterGroup(unittest.TestCase): + pass diff --git a/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json b/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json index 35d58eff58..0eff5a8f00 100644 --- a/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json +++ b/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json @@ -7,6 +7,7 @@ "engine": "InnoDB", "field_order": [ "specification", + "parameter_group", "status", "value", "numeric", @@ -210,12 +211,20 @@ "fieldtype": "Check", "in_list_view": 1, "label": "Numeric" + }, + { + "fetch_from": "specification.parameter_group", + "fieldname": "parameter_group", + "fieldtype": "Link", + "label": "Parameter Group", + "options": "Quality Inspection Parameter Group", + "read_only": 1 } ], "idx": 1, "istable": 1, "links": [], - "modified": "2021-02-01 19:46:22.138018", + "modified": "2021-02-04 19:15:37.991221", "modified_by": "Administrator", "module": "Stock", "name": "Quality Inspection Reading", From fb4051bdddac7415eb370ccd8a25418797c0e35c Mon Sep 17 00:00:00 2001 From: Saqib Date: Wed, 31 Mar 2021 15:52:51 +0530 Subject: [PATCH 374/449] feat: discount configuration on early payments (#25089) * feat: discount configuration on early payments Co-authored-by: Nabin Hait * fix: remove duplicate patch call Co-authored-by: Nabin Hait --- .../doctype/payment_entry/payment_entry.js | 42 +- .../doctype/payment_entry/payment_entry.py | 131 ++++- .../payment_entry/test_payment_entry.py | 48 ++ .../payment_entry_reference.json | 5 +- .../payment_schedule/payment_schedule.json | 87 ++- .../doctype/payment_term/payment_term.js | 20 + .../doctype/payment_term/payment_term.json | 512 +++++------------- .../payment_terms_template.js | 7 +- .../payment_terms_template.py | 6 - .../payment_terms_template_detail.json | 420 ++++++-------- .../accounts_receivable.py | 8 +- erpnext/controllers/accounts_controller.py | 23 +- erpnext/patches.txt | 1 + .../v13_0/update_payment_terms_outstanding.py | 15 + erpnext/setup/doctype/company/company.js | 3 +- erpnext/setup/doctype/company/company.json | 7 + 16 files changed, 644 insertions(+), 691 deletions(-) create mode 100644 erpnext/patches/v13_0/update_payment_terms_outstanding.py diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index b5f6a401df..c2e804e441 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -637,13 +637,13 @@ frappe.ui.form.on('Payment Entry', { let to_field = fields[key][1]; if (filters[from_field] && !filters[to_field]) { - frappe.throw(__("Error: {0} is mandatory field", - [to_field.replace(/_/g, " ")] - )); + frappe.throw( + __("Error: {0} is mandatory field", [to_field.replace(/_/g, " ")]) + ); } else if (filters[from_field] && filters[from_field] > filters[to_field]) { - frappe.throw(__("{0}: {1} must be less than {2}", - [key, from_field.replace(/_/g, " "), to_field.replace(/_/g, " ")] - )); + frappe.throw( + __("{0}: {1} must be less than {2}", [key, from_field.replace(/_/g, " "), to_field.replace(/_/g, " ")]) + ); } } }, @@ -692,6 +692,8 @@ frappe.ui.form.on('Payment Entry', { c.total_amount = d.invoice_amount; c.outstanding_amount = d.outstanding_amount; c.bill_no = d.bill_no; + c.payment_term = d.payment_term; + c.allocated_amount = d.allocated_amount; if(!in_list(["Sales Order", "Purchase Order", "Expense Claim", "Fees"], d.voucher_type)) { if(flt(d.outstanding_amount) > 0) @@ -774,12 +776,15 @@ frappe.ui.form.on('Payment Entry', { } else if (in_list(["Customer", "Supplier"], frm.doc.party_type)) { if(paid_amount > total_negative_outstanding) { if(total_negative_outstanding == 0) { - frappe.msgprint(__("Cannot {0} {1} {2} without any negative outstanding invoice", - [frm.doc.payment_type, - (frm.doc.party_type=="Customer" ? "to" : "from"), frm.doc.party_type])); + frappe.msgprint( + __("Cannot {0} {1} {2} without any negative outstanding invoice", [frm.doc.payment_type, + (frm.doc.party_type=="Customer" ? "to" : "from"), frm.doc.party_type]) + ); return false } else { - frappe.msgprint(__("Paid Amount cannot be greater than total negative outstanding amount {0}", [total_negative_outstanding])); + frappe.msgprint( + __("Paid Amount cannot be greater than total negative outstanding amount {0}", [total_negative_outstanding]) + ); return false; } } else { @@ -791,10 +796,13 @@ frappe.ui.form.on('Payment Entry', { } $.each(frm.doc.references || [], function(i, row) { - row.allocated_amount = 0 //If allocate payment amount checkbox is unchecked, set zero to allocate amount - if(frappe.flags.allocate_payment_amount != 0){ - if(row.outstanding_amount > 0 && allocated_positive_outstanding > 0) { - if(row.outstanding_amount >= allocated_positive_outstanding) { + if (frappe.flags.allocate_payment_amount == 0) { + //If allocate payment amount checkbox is unchecked, set zero to allocate amount + row.allocated_amount = 0; + + } else if (frappe.flags.allocate_payment_amount != 0 && !row.allocated_amount) { + if (row.outstanding_amount > 0 && allocated_positive_outstanding > 0) { + if (row.outstanding_amount >= allocated_positive_outstanding) { row.allocated_amount = allocated_positive_outstanding; } else { row.allocated_amount = row.outstanding_amount; @@ -802,9 +810,11 @@ frappe.ui.form.on('Payment Entry', { allocated_positive_outstanding -= flt(row.allocated_amount); } else if (row.outstanding_amount < 0 && allocated_negative_outstanding) { - if(Math.abs(row.outstanding_amount) >= allocated_negative_outstanding) + if (Math.abs(row.outstanding_amount) >= allocated_negative_outstanding) { row.allocated_amount = -1*allocated_negative_outstanding; - else row.allocated_amount = row.outstanding_amount; + } else { + row.allocated_amount = row.outstanding_amount; + }; allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount)); } diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 203d06a41f..c0d53b52dd 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -333,33 +333,50 @@ class PaymentEntry(AccountsController): invoice_payment_amount_map = {} invoice_paid_amount_map = {} - for reference in self.get('references'): - if reference.payment_term and reference.reference_name: - key = (reference.payment_term, reference.reference_name) + for ref in self.get('references'): + if ref.payment_term and ref.reference_name: + key = (ref.payment_term, ref.reference_name) invoice_payment_amount_map.setdefault(key, 0.0) - invoice_payment_amount_map[key] += reference.allocated_amount + invoice_payment_amount_map[key] += ref.allocated_amount if not invoice_paid_amount_map.get(key): - payment_schedule = frappe.get_all('Payment Schedule', filters={'parent': reference.reference_name}, - fields=['paid_amount', 'payment_amount', 'payment_term']) + payment_schedule = frappe.get_all( + 'Payment Schedule', + filters={'parent': ref.reference_name}, + fields=['paid_amount', 'payment_amount', 'payment_term', 'discount', 'outstanding'] + ) for term in payment_schedule: - invoice_key = (term.payment_term, reference.reference_name) + invoice_key = (term.payment_term, ref.reference_name) invoice_paid_amount_map.setdefault(invoice_key, {}) - invoice_paid_amount_map[invoice_key]['outstanding'] = term.payment_amount - term.paid_amount + invoice_paid_amount_map[invoice_key]['outstanding'] = term.outstanding + invoice_paid_amount_map[invoice_key]['discounted_amt'] = ref.total_amount * (term.discount / 100) + + for key, allocated_amount in iteritems(invoice_payment_amount_map): + outstanding = flt(invoice_paid_amount_map.get(key, {}).get('outstanding')) + discounted_amt = flt(invoice_paid_amount_map.get(key, {}).get('discounted_amt')) - for key, amount in iteritems(invoice_payment_amount_map): if cancel: - frappe.db.sql(""" UPDATE `tabPayment Schedule` SET paid_amount = `paid_amount` - %s - WHERE parent = %s and payment_term = %s""", (amount, key[1], key[0])) + frappe.db.sql(""" + UPDATE `tabPayment Schedule` + SET + paid_amount = `paid_amount` - %s, + discounted_amount = `discounted_amount` - %s, + outstanding = `outstanding` + %s + WHERE parent = %s and payment_term = %s""", + (allocated_amount - discounted_amt, discounted_amt, allocated_amount, key[1], key[0])) else: - outstanding = flt(invoice_paid_amount_map.get(key, {}).get('outstanding')) - - if amount > outstanding: + if allocated_amount > outstanding: frappe.throw(_('Cannot allocate more than {0} against payment term {1}').format(outstanding, key[0])) - if amount and outstanding: - frappe.db.sql(""" UPDATE `tabPayment Schedule` SET paid_amount = `paid_amount` + %s - WHERE parent = %s and payment_term = %s""", (amount, key[1], key[0])) + if allocated_amount and outstanding: + frappe.db.sql(""" + UPDATE `tabPayment Schedule` + SET + paid_amount = `paid_amount` + %s, + discounted_amount = `discounted_amount` + %s, + outstanding = `outstanding` - %s + WHERE parent = %s and payment_term = %s""", + (allocated_amount - discounted_amt, discounted_amt, allocated_amount, key[1], key[0])) def set_status(self): if self.docstatus == 2: @@ -704,6 +721,8 @@ def get_outstanding_reference_documents(args): outstanding_invoices = get_outstanding_invoices(args.get("party_type"), args.get("party"), args.get("party_account"), filters=args, condition=condition) + outstanding_invoices = split_invoices_based_on_payment_terms(outstanding_invoices) + for d in outstanding_invoices: d["exchange_rate"] = 1 if party_account_currency != company_currency: @@ -731,6 +750,46 @@ def get_outstanding_reference_documents(args): return data +def split_invoices_based_on_payment_terms(outstanding_invoices): + invoice_ref_based_on_payment_terms = {} + for idx, d in enumerate(outstanding_invoices): + if d.voucher_type in ['Sales Invoice', 'Purchase Invoice']: + payment_term_template = frappe.db.get_value(d.voucher_type, d.voucher_no, 'payment_terms_template') + if payment_term_template: + allocate_payment_based_on_payment_terms = frappe.db.get_value( + 'Payment Terms Template', payment_term_template, 'allocate_payment_based_on_payment_terms') + if allocate_payment_based_on_payment_terms: + payment_schedule = frappe.get_all('Payment Schedule', filters={'parent': d.voucher_no}, fields=["*"]) + + for payment_term in payment_schedule: + if payment_term.outstanding > 0.1: + invoice_ref_based_on_payment_terms.setdefault(idx, []) + invoice_ref_based_on_payment_terms[idx].append(frappe._dict({ + 'due_date': d.due_date, + 'currency': d.currency, + 'voucher_no': d.voucher_no, + 'voucher_type': d.voucher_type, + 'posting_date': d.posting_date, + 'invoice_amount': flt(d.invoice_amount), + 'outstanding_amount': flt(d.outstanding_amount), + 'payment_amount': payment_term.payment_amount, + 'payment_term': payment_term.payment_term, + 'allocated_amount': payment_term.outstanding + })) + + if invoice_ref_based_on_payment_terms: + for idx, ref in invoice_ref_based_on_payment_terms.items(): + voucher_no = outstanding_invoices[idx]['voucher_no'] + voucher_type = outstanding_invoices[idx]['voucher_type'] + + frappe.msgprint(_("Spliting {} {} into {} rows as per payment terms").format( + voucher_type, voucher_no, len(ref)), alert=True) + + outstanding_invoices.pop(idx - 1) + outstanding_invoices += invoice_ref_based_on_payment_terms[idx] + + return outstanding_invoices + def get_orders_to_be_billed(posting_date, party_type, party, company, party_account_currency, company_currency, cost_center=None, filters=None): if party_type == "Customer": @@ -1083,6 +1142,8 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount= paid_amount, received_amount = set_paid_amount_and_received_amount( dt, party_account_currency, bank, outstanding_amount, payment_type, bank_amount, doc) + paid_amount, received_amount, discount_amount = apply_early_payment_discount(paid_amount, received_amount, doc) + pe = frappe.new_doc("Payment Entry") pe.payment_type = payment_type pe.company = doc.company @@ -1152,11 +1213,20 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount= pe.setup_party_account_field() pe.set_missing_values() + if party_account and bank: if dt == "Employee Advance": reference_doc = doc pe.set_exchange_rate(ref_doc=reference_doc) pe.set_amounts() + if discount_amount: + pe.set_gain_or_loss(account_details={ + 'account': frappe.get_cached_value('Company', pe.company, "default_discount_account"), + 'cost_center': pe.cost_center or frappe.get_cached_value('Company', pe.company, "cost_center"), + 'amount': discount_amount * (-1 if payment_type == "Pay" else 1) + }) + pe.set_difference_amount() + return pe def get_bank_cash_account(doc, bank_account): @@ -1272,6 +1342,33 @@ def set_paid_amount_and_received_amount(dt, party_account_currency, bank, outsta paid_amount = received_amount * doc.get('exchange_rate', 1) return paid_amount, received_amount +def apply_early_payment_discount(paid_amount, received_amount, doc): + total_discount = 0 + if doc.doctype in ['Sales Invoice', 'Purchase Invoice'] and doc.payment_schedule: + for term in doc.payment_schedule: + if not term.discounted_amount and term.discount and getdate(nowdate()) <= term.discount_date: + if term.discount_type == 'Percentage': + discount_amount = flt(doc.get('grand_total')) * (term.discount / 100) + else: + discount_amount = term.discount + + discount_amount_in_foreign_currency = discount_amount * doc.get('conversion_rate', 1) + + if doc.doctype == 'Sales Invoice': + paid_amount -= discount_amount + received_amount -= discount_amount_in_foreign_currency + else: + received_amount -= discount_amount + paid_amount -= discount_amount_in_foreign_currency + + total_discount += discount_amount + + if total_discount: + money = frappe.utils.fmt_money(total_discount, currency=doc.get('currency')) + frappe.msgprint(_("Discount of {} applied as per Payment Term").format(money), alert=1) + + return paid_amount, received_amount, total_discount + def get_reference_as_per_payment_terms(payment_schedule, dt, dn, doc, grand_total, outstanding_amount): references = [] for payment_term in payment_schedule: diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py index 772fc1a252..4641d6b5ff 100644 --- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py @@ -193,6 +193,34 @@ class TestPaymentEntry(unittest.TestCase): self.assertEqual(si.payment_schedule[0].paid_amount, 200.0) self.assertEqual(si.payment_schedule[1].paid_amount, 36.0) + def test_payment_entry_against_payment_terms_with_discount(self): + si = create_sales_invoice(do_not_save=1, qty=1, rate=200) + create_payment_terms_template_with_discount() + si.payment_terms_template = 'Test Discount Template' + + frappe.db.set_value('Company', si.company, 'default_discount_account', 'Write Off - _TC') + + si.append('taxes', { + "charge_type": "On Net Total", + "account_head": "_Test Account Service Tax - _TC", + "cost_center": "_Test Cost Center - _TC", + "description": "Service Tax", + "rate": 18 + }) + si.save() + + si.submit() + + pe = get_payment_entry("Sales Invoice", si.name, bank_account="_Test Cash - _TC") + pe.submit() + si.load_from_db() + + self.assertEqual(pe.references[0].payment_term, '30 Credit Days with 10% Discount') + self.assertEqual(si.payment_schedule[0].payment_amount, 236.0) + self.assertEqual(si.payment_schedule[0].paid_amount, 212.40) + self.assertEqual(si.payment_schedule[0].outstanding, 0) + self.assertEqual(si.payment_schedule[0].discounted_amount, 23.6) + def test_payment_against_purchase_invoice_to_check_status(self): pi = make_purchase_invoice(supplier="_Test Supplier USD", debit_to="_Test Payable USD - _TC", @@ -591,6 +619,26 @@ def create_payment_terms_template(): }] }).insert() +def create_payment_terms_template_with_discount(): + + create_payment_term('30 Credit Days with 10% Discount') + + if not frappe.db.exists('Payment Terms Template', 'Test Discount Template'): + payment_term_template = frappe.get_doc({ + 'doctype': 'Payment Terms Template', + 'template_name': 'Test Discount Template', + 'allocate_payment_based_on_payment_terms': 1, + 'terms': [{ + 'doctype': 'Payment Terms Template Detail', + 'payment_term': '30 Credit Days with 10% Discount', + 'invoice_portion': 100, + 'credit_days_based_on': 'Day(s) after invoice date', + 'credit_days': 2, + 'discount': 10, + 'discount_validity_based_on': 'Day(s) after invoice date', + 'discount_validity': 1 + }] + }).insert() def create_payment_term(name): if not frappe.db.exists('Payment Term', name): diff --git a/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.json b/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.json index 8f5e9fbc28..912ad0977a 100644 --- a/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.json +++ b/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.json @@ -58,7 +58,7 @@ "fieldname": "total_amount", "fieldtype": "Float", "in_list_view": 1, - "label": "Total Amount", + "label": "Grand Total", "print_hide": 1, "read_only": 1 }, @@ -92,9 +92,10 @@ "options": "Payment Term" } ], + "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2020-03-13 12:07:19.362539", + "modified": "2021-02-10 11:25:47.144392", "modified_by": "Administrator", "module": "Accounts", "name": "Payment Entry Reference", diff --git a/erpnext/accounts/doctype/payment_schedule/payment_schedule.json b/erpnext/accounts/doctype/payment_schedule/payment_schedule.json index d363cf161b..e362566af0 100644 --- a/erpnext/accounts/doctype/payment_schedule/payment_schedule.json +++ b/erpnext/accounts/doctype/payment_schedule/payment_schedule.json @@ -6,11 +6,23 @@ "engine": "InnoDB", "field_order": [ "payment_term", + "section_break_15", "description", + "section_break_4", "due_date", - "invoice_portion", - "payment_amount", "mode_of_payment", + "column_break_5", + "invoice_portion", + "section_break_6", + "discount_type", + "discount_date", + "column_break_9", + "discount", + "section_break_9", + "payment_amount", + "discounted_amount", + "column_break_3", + "outstanding", "paid_amount" ], "fields": [ @@ -25,6 +37,7 @@ }, { "columns": 2, + "fetch_from": "payment_term.description", "fieldname": "description", "fieldtype": "Small Text", "in_list_view": 1, @@ -62,14 +75,82 @@ "options": "Mode of Payment" }, { + "depends_on": "paid_amount", "fieldname": "paid_amount", "fieldtype": "Currency", "label": "Paid Amount" + }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, + { + "default": "0", + "depends_on": "discounted_amount", + "fieldname": "discounted_amount", + "fieldtype": "Currency", + "label": "Discounted Amount", + "read_only": 1 + }, + { + "fetch_from": "payment_amount", + "fieldname": "outstanding", + "fieldtype": "Currency", + "label": "Outstanding", + "read_only": 1 + }, + { + "fieldname": "column_break_5", + "fieldtype": "Column Break" + }, + { + "depends_on": "discount", + "fieldname": "discount_date", + "fieldtype": "Date", + "label": "Discount Date", + "mandatory_depends_on": "discount" + }, + { + "default": "Percentage", + "fetch_from": "payment_term.discount_type", + "fieldname": "discount_type", + "fieldtype": "Select", + "label": "Discount Type", + "options": "Percentage\nAmount" + }, + { + "fetch_from": "payment_term.discount", + "fieldname": "discount", + "fieldtype": "Float", + "label": "Discount" + }, + { + "fieldname": "section_break_9", + "fieldtype": "Section Break" + }, + { + "collapsible": 1, + "fieldname": "section_break_15", + "fieldtype": "Section Break", + "label": "Description" + }, + { + "fieldname": "section_break_6", + "fieldtype": "Section Break" + }, + { + "fieldname": "column_break_9", + "fieldtype": "Column Break" + }, + { + "fieldname": "section_break_4", + "fieldtype": "Section Break" } ], + "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2020-03-13 17:58:24.729526", + "modified": "2021-02-15 21:03:12.540546", "modified_by": "Administrator", "module": "Accounts", "name": "Payment Schedule", diff --git a/erpnext/accounts/doctype/payment_term/payment_term.js b/erpnext/accounts/doctype/payment_term/payment_term.js index 054c2d1191..acd0144c2e 100644 --- a/erpnext/accounts/doctype/payment_term/payment_term.js +++ b/erpnext/accounts/doctype/payment_term/payment_term.js @@ -1,2 +1,22 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt +frappe.ui.form.on('Payment Term', { + onload(frm) { + frm.trigger('set_dynamic_description'); + }, + discount(frm) { + frm.trigger('set_dynamic_description'); + }, + discount_type(frm) { + frm.trigger('set_dynamic_description'); + }, + set_dynamic_description(frm) { + if (frm.doc.discount) { + let description = __("{0}% of total invoice value will be given as discount.", [frm.doc.discount]); + if (frm.doc.discount_type == 'Amount') { + description = __("{0} will be given as discount.", [fmt_money(frm.doc.discount)]); + } + frm.set_df_property("discount", "description", description); + } + } +}); \ No newline at end of file diff --git a/erpnext/accounts/doctype/payment_term/payment_term.json b/erpnext/accounts/doctype/payment_term/payment_term.json index e77c244d3d..aec4965d79 100644 --- a/erpnext/accounts/doctype/payment_term/payment_term.json +++ b/erpnext/accounts/doctype/payment_term/payment_term.json @@ -1,386 +1,166 @@ { - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 1, - "allow_rename": 1, - "autoname": "field:payment_term_name", - "beta": 0, - "creation": "2017-08-10 15:24:54.876365", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "", - "editable_grid": 1, - "engine": "InnoDB", + "actions": [], + "allow_import": 1, + "allow_rename": 1, + "autoname": "field:payment_term_name", + "creation": "2017-08-10 15:24:54.876365", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "payment_term_name", + "invoice_portion", + "mode_of_payment", + "column_break_3", + "due_date_based_on", + "credit_days", + "credit_months", + "section_break_8", + "discount_type", + "discount", + "column_break_11", + "discount_validity_based_on", + "discount_validity", + "section_break_6", + "description" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 1, - "collapsible": 0, - "columns": 0, - "fieldname": "payment_term_name", - "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Payment Term Name", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "bold": 1, + "fieldname": "payment_term_name", + "fieldtype": "Data", + "label": "Payment Term Name", + "unique": 1 + }, { - "description": "Provide the invoice portion in percent", - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 1, - "collapsible": 0, - "columns": 0, - "fieldname": "invoice_portion", - "fieldtype": "Float", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Invoice Portion", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "bold": 1, + "fieldname": "invoice_portion", + "fieldtype": "Float", + "label": "Invoice Portion (%)" + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "mode_of_payment", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Mode of Payment", - "length": 0, - "no_copy": 0, - "options": "Mode of Payment", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "mode_of_payment", + "fieldtype": "Link", + "label": "Mode of Payment", + "options": "Mode of Payment" + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "column_break_3", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 1, - "collapsible": 0, - "columns": 0, - "fieldname": "due_date_based_on", - "fieldtype": "Select", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Due Date Based On", - "length": 0, - "no_copy": 0, - "options": "Day(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "bold": 1, + "fieldname": "due_date_based_on", + "fieldtype": "Select", + "label": "Due Date Based On", + "options": "Day(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month" + }, { - "description": "Give number of days according to prior selection", - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 1, - "collapsible": 0, - "columns": 0, - "depends_on": "eval:in_list(['Day(s) after invoice date', 'Day(s) after the end of the invoice month'], doc.due_date_based_on)", - "fieldname": "credit_days", - "fieldtype": "Int", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Credit Days", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "bold": 1, + "depends_on": "eval:in_list(['Day(s) after invoice date', 'Day(s) after the end of the invoice month'], doc.due_date_based_on)", + "fieldname": "credit_days", + "fieldtype": "Int", + "label": "Credit Days" + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "depends_on": "eval:doc.due_date_based_on=='Month(s) after the end of the invoice month'", - "fieldname": "credit_months", - "fieldtype": "Int", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Credit Months", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "depends_on": "eval:doc.due_date_based_on=='Month(s) after the end of the invoice month'", + "fieldname": "credit_months", + "fieldtype": "Int", + "label": "Credit Months" + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "section_break_6", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "section_break_6", + "fieldtype": "Section Break" + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 1, - "collapsible": 0, - "columns": 0, - "fieldname": "description", - "fieldtype": "Small Text", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Description", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "bold": 1, + "fieldname": "description", + "fieldtype": "Small Text", + "label": "Description" + }, + { + "fieldname": "section_break_8", + "fieldtype": "Section Break", + "label": "Discount Settings" + }, + { + "default": "Percentage", + "fieldname": "discount_type", + "fieldtype": "Select", + "label": "Discount Type", + "options": "Percentage\nAmount" + }, + { + "fieldname": "discount", + "fieldtype": "Float", + "label": "Discount" + }, + { + "default": "Day(s) after invoice date", + "depends_on": "discount", + "fieldname": "discount_validity_based_on", + "fieldtype": "Select", + "label": "Discount Validity Based On", + "options": "Day(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month" + }, + { + "depends_on": "discount", + "fieldname": "discount_validity", + "fieldtype": "Int", + "label": "Discount Validity", + "mandatory_depends_on": "discount" + }, + { + "fieldname": "column_break_11", + "fieldtype": "Column Break" } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 0, - "max_attachments": 0, - "modified": "2020-10-14 10:47:32.830478", - "modified_by": "Administrator", - "module": "Accounts", - "name": "Payment Term", - "name_case": "", - "owner": "Administrator", + ], + "links": [], + "modified": "2021-02-15 20:30:56.256403", + "modified_by": "Administrator", + "module": "Accounts", + "name": "Payment Term", + "owner": "Administrator", "permissions": [ { - "amend": 0, - "apply_user_permissions": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "System Manager", - "set_user_permissions": 0, - "share": 1, - "submit": 0, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, "write": 1 - }, + }, { - "amend": 0, - "apply_user_permissions": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Accounts Manager", - "set_user_permissions": 0, - "share": 1, - "submit": 0, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts Manager", + "share": 1, "write": 1 - }, + }, { - "amend": 0, - "apply_user_permissions": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Accounts User", - "set_user_permissions": 0, - "share": 1, - "submit": 0, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts User", + "share": 1, "write": 1 } - ], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0 -} + ], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.js b/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.js index f5c5bca87a..84c8d09b16 100644 --- a/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.js +++ b/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.js @@ -3,11 +3,6 @@ frappe.ui.form.on('Payment Terms Template', { setup: function(frm) { - frm.add_fetch("payment_term", "description", "description"); - frm.add_fetch("payment_term", "invoice_portion", "invoice_portion"); - frm.add_fetch("payment_term", "due_date_based_on", "due_date_based_on"); - frm.add_fetch("payment_term", "credit_days", "credit_days"); - frm.add_fetch("payment_term", "credit_months", "credit_months"); - frm.add_fetch("payment_term", "mode_of_payment", "mode_of_payment"); + } }); diff --git a/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.py b/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.py index 2b2b6afe79..80e3348d81 100644 --- a/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.py +++ b/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.py @@ -13,7 +13,6 @@ from frappe import _ class PaymentTermsTemplate(Document): def validate(self): self.validate_invoice_portion() - self.validate_credit_days() self.check_duplicate_terms() def validate_invoice_portion(self): @@ -24,11 +23,6 @@ class PaymentTermsTemplate(Document): if flt(total_portion, 2) != 100.00: frappe.msgprint(_('Combined invoice portion must equal 100%'), raise_exception=1, indicator='red') - def validate_credit_days(self): - for term in self.terms: - if cint(term.credit_days) < 0: - frappe.msgprint(_('Credit Days cannot be a negative number'), raise_exception=1, indicator='red') - def check_duplicate_terms(self): terms = [] for term in self.terms: diff --git a/erpnext/accounts/doctype/payment_terms_template_detail/payment_terms_template_detail.json b/erpnext/accounts/doctype/payment_terms_template_detail/payment_terms_template_detail.json index eee3223314..20b3dca6aa 100644 --- a/erpnext/accounts/doctype/payment_terms_template_detail/payment_terms_template_detail.json +++ b/erpnext/accounts/doctype/payment_terms_template_detail/payment_terms_template_detail.json @@ -1,278 +1,164 @@ { - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "autoname": "", - "beta": 0, - "creation": "2017-08-10 15:34:09.409562", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "", - "editable_grid": 1, - "engine": "InnoDB", + "actions": [], + "creation": "2017-08-10 15:34:09.409562", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "payment_term", + "section_break_13", + "description", + "section_break_4", + "invoice_portion", + "mode_of_payment", + "column_break_3", + "due_date_based_on", + "credit_days", + "credit_months", + "section_break_8", + "discount_type", + "discount", + "column_break_11", + "discount_validity_based_on", + "discount_validity" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 2, - "fieldname": "payment_term", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Payment Term", - "length": 0, - "no_copy": 0, - "options": "Payment Term", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "columns": 2, + "fieldname": "payment_term", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Payment Term", + "options": "Payment Term" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 2, - "fieldname": "description", - "fieldtype": "Small Text", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Description", - "length": 0, - "no_copy": 0, - "options": "", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "columns": 2, + "fetch_from": "payment_term.description", + "fieldname": "description", + "fieldtype": "Small Text", + "in_list_view": 1, + "label": "Description" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 2, - "default": "0", - "fieldname": "invoice_portion", - "fieldtype": "Percent", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Invoice Portion", - "length": 0, - "no_copy": 0, - "options": "", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "columns": 2, + "fetch_from": "payment_term.invoice_portion", + "fetch_if_empty": 1, + "fieldname": "invoice_portion", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Invoice Portion (%)", + "reqd": 1 + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 2, - "fieldname": "due_date_based_on", - "fieldtype": "Select", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Due Date Based On", - "length": 0, - "no_copy": 0, - "options": "Day(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "columns": 2, + "fetch_from": "payment_term.due_date_based_on", + "fetch_if_empty": 1, + "fieldname": "due_date_based_on", + "fieldtype": "Select", + "in_list_view": 1, + "label": "Due Date Based On", + "options": "Day(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month", + "reqd": 1 + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 2, - "default": "0", - "depends_on": "eval:in_list(['Day(s) after invoice date', 'Day(s) after the end of the invoice month'], doc.due_date_based_on)", - "fieldname": "credit_days", - "fieldtype": "Int", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Credit Days", - "length": 0, - "no_copy": 0, - "options": "", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "columns": 2, + "default": "0", + "depends_on": "eval:in_list(['Day(s) after invoice date', 'Day(s) after the end of the invoice month'], doc.due_date_based_on)", + "fetch_from": "payment_term.credit_days", + "fetch_if_empty": 1, + "fieldname": "credit_days", + "fieldtype": "Int", + "in_list_view": 1, + "label": "Credit Days", + "non_negative": 1 + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "default": "0", - "depends_on": "eval:doc.due_date_based_on=='Month(s) after the end of the invoice month'", - "fieldname": "credit_months", - "fieldtype": "Int", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Credit Months", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "default": "0", + "depends_on": "eval:doc.due_date_based_on=='Month(s) after the end of the invoice month'", + "fetch_from": "payment_term.credit_months", + "fetch_if_empty": 1, + "fieldname": "credit_months", + "fieldtype": "Int", + "label": "Credit Months", + "non_negative": 1 + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "mode_of_payment", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Mode of Payment", - "length": 0, - "no_copy": 0, - "options": "Mode of Payment", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fetch_from": "payment_term.mode_of_payment", + "fieldname": "mode_of_payment", + "fieldtype": "Link", + "label": "Mode of Payment", + "options": "Mode of Payment" + }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, + { + "fieldname": "section_break_8", + "fieldtype": "Section Break", + "label": "Discount Settings" + }, + { + "default": "Percentage", + "fetch_from": "payment_term.discount_type", + "fetch_if_empty": 1, + "fieldname": "discount_type", + "fieldtype": "Select", + "label": "Discount Type", + "options": "Percentage\nAmount" + }, + { + "fetch_from": "payment_term.discount", + "fetch_if_empty": 1, + "fieldname": "discount", + "fieldtype": "Float", + "label": "Discount" + }, + { + "fieldname": "column_break_11", + "fieldtype": "Column Break" + }, + { + "default": "Day(s) after invoice date", + "depends_on": "discount", + "fetch_from": "payment_term.discount_validity_based_on", + "fetch_if_empty": 1, + "fieldname": "discount_validity_based_on", + "fieldtype": "Select", + "label": "Discount Validity Based On", + "options": "Day(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month" + }, + { + "collapsible": 1, + "fieldname": "section_break_13", + "fieldtype": "Section Break", + "label": "Description" + }, + { + "depends_on": "discount", + "fetch_from": "payment_term.discount_validity", + "fetch_if_empty": 1, + "fieldname": "discount_validity", + "fieldtype": "Int", + "label": "Discount Validity", + "mandatory_depends_on": "discount" + }, + { + "fieldname": "section_break_4", + "fieldtype": "Section Break" } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 1, - "max_attachments": 0, - "modified": "2018-08-21 16:15:55.143025", - "modified_by": "Administrator", - "module": "Accounts", - "name": "Payment Terms Template Detail", - "name_case": "", - "owner": "Administrator", - "permissions": [], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0, - "track_views": 0 + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-02-24 11:56:12.410807", + "modified_by": "Administrator", + "module": "Accounts", + "name": "Payment Terms Template Detail", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py index 51fc7ec49a..444b40ed79 100755 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py @@ -364,7 +364,7 @@ class ReceivablePayableReport(object): payment_terms_details = frappe.db.sql(""" select si.name, si.party_account_currency, si.currency, si.conversion_rate, - ps.due_date, ps.payment_amount, ps.description, ps.paid_amount + ps.due_date, ps.payment_amount, ps.description, ps.paid_amount, ps.discounted_amount from `tab{0}` si, `tabPayment Schedule` ps where si.name = ps.parent and @@ -395,13 +395,13 @@ class ReceivablePayableReport(object): "invoiced": invoiced, "invoice_grand_total": row.invoiced, "payment_term": d.description, - "paid": d.paid_amount, + "paid": d.paid_amount + d.discounted_amount, "credit_note": 0.0, - "outstanding": invoiced - d.paid_amount + "outstanding": invoiced - d.paid_amount - d.discounted_amount })) if d.paid_amount: - row['paid'] -= d.paid_amount + row['paid'] -= d.paid_amount + d.discounted_amount def allocate_closing_to_term(self, row, term, key): if row[key]: diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 256437966b..3a0a0f18b1 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -904,7 +904,8 @@ class AccountsController(TransactionBase): else: for d in self.get("payment_schedule"): if d.invoice_portion: - d.payment_amount = flt(grand_total * flt(d.invoice_portion) / 100, d.precision('payment_amount')) + d.payment_amount = flt(grand_total * flt(d.invoice_portion / 100), d.precision('payment_amount')) + d.outstanding = d.payment_amount def set_due_date(self): due_dates = [d.due_date for d in self.get("payment_schedule") if d.due_date] @@ -1219,18 +1220,24 @@ def get_payment_term_details(term, posting_date=None, grand_total=None, bill_dat term_details.description = term.description term_details.invoice_portion = term.invoice_portion term_details.payment_amount = flt(term.invoice_portion) * flt(grand_total) / 100 + term_details.discount_type = term.discount_type + term_details.discount = term.discount + # term_details.discounted_amount = flt(grand_total) * (term.discount / 100) if term.discount_type == 'Percentage' else discount + term_details.outstanding = term_details.payment_amount + term_details.mode_of_payment = term.mode_of_payment + if bill_date: term_details.due_date = get_due_date(term, bill_date) + term_details.discount_date = get_discount_date(term, bill_date) elif posting_date: term_details.due_date = get_due_date(term, posting_date) + term_details.discount_date = get_discount_date(term, posting_date) if getdate(term_details.due_date) < getdate(posting_date): term_details.due_date = posting_date - term_details.mode_of_payment = term.mode_of_payment return term_details - def get_due_date(term, posting_date=None, bill_date=None): due_date = None date = bill_date or posting_date @@ -1242,6 +1249,16 @@ def get_due_date(term, posting_date=None, bill_date=None): due_date = add_months(get_last_day(date), term.credit_months) return due_date +def get_discount_date(term, posting_date=None, bill_date=None): + discount_validity = None + date = bill_date or posting_date + if term.discount_validity_based_on == "Day(s) after invoice date": + discount_validity = add_days(date, term.discount_validity) + elif term.discount_validity_based_on == "Day(s) after the end of the invoice month": + discount_validity = add_days(get_last_day(date), term.discount_validity) + elif term.discount_validity_based_on == "Month(s) after the end of the invoice month": + discount_validity = add_months(get_last_day(date), term.discount_validity) + return discount_validity def get_supplier_block_status(party_name): """ diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 20ea5097bf..bdae215dc8 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -750,6 +750,7 @@ erpnext.patches.v13_0.set_company_in_leave_ledger_entry erpnext.patches.v13_0.convert_qi_parameter_to_link_field erpnext.patches.v13_0.setup_patient_history_settings_for_standard_doctypes erpnext.patches.v13_0.add_naming_series_to_old_projects # 1-02-2021 +erpnext.patches.v13_0.update_payment_terms_outstanding erpnext.patches.v13_0.item_reposting_for_incorrect_sl_and_gl erpnext.patches.v12_0.add_state_code_for_ladakh erpnext.patches.v13_0.update_vehicle_no_reqd_condition diff --git a/erpnext/patches/v13_0/update_payment_terms_outstanding.py b/erpnext/patches/v13_0/update_payment_terms_outstanding.py new file mode 100644 index 0000000000..4816b40250 --- /dev/null +++ b/erpnext/patches/v13_0/update_payment_terms_outstanding.py @@ -0,0 +1,15 @@ +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + frappe.reload_doc("accounts", "doctype", "Payment Schedule") + if frappe.db.count('Payment Schedule'): + frappe.db.sql(''' + UPDATE + `tabPayment Schedule` ps + SET + ps.outstanding = (ps.payment_amount - ps.paid_amount) + ''') diff --git a/erpnext/setup/doctype/company/company.js b/erpnext/setup/doctype/company/company.js index 36033d9dae..5dacb17b81 100644 --- a/erpnext/setup/doctype/company/company.js +++ b/erpnext/setup/doctype/company/company.js @@ -259,6 +259,7 @@ erpnext.company.setup_queries = function(frm) { ["default_payroll_payable_account", {"root_type": "Liability"}], ["round_off_account", {"root_type": "Expense"}], ["write_off_account", {"root_type": "Expense"}], + ["default_discount_account", {}], ["discount_allowed_account", {"root_type": "Expense"}], ["discount_received_account", {"root_type": "Income"}], ["exchange_gain_loss_account", {"root_type": "Expense"}], @@ -275,7 +276,7 @@ erpnext.company.setup_queries = function(frm) { ["expenses_included_in_asset_valuation", {"account_type": "Expenses Included In Asset Valuation"}], ["capital_work_in_progress_account", {"account_type": "Capital Work in Progress"}], ["asset_received_but_not_billed", {"account_type": "Asset Received But Not Billed"}], - ["unrealized_profit_loss_account", {"root_type": "Liability"}] + ["unrealized_profit_loss_account", {"root_type": "Liability"},] ], function(i, v) { erpnext.company.set_custom_query(frm, v); }); diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json index d49ae7ce8a..b27e2448d4 100644 --- a/erpnext/setup/doctype/company/company.json +++ b/erpnext/setup/doctype/company/company.json @@ -59,6 +59,7 @@ "default_deferred_expense_account", "default_payroll_payable_account", "default_expense_claim_payable_account", + "default_discount_account", "section_break_22", "cost_center", "column_break_26", @@ -733,6 +734,12 @@ "fieldtype": "Link", "label": "Unrealized Profit / Loss Account", "options": "Account" + }, + { + "fieldname": "default_discount_account", + "fieldtype": "Link", + "label": "Default Payment Discount Account", + "options": "Account" } ], "icon": "fa fa-building", From c482c9592f821039cda757a02ff47a8de65428a8 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Wed, 31 Mar 2021 16:04:46 +0530 Subject: [PATCH 375/449] fix: Purchase from registered composition dealer (#25057) * fix: Purchase from registered composition dealer * fix: Test case for GSTR 3b report --- .../doctype/gstr_3b_report/gstr_3b_report.html | 2 +- .../doctype/gstr_3b_report/gstr_3b_report.py | 16 ++++++++++++---- .../gstr_3b_report/test_gstr_3b_report.py | 15 ++++++++++++++- erpnext/regional/report/gstr_2/gstr_2.py | 4 ++-- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.html b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.html index 888b2da48e..369a4001ef 100644 --- a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.html +++ b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.html @@ -109,7 +109,7 @@ - {{__("Suppliies made to Composition Taxable Persons")}} + {{__("Supplies made to Composition Taxable Persons")}} {% for row in data.inter_sup.comp_details %} {% if row %} diff --git a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py index a49996d107..a5dd5a2e09 100644 --- a/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py +++ b/erpnext/regional/doctype/gstr_3b_report/gstr_3b_report.py @@ -172,7 +172,6 @@ class GSTR3BReport(Document): self.json_output = frappe.as_json(self.report_dict) def set_inward_nil_exempt(self, inward_nil_exempt): - self.report_dict["inward_sup"]["isup_details"][0]["inter"] = flt(inward_nil_exempt.get("gst").get("inter"), 2) self.report_dict["inward_sup"]["isup_details"][0]["intra"] = flt(inward_nil_exempt.get("gst").get("intra"), 2) self.report_dict["inward_sup"]["isup_details"][1]["inter"] = flt(inward_nil_exempt.get("non_gst").get("inter"), 2) @@ -238,7 +237,6 @@ class GSTR3BReport(Document): self.report_dict[supply_type][supply_category]["txval"] += flt(txval, 2) def set_inter_state_supply(self, inter_state_supply): - osup_det = self.report_dict["sup_details"]["osup_det"] for key, value in iteritems(inter_state_supply): @@ -352,10 +350,18 @@ class GSTR3BReport(Document): inward_nil_exempt = frappe.db.sql(""" select p.place_of_supply, sum(i.base_amount) as base_amount, i.is_nil_exempt, i.is_non_gst from `tabPurchase Invoice` p , `tabPurchase Invoice Item` i where p.docstatus = 1 and p.name = i.parent + and p.gst_category != 'Registered Composition' and (i.is_nil_exempt = 1 or i.is_non_gst = 1) and month(p.posting_date) = %s and year(p.posting_date) = %s and p.company = %s and p.company_gstin = %s group by p.place_of_supply, i.is_nil_exempt, i.is_non_gst""", (self.month_no, self.year, self.company, self.gst_details.get("gstin")), as_dict=1) + inward_nil_exempt += frappe.db.sql("""SELECT sum(base_net_total) as base_amount, gst_category, place_of_supply + FROM `tabPurchase Invoice` + WHERE docstatus = 1 and gst_category = 'Registered Composition' + and month(posting_date) = %s and year(posting_date) = %s + and company = %s and company_gstin = %s + group by place_of_supply""", (self.month_no, self.year, self.company, self.gst_details.get("gstin")), as_dict=1) + inward_nil_exempt_details = { "gst": { "intra": 0.0, @@ -369,9 +375,11 @@ class GSTR3BReport(Document): for d in inward_nil_exempt: if d.place_of_supply: - if d.is_nil_exempt == 1 and state == d.place_of_supply.split("-")[1]: + if (d.is_nil_exempt == 1 or d.get('gst_category') == 'Registered Composition') \ + and state == d.place_of_supply.split("-")[1]: inward_nil_exempt_details["gst"]["intra"] += d.base_amount - elif d.is_nil_exempt == 1 and state != d.place_of_supply.split("-")[1]: + elif (d.is_nil_exempt == 1 or d.get('gst_category') == 'Registered Composition') \ + and state != d.place_of_supply.split("-")[1]: inward_nil_exempt_details["gst"]["inter"] += d.base_amount elif d.is_non_gst == 1 and state == d.place_of_supply.split("-")[1]: inward_nil_exempt_details["non_gst"]["intra"] += d.base_amount diff --git a/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py b/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py index 023b4ed22b..ef8af24c42 100644 --- a/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py +++ b/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py @@ -64,7 +64,7 @@ class TestGSTR3BReport(unittest.TestCase): self.assertEqual(output["sup_details"]["osup_zero"]["iamt"], 18), self.assertEqual(output["inter_sup"]["unreg_details"][0]["iamt"], 18), self.assertEqual(output["sup_details"]["osup_nil_exmp"]["txval"], 100), - self.assertEqual(output["inward_sup"]["isup_details"][0]["inter"], 250) + self.assertEqual(output["inward_sup"]["isup_details"][0]["intra"], 250) self.assertEqual(output["itc_elg"]["itc_avl"][4]["samt"], 22.50) self.assertEqual(output["itc_elg"]["itc_avl"][4]["camt"], 22.50) @@ -228,6 +228,19 @@ def create_purchase_invoices(): pi1.submit() + pi2 = make_purchase_invoice(company="_Test Company GST", + customer = '_Test Registered Supplier', + currency = 'INR', + item = 'Milk', + warehouse = 'Finished Goods - _GST', + expense_account = 'Cost of Goods Sold - _GST', + cost_center = 'Main - _GST', + rate=250, + qty=1, + do_not_save=1 + ) + pi2.submit() + def make_suppliers(): if not frappe.db.exists("Supplier", "_Test Registered Supplier"): frappe.get_doc({ diff --git a/erpnext/regional/report/gstr_2/gstr_2.py b/erpnext/regional/report/gstr_2/gstr_2.py index f899349ccc..616c2b853d 100644 --- a/erpnext/regional/report/gstr_2/gstr_2.py +++ b/erpnext/regional/report/gstr_2/gstr_2.py @@ -44,7 +44,7 @@ class Gstr2Report(Gstr1Report): for inv, items_based_on_rate in self.items_based_on_tax_rate.items(): invoice_details = self.invoices.get(inv) for rate, items in items_based_on_rate.items(): - if rate: + if rate or invoice_details.get('gst_category') == 'Registered Composition': if inv not in self.igst_invoices: rate = rate / 2 row, taxable_value = self.get_row_data_for_invoice(inv, invoice_details, rate, items) @@ -86,7 +86,7 @@ class Gstr2Report(Gstr1Report): conditions += opts[1] if self.filters.get("type_of_business") == "B2B": - conditions += "and ifnull(gst_category, '') in ('Registered Regular', 'Deemed Export', 'SEZ') and is_return != 1 " + conditions += "and ifnull(gst_category, '') in ('Registered Regular', 'Deemed Export', 'SEZ', 'Registered Composition') and is_return != 1 " elif self.filters.get("type_of_business") == "CDNR": conditions += """ and is_return = 1 """ From c5ae9ee0e1255d9b8e0656b181de9e58fb98c379 Mon Sep 17 00:00:00 2001 From: Prssanna Desai Date: Wed, 31 Mar 2021 16:16:12 +0530 Subject: [PATCH 376/449] fix: do not set standard link in Sales Invoice as custom (#25097) --- erpnext/accounts/doctype/sales_invoice/sales_invoice.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index 720a9175e6..d382386a32 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -1952,13 +1952,12 @@ "is_submittable": 1, "links": [ { - "custom": 1, "group": "Reference", "link_doctype": "POS Invoice", "link_fieldname": "consolidated_invoice" } ], - "modified": "2021-02-01 15:42:26.261540", + "modified": "2021-03-31 15:42:26.261540", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", From c814aab0b6a75b5b0737b738772e6bed9faf918a Mon Sep 17 00:00:00 2001 From: Jannat Patel <31363128+pateljannat@users.noreply.github.com> Date: Wed, 31 Mar 2021 16:24:31 +0530 Subject: [PATCH 377/449] fix: delivery note print error (#25081) --- erpnext/stock/doctype/delivery_note/delivery_note.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index 35443906c8..d326a04173 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -101,7 +101,7 @@ class DeliveryNote(SellingController): for f in fieldname: toggle_print_hide(self.meta if key == "parent" else item_meta, f) - super(DeliveryNote, self).before_print() + super(DeliveryNote, self).before_print(settings) def set_actual_qty(self): for d in self.get('items'): From 75ce336c8428c47f74b61c56c57b595d34959834 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 31 Mar 2021 16:27:20 +0530 Subject: [PATCH 378/449] chore: add sider config (#24892) (#25098) Co-authored-by: Sagar Vora Co-authored-by: Mohammad Hasnain Mohsin Rajan Co-authored-by: Sagar Vora --- .flake8 | 32 ++++++++++++++++++++++++++++++++ sider.yml | 3 +++ 2 files changed, 35 insertions(+) create mode 100644 .flake8 create mode 100644 sider.yml diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000000..399b176e1d --- /dev/null +++ b/.flake8 @@ -0,0 +1,32 @@ +[flake8] +ignore = + E121, + E126, + E127, + E128, + E203, + E225, + E226, + E231, + E241, + E251, + E261, + E265, + E302, + E303, + E305, + E402, + E501, + E741, + W291, + W292, + W293, + W391, + W503, + W504, + F403, + B007, + B950, + W191, + +max-line-length = 200 \ No newline at end of file diff --git a/sider.yml b/sider.yml new file mode 100644 index 0000000000..2ca6e8deb1 --- /dev/null +++ b/sider.yml @@ -0,0 +1,3 @@ +linter: + flake8: + config: .flake8 \ No newline at end of file From b6ce868199da35b051e03815cb24b4690505dd9c Mon Sep 17 00:00:00 2001 From: prssanna Date: Wed, 17 Mar 2021 19:23:50 +0530 Subject: [PATCH 379/449] fix: POS print receipt --- .../page/point_of_sale/pos_past_order_summary.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/erpnext/selling/page/point_of_sale/pos_past_order_summary.js b/erpnext/selling/page/point_of_sale/pos_past_order_summary.js index 39f54fa1f8..5ac32b6a28 100644 --- a/erpnext/selling/page/point_of_sale/pos_past_order_summary.js +++ b/erpnext/selling/page/point_of_sale/pos_past_order_summary.js @@ -201,9 +201,13 @@ erpnext.PointOfSale.PastOrderSummary = class { this.$summary_container.on('click', '.print-btn', () => { const frm = this.events.get_frm(); - frm.doc = this.doc; - frm.print_preview.lang_code = frm.doc.language; - frm.print_preview.printit(true); + frappe.utils.print( + frm.doctype, + frm.docname, + frm.pos_print_format, + frm.doc.letter_head, + frm.doc.language || frappe.boot.lang + ) }); } From b5843dbdcdeb36626be0fef67eef21623b71002b Mon Sep 17 00:00:00 2001 From: prssanna Date: Thu, 18 Mar 2021 17:02:19 +0530 Subject: [PATCH 380/449] fix: print recepit dialog --- .../point_of_sale/pos_past_order_summary.js | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/erpnext/selling/page/point_of_sale/pos_past_order_summary.js b/erpnext/selling/page/point_of_sale/pos_past_order_summary.js index 5ac32b6a28..a5a739cff9 100644 --- a/erpnext/selling/page/point_of_sale/pos_past_order_summary.js +++ b/erpnext/selling/page/point_of_sale/pos_past_order_summary.js @@ -64,10 +64,7 @@ erpnext.PointOfSale.PastOrderSummary = class { {fieldname: 'print', fieldtype: 'Data', label: 'Print Preview'} ], primary_action: () => { - const frm = this.events.get_frm(); - frm.doc = this.doc; - frm.print_preview.lang_code = frm.doc.language; - frm.print_preview.printit(true); + this.print_receipt(); }, primary_action_label: __('Print'), }); @@ -200,17 +197,21 @@ erpnext.PointOfSale.PastOrderSummary = class { }); this.$summary_container.on('click', '.print-btn', () => { - const frm = this.events.get_frm(); - frappe.utils.print( - frm.doctype, - frm.docname, - frm.pos_print_format, - frm.doc.letter_head, - frm.doc.language || frappe.boot.lang - ) + this.print_receipt(); }); } + print_receipt() { + const frm = this.events.get_frm(); + frappe.utils.print( + frm.doctype, + frm.docname, + frm.pos_print_format, + frm.doc.letter_head, + frm.doc.language || frappe.boot.lang + ); + } + attach_shortcuts() { const ctrl_label = frappe.utils.is_mac() ? '⌘' : 'Ctrl'; this.$summary_container.find('.print-btn').attr("title", `${ctrl_label}+P`); From 56ab3fb1327bf22cbdc167b4f58deb8290d7e54d Mon Sep 17 00:00:00 2001 From: prssanna Date: Tue, 16 Mar 2021 14:15:59 +0530 Subject: [PATCH 381/449] fix: issue web list style --- erpnext/templates/includes/issue_row.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/templates/includes/issue_row.html b/erpnext/templates/includes/issue_row.html index d909c5feea..a04f558509 100644 --- a/erpnext/templates/includes/issue_row.html +++ b/erpnext/templates/includes/issue_row.html @@ -1,6 +1,6 @@
-
+
{% set indicator = 'red' if doc.status == 'Open' else 'gray' %} {% set indicator = 'green' if doc.status == 'Closed' else indicator %} From 5cdb1cb7a94ba0da2b9dd5072e3cba41094c4083 Mon Sep 17 00:00:00 2001 From: prssanna Date: Tue, 16 Mar 2021 14:16:22 +0530 Subject: [PATCH 382/449] fix: item variant dialog dropdown issue --- erpnext/stock/doctype/item/item.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js index 55391235cb..7489d1fefb 100644 --- a/erpnext/stock/doctype/item/item.js +++ b/erpnext/stock/doctype/item/item.js @@ -717,6 +717,18 @@ $.extend(erpnext.item, { .on('focus', function(e) { $(e.target).val('').trigger('input'); }) + .on("awesomplete-open", () => { + let modal = field.$input.parents('.modal-dialog')[0]; + if (modal) { + $(modal).removeClass("modal-dialog-scrollable"); + } + }) + .on("awesomplete-close", () => { + let modal = field.$input.parents('.modal-dialog')[0]; + if (modal) { + $(modal).addClass("modal-dialog-scrollable"); + } + }) }); }, From bcd63f04da541514b5e0517d2feedec51bc4223a Mon Sep 17 00:00:00 2001 From: prssanna Date: Tue, 16 Mar 2021 15:39:16 +0530 Subject: [PATCH 383/449] style: missing semicolon --- erpnext/stock/doctype/item/item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js index 7489d1fefb..2079cf88dd 100644 --- a/erpnext/stock/doctype/item/item.js +++ b/erpnext/stock/doctype/item/item.js @@ -728,7 +728,7 @@ $.extend(erpnext.item, { if (modal) { $(modal).addClass("modal-dialog-scrollable"); } - }) + }); }); }, From ad520e08bab34b58666ba140ce513e062c07e39d Mon Sep 17 00:00:00 2001 From: Anupam Date: Sat, 20 Feb 2021 22:32:00 +0530 Subject: [PATCH 384/449] feat: price margin in buying --- .../doctype/pricing_rule/pricing_rule.json | 3 +- .../purchase_invoice_item.json | 55 +++++++++++++++++- .../sales_invoice_item.json | 3 +- .../purchase_order_item.json | 58 +++++++++++++++++-- erpnext/controllers/taxes_and_totals.py | 2 +- erpnext/public/js/controllers/buying.js | 23 -------- erpnext/public/js/controllers/transaction.js | 44 ++++++++++++-- .../quotation_item/quotation_item.json | 3 +- .../sales_order_item/sales_order_item.json | 3 +- erpnext/selling/sales_common.js | 34 ----------- .../delivery_note_item.json | 3 +- .../purchase_receipt_item.json | 56 +++++++++++++++++- 12 files changed, 208 insertions(+), 79 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.json b/erpnext/accounts/doctype/pricing_rule/pricing_rule.json index d08a854142..33771645fe 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.json +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.json @@ -357,7 +357,6 @@ "reqd": 1 }, { - "depends_on": "eval: doc.selling == 1", "fieldname": "margin", "fieldtype": "Section Break", "label": "Margin" @@ -565,7 +564,7 @@ "icon": "fa fa-gift", "idx": 1, "links": [], - "modified": "2020-12-04 00:36:24.698219", + "modified": "2021-03-01 23:18:38.717613", "modified_by": "Administrator", "module": "Accounts", "name": "Pricing Rule", diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json index 07e75acb41..96ad0fd785 100644 --- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json +++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json @@ -28,10 +28,16 @@ "stock_qty", "sec_break1", "price_list_rate", - "discount_percentage", - "discount_amount", "col_break3", "base_price_list_rate", + "section_break_26", + "margin_type", + "margin_rate_or_amount", + "rate_with_margin", + "column_break_30", + "discount_percentage", + "discount_amount", + "base_rate_with_margin", "sec_break2", "rate", "amount", @@ -789,6 +795,7 @@ "fieldname": "stock_uom_rate", "fieldtype": "Currency", "label": "Rate of Stock UOM", + "no_copy": 1, "options": "currency", "read_only": 1 }, @@ -799,12 +806,54 @@ "no_copy": 1, "print_hide": 1, "read_only": 1 + }, + { + "collapsible": 1, + "fieldname": "section_break_26", + "fieldtype": "Section Break", + "label": "Discount and Margin" + }, + { + "depends_on": "price_list_rate", + "fieldname": "margin_type", + "fieldtype": "Select", + "label": "Margin Type", + "options": "\nPercentage\nAmount", + "print_hide": 1 + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate", + "fieldname": "margin_rate_or_amount", + "fieldtype": "Float", + "label": "Margin Rate or Amount", + "print_hide": 1 + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate && doc.margin_rate_or_amount", + "fieldname": "rate_with_margin", + "fieldtype": "Currency", + "label": "Rate With Margin", + "options": "currency", + "read_only": 1 + }, + { + "fieldname": "column_break_30", + "fieldtype": "Column Break" + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate && doc.margin_rate_or_amount", + "fieldname": "base_rate_with_margin", + "fieldtype": "Currency", + "label": "Rate With Margin (Company Currency)", + "options": "Company:company:default_currency", + "print_hide": 1, + "read_only": 1 } ], "idx": 1, "istable": 1, "links": [], - "modified": "2021-01-30 21:43:21.488258", + "modified": "2021-02-23 00:59:52.614805", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice Item", diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json index b403c7b237..8e6952a93c 100644 --- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json +++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json @@ -818,6 +818,7 @@ "fieldname": "stock_uom_rate", "fieldtype": "Currency", "label": "Rate of Stock UOM", + "no_copy": 1, "options": "currency", "read_only": 1 } @@ -825,7 +826,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2021-01-30 21:42:37.796771", + "modified": "2021-02-23 01:05:22.123527", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice Item", diff --git a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json index 75b2954ddd..5baf6939cd 100644 --- a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json +++ b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json @@ -27,11 +27,17 @@ "stock_qty", "sec_break1", "price_list_rate", + "last_purchase_rate", + "col_break3", + "base_price_list_rate", + "discount_and_margin_section", + "margin_type", + "margin_rate_or_amount", + "rate_with_margin", + "column_break_28", "discount_percentage", "discount_amount", - "col_break3", - "last_purchase_rate", - "base_price_list_rate", + "base_rate_with_margin", "sec_break2", "rate", "amount", @@ -733,15 +739,59 @@ "fieldname": "stock_uom_rate", "fieldtype": "Currency", "label": "Rate of Stock UOM", + "no_copy": 1, "options": "currency", "read_only": 1 + }, + { + "collapsible": 1, + "fieldname": "discount_and_margin_section", + "fieldtype": "Section Break", + "label": "Discount and Margin" + }, + { + "depends_on": "price_list_rate", + "fieldname": "margin_type", + "fieldtype": "Select", + "label": "Margin Type", + "options": "\nPercentage\nAmount", + "print_hide": 1 + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate", + "fieldname": "margin_rate_or_amount", + "fieldtype": "Float", + "label": "Margin Rate or Amount", + "print_hide": 1 + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate && doc.margin_rate_or_amount", + "fieldname": "rate_with_margin", + "fieldtype": "Currency", + "label": "Rate With Margin", + "options": "currency", + "print_hide": 1, + "read_only": 1 + }, + { + "fieldname": "column_break_28", + "fieldtype": "Column Break" + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate && doc.margin_rate_or_amount", + "fieldname": "base_rate_with_margin", + "fieldtype": "Currency", + "label": "Rate With Margin (Company Currency)", + "options": "Company:company:default_currency", + "print_hide": 1, + "read_only": 1 } ], "idx": 1, "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-01-30 21:44:41.816974", + "modified": "2021-02-23 01:00:27.132705", "modified_by": "Administrator", "module": "Buying", "name": "Purchase Order Item", diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 10271cbcc9..aab5770a94 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -109,7 +109,7 @@ class calculate_taxes_and_totals(object): elif item.discount_amount and item.pricing_rules: item.rate = item.price_list_rate - item.discount_amount - if item.doctype in ['Quotation Item', 'Sales Order Item', 'Delivery Note Item', 'Sales Invoice Item', 'POS Invoice Item']: + if item.doctype in ['Quotation Item', 'Sales Order Item', 'Delivery Note Item', 'Sales Invoice Item', 'POS Invoice Item', 'Purchase Invoice Item', 'Purchase Order Item', 'Purchase Receipt Item']: item.rate_with_margin, item.base_rate_with_margin = self.calculate_margin(item) if flt(item.rate_with_margin) > 0: item.rate = flt(item.rate_with_margin * (1.0 - (item.discount_percentage / 100.0)), item.precision("rate")) diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index c96386611b..67b12fbca4 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -141,29 +141,6 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ this.apply_price_list(); }, - price_list_rate: function(doc, cdt, cdn) { - var item = frappe.get_doc(cdt, cdn); - - frappe.model.round_floats_in(item, ["price_list_rate", "discount_percentage"]); - - let item_rate = item.price_list_rate; - if (doc.doctype == "Purchase Order" && item.blanket_order_rate) { - item_rate = item.blanket_order_rate; - } - - if (item.discount_percentage) { - item.discount_amount = flt(item_rate) * flt(item.discount_percentage) / 100; - } - - if (item.discount_amount) { - item.rate = flt((item.price_list_rate) - (item.discount_amount), precision('rate', item)); - } else { - item.rate = item_rate; - } - - this.calculate_taxes_and_totals(); - }, - discount_percentage: function(doc, cdt, cdn) { var item = frappe.get_doc(cdt, cdn); item.discount_amount = 0.0; diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 9351f6d206..1c0abdffcf 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -649,6 +649,40 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ } }, + price_list_rate: function(doc, cdt, cdn) { + var item = frappe.get_doc(cdt, cdn); + frappe.model.round_floats_in(item, ["price_list_rate", "discount_percentage"]); + + // check if child doctype is Sales Order Item/Qutation Item and calculate the rate + if (in_list(["Quotation Item", "Sales Order Item", "Delivery Note Item", "Sales Invoice Item", "POS Invoice Item", "Purchase Invoice Item", "Purchase Order Item", "Purchase Receipt Item"]), cdt) + this.apply_pricing_rule_on_item(item); + else + item.rate = flt(item.price_list_rate * (1 - item.discount_percentage / 100.0), + precision("rate", item)); + + this.calculate_taxes_and_totals(); + }, + + margin_rate_or_amount: function(doc, cdt, cdn) { + // calculated the revised total margin and rate on margin rate changes + let item = frappe.get_doc(cdt, cdn); + this.apply_pricing_rule_on_item(item); + this.calculate_taxes_and_totals(); + cur_frm.refresh_fields(); + }, + + margin_type: function(doc, cdt, cdn) { + // calculate the revised total margin and rate on margin type changes + let item = frappe.get_doc(cdt, cdn); + if (!item.margin_type) { + frappe.model.set_value(cdt, cdn, "margin_rate_or_amount", 0); + } else { + this.apply_pricing_rule_on_item(item, doc, cdt, cdn); + this.calculate_taxes_and_totals(); + cur_frm.refresh_fields(); + } + }, + get_incoming_rate: function(item, posting_date, posting_time, voucher_type, company) { let item_args = { @@ -1030,7 +1064,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ }, set_margin_amount_based_on_currency: function(exchange_rate) { - if (in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]), this.frm.doc.doctype) { + if (in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice", "Purchase Invoice", "Purchase Order", "Purchase Receipt"]), this.frm.doc.doctype) { var me = this; $.each(this.frm.doc.items || [], function(i, d) { if(d.margin_type == "Amount") { @@ -1280,10 +1314,10 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ change_grid_labels: function(company_currency) { var me = this; - this.frm.set_currency_labels(["base_rate", "base_net_rate", "base_price_list_rate", "base_amount", "base_net_amount"], + this.frm.set_currency_labels(["base_rate", "base_net_rate", "base_price_list_rate", "base_amount", "base_net_amount", "base_rate_with_margin"], company_currency, "items"); - this.frm.set_currency_labels(["rate", "net_rate", "price_list_rate", "amount", "net_amount", "stock_uom_rate"], + this.frm.set_currency_labels(["rate", "net_rate", "price_list_rate", "amount", "net_amount", "stock_uom_rate", "rate_with_margin"], this.frm.doc.currency, "items"); if(this.frm.fields_dict["operations"]) { @@ -1321,7 +1355,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ // toggle columns var item_grid = this.frm.fields_dict["items"].grid; - $.each(["base_rate", "base_price_list_rate", "base_amount"], function(i, fname) { + $.each(["base_rate", "base_price_list_rate", "base_amount", "base_rate_with_margin"], function(i, fname) { if(frappe.meta.get_docfield(item_grid.doctype, fname)) item_grid.set_column_disp(fname, me.frm.doc.currency != company_currency); }); @@ -1468,7 +1502,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ }); // if doctype is Quotation Item / Sales Order Iten then add Margin Type and rate in item_list - if (in_list(["Quotation Item", "Sales Order Item", "Delivery Note Item", "Sales Invoice Item"]), d.doctype){ + if (in_list(["Quotation Item", "Sales Order Item", "Delivery Note Item", "Sales Invoice Item", "Purchase Invoice Item", "Purchase Order Item", "Purchase Receipt Item"]), d.doctype) { item_list[0]["margin_type"] = d.margin_type; item_list[0]["margin_rate_or_amount"] = d.margin_rate_or_amount; } diff --git a/erpnext/selling/doctype/quotation_item/quotation_item.json b/erpnext/selling/doctype/quotation_item/quotation_item.json index a6785f709a..8b53902d32 100644 --- a/erpnext/selling/doctype/quotation_item/quotation_item.json +++ b/erpnext/selling/doctype/quotation_item/quotation_item.json @@ -641,6 +641,7 @@ "fieldname": "stock_uom_rate", "fieldtype": "Currency", "label": "Rate of Stock UOM", + "no_copy": 1, "options": "currency", "read_only": 1 } @@ -648,7 +649,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2021-01-30 21:39:40.174551", + "modified": "2021-02-23 01:13:54.670763", "modified_by": "Administrator", "module": "Selling", "name": "Quotation Item", diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.json b/erpnext/selling/doctype/sales_order_item/sales_order_item.json index 37e47a9d41..1e5590e748 100644 --- a/erpnext/selling/doctype/sales_order_item/sales_order_item.json +++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.json @@ -786,6 +786,7 @@ "fieldname": "stock_uom_rate", "fieldtype": "Currency", "label": "Rate of Stock UOM", + "no_copy": 1, "options": "currency", "read_only": 1 } @@ -793,7 +794,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2021-01-30 21:35:07.617320", + "modified": "2021-02-23 01:15:05.803091", "modified_by": "Administrator", "module": "Selling", "name": "Sales Order Item", diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index ce084646e1..04285735ab 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -127,20 +127,6 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ this.set_dynamic_labels(); }, - price_list_rate: function(doc, cdt, cdn) { - var item = frappe.get_doc(cdt, cdn); - frappe.model.round_floats_in(item, ["price_list_rate", "discount_percentage"]); - - // check if child doctype is Sales Order Item/Qutation Item and calculate the rate - if(in_list(["Quotation Item", "Sales Order Item", "Delivery Note Item", "Sales Invoice Item", "POS Invoice Item"]), cdt) - this.apply_pricing_rule_on_item(item); - else - item.rate = flt(item.price_list_rate * (1 - item.discount_percentage / 100.0), - precision("rate", item)); - - this.calculate_taxes_and_totals(); - }, - discount_percentage: function(doc, cdt, cdn) { var item = frappe.get_doc(cdt, cdn); item.discount_amount = 0.0; @@ -353,26 +339,6 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ refresh_field('product_bundle_help'); }, - margin_rate_or_amount: function(doc, cdt, cdn) { - // calculated the revised total margin and rate on margin rate changes - var item = locals[cdt][cdn]; - this.apply_pricing_rule_on_item(item) - this.calculate_taxes_and_totals(); - cur_frm.refresh_fields(); - }, - - margin_type: function(doc, cdt, cdn){ - // calculate the revised total margin and rate on margin type changes - var item = locals[cdt][cdn]; - if(!item.margin_type) { - frappe.model.set_value(cdt, cdn, "margin_rate_or_amount", 0); - } else { - this.apply_pricing_rule_on_item(item, doc,cdt, cdn) - this.calculate_taxes_and_totals(); - cur_frm.refresh_fields(); - } - }, - company_address: function() { var me = this; if(this.frm.doc.company_address) { diff --git a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json index 17996247c5..b05090a237 100644 --- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json +++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json @@ -750,6 +750,7 @@ "fieldname": "stock_uom_rate", "fieldtype": "Currency", "label": "Rate of Stock UOM", + "no_copy": 1, "options": "currency", "read_only": 1 } @@ -758,7 +759,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-01-30 21:42:03.767968", + "modified": "2021-02-23 01:04:08.588104", "modified_by": "Administrator", "module": "Stock", "name": "Delivery Note Item", diff --git a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json index 8974ad9318..efe3642d23 100644 --- a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json +++ b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json @@ -37,10 +37,16 @@ "returned_qty", "rate_and_amount", "price_list_rate", - "discount_percentage", - "discount_amount", "col_break3", "base_price_list_rate", + "discount_and_margin_section", + "margin_type", + "margin_rate_or_amount", + "rate_with_margin", + "column_break_37", + "discount_percentage", + "discount_amount", + "base_rate_with_margin", "sec_break1", "rate", "amount", @@ -880,6 +886,7 @@ "fieldname": "stock_uom_rate", "fieldtype": "Currency", "label": "Rate of Stock UOM", + "no_copy": 1, "options": "currency", "read_only": 1 }, @@ -890,12 +897,55 @@ "no_copy": 1, "print_hide": 1, "read_only": 1 + }, + { + "collapsible": 1, + "fieldname": "discount_and_margin_section", + "fieldtype": "Section Break", + "label": "Discount and Margin" + }, + { + "depends_on": "price_list_rate", + "fieldname": "margin_type", + "fieldtype": "Select", + "label": "Margin Type", + "options": "\nPercentage\nAmount", + "print_hide": 1 + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate", + "fieldname": "margin_rate_or_amount", + "fieldtype": "Float", + "label": "Margin Rate or Amount", + "print_hide": 1 + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate && doc.margin_rate_or_amount", + "fieldname": "rate_with_margin", + "fieldtype": "Currency", + "label": "Rate With Margin", + "options": "currency", + "print_hide": 1, + "read_only": 1 + }, + { + "fieldname": "column_break_37", + "fieldtype": "Column Break" + }, + { + "depends_on": "eval:doc.margin_type && doc.price_list_rate && doc.margin_rate_or_amount", + "fieldname": "base_rate_with_margin", + "fieldtype": "Currency", + "label": "Rate With Margin (Company Currency)", + "options": "Company:company:default_currency", + "print_hide": 1, + "read_only": 1 } ], "idx": 1, "istable": 1, "links": [], - "modified": "2021-01-30 21:44:06.918515", + "modified": "2021-02-23 00:59:14.360847", "modified_by": "Administrator", "module": "Stock", "name": "Purchase Receipt Item", From 35415fa575c66282e87235a758e83b720e9ef410 Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Wed, 31 Mar 2021 19:39:33 +0530 Subject: [PATCH 385/449] fix: added flag for dont_fetch_price_list_rate in transaction (#25083) --- erpnext/public/js/controllers/transaction.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 1c0abdffcf..310f3d378b 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1173,6 +1173,11 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ this.calculate_net_weight(); } + // for handling customization not to fetch price list rate + if (frappe.flags.dont_fetch_price_list_rate) { + return; + } + if (!dont_fetch_price_list_rate && frappe.meta.has_field(doc.doctype, "price_list_currency")) { this.apply_price_list(item, true); From 85a7ec91a13589624eabcce06de96eaa7537407a Mon Sep 17 00:00:00 2001 From: marination Date: Wed, 31 Mar 2021 21:03:55 +0530 Subject: [PATCH 386/449] fix: Run Patches to updated Reserved, Requested and Ordered Qty --- erpnext/patches.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index ff9433a7ef..578bc0abcc 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -99,7 +99,7 @@ execute:frappe.delete_doc("DocType", "Purchase Request") execute:frappe.delete_doc("DocType", "Purchase Request Item") erpnext.patches.v4_2.recalculate_bom_cost erpnext.patches.v4_2.fix_gl_entries_for_stock_transactions -erpnext.patches.v4_2.update_requested_and_ordered_qty +erpnext.patches.v4_2.update_requested_and_ordered_qty #2021-03-31 execute:frappe.rename_doc("DocType", "Support Ticket", "Issue", force=True) erpnext.patches.v4_4.make_email_accounts execute:frappe.delete_doc("DocType", "Contact Control") @@ -208,7 +208,7 @@ erpnext.patches.v5_7.update_item_description_based_on_item_master erpnext.patches.v5_7.item_template_attributes execute:frappe.delete_doc_if_exists("DocType", "Manage Variants") execute:frappe.delete_doc_if_exists("DocType", "Manage Variants Item") -erpnext.patches.v4_2.repost_reserved_qty #2016-04-15 +erpnext.patches.v4_2.repost_reserved_qty #2021-03-31 erpnext.patches.v5_4.update_purchase_cost_against_project erpnext.patches.v5_8.update_order_reference_in_return_entries erpnext.patches.v5_8.add_credit_note_print_heading From 2fef245607b801896ef4a8f75b26118571a98747 Mon Sep 17 00:00:00 2001 From: Afshan <33727827+AfshanKhan@users.noreply.github.com> Date: Wed, 31 Mar 2021 21:57:04 +0530 Subject: [PATCH 387/449] fix: don't set Company:company:default_currency as default for currency link fields (#25111) --- .../employee_advance/employee_advance.json | 3 +-- .../leave_encashment/leave_encashment.json | 3 +-- .../additional_salary/additional_salary.json | 3 +-- .../employee_benefit_application.json | 3 +-- .../employee_benefit_claim.js | 1 - .../employee_benefit_claim.json | 5 ++-- .../employee_incentive.json | 3 +-- .../employee_tax_exemption_declaration.js | 21 +++++++++++++++++ .../employee_tax_exemption_declaration.json | 4 ++-- ...employee_tax_exemption_proof_submission.js | 23 ++++++++++++++++++- ...ployee_tax_exemption_proof_submission.json | 4 ++-- .../income_tax_slab/income_tax_slab.json | 4 ++-- .../retention_bonus/retention_bonus.json | 3 +-- .../doctype/salary_slip/salary_slip.json | 3 +-- .../salary_structure_assignment.json | 3 +-- 15 files changed, 59 insertions(+), 27 deletions(-) diff --git a/erpnext/hr/doctype/employee_advance/employee_advance.json b/erpnext/hr/doctype/employee_advance/employee_advance.json index cf6b5404ec..a25a828344 100644 --- a/erpnext/hr/doctype/employee_advance/employee_advance.json +++ b/erpnext/hr/doctype/employee_advance/employee_advance.json @@ -181,7 +181,6 @@ "read_only": 1 }, { - "default": "Company:company:default_currency", "depends_on": "eval:(doc.docstatus==1 || doc.employee)", "fieldname": "currency", "fieldtype": "Link", @@ -201,7 +200,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-11-25 12:01:55.980721", + "modified": "2021-03-31 21:31:53.746659", "modified_by": "Administrator", "module": "HR", "name": "Employee Advance", diff --git a/erpnext/hr/doctype/leave_encashment/leave_encashment.json b/erpnext/hr/doctype/leave_encashment/leave_encashment.json index 83eeae3adb..ec419ec2c6 100644 --- a/erpnext/hr/doctype/leave_encashment/leave_encashment.json +++ b/erpnext/hr/doctype/leave_encashment/leave_encashment.json @@ -130,7 +130,6 @@ "read_only": 1 }, { - "default": "Company:company:default_currency", "depends_on": "eval:(doc.docstatus==1 || doc.employee)", "fieldname": "currency", "fieldtype": "Link", @@ -155,7 +154,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-11-25 11:56:06.777241", + "modified": "2021-03-31 21:32:55.492327", "modified_by": "Administrator", "module": "HR", "name": "Leave Encashment", diff --git a/erpnext/payroll/doctype/additional_salary/additional_salary.json b/erpnext/payroll/doctype/additional_salary/additional_salary.json index 2b29f667fb..3544244d60 100644 --- a/erpnext/payroll/doctype/additional_salary/additional_salary.json +++ b/erpnext/payroll/doctype/additional_salary/additional_salary.json @@ -163,7 +163,6 @@ "read_only": 1 }, { - "default": "Company:company:default_currency", "depends_on": "eval:(doc.docstatus==1 || doc.employee)", "fieldname": "currency", "fieldtype": "Link", @@ -176,7 +175,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-10-20 17:51:13.419716", + "modified": "2021-03-31 21:33:59.098532", "modified_by": "Administrator", "module": "Payroll", "name": "Additional Salary", diff --git a/erpnext/payroll/doctype/employee_benefit_application/employee_benefit_application.json b/erpnext/payroll/doctype/employee_benefit_application/employee_benefit_application.json index 4c45580bf0..dcd01b5445 100644 --- a/erpnext/payroll/doctype/employee_benefit_application/employee_benefit_application.json +++ b/erpnext/payroll/doctype/employee_benefit_application/employee_benefit_application.json @@ -124,7 +124,6 @@ "read_only": 1 }, { - "default": "Company:company:default_currency", "depends_on": "eval:(doc.docstatus==1 || doc.employee)", "fieldname": "currency", "fieldtype": "Link", @@ -148,7 +147,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-12-14 15:52:08.566418", + "modified": "2021-03-31 21:35:08.940087", "modified_by": "Administrator", "module": "Payroll", "name": "Employee Benefit Application", diff --git a/erpnext/payroll/doctype/employee_benefit_claim/employee_benefit_claim.js b/erpnext/payroll/doctype/employee_benefit_claim/employee_benefit_claim.js index ea9ccd5205..e1f8431ec5 100644 --- a/erpnext/payroll/doctype/employee_benefit_claim/employee_benefit_claim.js +++ b/erpnext/payroll/doctype/employee_benefit_claim/employee_benefit_claim.js @@ -21,7 +21,6 @@ frappe.ui.form.on('Employee Benefit Claim', { callback: function(r) { if (r.message) { frm.set_value('currency', r.message); - frm.set_df_property('currency', 'hidden', 0); } } }); diff --git a/erpnext/payroll/doctype/employee_benefit_claim/employee_benefit_claim.json b/erpnext/payroll/doctype/employee_benefit_claim/employee_benefit_claim.json index da24aacda1..d731ff90c0 100644 --- a/erpnext/payroll/doctype/employee_benefit_claim/employee_benefit_claim.json +++ b/erpnext/payroll/doctype/employee_benefit_claim/employee_benefit_claim.json @@ -125,10 +125,9 @@ "label": "Attachments" }, { - "default": "Company:company:default_currency", + "depends_on": "eval: doc.employee", "fieldname": "currency", "fieldtype": "Link", - "hidden": 1, "label": "Currency", "options": "Currency", "read_only": 1, @@ -145,7 +144,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-11-25 11:49:56.097352", + "modified": "2021-03-31 21:37:21.024625", "modified_by": "Administrator", "module": "Payroll", "name": "Employee Benefit Claim", diff --git a/erpnext/payroll/doctype/employee_incentive/employee_incentive.json b/erpnext/payroll/doctype/employee_incentive/employee_incentive.json index e5b1052b3a..f11e3aa32d 100644 --- a/erpnext/payroll/doctype/employee_incentive/employee_incentive.json +++ b/erpnext/payroll/doctype/employee_incentive/employee_incentive.json @@ -75,7 +75,6 @@ "reqd": 1 }, { - "default": "Company:company:default_currency", "depends_on": "eval:(doc.docstatus==1 || doc.employee)", "fieldname": "currency", "fieldtype": "Link", @@ -95,7 +94,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-10-20 17:22:16.468042", + "modified": "2021-03-31 21:38:20.332316", "modified_by": "Administrator", "module": "Payroll", "name": "Employee Incentive", diff --git a/erpnext/payroll/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.js b/erpnext/payroll/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.js index 0e0c9b5a1a..fb11875e96 100644 --- a/erpnext/payroll/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.js +++ b/erpnext/payroll/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.js @@ -47,5 +47,26 @@ frappe.ui.form.on('Employee Tax Exemption Declaration', { }); }).addClass("btn-primary"); } + }, + + employee: function(frm) { + if (frm.doc.employee) { + frm.trigger('get_employee_currency'); + } + }, + + get_employee_currency: function(frm) { + frappe.call({ + method: "erpnext.payroll.doctype.salary_structure_assignment.salary_structure_assignment.get_employee_currency", + args: { + employee: frm.doc.employee, + }, + callback: function(r) { + if (r.message) { + frm.set_value('currency', r.message); + frm.refresh_fields(); + } + } + }); } }); diff --git a/erpnext/payroll/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.json b/erpnext/payroll/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.json index 83d4ae53df..bceada3870 100644 --- a/erpnext/payroll/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.json +++ b/erpnext/payroll/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.json @@ -108,7 +108,7 @@ "read_only": 1 }, { - "default": "Company:company:default_currency", + "depends_on": "eval: doc.employee", "fieldname": "currency", "fieldtype": "Link", "label": "Currency", @@ -119,7 +119,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-10-20 16:42:24.493761", + "modified": "2021-03-31 21:39:59.237361", "modified_by": "Administrator", "module": "Payroll", "name": "Employee Tax Exemption Declaration", diff --git a/erpnext/payroll/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.js b/erpnext/payroll/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.js index 497f35c41e..4fb0a3771e 100644 --- a/erpnext/payroll/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.js +++ b/erpnext/payroll/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.js @@ -58,5 +58,26 @@ frappe.ui.form.on('Employee Tax Exemption Proof Submission', { currency: function(frm) { frm.refresh_fields(); - } + }, + + employee: function(frm) { + if (frm.doc.employee) { + frm.trigger('get_employee_currency'); + } + }, + + get_employee_currency: function(frm) { + frappe.call({ + method: "erpnext.payroll.doctype.salary_structure_assignment.salary_structure_assignment.get_employee_currency", + args: { + employee: frm.doc.employee, + }, + callback: function(r) { + if (r.message) { + frm.set_value('currency', r.message); + frm.refresh_fields(); + } + } + }); + }, }); diff --git a/erpnext/payroll/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.json b/erpnext/payroll/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.json index 53f18cb1fe..6770d3e1a8 100644 --- a/erpnext/payroll/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.json +++ b/erpnext/payroll/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.json @@ -131,7 +131,7 @@ "read_only": 1 }, { - "default": "Company:company:default_currency", + "depends_on": "eval: doc.employee", "fieldname": "currency", "fieldtype": "Link", "label": "Currency", @@ -142,7 +142,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-10-20 16:47:03.410020", + "modified": "2021-03-31 21:41:13.723339", "modified_by": "Administrator", "module": "Payroll", "name": "Employee Tax Exemption Proof Submission", diff --git a/erpnext/payroll/doctype/income_tax_slab/income_tax_slab.json b/erpnext/payroll/doctype/income_tax_slab/income_tax_slab.json index 9fa261dea2..935d89fbc9 100644 --- a/erpnext/payroll/doctype/income_tax_slab/income_tax_slab.json +++ b/erpnext/payroll/doctype/income_tax_slab/income_tax_slab.json @@ -93,7 +93,7 @@ "options": "Income Tax Slab Other Charges" }, { - "default": "Company:company:default_currency", + "fetch_from": "company.default_currency", "fieldname": "currency", "fieldtype": "Link", "label": "Currency", @@ -104,7 +104,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-10-19 13:54:24.728075", + "modified": "2021-03-31 21:42:08.139520", "modified_by": "Administrator", "module": "Payroll", "name": "Income Tax Slab", diff --git a/erpnext/payroll/doctype/retention_bonus/retention_bonus.json b/erpnext/payroll/doctype/retention_bonus/retention_bonus.json index 6647230078..65b566f83a 100644 --- a/erpnext/payroll/doctype/retention_bonus/retention_bonus.json +++ b/erpnext/payroll/doctype/retention_bonus/retention_bonus.json @@ -93,7 +93,6 @@ "reqd": 1 }, { - "default": "Company:company:default_currency", "depends_on": "eval:(doc.docstatus==1 || doc.employee)", "fieldname": "currency", "fieldtype": "Link", @@ -106,7 +105,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-10-20 17:27:47.003134", + "modified": "2021-03-31 21:43:28.363644", "modified_by": "Administrator", "module": "Payroll", "name": "Retention Bonus", diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.json b/erpnext/payroll/doctype/salary_slip/salary_slip.json index 6688368262..262b7164a1 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.json +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.json @@ -500,7 +500,6 @@ "fieldtype": "Column Break" }, { - "default": "Company:company:default_currency", "depends_on": "eval:(doc.docstatus==1 || doc.salary_structure)", "fetch_from": "salary_structure.currency", "fieldname": "currency", @@ -632,7 +631,7 @@ "idx": 9, "is_submittable": 1, "links": [], - "modified": "2021-02-19 11:48:05.383945", + "modified": "2021-03-31 21:44:09.772331", "modified_by": "Administrator", "module": "Payroll", "name": "Salary Slip", diff --git a/erpnext/payroll/doctype/salary_structure_assignment/salary_structure_assignment.json b/erpnext/payroll/doctype/salary_structure_assignment/salary_structure_assignment.json index 92bb347661..a4e1a5ad1a 100644 --- a/erpnext/payroll/doctype/salary_structure_assignment/salary_structure_assignment.json +++ b/erpnext/payroll/doctype/salary_structure_assignment/salary_structure_assignment.json @@ -125,7 +125,6 @@ "options": "Income Tax Slab" }, { - "default": "Company:company:default_currency", "depends_on": "eval:(doc.docstatus==1 || doc.salary_structure)", "fetch_from": "salary_structure.currency", "fieldname": "currency", @@ -146,7 +145,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-11-30 18:07:48.251311", + "modified": "2021-03-31 21:44:46.267974", "modified_by": "Administrator", "module": "Payroll", "name": "Salary Structure Assignment", From d765b21825da6d83ed76259e7a1eabd721e76112 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 1 Apr 2021 14:39:52 +0530 Subject: [PATCH 388/449] fix: Salary Structure object has no attribute set_totals (#25114) --- erpnext/payroll/doctype/salary_slip/salary_slip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.js b/erpnext/payroll/doctype/salary_slip/salary_slip.js index d5278393a1..3e8a213ca9 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.js +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.js @@ -216,7 +216,7 @@ frappe.ui.form.on('Salary Slip Timesheet', { }); var set_totals = function(frm) { - if (frm.doc.docstatus === 0) { + if (frm.doc.docstatus === 0 && frm.doc.doctype === "Salary Slip") { if (frm.doc.earnings || frm.doc.deductions) { frappe.call({ method: "set_totals", From 58ca5a73298ef0fd95e61992e244c1410fb5afa3 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 23 Mar 2021 11:37:27 +0530 Subject: [PATCH 389/449] fix: repost not completed backdated transactions --- erpnext/hooks.py | 1 + .../repost_item_valuation.py | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/erpnext/hooks.py b/erpnext/hooks.py index f87769c182..a76fb07b80 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -324,6 +324,7 @@ scheduler_events = { "erpnext.hr.doctype.shift_type.shift_type.process_auto_attendance_for_all_shifts", "erpnext.support.doctype.issue.issue.set_service_level_agreement_variance", "erpnext.erpnext_integrations.connectors.shopify_connection.sync_old_orders", + "erpnext.stock.doctype.repost_item_valuation.repost_item_valuation.repost_entries" ], "daily": [ "erpnext.stock.reorder_item.reorder_item", diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py index 8436acbed2..559f9a5ed9 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe, erpnext from frappe.model.document import Document -from frappe.utils import cint, get_link_to_form +from frappe.utils import cint, get_link_to_form, add_to_date, today from erpnext.stock.stock_ledger import repost_future_sle from erpnext.accounts.utils import update_gl_entries_after, check_if_stock_and_account_balance_synced from frappe.utils.user import get_users_with_role @@ -29,7 +29,7 @@ class RepostItemValuation(Document): self.company = frappe.get_cached_value(self.voucher_type, self.voucher_no, "company") elif self.warehouse: self.company = frappe.get_cached_value("Warehouse", self.warehouse, "company") - + def set_status(self, status=None): if not status: status = 'Queued' @@ -54,7 +54,6 @@ def repost(doc): repost_sl_entries(doc) repost_gl_entries(doc) - check_if_stock_and_account_balance_synced(doc.posting_date, doc.company) doc.set_status('Completed') except Exception: @@ -103,7 +102,7 @@ def notify_error_to_stock_managers(doc, traceback): recipients = get_users_with_role("Stock Manager") if not recipients: get_users_with_role("System Manager") - + subject = _("Error while reposting item valuation") message = (_("Hi,") + "
" + _("An error has been appeared while reposting item valuation via {0}") @@ -112,4 +111,24 @@ def notify_error_to_stock_managers(doc, traceback): ) frappe.sendmail(recipients=recipients, subject=subject, message=message) +def repost_entries(): + riv_entries = get_repost_item_valuation_entries() + for row in riv_entries: + doc = frappe.get_cached_doc('Repost Item Valuation', row.name) + repost(doc) + + riv_entries = get_repost_item_valuation_entries() + if riv_entries: + return + + for d in frappe.get_all('Company', filters= {'enable_perpetual_inventory': 1}): + check_if_stock_and_account_balance_synced(today(), d.company) + +def get_repost_item_valuation_entries(): + date = add_to_date(today(), hours=-12) + + return frappe.db.sql(""" SELECT name from `tabRepost Item Valuation` + WHERE status != 'Completed' and creation <= %s and docstatus = 1 + ORDER BY timestamp(posting_date, posting_time) asc, creation asc + """, date, as_dict=1) \ No newline at end of file From 6717773c28bf3d1fa305ee61663f96d72c6bf495 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 1 Apr 2021 15:30:34 +0530 Subject: [PATCH 390/449] fix: Travis (#25078) * fix(test): set default accounts in mode of payment * fix(test): import_doc params in shopify settings test * fix: syntax error in salary slip test * fix(test): use Temporary Opening account for Stock Reco opening entry * fix(test): skip GST doc naming validations for tests * fix(test): Salary Structure Assignment date edge case * fix(test): GST doc naming validations * fix: sider * revert: skip GST doc naming validations for tests --- .../accounts/doctype/pos_profile/pos_profile.py | 5 +++-- .../doctype/pos_profile/test_pos_profile.py | 16 +++++++++++++--- .../shopify_settings/test_shopify_settings.py | 3 +-- .../doctype/salary_slip/test_salary_slip.py | 2 +- .../salary_structure/test_salary_structure.py | 8 +++++++- erpnext/regional/india/test_utils.py | 8 ++++---- erpnext/regional/india/utils.py | 1 + .../test_stock_ledger_entry.py | 16 ++++++++-------- 8 files changed, 38 insertions(+), 21 deletions(-) diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.py b/erpnext/accounts/doctype/pos_profile/pos_profile.py index ee76bba750..cf7ed26d27 100644 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.py +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.py @@ -62,14 +62,15 @@ class POSProfile(Document): if len(default_mode) > 1: frappe.throw(_("You can only select one mode of payment as default")) - + invalid_modes = [] for d in self.payments: account = frappe.db.get_value( - "Mode of Payment Account", + "Mode of Payment Account", {"parent": d.mode_of_payment, "company": self.company}, "default_account" ) + if not account: invalid_modes.append(get_link_to_form("Mode of Payment", d.mode_of_payment)) diff --git a/erpnext/accounts/doctype/pos_profile/test_pos_profile.py b/erpnext/accounts/doctype/pos_profile/test_pos_profile.py index 62dc1fcb20..0033965700 100644 --- a/erpnext/accounts/doctype/pos_profile/test_pos_profile.py +++ b/erpnext/accounts/doctype/pos_profile/test_pos_profile.py @@ -92,11 +92,21 @@ def make_pos_profile(**args): "write_off_cost_center": args.write_off_cost_center or "_Test Write Off Cost Center - _TC" }) - payments = [{ + mode_of_payment = frappe.get_doc("Mode of Payment", "Cash") + company = args.company or "_Test Company" + default_account = args.income_account or "Sales - _TC" + + if not frappe.db.get_value("Mode of Payment Account", {"company": company, "parent": "Cash"}): + mode_of_payment.append("accounts", { + "company": company, + "default_account": default_account + }) + mode_of_payment.save() + + pos_profile.append("payments", { 'mode_of_payment': 'Cash', 'default': 1 - }] - pos_profile.set("payments", payments) + }) if not frappe.db.exists("POS Profile", args.name or "_Test POS Profile"): pos_profile.insert() diff --git a/erpnext/erpnext_integrations/doctype/shopify_settings/test_shopify_settings.py b/erpnext/erpnext_integrations/doctype/shopify_settings/test_shopify_settings.py index 30fa23cfb4..24cbf744ae 100644 --- a/erpnext/erpnext_integrations/doctype/shopify_settings/test_shopify_settings.py +++ b/erpnext/erpnext_integrations/doctype/shopify_settings/test_shopify_settings.py @@ -17,8 +17,7 @@ class ShopifySettings(unittest.TestCase): frappe.set_user("Administrator") # use the fixture data - import_doc(path=frappe.get_app_path("erpnext", "erpnext_integrations/doctype/shopify_settings/test_data/custom_field.json"), - ignore_links=True, overwrite=True) + import_doc(path=frappe.get_app_path("erpnext", "erpnext_integrations/doctype/shopify_settings/test_data/custom_field.json")) frappe.reload_doctype("Customer") frappe.reload_doctype("Sales Order") diff --git a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py index 143a306eb3..a59a67c51e 100644 --- a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py @@ -312,7 +312,7 @@ class TestSalarySlip(unittest.TestCase): frappe.db.sql("DELETE FROM `tabSalary Slip` where employee_name = 'test_ytd@salary.com'") create_salary_slips_for_payroll_period(applicant, salary_structure.name, - payroll_period, deduct_random=False) + payroll_period, deduct_random=False, num=6) salary_slips = frappe.get_all('Salary Slip', fields=['year_to_date', 'net_pay'], filters={'employee_name': 'test_ytd@salary.com'}, order_by = 'posting_date') diff --git a/erpnext/payroll/doctype/salary_structure/test_salary_structure.py b/erpnext/payroll/doctype/salary_structure/test_salary_structure.py index f2fb558a14..36387f23df 100644 --- a/erpnext/payroll/doctype/salary_structure/test_salary_structure.py +++ b/erpnext/payroll/doctype/salary_structure/test_salary_structure.py @@ -164,7 +164,13 @@ def create_salary_structure_assignment(employee, salary_structure, from_date=Non salary_structure_assignment.employee = employee salary_structure_assignment.base = 50000 salary_structure_assignment.variable = 5000 - salary_structure_assignment.from_date = from_date or add_days(nowdate(), -1) + + if getdate(nowdate()).day == 1: + date = from_date or nowdate() + else: + date = from_date or add_days(nowdate(), -1) + + salary_structure_assignment.from_date = date salary_structure_assignment.salary_structure = salary_structure salary_structure_assignment.currency = currency salary_structure_assignment.payroll_payable_account = get_payable_account(company) diff --git a/erpnext/regional/india/test_utils.py b/erpnext/regional/india/test_utils.py index 7ce27f6cf5..a16f56c704 100644 --- a/erpnext/regional/india/test_utils.py +++ b/erpnext/regional/india/test_utils.py @@ -12,14 +12,14 @@ class TestIndiaUtils(unittest.TestCase): mock_get_cached.return_value = "India" # mock country posting_date = "2021-05-01" - invalid_names = [ "SI$1231", "012345678901234567", "SI 2020 05", - "SI.2020.0001", "PI2021 - 001" ] + invalid_names = ["SI$1231", "012345678901234567", "SI 2020 05", + "SI.2020.0001", "PI2021 - 001"] for name in invalid_names: doc = frappe._dict(name=name, posting_date=posting_date) self.assertRaises(frappe.ValidationError, validate_document_name, doc) - valid_names = [ "012345678901236", "SI/2020/0001", "SI/2020-0001", - "2020-PI-0001", "PI2020-0001" ] + valid_names = ["012345678901236", "SI/2020/0001", "SI/2020-0001", + "2020-PI-0001", "PI2020-0001"] for name in valid_names: doc = frappe._dict(name=name, posting_date=posting_date) try: diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index e24bd6c3d0..ddcedd5e4f 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -154,6 +154,7 @@ def set_place_of_supply(doc, method=None): def validate_document_name(doc, method=None): """Validate GST invoice number requirements.""" + country = frappe.get_cached_value("Company", doc.company, "country") # Date was chosen as start of next FY to avoid irritating current users. diff --git a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py index 59f1f3961b..ba01f70d1c 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py @@ -34,7 +34,7 @@ class TestStockLedgerEntry(unittest.TestCase): qty=50, rate=100, company=company, - expense_account = "Stock Adjustment - _TC", + expense_account = "Stock Adjustment - _TC" if frappe.get_all("Stock Ledger Entry") else "Temporary Opening - _TC", posting_date='2020-04-10', posting_time='14:00' ) @@ -46,7 +46,7 @@ class TestStockLedgerEntry(unittest.TestCase): qty=10, rate=200, company=company, - expense_account = "Stock Adjustment - _TC", + expense_account="Stock Adjustment - _TC" if frappe.get_all("Stock Ledger Entry") else "Temporary Opening - _TC", posting_date='2020-04-20', posting_time='14:00' ) @@ -58,7 +58,7 @@ class TestStockLedgerEntry(unittest.TestCase): target="Finished Goods - _TC", company=company, qty=10, - expense_account="Stock Adjustment - _TC", + expense_account="Stock Adjustment - _TC" if frappe.get_all("Stock Ledger Entry") else "Temporary Opening - _TC", posting_date='2020-04-30', posting_time='14:00' ) @@ -90,7 +90,7 @@ class TestStockLedgerEntry(unittest.TestCase): qty=50, rate=150, company=company, - expense_account = "Stock Adjustment - _TC", + expense_account ="Stock Adjustment - _TC" if frappe.get_all("Stock Ledger Entry") else "Temporary Opening - _TC", posting_date='2020-04-12', posting_time='14:00' ) @@ -125,7 +125,7 @@ class TestStockLedgerEntry(unittest.TestCase): pr = make_purchase_receipt(company="_Test Company", posting_date='2020-04-10', warehouse="Stores - _TC", item_code="_Test Item for Reposting", qty=5, rate=100) - return_pr = make_purchase_receipt(company="_Test Company", posting_date='2020-04-15', + return_pr = make_purchase_receipt(company="_Test Company", posting_date='2020-04-15', warehouse="Stores - _TC", item_code="_Test Item for Reposting", is_return=1, return_against=pr.name, qty=-2) # check sle @@ -278,7 +278,7 @@ class TestStockLedgerEntry(unittest.TestCase): frappe.db.set_value("Buying Settings", None, "backflush_raw_materials_of_subcontract_based_on", "BOM") make_bom(item = subcontracted_item, raw_materials =[rm_item_code], currency="INR") - + # Purchase raw materials on supplier warehouse: Qty = 50, Rate = 100 pr = make_purchase_receipt(company=company, posting_date='2020-04-10', warehouse="Stores - _TC", item_code=rm_item_code, qty=10, rate=100) @@ -292,7 +292,7 @@ class TestStockLedgerEntry(unittest.TestCase): # Update raw material's valuation via LCV, Additional cost = 50 lcv = create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company) - + pr1.reload() self.assertEqual(pr1.items[0].valuation_rate, 125) @@ -310,7 +310,7 @@ class TestStockLedgerEntry(unittest.TestCase): # Back dated stock transactions are only allowed to stock managers frappe.db.set_value("Stock Settings", None, "role_allowed_to_create_edit_back_dated_transactions", "Stock Manager") - + # Set User with Stock User role but not Stock Manager frappe.set_user("test@example.com") user = frappe.get_doc("User", "test@example.com") From a3da206b64262f64782753a22309c6234c35b7ff Mon Sep 17 00:00:00 2001 From: marination Date: Thu, 1 Apr 2021 12:53:22 +0530 Subject: [PATCH 391/449] fix: Don't string format args as they may not be escaped properly - Append even conditional args to args list and send to query executer - It will escape all values that are sent to it - String formatting without escaping causes issues with % sign, etc. --- .../doctype/quality_inspection/quality_inspection.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.py b/erpnext/stock/doctype/quality_inspection/quality_inspection.py index 58b1eca2d3..264a673ba4 100644 --- a/erpnext/stock/doctype/quality_inspection/quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.py @@ -62,17 +62,21 @@ class QualityInspection(Document): (quality_inspection, self.modified, self.reference_name, self.item_code)) else: + args = [quality_inspection, self.modified, self.reference_name, self.item_code] doctype = self.reference_type + ' Item' + if self.reference_type == 'Stock Entry': doctype = 'Stock Entry Detail' if self.reference_type and self.reference_name: conditions = "" if self.batch_no and self.docstatus == 1: - conditions += " and t1.batch_no = '%s'"%(self.batch_no) + conditions += " and t1.batch_no = %s" + args.append(self.batch_no) if self.docstatus == 2: # if cancel, then remove qi link wherever same name - conditions += " and t1.quality_inspection = '%s'"%(self.name) + conditions += " and t1.quality_inspection = %s" + args.append(self.name) frappe.db.sql(""" UPDATE @@ -85,7 +89,7 @@ class QualityInspection(Document): and t1.parent = t2.name {conditions} """.format(parent_doc=self.reference_type, child_doc=doctype, conditions=conditions), - (quality_inspection, self.modified, self.reference_name, self.item_code)) + args) def inspect_and_set_status(self): for reading in self.readings: From 98d250995d86d8721dd534e8467e7d111492aa72 Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Thu, 1 Apr 2021 16:52:28 +0530 Subject: [PATCH 392/449] fix(India): create property setters for shorter naming series (#25134) --- .../accounts/doctype/purchase_invoice/test_records.json | 4 ++-- erpnext/accounts/doctype/sales_invoice/test_records.json | 8 ++++---- .../accounts/doctype/sales_invoice/test_sales_invoice.py | 1 + erpnext/regional/india/setup.py | 9 ++++++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/test_records.json b/erpnext/accounts/doctype/purchase_invoice/test_records.json index e7166c5a12..9f9e90d8a7 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_records.json +++ b/erpnext/accounts/doctype/purchase_invoice/test_records.json @@ -43,7 +43,7 @@ } ], "grand_total": 0, - "naming_series": "_T-BILL", + "naming_series": "T-PINV-", "taxes": [ { "account_head": "_Test Account Shipping Charges - _TC", @@ -167,7 +167,7 @@ } ], "grand_total": 0, - "naming_series": "_T-Purchase Invoice-", + "naming_series": "T-PINV-", "taxes": [ { "account_head": "_Test Account Shipping Charges - _TC", diff --git a/erpnext/accounts/doctype/sales_invoice/test_records.json b/erpnext/accounts/doctype/sales_invoice/test_records.json index e00a58f864..3781f8ccc9 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_records.json +++ b/erpnext/accounts/doctype/sales_invoice/test_records.json @@ -31,7 +31,7 @@ "base_grand_total": 561.8, "grand_total": 561.8, "is_pos": 0, - "naming_series": "_T-Sales Invoice-", + "naming_series": "T-SINV-", "base_net_total": 500.0, "taxes": [ { @@ -104,7 +104,7 @@ "base_grand_total": 630.0, "grand_total": 630.0, "is_pos": 0, - "naming_series": "_T-Sales Invoice-", + "naming_series": "T-SINV-", "base_net_total": 500.0, "taxes": [ { @@ -175,7 +175,7 @@ ], "grand_total": 0, "is_pos": 0, - "naming_series": "_T-Sales Invoice-", + "naming_series": "T-SINV-", "taxes": [ { "account_head": "_Test Account Shipping Charges - _TC", @@ -301,7 +301,7 @@ ], "grand_total": 0, "is_pos": 0, - "naming_series": "_T-Sales Invoice-", + "naming_series": "T-SINV-", "taxes": [ { "account_head": "_Test Account Excise Duty - _TC", diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 72e3125c84..dd08e844b7 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -2108,6 +2108,7 @@ def create_sales_invoice(**args): si.return_against = args.return_against si.currency=args.currency or "INR" si.conversion_rate = args.conversion_rate or 1 + si.naming_series = args.naming_series or "T-SINV-" si.append("items", { "item_code": args.item or args.item_code or "_Test Item", diff --git a/erpnext/regional/india/setup.py b/erpnext/regional/india/setup.py index ee49aae050..f7689cfa19 100644 --- a/erpnext/regional/india/setup.py +++ b/erpnext/regional/india/setup.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import frappe, os, json from frappe.custom.doctype.custom_field.custom_field import create_custom_fields +from frappe.custom.doctype.property_setter.property_setter import make_property_setter from frappe.permissions import add_permission, update_permission_property from erpnext.regional.india import states from erpnext.accounts.utils import get_fiscal_year, FiscalYearError @@ -18,6 +19,7 @@ def setup(company=None, patch=True): # TODO: for all countries def setup_company_independent_fixtures(): make_custom_fields() + make_property_setters() add_permissions() add_custom_roles_for_reports() frappe.enqueue('erpnext.regional.india.setup.add_hsn_sac_codes', now=frappe.flags.in_test) @@ -110,6 +112,11 @@ def add_print_formats(): frappe.db.set_value("Print Format", "GST Tax Invoice", "disabled", 0) frappe.db.set_value("Print Format", "GST E-Invoice", "disabled", 0) +def make_property_setters(): + # GST rules do not allow for an invoice no. bigger than 16 characters + make_property_setter('Sales Invoice', 'naming_series', 'options', 'SINV-.YY.-\nSRET-.YY.-', '') + make_property_setter('Purchase Invoice', 'naming_series', 'options', 'PINV-.YY.-\nPRET-.YY.-', '') + def make_custom_fields(update=True): hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC', fieldtype='Data', fetch_from='item_code.gst_hsn_code', insert_after='description', @@ -860,4 +867,4 @@ def create_gratuity_rule(): }) rule.flags.ignore_mandatory = True - rule.save() \ No newline at end of file + rule.save() From 0773d6772dcebde9cf21eb74e10143e529eeb8b7 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 1 Apr 2021 17:47:19 +0530 Subject: [PATCH 393/449] fix(POS): local variable 'customer_currency' referenced before assignment (#25137) --- erpnext/accounts/doctype/pos_invoice/pos_invoice.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index 3fa9846c72..304e1f27c8 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -57,7 +57,7 @@ class POSInvoice(SalesInvoice): self.apply_loyalty_points() self.check_phone_payments() self.set_status(update=True) - + def before_cancel(self): if self.consolidated_invoice and frappe.db.get_value('Sales Invoice', self.consolidated_invoice, 'docstatus') == 1: pos_closing_entry = frappe.get_all( @@ -332,8 +332,6 @@ class POSInvoice(SalesInvoice): if selling_price_list: self.set('selling_price_list', selling_price_list) - if customer_currency != profile.get('currency'): - self.set('currency', customer_currency) # set pos values in items for item in self.get("items"): @@ -401,7 +399,7 @@ class POSInvoice(SalesInvoice): pay_req.request_phone_payment() return pay_req - + def get_new_payment_request(self, mop): payment_gateway_account = frappe.db.get_value("Payment Gateway Account", { "payment_account": mop.account, From db5f0f79b16775b92392c633573ca509dfa98dd5 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 1 Apr 2021 19:59:02 +0530 Subject: [PATCH 394/449] chore: added v13 change log (#25140) --- erpnext/change_log/v13/v13_0_0-beta_1.md | 52 --- erpnext/change_log/v13/v13_0_0-beta_11.md | 77 ---- erpnext/change_log/v13/v13_0_0-beta_12.md | 14 - erpnext/change_log/v13/v13_0_0-beta_14.md | 25 -- erpnext/change_log/v13/v13_0_0-beta_2.md | 68 ---- erpnext/change_log/v13/v13_0_0-beta_3.md | 66 --- erpnext/change_log/v13/v13_0_0-beta_4.md | 72 ---- erpnext/change_log/v13/v13_0_0-beta_5.md | 89 ---- erpnext/change_log/v13/v13_0_0-beta_6.md | 151 ------- erpnext/change_log/v13/v13_0_0.md | 471 ++++++++++++++++++++++ 10 files changed, 471 insertions(+), 614 deletions(-) delete mode 100644 erpnext/change_log/v13/v13_0_0-beta_1.md delete mode 100644 erpnext/change_log/v13/v13_0_0-beta_11.md delete mode 100644 erpnext/change_log/v13/v13_0_0-beta_12.md delete mode 100644 erpnext/change_log/v13/v13_0_0-beta_14.md delete mode 100644 erpnext/change_log/v13/v13_0_0-beta_2.md delete mode 100644 erpnext/change_log/v13/v13_0_0-beta_3.md delete mode 100644 erpnext/change_log/v13/v13_0_0-beta_4.md delete mode 100644 erpnext/change_log/v13/v13_0_0-beta_5.md delete mode 100644 erpnext/change_log/v13/v13_0_0-beta_6.md create mode 100644 erpnext/change_log/v13/v13_0_0.md diff --git a/erpnext/change_log/v13/v13_0_0-beta_1.md b/erpnext/change_log/v13/v13_0_0-beta_1.md deleted file mode 100644 index 5bd13dd823..0000000000 --- a/erpnext/change_log/v13/v13_0_0-beta_1.md +++ /dev/null @@ -1,52 +0,0 @@ -# Version 13.0.0 Beta 1 Release Notes - -## Accounting -- [Loan Management and Accounting](https://docs.erpnext.com/docs/user/manual/en/loan-management) -- [Accounting Dimensions in Budget Variance Report](https://github.com/frappe/erpnext/pull/19973) -- [Tax Category in POS Profile](https://docs.erpnext.com/docs/user/manual/en/accounts/pos-profile) -- [Custom Fields in POS](https://github.com/frappe/erpnext/pull/19876) -- [HSN Code Wise Item Tax](https://github.com/frappe/erpnext/pull/19478) -- Auto State-wise Taxation for GST India - - The Accounts entered in CGST and SGST accounts in GST Settings will be automatically skipped for Interstate Transaction and the Accounts in IGST Account will be skipped in Intrastate transaction. - -## Stock -- [Fetch Items from BOM in Stock Entry](https://github.com/frappe/erpnext/pull/19498) -- [Inter Warehouse Stock Transfer in Purchase Receipt](https://docs.erpnext.com/docs/user/manual/en/stock/articles/material-transfer-from-delivery-note) - -## HR -- [Work From Home in Attendance](https://github.com/frappe/erpnext/pull/20464) -- [Bulk Mark Attendance](https://github.com/frappe/erpnext/pull/20062) - -## Healthcare -- [Refactored Healthcare Module](https://docs.erpnext.com/docs/user/manual/en/healthcare) -- [Rehabilitation Module](https://docs.erpnext.com/docs/user/manual/en/healthcare/exercise_type) - -## CRM -- [Social Media Post](https://docs.erpnext.com/docs/user/manual/en/CRM/social-media-post) -- [Make Quotation against Blanket Order](https://docs.erpnext.com/docs/user/manual/en/selling/blanket-order) -- [Calendar View for Opportunity](https://github.com/frappe/erpnext/pull/21280) - -## New Reports -- [Item-wise Sales Register](https://docs.erpnext.com/docs/user/manual/en/accounts/accounting-reports) -- [Territory-wise Sales](https://github.com/frappe/erpnext/pull/20428) - -## Regional - -- Germany - - - [Update report DATEV Export to version 7.0](https://github.com/frappe/erpnext/pull/20582) and [allow to filter by voucher type](https://github.com/frappe/erpnext/pull/21060). - -- [Use any available Address Template](https://github.com/frappe/erpnext/pull/19862), not just your country's. - -## Other Changes -- [Report Summary in Financial Statement](https://github.com/frappe/erpnext/pull/20876) -- [Accounts Payable Report based on Payment Terms](https://docs.erpnext.com/docs/user/manual/en/accounts/accounting-reports) -- [Allow Purchase Invoice Creation Without Purchase Receipt Checkbox in Supplier](https://github.com/frappe/erpnext/pull/20864) -- [Allow Purchase Invoice Creation Without Purchase Order Checkbox in Supplier](https://github.com/frappe/erpnext/pull/20864) -- Add / Delete Items in submitted Sales / Purchase Order -- Provision to edit Item Details from Marketplace -- Nested Set filtering for Accounting Dimension -- UX changes and better validation message in all Modules -- Scan Barcode in Purchase Receipt -- Disable Rounded Totals Checkbox for Salary Slips in HR Settings - diff --git a/erpnext/change_log/v13/v13_0_0-beta_11.md b/erpnext/change_log/v13/v13_0_0-beta_11.md deleted file mode 100644 index 5c40ffbf73..0000000000 --- a/erpnext/change_log/v13/v13_0_0-beta_11.md +++ /dev/null @@ -1,77 +0,0 @@ -### Version 13.0.0 Beta 11 Release Notes - -#### Features and Enhancements - -- Provision to disable serial no and batch selector ([#24398](https://github.com/frappe/erpnext/pull/24398)) -- Multi currency in landed cost voucher ([#24127](https://github.com/frappe/erpnext/pull/24127)) -- Putaway ([#23969](https://github.com/frappe/erpnext/pull/23969)) -- Item valuation for internal stock transfers ([#24200](https://github.com/frappe/erpnext/pull/24200)) -- Batch wise item pricing ([#24470](https://github.com/frappe/erpnext/pull/24470)) -- Project template with dependent tasks ([#24092](https://github.com/frappe/erpnext/pull/24092)) -- Patient History Enhancements ([#24033](https://github.com/frappe/erpnext/pull/24033)) -- Compute Year to Date for Salary Slip components ([#24362](https://github.com/frappe/erpnext/pull/24362)) -- Configurable accounting dimension filters and validations ([#23912](https://github.com/frappe/erpnext/pull/23912)) -- Issue Summary Script Report ([#23603](https://github.com/frappe/erpnext/pull/23603)) -- Issue Analytics Script Report ([#23604](https://github.com/frappe/erpnext/pull/23604)) -- Loan report and enhancements ([#24370](https://github.com/frappe/erpnext/pull/24370)) -- Enhancements to erpnext membership ([#23865](https://github.com/frappe/erpnext/pull/23865)) -- Allow Discharge despite Unbilled Healthcare Services ([#24281](https://github.com/frappe/erpnext/pull/24281)) -- Patient appointment status changes ([#24201](https://github.com/frappe/erpnext/pull/24201)) -- Allow selecting admission service unit in Patient Appointment for inpatients ([#24410](https://github.com/frappe/erpnext/pull/24410)) -- Separate equity tree in CoA SKR04 ([#24095](https://github.com/frappe/erpnext/pull/24095)) -- Do Not Bill Patient Encounters for Inpatients ([#24355](https://github.com/frappe/erpnext/pull/24355)) -- Value Based and Numeric Quality Inspection ([#24181](https://github.com/frappe/erpnext/pull/24181)) -- Deleting account & stock entries on deletion of transaction ([#24298](https://github.com/frappe/erpnext/pull/24298)) -- Remove german sales invoice validation ([#24441](https://github.com/frappe/erpnext/pull/24441)) -- Voice Call Settings doctype added ([#24126](https://github.com/frappe/erpnext/pull/24126)) -- Shopping portal changes ([#24445](https://github.com/frappe/erpnext/pull/24445)) -- Add "Sync Now" to Plaid Settings ([#23602](https://github.com/frappe/erpnext/pull/23602)) - -#### Fixes - -- Multiple pricing rule with margin type as Percentage is not working ([#24204](https://github.com/frappe/erpnext/pull/24204)) -- Allow statistical component in salary structure. ([#24424](https://github.com/frappe/erpnext/pull/24424)) -- Set current asset value before calculating difference amount ([#24119](https://github.com/frappe/erpnext/pull/24119)) -- To use Stock UoM in BOM Stock Report ([#24339](https://github.com/frappe/erpnext/pull/24339)) -- Accounting entries of asset when submitting purchase receipt ([#24191](https://github.com/frappe/erpnext/pull/24191)) -- Cancelling of asset value adjustement ([#24193](https://github.com/frappe/erpnext/pull/24193)) -- Batch/Serial Selector for Scanned Batched Item ([#24338](https://github.com/frappe/erpnext/pull/24338)) -- Link timesheets with corresponding projects ([#24346](https://github.com/frappe/erpnext/pull/24346)) -- Material request wrong status issue ([#24019](https://github.com/frappe/erpnext/pull/24019)) -- UX issues in e-invoicing ([#24358](https://github.com/frappe/erpnext/pull/24358)) -- Company Wise Valuation Rate for RM in BOM ([#24324](https://github.com/frappe/erpnext/pull/24324)) -- Stock ageing should not take cancelled stock entries. ([#24437](https://github.com/frappe/erpnext/pull/24437)) -- Partial loan security unpledging ([#24252](https://github.com/frappe/erpnext/pull/24252)) -- Asset depreciation ledger ([#24226](https://github.com/frappe/erpnext/pull/24226)) -- Back Update from QC based on Batch No ([#24329](https://github.com/frappe/erpnext/pull/24329)) -- Fix for not having fiscal year while creating new company ([#24130](https://github.com/frappe/erpnext/pull/24130)) -- E-invoice print format not showing other charges ([#24474](https://github.com/frappe/erpnext/pull/24474)) -- Tax template update on customer address change ([#24146](https://github.com/frappe/erpnext/pull/24146)) -- Do not manufacture same serial no multiple times ([#24164](https://github.com/frappe/erpnext/pull/24164)) -- Ignore group cost center validation for period closing voucher ([#24375](https://github.com/frappe/erpnext/pull/24375)) -- Partial serial no return issue ([#24207](https://github.com/frappe/erpnext/pull/24207)) -- GSTR-1 double entry issue ([#24376](https://github.com/frappe/erpnext/pull/24376)) -- Not able to create dunning from sales invoice ([#24349](https://github.com/frappe/erpnext/pull/24349)) -- Set company in leave allocation and leave ledger entry ([#24296](https://github.com/frappe/erpnext/pull/24296)) -- Allow leave policy assignment to be canceled. ([#24265](https://github.com/frappe/erpnext/pull/24265)) -- Removed all day event from shift assignment calendar ([#24397](https://github.com/frappe/erpnext/pull/24397)) -- Tax calculation on salary slip for the first month ([#24272](https://github.com/frappe/erpnext/pull/24272)) -- Validate tax template for tax category ([#24402](https://github.com/frappe/erpnext/pull/24402)) -- Numeric/Non-numeric QI UX ([#24517](https://github.com/frappe/erpnext/pull/24517)) -- Finished good produced qty validation ([#24220](https://github.com/frappe/erpnext/pull/24220)) -- Incorrect serial no in the subcontracted purchase receipt ([#24354](https://github.com/frappe/erpnext/pull/24354)) -- Don't validate warehouse values between Material Request and Stock Entry ([#24294](https://github.com/frappe/erpnext/pull/24294)) -- Don't cancel job card if manufacturing entry has made ([#24063](https://github.com/frappe/erpnext/pull/24063)) -- Subscription prepaid date validation ([#24356](https://github.com/frappe/erpnext/pull/24356)) -- Allow addition and removal of employee in payroll Entry ([#24169](https://github.com/frappe/erpnext/pull/24169)) -- Filter Therapy Types and Therapy Plan in Patient Appointment ([#24152](https://github.com/frappe/erpnext/pull/24152)) -- Payment Period based on invoice date report fix/refactor ([#24378](https://github.com/frappe/erpnext/pull/24378)) -- Drop ship partial order fixed ([#24072](https://github.com/frappe/erpnext/pull/24072)) -- E-invoicing qrcode image generation ([#24395](https://github.com/frappe/erpnext/pull/24395)) -- Payment entry multi-currency issue ([#24332](https://github.com/frappe/erpnext/pull/24332)) -- Multiple pricing rule issue ([#24515](https://github.com/frappe/erpnext/pull/24515)) -- Last purchase rate not updating when voucher cancelled if only one voucher is present ([#24322](https://github.com/frappe/erpnext/pull/24322)) -- Do not cancel reference document on Quality Inspection cancellation ([#24197](https://github.com/frappe/erpnext/pull/24197)) -- Refactored fetching & validating address from erpnext rather than gst portal ([#24297](https://github.com/frappe/erpnext/pull/24297)) -- Opportunity Status fix ([#22944](https://github.com/frappe/erpnext/pull/22944)) -- Extra transferred qty has not consumed against work order ([#24495](https://github.com/frappe/erpnext/pull/24495)) \ No newline at end of file diff --git a/erpnext/change_log/v13/v13_0_0-beta_12.md b/erpnext/change_log/v13/v13_0_0-beta_12.md deleted file mode 100644 index cb981f1488..0000000000 --- a/erpnext/change_log/v13/v13_0_0-beta_12.md +++ /dev/null @@ -1,14 +0,0 @@ -### Version 13.0.0 Beta 12 Release Notes -#### Features -- Department wise Appointment Type charges ([#24572](https://github.com/frappe/erpnext/pull/24572)) -- Capture Rate of stock UOM in purchase ([#24315](https://github.com/frappe/erpnext/pull/24315)) - -#### Fixes - -- Fixed stock and account balance syncing ([#24644](https://github.com/frappe/erpnext/pull/24644)) -- Fixed incorrect stock ledger qty in the stock ledger report and bin ([#24649](https://github.com/frappe/erpnext/pull/24649)) -- Added patch to fix incorrect stock ledger and stock account value ([#24702](https://github.com/frappe/erpnext/pull/24702)) -- Skip e-invoice generation for non-taxable invoices ([#24568](https://github.com/frappe/erpnext/pull/24568)) -- Cannot cancel old invoices if eligible for e-invoicing ([#24608](https://github.com/frappe/erpnext/pull/24608)) -- Mpesa fixes and enhancement ([#24306](https://github.com/frappe/erpnext/pull/24306)) -- Fixed Consolidated Financial Statement report ([#24580](https://github.com/frappe/erpnext/pull/24580)) \ No newline at end of file diff --git a/erpnext/change_log/v13/v13_0_0-beta_14.md b/erpnext/change_log/v13/v13_0_0-beta_14.md deleted file mode 100644 index 1fa4376a72..0000000000 --- a/erpnext/change_log/v13/v13_0_0-beta_14.md +++ /dev/null @@ -1,25 +0,0 @@ -## Version 13.0.0 Beta 14 Release Notes -### Fixes and Enhancements - -- Repost incompleted backdated transactions ([#24991](https://github.com/frappe/erpnext/pull/24991)) -- Revert stock balance value calculation ([#24957](https://github.com/frappe/erpnext/pull/24957)) -- Allow user to update exchange rate in Multi-currency LCV ([#24947](https://github.com/frappe/erpnext/pull/24947)) -- Added correct path in hooks ([#24865](https://github.com/frappe/erpnext/pull/24865)) -- Unequal debit and credit issue on RCM Invoice ([#24838](https://github.com/frappe/erpnext/pull/24838)) -- Period list for exponential smoothing forecasting report ([#24983](https://github.com/frappe/erpnext/pull/24983)) -- POS Opening Entry with empty balance detail rows ([#24891](https://github.com/frappe/erpnext/pull/24891)) -- Use account_name only in consolidated report ([#24840](https://github.com/frappe/erpnext/pull/24840)) -- Validation of job card in stock entry ([#24882](https://github.com/frappe/erpnext/pull/24882)) -- Added supplier warehouse field back again ([#24827](https://github.com/frappe/erpnext/pull/24827)) -- Don't throw exception on invoice lines when there is no item_cod… ([#24864](https://github.com/frappe/erpnext/pull/24864)) -- Incorrect Nil Exempt and Non GST amount in GSTR3B report ([#24918](https://github.com/frappe/erpnext/pull/24918)) -- Payment References on adding Cost Center in PE and Report Issue Summary fix for V13 beta pre-release ([#24951](https://github.com/frappe/erpnext/pull/24951)) -- TDS check getting checked after reload ([#24973](https://github.com/frappe/erpnext/pull/24973)) -- Membership and Donation API fixes ([#24900](https://github.com/frappe/erpnext/pull/24900)) -- Serial no trim issue ([#24981](https://github.com/frappe/erpnext/pull/24981)) -- Add method for regional round off account back ([#24894](https://github.com/frappe/erpnext/pull/24894)) -- Allow zero valuation in stock reconciliation ([#24985](https://github.com/frappe/erpnext/pull/24985)) -- Simplified logic for additional salary ([#24907](https://github.com/frappe/erpnext/pull/24907)) -- Allow to select item code in batch naming ([#24825](https://github.com/frappe/erpnext/pull/24825)) -- 80G Certificates and Donations ([#24848](https://github.com/frappe/erpnext/pull/24848)) -- Membership renewal validation (#24963) ([#24964](https://github.com/frappe/erpnext/pull/24964)) \ No newline at end of file diff --git a/erpnext/change_log/v13/v13_0_0-beta_2.md b/erpnext/change_log/v13/v13_0_0-beta_2.md deleted file mode 100644 index 05c52c9c28..0000000000 --- a/erpnext/change_log/v13/v13_0_0-beta_2.md +++ /dev/null @@ -1,68 +0,0 @@ -### Version 13.0.0 Beta 2 Release Notes - -#### Accounting -- Onboarding and Dashboard ([#21677](https://github.com/frappe/erpnext/pull/21677)) -- Immutable Ledger ([#18740](https://github.com/frappe/erpnext/pull/18740)) -- Process Deferred Accounting document ([#19658](https://github.com/frappe/erpnext/pull/19658)) -- Journal Entry Template ([#21404](https://github.com/frappe/erpnext/pull/21404)) - - -#### Buying -- Onboarding and Dashboard ([#21611](https://github.com/frappe/erpnext/pull/21611)) -- New Reports - - Requested Items To Order ([#21611](https://github.com/frappe/erpnext/pull/21611)) - - Purchase Order Analysis ([#21611](https://github.com/frappe/erpnext/pull/21611)) - - Refactored Quoted Item Comparison report ([#21273](https://github.com/frappe/erpnext/pull/21273)) - -#### Stock -- Onboarding and Dashboard ([#21727](https://github.com/frappe/erpnext/pull/21727)) -- Invoice from Purchase Receipt with duplicate items which has been partially returned ([#20724](https://github.com/frappe/erpnext/pull/20724)) -- Report Enhancements ([#21727](https://github.com/frappe/erpnext/pull/21727)) - - Item Shortage Report - - Stock Ageing - - Purchase Receipt Trends - - Delivery Note Trends - -#### Manufacturing -- Onboarding and Dashboard ([#21430](https://github.com/frappe/erpnext/pull/21430)) -- Production forecasting using exponential smoothing method ([#21724](https://github.com/frappe/erpnext/pull/21724)) -- BOM Template ([#21262](https://github.com/frappe/erpnext/pull/21262)) -- Run MRP at parent level in the production plan and make material transfer based upon materials availability ([#21545](https://github.com/frappe/erpnext/pull/21545)) -- Downtime Entry ([#21430](https://github.com/frappe/erpnext/pull/21430)) -- New Reports - - Production Planning Report ([#21763](https://github.com/frappe/erpnext/pull/21763)) - - BOM Operations Time ([#21763](https://github.com/frappe/erpnext/pull/21763)) - - Work Order Summary ([#21430](https://github.com/frappe/erpnext/pull/21430)) - - Job card Summary ([#21430](https://github.com/frappe/erpnext/pull/21430)) - - Downtime Analysis ([#21430](https://github.com/frappe/erpnext/pull/21430)) - - Quality Inspection ([#21430](https://github.com/frappe/erpnext/pull/21430)) - - -#### HR -- Onboarding and Dashboard ([#21705](https://github.com/frappe/erpnext/pull/21705)) -- Recurring Additional Salary and reference fields ([#20936](https://github.com/frappe/erpnext/pull/20936)) -- Payroll based on employee cost center ([#21609](https://github.com/frappe/erpnext/pull/21609)) -- Payroll based on attendance ([#21258](https://github.com/frappe/erpnext/pull/21258)) -- Monthly attendance sheet report enhancements, group by Department, Designation, Employee Grade and Branch ([#21331](https://github.com/frappe/erpnext/pull/21331)) -- Upload Attendance template now have pre-filled holiday status ([#20947](https://github.com/frappe/erpnext/pull/20947)) -- New and enhanced reports - - Employee Analytics report ([#21705](https://github.com/frappe/erpnext/pull/21705)) - - Employee Leave Balance ([#20754](https://github.com/frappe/erpnext/pull/20754)) - - Employee Leave Balance Summary ([#20754](https://github.com/frappe/erpnext/pull/20754)) - -#### Healthcare -- Onboarding and Dashboard ([#21774](https://github.com/frappe/erpnext/pull/21774)) -- Multi company support in Healthcare ([#21290](https://github.com/frappe/erpnext/pull/21290)) - -#### CRM -- Onboarding and Dashboard ([#21733](https://github.com/frappe/erpnext/pull/21733)) - -#### Selling -- Territory tree in Customer Acquisition and Loyalty report ([#21668](https://github.com/frappe/erpnext/pull/21668)) - -#### Project -- Onboarding and Dashboard ([#21587](https://github.com/frappe/erpnext/pull/21587)) -- Project Summary Report ([#21587](https://github.com/frappe/erpnext/pull/21587)) - -#### Integrations -- Woocommerce Integration ([#13217](https://github.com/frappe/erpnext/pull/13217)) \ No newline at end of file diff --git a/erpnext/change_log/v13/v13_0_0-beta_3.md b/erpnext/change_log/v13/v13_0_0-beta_3.md deleted file mode 100644 index 09ea90087d..0000000000 --- a/erpnext/change_log/v13/v13_0_0-beta_3.md +++ /dev/null @@ -1,66 +0,0 @@ -### Version 13.0.0 Beta 3 Release Notes - -#### Features and Enhancements -- Dedicated Payroll module with Onboarding and Dashboard ([#21990](https://github.com/frappe/erpnext/pull/21990)) -- New Payroll Reports - - Income Tax Deductions - - Professional Tax Deductions - - Provident Fund Deductions - - Total Salary Payments Based on Payment Mode - - Salary Payments via ECS -- Distributed Cost Center ([#21531](https://github.com/frappe/erpnext/pull/21531)) -- More controlled deferred revenue booking ([#21671](https://github.com/frappe/erpnext/pull/21671)) - - Book deferred accounting via Journal Entry, provision to keep in draft - - Provision to book deferred revenue/expense on a monthly basis rather than by days -- Selling Desk, Dashboard and Onboarding ([#22055](https://github.com/frappe/erpnext/pull/22055)) -- Help Articles on support portal ([#22194](https://github.com/frappe/erpnext/pull/22194)) -- Issue Metrics and SLA Enhancements ([#21617](https://github.com/frappe/erpnext/pull/21617)) -- Multi UOM support in Request for Quotation ([#22249](https://github.com/frappe/erpnext/pull/22249)) -- The ability for a contract to be authorized internally using a signature field ([#22095](https://github.com/frappe/erpnext/pull/22095)) -- Gross Profit In Quotation ([#21795](https://github.com/frappe/erpnext/pull/21795)) -- Notify credit controller users for credit limit extension via Email ([#22213](https://github.com/frappe/erpnext/pull/22213)) -- Added In and Out time in attendance ([#21547](https://github.com/frappe/erpnext/pull/21547)) -- Renamed Loan Management to Loan on Desk Page ([#21877](https://github.com/frappe/erpnext/pull/21877)) -- Document tour to manufacturing settings ([#21962](https://github.com/frappe/erpnext/pull/21962)) -- Added Expense Approver field in Employee master ([#22244](https://github.com/frappe/erpnext/pull/22244)) - - -#### Fixes -- Bill all hours by default on Timesheet ([#22155](https://github.com/frappe/erpnext/pull/22155)) -- Unable to cancel employee advance ([#22374](https://github.com/frappe/erpnext/pull/22374)) -- Status error in purchase invoice ([#22351](https://github.com/frappe/erpnext/pull/22351)) -- Item-wise sales and purchase register export ([#22184](https://github.com/frappe/erpnext/pull/22184)) -- Billing address in for Purchase documents ([#22233](https://github.com/frappe/erpnext/pull/22233)) -- Handle canceled entries in financial statements ([#22231](https://github.com/frappe/erpnext/pull/22231)) -- Default period start date and period end date for financial statements ([#22011](https://github.com/frappe/erpnext/pull/22011)) -- Update Packed Items via Update Items in Sales Order ([#22392](https://github.com/frappe/erpnext/pull/22392)) -- Hide delete company transactions button if not system manager ([#21839](https://github.com/frappe/erpnext/pull/21839)) -- Skipping total row for tree-view reports ([#22350](https://github.com/frappe/erpnext/pull/22350)) -- Cancelled entries in tds payable monthly report ([#22131](https://github.com/frappe/erpnext/pull/22131)) -- Inter-company Invoice currency for multicurrency transactions ([#21984](https://github.com/frappe/erpnext/pull/21984)) -- Filter batches based on item and warehouse in Pick List (develop) ([#21780](https://github.com/frappe/erpnext/pull/21780)) -- Set cost center in Expense Claim child based on parent (if missing) ([#22175](https://github.com/frappe/erpnext/pull/22175)) -- Item wise backdated stock entry posting for immutable ledger ([#22366](https://github.com/frappe/erpnext/pull/22366)) -- Shopping cart UI fixes ([#22137](https://github.com/frappe/erpnext/pull/22137)) -- Filter Leave Type based on allocation for a particular employee ([#22050](https://github.com/frappe/erpnext/pull/22050)) -- Party validation for inter-warehouse transaction ([#22186](https://github.com/frappe/erpnext/pull/22186)) -- Manufacturing dashboard and work order summary chart ([#21946](https://github.com/frappe/erpnext/pull/21946)) -- IP Admission and Discharge, Minor fixes ([#21817](https://github.com/frappe/erpnext/pull/21817)) -- Validation of Purchase Order against Material Request missing ([#22192](https://github.com/frappe/erpnext/pull/22192)) -- Staffing Plan validation ([#22379](https://github.com/frappe/erpnext/pull/22379)) -- Do not allow backdated stock transactions in previous fiscal year ([#21967](https://github.com/frappe/erpnext/pull/21967)) -- Employee Advance Return not working ([#21812](https://github.com/frappe/erpnext/pull/21812)) -- Added card for reports on education desk ([#21853](https://github.com/frappe/erpnext/pull/21853)) -- Refactored project summary report ([#21943](https://github.com/frappe/erpnext/pull/21943)) -- Revenue and Customer Count only in date range in Customer Acquitition Report ([#22210](https://github.com/frappe/erpnext/pull/22210)) -- Alternative item not working for subcontract ([#22386](https://github.com/frappe/erpnext/pull/22386)) -- Unable to create batched Item ([#22393](https://github.com/frappe/erpnext/pull/22393)) -- Filters for the manufacturing reports ([#21960](https://github.com/frappe/erpnext/pull/21960)) -- Raw material warehouse in Production Planning Report ([#21982](https://github.com/frappe/erpnext/pull/21982)) -- Allowed LWP leave types to select in Leave Application even if there is no allocation against them ([#22197](https://github.com/frappe/erpnext/pull/22197)) -- Report not working on parameter Grade ([#21951](https://github.com/frappe/erpnext/pull/21951)) -- Allow to enter Relieving date if employee status is Left ([#22242](https://github.com/frappe/erpnext/pull/22242)) -- Resetting lost reason in opportunity and quotation ([#22378](https://github.com/frappe/erpnext/pull/22378)) -- Filtering issues in opening invoice creation tool ([#21969](https://github.com/frappe/erpnext/pull/21969)) -- Set default reference Id for "On Previous Row Amount" and "On Previous Row Total" ([#22346](https://github.com/frappe/erpnext/pull/22346)) -- UX date range field separated in from and to date fields. ([#21765](https://github.com/frappe/erpnext/pull/21765)) diff --git a/erpnext/change_log/v13/v13_0_0-beta_4.md b/erpnext/change_log/v13/v13_0_0-beta_4.md deleted file mode 100644 index b835cec211..0000000000 --- a/erpnext/change_log/v13/v13_0_0-beta_4.md +++ /dev/null @@ -1,72 +0,0 @@ -### Version 13.0.0 Beta 4 Release Notes - -#### Features and Enhancements -- New and refreshed POS ([#20789](https://github.com/frappe/erpnext/pull/20789)) -- Introduced Dunning ([#22559](https://github.com/frappe/erpnext/pull/22559)) -- Taxjar Integration ([#21047](https://github.com/frappe/erpnext/pull/21047)) -- Patient Progress Page ([#22474](https://github.com/frappe/erpnext/pull/22474)) -- Provision to make RFQ against Opportunity ([#22765](https://github.com/frappe/erpnext/pull/22765)) -- Added form dashboards and refactored custom buttons in Education module ([#22727](https://github.com/frappe/erpnext/pull/22727)) -- Student Attendance and Leave Enhancements ([#22623](https://github.com/frappe/erpnext/pull/22623)) -- Recruitment analytics ([#21732](https://github.com/frappe/erpnext/pull/21732)) -- Add medical coding fields to Healthcare DocTypes ([#22501](https://github.com/frappe/erpnext/pull/22501)) -- Autofill Supplier pop-up when only 1 Supplier in RFQ ([#22512](https://github.com/frappe/erpnext/pull/22512)) -- Accounting entries for service item in Purchase receipt ([#22223](https://github.com/frappe/erpnext/pull/22223)) -- Enhancement in subscription ([#22263](https://github.com/frappe/erpnext/pull/22263)) -- Laboratory Module Enhancements ([#22416](https://github.com/frappe/erpnext/pull/22416)) -- Added columns to get complete analysis for material request ([#22607](https://github.com/frappe/erpnext/pull/22607)) -- Added all companies option in employee tree to view employee across all companies ([#22573](https://github.com/frappe/erpnext/pull/22573)) -- Email Group Option In Email Campaign ([#22731](https://github.com/frappe/erpnext/pull/22731)) -- Added range for age in stock ageing ([#22622](https://github.com/frappe/erpnext/pull/22622)) -- Refactored shopping cart ([#22617](https://github.com/frappe/erpnext/pull/22617)) - -#### Fixes: -- Enable show_configure_button when shopping cart is enabled ([#22468](https://github.com/frappe/erpnext/pull/22468)) -- Setup status indicators for Job Offer and Job Applicant (develop) ([#22445](https://github.com/frappe/erpnext/pull/22445)) -- Item-wise sales history report ([#22783](https://github.com/frappe/erpnext/pull/22783)) -- Setting filter for project in kanban board ([#22717](https://github.com/frappe/erpnext/pull/22717)) -- Dashboard For Timesheet ([#22750](https://github.com/frappe/erpnext/pull/22750)) -- Handle custom statuses for the pause SLA configuration ([#22349](https://github.com/frappe/erpnext/pull/22349)) -- Quality Feedback and Template ([#22571](https://github.com/frappe/erpnext/pull/22571)) -- Unable to change link from new lead to existing customer ([#22787](https://github.com/frappe/erpnext/pull/22787)) -- Job applicant fixes ([#22448](https://github.com/frappe/erpnext/pull/22448)) -- Move Issue List actions under 'Actions' dropdown (ux) ([#22710](https://github.com/frappe/erpnext/pull/22710)) -- Cost center should only show option of selected company ([#22598](https://github.com/frappe/erpnext/pull/22598)) -- Serial No Rename does not affect Stock Ledger Entry ([#22746](https://github.com/frappe/erpnext/pull/22746)) -- Descriptions not copied while creating Fees from Fee Structure ([#22792](https://github.com/frappe/erpnext/pull/22792)) -- Company filter for cost_center and expense_account in all sales and purchase transactions ([#22478](https://github.com/frappe/erpnext/pull/22478)) -- Arrangements of filters for reports accounts payable & receivable ([#22636](https://github.com/frappe/erpnext/pull/22636)) -- Update the project after task deletion so that the % completed shows correct value ([#22591](https://github.com/frappe/erpnext/pull/22591)) -- Block Invalid Serial No updates in Maintenance Schedule ([#22665](https://github.com/frappe/erpnext/pull/22665)) -- Fetch item price in sales invoice based on it's validity ([#22563](https://github.com/frappe/erpnext/pull/22563)) -- Add view ledger button for cancelled docs ([#22432](https://github.com/frappe/erpnext/pull/22432)) -- Allow creating SLA documents even if SLA tracking is not enabled ([#22608](https://github.com/frappe/erpnext/pull/22608)) -- Quotation list view blank if quotation_to field not set as a standard filter ([#22672](https://github.com/frappe/erpnext/pull/22672)) -- Salary deductions report fixes ([#22397](https://github.com/frappe/erpnext/pull/22397)) -22727)) -- Incorrect delivered qty in Supplier-Wise Sales Analytics ([#22631](https://github.com/frappe/erpnext/pull/22631)) -- Moved parent warehouse to top section also added a section break ([#22708](https://github.com/frappe/erpnext/pull/22708)) -- Skip Progress and Completed by fields on Task Duplication ([#22565](https://github.com/frappe/erpnext/pull/22565)) -- Incorrect stock after merging the items ([#22526](https://github.com/frappe/erpnext/pull/22526)) -- Letter head not found in opening invoice creation tool ([#22488](https://github.com/frappe/erpnext/pull/22488)) -- Cannot cancel asset and asset movement ([#22441](https://github.com/frappe/erpnext/pull/22441)) -- Fetch project-related info in Timesheet ([#22423](https://github.com/frappe/erpnext/pull/22423)) -- Currency symbol not showing as per company currency in stock balance report ([#22724](https://github.com/frappe/erpnext/pull/22724)) -- Add default cost center in payment reconciliation JV ([#22614](https://github.com/frappe/erpnext/pull/22614)) -- Stock Reconciliation Invalid Quantity for Batched Item ([#22726](https://github.com/frappe/erpnext/pull/22726)) -- Project link not set in accounts other than profit and loss accounts ([#22051](https://github.com/frappe/erpnext/pull/22051)) -- Buying price for non stock item in gross profit report ([#22616](https://github.com/frappe/erpnext/pull/22616)) -- Heatmap in Vehicle ([#22743](https://github.com/frappe/erpnext/pull/22743)) -- Added Project Field in Purchase Receipt for Stock Ledger Tagging ([#22666](https://github.com/frappe/erpnext/pull/22666)) -- Multi currency payment reconciliation ([#22738](https://github.com/frappe/erpnext/pull/22738)) -- Cannot cancel assets with repair pending ([#22440](https://github.com/frappe/erpnext/pull/22440)) -- Reset homepage to home after unchecking products page ([#22736](https://github.com/frappe/erpnext/pull/22736)) -- Add project filter in parent task field ([#22655](https://github.com/frappe/erpnext/pull/22655)) -- Generic Message in previous doc validation for buying and selling ([#22546](https://github.com/frappe/erpnext/pull/22546)) -- Cess amount in GSTR 3B report ([#22701](https://github.com/frappe/erpnext/pull/22701)) -- Expense claim outstanding while making payment entry ([#22735](https://github.com/frappe/erpnext/pull/22735)) -- Take parent cost center for child if no cost center at child in expense claim ([#22496](https://github.com/frappe/erpnext/pull/22496)) -- Consider company fiscal year for getting balance ([#22577](https://github.com/frappe/erpnext/pull/22577)) -- Pick List empty table and Serial-Batch items handling ([#22426](https://github.com/frappe/erpnext/pull/22426)) -- Show total row in print format of financial statement ([#22693](https://github.com/frappe/erpnext/pull/22693)) -- Set Root as Parent if no parent in new tree view node ([#22497](https://github.com/frappe/erpnext/pull/22497)) \ No newline at end of file diff --git a/erpnext/change_log/v13/v13_0_0-beta_5.md b/erpnext/change_log/v13/v13_0_0-beta_5.md deleted file mode 100644 index 8374c775fe..0000000000 --- a/erpnext/change_log/v13/v13_0_0-beta_5.md +++ /dev/null @@ -1,89 +0,0 @@ -### Version 13.0.0 Beta 5 Release Notes - -#### Features and Enhancements -- Add company and correct filter in bank reconciliation statement ([#23614](https://github.com/frappe/erpnext/pull/23614)) -- Process Statement Of Accounts ([#22901](https://github.com/frappe/erpnext/pull/22901)) -- Added Condition field in Pricing Rule ([#23014](https://github.com/frappe/erpnext/pull/23014)) -- Material Request and Stock Entry Enhancement ([#22671](https://github.com/frappe/erpnext/pull/22671)) -- Added sequence id in routing for the completion of operations sequentially ([#23641](https://github.com/frappe/erpnext/pull/23641)) -- Appraisal form Enhancements ([#23500](https://github.com/frappe/erpnext/pull/23500)) -- Crm reports cleanup ([#22844](https://github.com/frappe/erpnext/pull/22844)) -- Open lead status on next contact date ([#23445](https://github.com/frappe/erpnext/pull/23445)) -- Quoted Item Comparison Report Enhancements v2 ([#23127](https://github.com/frappe/erpnext/pull/23127)) -- Added phone field in product Inquiry ([#23170](https://github.com/frappe/erpnext/pull/23170)) -- Added address template for luxembourg ([#23621](https://github.com/frappe/erpnext/pull/23621)) -- Provision to draft quotation from portal ([#23416](https://github.com/frappe/erpnext/pull/23416)) -- M-pesa integration ([#23439](https://github.com/frappe/erpnext/pull/23439)) -- Education Desk, Dashboard, and Onboarding ([#22825](https://github.com/frappe/erpnext/pull/22825)) -- Added search to support page ([#22447](https://github.com/frappe/erpnext/pull/22447)) -- Balance Serial Nos in Stock Ledger report ([#23675](https://github.com/frappe/erpnext/pull/23675)) -- Added POS Register report ([#23313](https://github.com/frappe/erpnext/pull/23313)) -- Added Project in Sales Analytics report ([#23309](https://github.com/frappe/erpnext/pull/23309)) -- Enhancement in Loan Topups ([#23049](https://github.com/frappe/erpnext/pull/23049)) -- Inpatient Medication Order and Entry ([#23473](https://github.com/frappe/erpnext/pull/23473)) -- Option to print UOM after quantity ([#23263](https://github.com/frappe/erpnext/pull/23263)) -- Supplier Quotation Comparison report ([#23323](https://github.com/frappe/erpnext/pull/23323)) -- Supplier Sourced Items in BOM ([#23557](https://github.com/frappe/erpnext/pull/23557)) -- Therapy Plan Template ([#23558](https://github.com/frappe/erpnext/pull/23558)) -- Youtube interactions via Video ([#22867](https://github.com/frappe/erpnext/pull/22867)) -- Laboratory Module ([#22853](https://github.com/frappe/erpnext/pull/22853)) -- Shift management ([#22262](https://github.com/frappe/erpnext/pull/22262)) - -#### Fixes -- Multiple pos issues ([#23725](https://github.com/frappe/erpnext/pull/23725)) -- Calculate taxes if tax is based on item quantity and inclusive on item price ([#23001](https://github.com/frappe/erpnext/pull/23001)) -- Contact us button not visible in the website for the non variant items ([#23217](https://github.com/frappe/erpnext/pull/23217)) -- Loan Security shortfall calculation fixes ([#22866](https://github.com/frappe/erpnext/pull/22866)) -- Not able to make Material Request from Sales Order ([#23669](https://github.com/frappe/erpnext/pull/23669)) -- Capture advance payments in payment order ([#23256](https://github.com/frappe/erpnext/pull/23256)) -- Program and Course Enrollment fixes ([#23333](https://github.com/frappe/erpnext/pull/23333)) -- Cannot create asset if cwip disabled and account not set ([#23580](https://github.com/frappe/erpnext/pull/23580)) -- Cannot merge pos invoices with inclusive tax ([#23541](https://github.com/frappe/erpnext/pull/23541)) -- Do not allow Company as accounting dimension ([#23755](https://github.com/frappe/erpnext/pull/23755)) -- Set value of wrong Bank Account field in Payment Entry ([#22302](https://github.com/frappe/erpnext/pull/22302)) -- Reverse journal entry for multi-currency ([#23165](https://github.com/frappe/erpnext/pull/23165)) -- Updated integrations desk page ([#23772](https://github.com/frappe/erpnext/pull/23772)) -- Assessment Result child table not visible when accessed via Assessment Plan dashboard ([#22880](https://github.com/frappe/erpnext/pull/22880)) -- Conversion factor fixes in Stock Entry ([#23407](https://github.com/frappe/erpnext/pull/23407)) -- Total calculations for multi-currency RCM invoices ([#23072](https://github.com/frappe/erpnext/pull/23072)) -- Show accounts in financial statements upto level 20 ([#23718](https://github.com/frappe/erpnext/pull/23718)) -- Consolidated financial statement sums values into wrong parent ([#23288](https://github.com/frappe/erpnext/pull/23288)) -- Set SLA variance in seconds for Duration fieldtype ([#23765](https://github.com/frappe/erpnext/pull/23765)) -- Added missing reports on selling desk ([#23548](https://github.com/frappe/erpnext/pull/23548)) -- Fixed heading in the mobile view ([#23145](https://github.com/frappe/erpnext/pull/23145)) -- Misleading filters on Item tax Template Link field ([#22918](https://github.com/frappe/erpnext/pull/22918)) -- Do not consider opening entries for TDS calculation ([#23597](https://github.com/frappe/erpnext/pull/23597)) -- Attendance calendar map fix ([#23245](https://github.com/frappe/erpnext/pull/23245)) -- Post cancellation accounting entry on posting date instead of current ([#23361](https://github.com/frappe/erpnext/pull/23361)) -- Set Customer only if Contact is present ([#23704](https://github.com/frappe/erpnext/pull/23704)) -- Add Delivery Note Count in Sales Invoice Dashboard ([#23161](https://github.com/frappe/erpnext/pull/23161)) -- Breadcrumbs for Maintenance Visit and Schedule ([#23369](https://github.com/frappe/erpnext/pull/23369)) -- Raise Error on over receipt/consumption for sub-contracted PR ([#23195](https://github.com/frappe/erpnext/pull/23195)) -- Validate if company not set in the Payment Entry ([#23419](https://github.com/frappe/erpnext/pull/23419)) -- Ignore company and bank account doctype while deleting company transactions ([#22953](https://github.com/frappe/erpnext/pull/22953)) -- Sales funnel data is inconsistent ([#23110](https://github.com/frappe/erpnext/pull/23110)) -- Credit Limit Email not working ([#23059](https://github.com/frappe/erpnext/pull/23059)) -- Add Company in list fields to fetch for Expense Claim ([#23007](https://github.com/frappe/erpnext/pull/23007)) -- Issue form cleaned up and renamed Minutes to First Response field ([#23066](https://github.com/frappe/erpnext/pull/23066)) -- Quotation lost reason options fix ([#22814](https://github.com/frappe/erpnext/pull/22814)) -- Tax amounts in HSN Wise Outward summary ([#23076](https://github.com/frappe/erpnext/pull/23076)) -- Patient Appointment not able to save ([#23434](https://github.com/frappe/erpnext/pull/23434)) -- Removed Working Hours field from Company ([#23009](https://github.com/frappe/erpnext/pull/23009)) -- Added check-in time validation in the Inpatient Record - Transfer ([#22958](https://github.com/frappe/erpnext/pull/22958)) -- Handle Blank from/to range in Numeric Item Attribute ([#23483](https://github.com/frappe/erpnext/pull/23483)) -- Sequence Matcher error in Bank Reconciliation ([#23539](https://github.com/frappe/erpnext/pull/23539)) -- Fixed Conversion Factor rate for the BOM Exploded Item ([#23151](https://github.com/frappe/erpnext/pull/23151)) -- Payment Schedule not fetching ([#23476](https://github.com/frappe/erpnext/pull/23476)) -- Validate if removed Item Attributes exist in variant items ([#22911](https://github.com/frappe/erpnext/pull/22911)) -- Set default billing address for purchase documents ([#22950](https://github.com/frappe/erpnext/pull/22950)) -- Added help link in navbar settings ([#22943](https://github.com/frappe/erpnext/pull/22943)) -- Apply TDS on Purchase Invoice creation from Purchase Order and Purchase Receipt ([#23282](https://github.com/frappe/erpnext/pull/23282)) -- Education Module fixes ([#23714](https://github.com/frappe/erpnext/pull/23714)) -- Filter out cancelled entries in customer ledger summary ([#23205](https://github.com/frappe/erpnext/pull/23205)) -- Fiscal Year and Tax Rates for Italy ([#23623](https://github.com/frappe/erpnext/pull/23623)) -- Production Plan incorrect Work Order qty ([#23264](https://github.com/frappe/erpnext/pull/23264)) -- Added new filters in the Batch-wise Balance History report ([#23676](https://github.com/frappe/erpnext/pull/23676)) -- Update state code and union territory for Daman and Diu ([#22988](https://github.com/frappe/erpnext/pull/22988)) -- Set Stock UOM in item while creating Material Request from Stock Entry ([#23436](https://github.com/frappe/erpnext/pull/23436)) -- Sales Order to Purchase Order flow improvement ([#23357](https://github.com/frappe/erpnext/pull/23357)) -- Student Admission and Student Applicant fixes ([#23515](https://github.com/frappe/erpnext/pull/23515)) diff --git a/erpnext/change_log/v13/v13_0_0-beta_6.md b/erpnext/change_log/v13/v13_0_0-beta_6.md deleted file mode 100644 index 4c6d9c28cf..0000000000 --- a/erpnext/change_log/v13/v13_0_0-beta_6.md +++ /dev/null @@ -1,151 +0,0 @@ -### Version 13.0.0 Beta 6 Release Notes - -#### Features and Enhancements - -- GST E-invoicing for India ([#23455](https://github.com/frappe/erpnext/pull/23455)) -- Multi-currency payroll ([#23519](https://github.com/frappe/erpnext/pull/23519)) -- Allow back-dated stock transactions and repost item costing via background job ([#24183](https://github.com/frappe/erpnext/pull/24183)) -- Introduced telephony feature using Twillio ([#24032](https://github.com/frappe/erpnext/pull/24032)) -- Shipment Doctype ([#22914](https://github.com/frappe/erpnext/pull/22914)) -- Leave policy assignment ([#23112](https://github.com/frappe/erpnext/pull/23112)) -- UAE VAT 201 Report ([#23447](https://github.com/frappe/erpnext/pull/23447)) -- Return tracking in PR/DN ([#22859](https://github.com/frappe/erpnext/pull/22859)) -- Close Production Plan ([#23728](https://github.com/frappe/erpnext/pull/23728)) -- Quality Inspection on Job Card ([#23964](https://github.com/frappe/erpnext/pull/23964)) -- Inpatient Medication Orders Script Report ([#23984](https://github.com/frappe/erpnext/pull/23984)) -- Leave type with partial payment ([#23173](https://github.com/frappe/erpnext/pull/23173)) -- Formula based Quality Inspection ([#23916](https://github.com/frappe/erpnext/pull/23916)) -- Link to Material Requests in Tools section for RFQ and Supplier Quotation ([#23429](https://github.com/frappe/erpnext/pull/23429)) -- Hide images & auto add item checkbox ([#24102](https://github.com/frappe/erpnext/pull/24102)) -- In reports get item details from Item instead of the transactions ([#24082](https://github.com/frappe/erpnext/pull/24082)) -- sales order status filter added for production plan ([#23805](https://github.com/frappe/erpnext/pull/23805)) -- Button to create Stock Entry for Drug Shortage ([#24012](https://github.com/frappe/erpnext/pull/24012)) -- Sync old shopify orders ([#23841](https://github.com/frappe/erpnext/pull/23841)) -- Added column cost center in Accounts Receivable report ([#23835](https://github.com/frappe/erpnext/pull/23835)) -- Added jinja templating in Contract Template ([#24046](https://github.com/frappe/erpnext/pull/24046)) -- Consider Holiday List in Student Leave Application and Attendance ([#23388](https://github.com/frappe/erpnext/pull/23388)) -- Make account number length configurable ([#23845](https://github.com/frappe/erpnext/pull/23845)) -- Add communication channel to communication medium ([#23793](https://github.com/frappe/erpnext/pull/23793)) - -#### Fixes - -- Loan disbursement amount validation ([#24000](https://github.com/frappe/erpnext/pull/24000)) -- Making company address read-only in delivery note ([#23890](https://github.com/frappe/erpnext/pull/23890)) -- BOM stock report color showing always red ([#23994](https://github.com/frappe/erpnext/pull/23994)) -- Added filter for customer field in Issue ([#24051](https://github.com/frappe/erpnext/pull/24051)) -- Added project link in timesheet form ([#23764](https://github.com/frappe/erpnext/pull/23764)) -- Update integrations desk page ([#23767](https://github.com/frappe/erpnext/pull/23767)) -- Place of supply change on address change ([#23941](https://github.com/frappe/erpnext/pull/23941)) -- TDS calculation, skip invoices with "Apply Tax Withholding Amount" has disabled ([#23672](https://github.com/frappe/erpnext/pull/23672)) -- Auto fetch serial nos with modified conversion factor ([#23854](https://github.com/frappe/erpnext/pull/23854)) -- Default cost center in item master not set in stock entry ([#23877](https://github.com/frappe/erpnext/pull/23877)) -- Incorrect de-link serial no and batch ([#23947](https://github.com/frappe/erpnext/pull/23947)) -- Accounting for internal transfer invoices within same company ([#24021](https://github.com/frappe/erpnext/pull/24021)) -- Multiple pricing rule with margin type as Percentage is not working ([#24205](https://github.com/frappe/erpnext/pull/24205)) -- Added Purchase Order to Global Search ([#24055](https://github.com/frappe/erpnext/pull/24055)) -- Cannot expand row in update items dialog ([#23839](https://github.com/frappe/erpnext/pull/23839)) -- Maintain stock can't be changed it there is product bundle ([#23989](https://github.com/frappe/erpnext/pull/23989)) -- SO to PO Mapping Issue ([#23820](https://github.com/frappe/erpnext/pull/23820)) -- Asset with value zero doesn't show up in fixed asset register ([#24091](https://github.com/frappe/erpnext/pull/24091)) -- Cannot save customer email & phone ([#23797](https://github.com/frappe/erpnext/pull/23797)) -- Incorrect balance value in stock balance report ([#24048](https://github.com/frappe/erpnext/pull/24048)) -- Payment Terms not fetched in Purchase Invoice from Purchase Receipt ([#23735](https://github.com/frappe/erpnext/pull/23735)) -- Fix for LMS Sign Up link ([#23743](https://github.com/frappe/erpnext/pull/23743)) -- Incorrect stock quantity if 'Allow Multiple Material Consumption… ([#24116](https://github.com/frappe/erpnext/pull/24116)) -- Added wrong absent days calculation in salary slip ([#23897](https://github.com/frappe/erpnext/pull/23897)) -- Purchase receipt to purchase invoice bill date mapping ([#23967](https://github.com/frappe/erpnext/pull/23967)) -- Overriding po ([#24022](https://github.com/frappe/erpnext/pull/24022)) -- Do not cancel reference document on Quality Inspection cancellation ([#24198](https://github.com/frappe/erpnext/pull/24198)) -- Get formatted value in 'taxes' print template ([#24035](https://github.com/frappe/erpnext/pull/24035)) -- Don't overrule Item Price via Pricing Rule Rate if 0 ([#23636](https://github.com/frappe/erpnext/pull/23636)) -- Job card error handling for operations field ([#23991](https://github.com/frappe/erpnext/pull/23991)) -- Validation for journal entry with 0 debit and credit values ([#23975](https://github.com/frappe/erpnext/pull/23975)) -- Check if customer exists in product listing ([#24030](https://github.com/frappe/erpnext/pull/24030)) -- Asset finance book posting date fix ([#23778](https://github.com/frappe/erpnext/pull/23778)) -- Same source and target tables in Status Updater's update query ([#24110](https://github.com/frappe/erpnext/pull/24110)) -- Asset finance book depreciation posting date fix ([#23833](https://github.com/frappe/erpnext/pull/23833)) -- Ignore exception during leave ledger creation from patch ([#24005](https://github.com/frappe/erpnext/pull/24005)) -- Added link of bank reconciliation and clearance in accounting desk page ([#23850](https://github.com/frappe/erpnext/pull/23850)) -- Sales invoice add button from sales order dashboard ([#24077](https://github.com/frappe/erpnext/pull/24077)) -- Incorrect calculation for consumed qty for subcontract item ([#23257](https://github.com/frappe/erpnext/pull/23257)) -- Incorrect required_qty in Production Planning Report ([#24074](https://github.com/frappe/erpnext/pull/24074)) -- Email digest user not found ([#23949](https://github.com/frappe/erpnext/pull/23949)) -- Delete Receive at Warehouse entry on cancellation of Send to War… ([#24115](https://github.com/frappe/erpnext/pull/24115)) -- Added TDS Payable account number and an error message ([#24065](https://github.com/frappe/erpnext/pull/24065)) -- Override field_map for job card gantt ([#24155](https://github.com/frappe/erpnext/pull/24155)) -- Old shopify order syncing date ([#23990](https://github.com/frappe/erpnext/pull/23990)) -- Shipping chanrges not sync in erpnext from shopify ([#24114](https://github.com/frappe/erpnext/pull/24114)) -- GSTR B2C report ([#24039](https://github.com/frappe/erpnext/pull/24039)) -- Ignore cancelled entries in stock balance report ([#23757](https://github.com/frappe/erpnext/pull/23757)) -- Stock ageing report not working ([#23923](https://github.com/frappe/erpnext/pull/23923)) -- Incorrect assign to in Maintenance Schedule ([#23831](https://github.com/frappe/erpnext/pull/23831)) -- Improve UX of DATEV report ([#23892](https://github.com/frappe/erpnext/pull/23892)) -- Set SLA variance in seconds for Duration fieldtype ([#23765](https://github.com/frappe/erpnext/pull/23765)) -- dDouble exception in payroll ([#24078](https://github.com/frappe/erpnext/pull/24078)) -- Make asset dashboard charts public ([#23751](https://github.com/frappe/erpnext/pull/23751)) -- Don't copy terms and discount from SO to PO ([#23903](https://github.com/frappe/erpnext/pull/23903)) -- Ignore doctypes on company transaction delete ([#23864](https://github.com/frappe/erpnext/pull/23864)) -- Error handling in Upload Attendance ([#23907](https://github.com/frappe/erpnext/pull/23907)) -- Tax template update on customer address change ([#24160](https://github.com/frappe/erpnext/pull/24160)) -- Not able to save bom ([#23910](https://github.com/frappe/erpnext/pull/23910)) -- Enable Allow Auto Repeat for standard doctypes having auto_repeat field ([#23776](https://github.com/frappe/erpnext/pull/23776)) -- Place of Supply fix in Sales Invoices ([#23785](https://github.com/frappe/erpnext/pull/23785)) -- Opening invoices in GSTR-1 report ([#24117](https://github.com/frappe/erpnext/pull/24117)) -- Add check for allowing access to european region ([#23770](https://github.com/frappe/erpnext/pull/23770)) -- Partial serial no return issue ([#24208](https://github.com/frappe/erpnext/pull/24208)) -- Multiple pos issues ([#23347](https://github.com/frappe/erpnext/pull/23347)) -- Import taxjar globally in the taxjar_integration module ([#24027](https://github.com/frappe/erpnext/pull/24027)) -- Payroll attendance error ([#23887](https://github.com/frappe/erpnext/pull/23887)) -- Cannot add items to cart ([#23796](https://github.com/frappe/erpnext/pull/23796)) -- Show tax amount in base currencies ([#24069](https://github.com/frappe/erpnext/pull/24069)) -- Loan application link on creating loan ([#23937](https://github.com/frappe/erpnext/pull/23937)) -- Added shipment link in delivery note dashboard ([#24210](https://github.com/frappe/erpnext/pull/24210)) -- POS item search includes non stock items ([#23914](https://github.com/frappe/erpnext/pull/23914)) -- Paid amount in Sales Invoice POS return resets to 0 ([#24057](https://github.com/frappe/erpnext/pull/24057)) -- Remove check for exempt_from_sales_tax ([#23870](https://github.com/frappe/erpnext/pull/23870)) -- Fiscal year can be shorter than 12 months ([#23838](https://github.com/frappe/erpnext/pull/23838)) -- Loan repayment type option remove ([#23582](https://github.com/frappe/erpnext/pull/23582)) -- Make contract template editable ([#23891](https://github.com/frappe/erpnext/pull/23891)) -- Item wise tax calculation ([#23744](https://github.com/frappe/erpnext/pull/23744)) -- Enabling track changes for stock settings ([#23982](https://github.com/frappe/erpnext/pull/23982)) -- Added link of bank reconciliation and clearance in accounting desk page ([#23809](https://github.com/frappe/erpnext/pull/23809)) -- Location data on Asset to use command(make_demo) ([#23825](https://github.com/frappe/erpnext/pull/23825)) -- Handle Account and Item None not found in Opening Invoice Creation Tool ([#23559](https://github.com/frappe/erpnext/pull/23559)) -- List index out of range on including UOM ([#23814](https://github.com/frappe/erpnext/pull/23814)) -- Showing error for wrong filters. ([#23726](https://github.com/frappe/erpnext/pull/23726)) -- Multiple subcontracting issues ([#23662](https://github.com/frappe/erpnext/pull/23662)) -- Sequence id override with workstation column ([#23810](https://github.com/frappe/erpnext/pull/23810)) -- Replaced formatdate -> format_date ([#23849](https://github.com/frappe/erpnext/pull/23849)) -- Test Payment Based on Leave Application (Travis) ([#24044](https://github.com/frappe/erpnext/pull/24044)) -- Leave policy dashboard fix and roles ([#24170](https://github.com/frappe/erpnext/pull/24170)) -- Budget test cases ([#23801](https://github.com/frappe/erpnext/pull/23801)) -- Handle for custom field IFSC code in Bank remittance report. ([#23905](https://github.com/frappe/erpnext/pull/23905)) -- Scan barcode does not update barcode item field in sales order ([#24090](https://github.com/frappe/erpnext/pull/24090)) -- Item price duplicate checking ([#23408](https://github.com/frappe/erpnext/pull/23408)) -- Tax template update on supplier change for India ([#24060](https://github.com/frappe/erpnext/pull/24060)) -- Consumed qty logic for subcontracted raw materials ([#23314](https://github.com/frappe/erpnext/pull/23314)) -- Finance book not getting added in journal Entry of asset value adjustment ([#24100](https://github.com/frappe/erpnext/pull/24100)) -- Fixed home desk page ([#24075](https://github.com/frappe/erpnext/pull/24075)) -- po_detail field has no value for subcontracted stock entry ([#23777](https://github.com/frappe/erpnext/pull/23777)) -- Set proper state code in ewaybill JSON when GST category is SEZ ([#23953](https://github.com/frappe/erpnext/pull/23953)) -- Copying po no when mapping doc ([#23729](https://github.com/frappe/erpnext/pull/23729)) -- Duplicate items validation for POS Invoice when allow multiple items is disabled ([#23896](https://github.com/frappe/erpnext/pull/23896)) -- POS register shows cancelled documents ([#23747](https://github.com/frappe/erpnext/pull/23747)) -- Subscription test case ([#23763](https://github.com/frappe/erpnext/pull/23763)) -- BOM stock report color issue ([#23980](https://github.com/frappe/erpnext/pull/23980)) -- Handle the "no leave_allocation found" case ([#23922](https://github.com/frappe/erpnext/pull/23922)) -- Filters for tax templates ([#23998](https://github.com/frappe/erpnext/pull/23998)) -- Do not allow Company as accounting dimension ([#23749](https://github.com/frappe/erpnext/pull/23749)) -- Validation for duplicate Tax Category ([#23978](https://github.com/frappe/erpnext/pull/23978)) -- Therapy plan and session fixes ([#23817](https://github.com/frappe/erpnext/pull/23817)) -- Correcting description field in taxes and charges for accounts with account number + account name ([#23836](https://github.com/frappe/erpnext/pull/23836)) -- Pricing rule with transaction not working for additional product ([#24053](https://github.com/frappe/erpnext/pull/24053)) -- Keyerror 'sourced_by_supplier' ([#24038](https://github.com/frappe/erpnext/pull/24038)) -- Validation for membership ([#23934](https://github.com/frappe/erpnext/pull/23934)) -- Inpatient Medication Order and Entry fixes ([#23799](https://github.com/frappe/erpnext/pull/23799)) -- Avoid using SQL query to get fiscal year dates ([#24050](https://github.com/frappe/erpnext/pull/24050)) -- Auto Statewise gst tax template ([#23832](https://github.com/frappe/erpnext/pull/23832)) -- POS profile has no attr 'show_only_available_items' ([#23758](https://github.com/frappe/erpnext/pull/23758)) -- On save sequence id column override with workstation ([#23812](https://github.com/frappe/erpnext/pull/23812)) -- Multiple pricing rules are not working on selling side ([#22711](https://github.com/frappe/erpnext/pull/22711)) -- Salary slip popup error ([#24192](https://github.com/frappe/erpnext/pull/24192)) \ No newline at end of file diff --git a/erpnext/change_log/v13/v13_0_0.md b/erpnext/change_log/v13/v13_0_0.md new file mode 100644 index 0000000000..a6cebabab1 --- /dev/null +++ b/erpnext/change_log/v13/v13_0_0.md @@ -0,0 +1,471 @@ +# Version 13.0.0 Release Notes + +### Accounting +- [New and refreshed POS](https://github.com/frappe/erpnext/pull/20789) +- [GST E-invoicing for India](https://docs.erpnext.com/docs/user/manual/en/regional/india/setup-e-invoicing) +- [Distributed Cost Center](https://docs.erpnext.com/docs/user/manual/en/accounts/distributed-cost-center) +- [Process Bulk Statement Of Accounts](https://docs.erpnext.com/docs/user/manual/en/accounts/process-statement-of-accounts) +- [More controlled deferred revenue booking](https://docs.erpnext.com/docs/user/manual/en/accounts/process-deferred-accounting) +- [Dunning](https://docs.erpnext.com/docs/user/manual/en/accounts/dunning) +- [Journal Entry Template](https://docs.erpnext.com/docs/user/manual/en/accounts/journal-entry-template) +- [POS Register report](https://github.com/frappe/erpnext/pull/23313) +- [UAE VAT 201 Report](https://github.com/frappe/erpnext/pull/23447) + + +### Loan Management +- [Loan Application](https://docs.erpnext.com/docs/user/manual/en/loan-management/loan-application) +- [Loan](https://docs.erpnext.com/docs/user/manual/en/loan-management/loan) +- [Loan Security Pledge](https://docs.erpnext.com/docs/user/manual/en/loan-management/loan-security-pledge) +- [Loan Disbursement](https://docs.erpnext.com/docs/user/manual/en/loan-management/loan-disbursement) +- [Loan Repayment](https://docs.erpnext.com/docs/user/manual/en/loan-management/loan-repayment) +- [Loan Interest Accrual](https://docs.erpnext.com/docs/user/manual/en/loan-management/loan-interest-accrual) +- [Loan Write Off](https://docs.erpnext.com/docs/user/manual/en/loan-management/loan-write-off) + +### Healthcare +- [Refactored Healthcare Module](https://docs.erpnext.com/docs/user/manual/en/healthcare) +- [Rehabilitation Module](https://docs.erpnext.com/docs/user/manual/en/healthcare/exercise_type) +- [Laboratory Module](https://docs.erpnext.com/docs/user/manual/en/healthcare/setup_laboratory) +- [Patient Progress Page](https://github.com/frappe/erpnext/pull/22474) +- [Inpatient Medication Order and Entry](https://docs.erpnext.com/docs/user/manual/en/healthcare/inpatient_medication_entry) +- [Therapy Plan Template](https://docs.erpnext.com/docs/user/manual/en/healthcare/therapy_plan) +- [Multi company support in Healthcare](https://github.com/frappe/erpnext/pull/21290) +- [Inpatient Medication Orders Script Report](https://github.com/frappe/erpnext/pull/23984) +- [Patient History Enhancements](https://github.com/frappe/erpnext/pull/24033) + + +### Stock +- [Putaway](https://docs.erpnext.com/docs/user/manual/en/stock/putaway-rule) +- [More accurate stock valuation in case of back-dated stock transactions](https://github.com/frappe/erpnext/pull/24183) +- [Repost item costing via background job](https://github.com/frappe/erpnext/pull/24183) +- [Item valuation for internal stock transfers](https://github.com/frappe/erpnext/pull/24200) +- [Multi currency in Landed Cost Voucher](https://github.com/frappe/erpnext/pull/24127) +- [Formula based Quality Inspection](https://docs.erpnext.com/docs/user/manual/en/stock/quality-inspection) +- [Value Based and Numeric Quality Inspection](https://github.com/frappe/erpnext/pull/24181) +- [Shipment](https://github.com/frappe/erpnext/pull/22914) +- [Return tracking in PR/DN](https://github.com/frappe/erpnext/pull/22859) + +### Manufacturing +- [Production forecasting using Exponential Smoothing method](https://docs.erpnext.com/docs/user/manual/en/manufacturing/reports/demand-driven-forecasting) +- [BOM Template](https://docs.erpnext.com/docs/user/manual/en/manufacturing/bill-of-materials#34-bom-template) +- [Downtime Entry](https://docs.erpnext.com/docs/user/manual/en/manufacturing/downtime-entry) +- [Quality Inspection on Job Card](https://github.com/frappe/erpnext/pull/23964) +- New Reports + - Production Planning Report ([#21763](https://github.com/frappe/erpnext/pull/21763)) + - BOM Operations Time ([#21763](https://github.com/frappe/erpnext/pull/21763)) + - Work Order Summary ([#21430](https://github.com/frappe/erpnext/pull/21430)) + - Job card Summary ([#21430](https://github.com/frappe/erpnext/pull/21430)) + - Downtime Analysis ([#21430](https://github.com/frappe/erpnext/pull/21430)) + - Quality Inspection ([#21430](https://github.com/frappe/erpnext/pull/21430)) + +### HR +- [Leave policy assignment](https://github.com/frappe/erpnext/pull/23112) +- [In and Out time in attendance](https://github.com/frappe/erpnext/pull/21547) +- [Shift management](https://docs.erpnext.com/docs/user/manual/en/human-resources/shift-management) +- [Recruitment analytics](https://github.com/frappe/erpnext/pull/21732) +- [Bulk Mark Attendance](https://github.com/frappe/erpnext/pull/20062) +- [Leave type with partial payment](https://github.com/frappe/erpnext/pull/23173) +- New and enhanced reports + - Employee Analytics ([#21705](https://github.com/frappe/erpnext/pull/21705)) + - Employee Leave Balance ([#20754](https://github.com/frappe/erpnext/pull/20754)) + - Employee Leave Balance Summary ([#20754](https://github.com/frappe/erpnext/pull/20754)) + +### Payroll +- [Multi-currency payroll](https://github.com/frappe/erpnext/pull/23519) +- [Payroll based on attendance](https://github.com/frappe/erpnext/pull/21258) +- [Payroll based on employee cost center](https://github.com/frappe/erpnext/pull/21609) +- [Recurring Additional Salary](https://github.com/frappe/erpnext/pull/20936) +- [Compute Year to Date for Salary Slip components](https://github.com/frappe/erpnext/pull/24362) +- New Reports + - Income Tax Deductions + - Professional Tax Deductions + - Provident Fund Deductions + - Total Salary Payments Based on Payment Mode + - Salary Payments via ECS + +### CRM +- [Social Media Post](https://docs.erpnext.com/docs/user/manual/en/CRM/social-media-post) +- [Make Quotation against Blanket Order](https://docs.erpnext.com/docs/user/manual/en/selling/blanket-order) +- [Calendar View for Opportunity](https://github.com/frappe/erpnext/pull/21280) + +### Selling +- [Batch wise item pricing](https://github.com/frappe/erpnext/pull/24470) +- [Refreshed shopping cart](https://github.com/frappe/erpnext/pull/22617) +- [Territory-wise Sales Report](https://github.com/frappe/erpnext/pull/20428) + +#### Buying +- [Multi UOM support in Request for Quotation](https://github.com/frappe/erpnext/pull/22249) +- [Provision to make RFQ against Opportunity](https://github.com/frappe/erpnext/pull/22765) +- [Item Rate in Stock UOM in purchase cycle](https://github.com/frappe/erpnext/pull/24315) +- New Reports + - Requested Items To Order ([#21611](https://github.com/frappe/erpnext/pull/21611)) + - Purchase Order Analysis ([#21611](https://github.com/frappe/erpnext/pull/21611)) + - Supplier Quotation Comparison report ([#23323](https://github.com/frappe/erpnext/pull/23323)) + +### Project +- [Project template with dependent tasks](https://github.com/frappe/erpnext/pull/24092) +- [Project Summary Report](https://github.com/frappe/erpnext/pull/21587) + +### Support +- [Help Articles on support portal](https://github.com/frappe/erpnext/pull/22194) +- [Issue Metrics and SLA Enhancements](https://github.com/frappe/erpnext/pull/21617) +- [Issue Summary Script Report](https://docs.erpnext.com/docs/user/manual/en/support/support_reports) +- [Issue Analytics Script Report](https://docs.erpnext.com/docs/user/manual/en/support/support_reports) + +### Non-Profits +- [80G Certificates and Donations](https://docs.erpnext.com/docs/user/manual/en/non_profit/tax_exemption_80g_certificate) + +#### Integrations +- [Woocommerce Integration](https://docs.erpnext.com/docs/user/manual/en/erpnext_integration/woocommerce_integration) +- [Taxjar Integration](https://github.com/frappe/erpnext/pull/21047) +- [M-pesa Integration](https://docs.erpnext.com/docs/user/manual/en/erpnext_integration/mpesa-integration) +- [Telephony feature using Twillio](https://github.com/frappe/erpnext/pull/24032) +- [Voice Call Settings](https://github.com/frappe/erpnext/pull/24126) + + +#### Other Enhancements and Fixes +- Accounting Dimensions in Budget Variance Report ([#19973](https://github.com/frappe/erpnext/pull/19973)) +- "Sync Now" option in Plaid Settings ([#23602](https://github.com/frappe/erpnext/pull/23602)) +- Custom Fields in POS ([#19876](https://github.com/frappe/erpnext/pull/19876)) +- [Inter Warehouse Stock Transfer in Purchase Receipt](https://docs.erpnext.com/docs/user/manual/en/stock/articles/material-transfer-from-delivery-note) +- [Accounts Payable Report based on Payment Terms](https://docs.erpnext.com/docs/user/manual/en/accounts/accounting-reports) +- Configurable accounting dimension filters and validations ([#23912](https://github.com/frappe/erpnext/pull/23912)) +- Territory tree in Customer Acquisition and Loyalty report ([#21668](https://github.com/frappe/erpnext/pull/21668)) +- Allow Purchase Invoice Creation Without Purchase Order Checkbox in Supplier ([#20864](https://github.com/frappe/erpnext/pull/20864)) +- Gross Profit In Quotation ([#21795](https://github.com/frappe/erpnext/pull/21795)) +- Notify credit controller users for credit limit extension via Email ([#22213](https://github.com/frappe/erpnext/pull/22213)) +- Run MRP at parent level in the production plan and make material transfer based upon materials availability ([#21545](https://github.com/frappe/erpnext/pull/21545)) +- Balance Serial Nos in Stock Ledger report ([#23675](https://github.com/frappe/erpnext/pull/23675)) +- Youtube interactions via Video ([#22867](https://github.com/frappe/erpnext/pull/22867)) +- Consider Holiday List in Student Leave Application and Attendance ([#23388](https://github.com/frappe/erpnext/pull/23388)) +- Patient appointment status changes ([#24201](https://github.com/frappe/erpnext/pull/24201)) +- Sales order status filter added for production plan ([#23805](https://github.com/frappe/erpnext/pull/23805)) +- Monthly attendance sheet report group by Department, Designation, Employee Grade and Branch ([#21331](https://github.com/frappe/erpnext/pull/21331)) +- Upload Attendance template now have pre-filled holiday status ([#20947](https://github.com/frappe/erpnext/pull/20947)) +- Provision to disable serial no and batch selector ([#24398](https://github.com/frappe/erpnext/pull/24398)) + +
+More + +- Fetch Items from BOM in Stock Entry([#19498](https://github.com/frappe/erpnext/pull/19498)) +- Supplier Sourced Items in BOM ([#23557](https://github.com/frappe/erpnext/pull/23557)) +- Close Production Plan ([#23728](https://github.com/frappe/erpnext/pull/23728)) +- Button to create Stock Entry for Drug Shortage ([#24012](https://github.com/frappe/erpnext/pull/24012)) +- Added column cost center in Accounts Receivable report ([#23835](https://github.com/frappe/erpnext/pull/23835)) +- Added jinja templating in Contract Template ([#24046](https://github.com/frappe/erpnext/pull/24046)) +- Make account number length configurable ([#23845](https://github.com/frappe/erpnext/pull/23845)) +- Add company and correct filter in bank reconciliation statement ([#23614](https://github.com/frappe/erpnext/pull/23614)) +- Added Condition field in Pricing Rule ([#23014](https://github.com/frappe/erpnext/pull/23014)) +- Open lead status on next contact date ([#23445](https://github.com/frappe/erpnext/pull/23445)) +- [Tax Category in POS Profile](https://docs.erpnext.com/docs/user/manual/en/accounts/pos-profile) +- Added phone field in product Inquiry ([#23170](https://github.com/frappe/erpnext/pull/23170)) +- Allow Discharge despite Unbilled Healthcare Services ([#24281](https://github.com/frappe/erpnext/pull/24281)) +- Do Not Bill Patient Encounters for Inpatients ([#24355](https://github.com/frappe/erpnext/pull/24355)) +- Autofill Supplier pop-up when only 1 Supplier in RFQ ([#22512](https://github.com/frappe/erpnext/pull/22512)) +- Accounting entries for service item in Purchase receipt ([#22223](https://github.com/frappe/erpnext/pull/22223)) +- Added Project in Sales Analytics report ([#23309](https://github.com/frappe/erpnext/pull/23309)) +- Added all companies option in employee tree to view employee across all companies ([#22573](https://github.com/frappe/erpnext/pull/22573)) +- Email Group Option In Email Campaign ([#22731](https://github.com/frappe/erpnext/pull/22731)) +- Stock Report Enhancements ([#21727](https://github.com/frappe/erpnext/pull/21727)) +- Added range for age in stock ageing ([#22622](https://github.com/frappe/erpnext/pull/22622)) +- Report Summary in Financial Statement([#20876](https://github.com/frappe/erpnext/pull/20876)) +- Added sequence id in routing for the completion of operations sequentially ([#23641](https://github.com/frappe/erpnext/pull/23641)) +- Nested Set filtering for Accounting Dimension +- Add/Remove Items from submitted Sales/Purchase Order +- Provision to edit Item Details from Marketplace +- Scan Barcode in Purchase Receipt +- Disable Rounded Totals Checkbox for Salary Slips in HR Settings + +- Renamed Loan Management to Loan on Desk Page ([#21877](https://github.com/frappe/erpnext/pull/21877)) +- Added Expense Approver field in Employee master ([#22244](https://github.com/frappe/erpnext/pull/22244)) +- Bill all hours by default on Timesheet ([#22155](https://github.com/frappe/erpnext/pull/22155)) +- Unable to cancel employee advance ([#22374](https://github.com/frappe/erpnext/pull/22374)) +- Status error in purchase invoice ([#22351](https://github.com/frappe/erpnext/pull/22351)) +- Item-wise sales and purchase register export ([#22184](https://github.com/frappe/erpnext/pull/22184)) +- Billing address in for Purchase documents ([#22233](https://github.com/frappe/erpnext/pull/22233)) +- Handle canceled entries in financial statements ([#22231](https://github.com/frappe/erpnext/pull/22231)) +- Default period start date and period end date for financial statements ([#22011](https://github.com/frappe/erpnext/pull/22011)) +- Update Packed Items via Update Items in Sales Order ([#22392](https://github.com/frappe/erpnext/pull/22392)) +- Hide delete company transactions button if not system manager ([#21839](https://github.com/frappe/erpnext/pull/21839)) +- Skipping total row for tree-view reports ([#22350](https://github.com/frappe/erpnext/pull/22350)) +- Cancelled entries in tds payable monthly report ([#22131](https://github.com/frappe/erpnext/pull/22131)) +- Inter-company Invoice currency for multicurrency transactions ([#21984](https://github.com/frappe/erpnext/pull/21984)) +- Filter batches based on item and warehouse in Pick List (develop) ([#21780](https://github.com/frappe/erpnext/pull/21780)) +- Set cost center in Expense Claim child based on parent (if missing) ([#22175](https://github.com/frappe/erpnext/pull/22175)) +- Item wise backdated stock entry posting for immutable ledger ([#22366](https://github.com/frappe/erpnext/pull/22366)) +- Shopping cart UI fixes ([#22137](https://github.com/frappe/erpnext/pull/22137)) +- Filter Leave Type based on allocation for a particular employee ([#22050](https://github.com/frappe/erpnext/pull/22050)) +- Party validation for inter-warehouse transaction ([#22186](https://github.com/frappe/erpnext/pull/22186)) +- Manufacturing dashboard and work order summary chart ([#21946](https://github.com/frappe/erpnext/pull/21946)) +- IP Admission and Discharge, Minor fixes ([#21817](https://github.com/frappe/erpnext/pull/21817)) +- Validation of Purchase Order against Material Request missing ([#22192](https://github.com/frappe/erpnext/pull/22192)) +- Staffing Plan validation ([#22379](https://github.com/frappe/erpnext/pull/22379)) +- Do not allow backdated stock transactions in previous fiscal year ([#21967](https://github.com/frappe/erpnext/pull/21967)) +- Employee Advance Return not working ([#21812](https://github.com/frappe/erpnext/pull/21812)) +- Added card for reports on education desk ([#21853](https://github.com/frappe/erpnext/pull/21853)) +- Refactored project summary report ([#21943](https://github.com/frappe/erpnext/pull/21943)) +- Revenue and Customer Count only in date range in Customer Acquitition Report ([#22210](https://github.com/frappe/erpnext/pull/22210)) +- Alternative item not working for subcontract ([#22386](https://github.com/frappe/erpnext/pull/22386)) +- Unable to create batched Item ([#22393](https://github.com/frappe/erpnext/pull/22393)) +- Filters for the manufacturing reports ([#21960](https://github.com/frappe/erpnext/pull/21960)) +- Raw material warehouse in Production Planning Report ([#21982](https://github.com/frappe/erpnext/pull/21982)) +- Allowed LWP leave types to select in Leave Application even if there is no allocation against them ([#22197](https://github.com/frappe/erpnext/pull/22197)) +- Report not working on parameter Grade ([#21951](https://github.com/frappe/erpnext/pull/21951)) +- Allow to enter Relieving date if employee status is Left ([#22242](https://github.com/frappe/erpnext/pull/22242)) +- Resetting lost reason in opportunity and quotation ([#22378](https://github.com/frappe/erpnext/pull/22378)) +- Filtering issues in opening invoice creation tool ([#21969](https://github.com/frappe/erpnext/pull/21969)) +- Set default reference Id for "On Previous Row Amount" and "On Previous Row Total" ([#22346](https://github.com/frappe/erpnext/pull/22346)) +- UX date range field separated in from and to date fields. ([#21765](https://github.com/frappe/erpnext/pull/21765)) +- Enable show_configure_button when shopping cart is enabled ([#22468](https://github.com/frappe/erpnext/pull/22468)) +- Setup status indicators for Job Offer and Job Applicant (develop) ([#22445](https://github.com/frappe/erpnext/pull/22445)) +- Item-wise sales history report ([#22783](https://github.com/frappe/erpnext/pull/22783)) +- Setting filter for project in kanban board ([#22717](https://github.com/frappe/erpnext/pull/22717)) +- Dashboard For Timesheet ([#22750](https://github.com/frappe/erpnext/pull/22750)) +- Handle custom statuses for the pause SLA configuration ([#22349](https://github.com/frappe/erpnext/pull/22349)) +- Quality Feedback and Template ([#22571](https://github.com/frappe/erpnext/pull/22571)) +- Unable to change link from new lead to existing customer ([#22787](https://github.com/frappe/erpnext/pull/22787)) +- Move Issue List actions under 'Actions' dropdown (ux) ([#22710](https://github.com/frappe/erpnext/pull/22710)) +- Cost center should only show option of selected company ([#22598](https://github.com/frappe/erpnext/pull/22598)) +- Serial No Rename does not affect Stock Ledger Entry ([#22746](https://github.com/frappe/erpnext/pull/22746)) +- Descriptions not copied while creating Fees from Fee Structure ([#22792](https://github.com/frappe/erpnext/pull/22792)) +- Company filter for cost_center and expense_account in all sales and purchase transactions ([#22478](https://github.com/frappe/erpnext/pull/22478)) +- Arrangements of filters for reports accounts payable & receivable ([#22636](https://github.com/frappe/erpnext/pull/22636)) +- Update the project after task deletion so that the % completed shows correct value ([#22591](https://github.com/frappe/erpnext/pull/22591)) +- Block Invalid Serial No updates in Maintenance Schedule ([#22665](https://github.com/frappe/erpnext/pull/22665)) +- Fetch item price in sales invoice based on it's validity ([#22563](https://github.com/frappe/erpnext/pull/22563)) +- Add view ledger button for cancelled docs ([#22432](https://github.com/frappe/erpnext/pull/22432)) +- Allow creating SLA documents even if SLA tracking is not enabled ([#22608](https://github.com/frappe/erpnext/pull/22608)) +- Quotation list view blank if quotation_to field not set as a standard filter ([#22672](https://github.com/frappe/erpnext/pull/22672)) +- Salary deductions report fixes ([#22397](https://github.com/frappe/erpnext/pull/22397)) +22727)) +- Incorrect delivered qty in Supplier-Wise Sales Analytics ([#22631](https://github.com/frappe/erpnext/pull/22631)) +- Moved parent warehouse to top section also added a section break ([#22708](https://github.com/frappe/erpnext/pull/22708)) +- Skip Progress and Completed by fields on Task Duplication ([#22565](https://github.com/frappe/erpnext/pull/22565)) +- Incorrect stock after merging the items ([#22526](https://github.com/frappe/erpnext/pull/22526)) +- Letter head not found in opening invoice creation tool ([#22488](https://github.com/frappe/erpnext/pull/22488)) +- Cannot cancel asset and asset movement ([#22441](https://github.com/frappe/erpnext/pull/22441)) +- Fetch project-related info in Timesheet ([#22423](https://github.com/frappe/erpnext/pull/22423)) +- Currency symbol not showing as per company currency in stock balance report ([#22724](https://github.com/frappe/erpnext/pull/22724)) +- Add default cost center in payment reconciliation JV ([#22614](https://github.com/frappe/erpnext/pull/22614)) +- Stock Reconciliation Invalid Quantity for Batched Item ([#22726](https://github.com/frappe/erpnext/pull/22726)) +- Project link not set in accounts other than profit and loss accounts ([#22051](https://github.com/frappe/erpnext/pull/22051)) +- Buying price for non stock item in gross profit report ([#22616](https://github.com/frappe/erpnext/pull/22616)) +- Multi currency payment reconciliation ([#22738](https://github.com/frappe/erpnext/pull/22738)) +- Cannot cancel assets with repair pending ([#22440](https://github.com/frappe/erpnext/pull/22440)) +- Reset homepage to home after unchecking products page ([#22736](https://github.com/frappe/erpnext/pull/22736)) +- Generic Message in previous doc validation for buying and selling ([#22546](https://github.com/frappe/erpnext/pull/22546)) +- Expense claim outstanding while making payment entry ([#22735](https://github.com/frappe/erpnext/pull/22735)) +- Take parent cost center for child if no cost center at child in expense claim ([#22496](https://github.com/frappe/erpnext/pull/22496)) +- Consider company fiscal year for getting balance ([#22577](https://github.com/frappe/erpnext/pull/22577)) +- Pick List empty table and Serial-Batch items handling ([#22426](https://github.com/frappe/erpnext/pull/22426)) +- Show total row in print format of financial statement ([#22693](https://github.com/frappe/erpnext/pull/22693)) +- Set Root as Parent if no parent in new tree view node ([#22497](https://github.com/frappe/erpnext/pull/22497)) +- Multiple pos issues ([#23725](https://github.com/frappe/erpnext/pull/23725)) +- Calculate taxes if tax is based on item quantity and inclusive on item price ([#23001](https://github.com/frappe/erpnext/pull/23001)) +- Contact us button not visible in the website for the non variant items ([#23217](https://github.com/frappe/erpnext/pull/23217)) +- Not able to make Material Request from Sales Order ([#23669](https://github.com/frappe/erpnext/pull/23669)) +- Capture advance payments in payment order ([#23256](https://github.com/frappe/erpnext/pull/23256)) +- Program and Course Enrollment fixes ([#23333](https://github.com/frappe/erpnext/pull/23333)) +- Cannot create asset if cwip disabled and account not set ([#23580](https://github.com/frappe/erpnext/pull/23580)) +- Cannot merge pos invoices with inclusive tax ([#23541](https://github.com/frappe/erpnext/pull/23541)) +- Do not allow Company as accounting dimension ([#23755](https://github.com/frappe/erpnext/pull/23755)) +- Set value of wrong Bank Account field in Payment Entry ([#22302](https://github.com/frappe/erpnext/pull/22302)) +- Reverse journal entry for multi-currency ([#23165](https://github.com/frappe/erpnext/pull/23165)) +- Updated integrations desk page ([#23772](https://github.com/frappe/erpnext/pull/23772)) +- Assessment Result child table not visible when accessed via Assessment Plan dashboard ([#22880](https://github.com/frappe/erpnext/pull/22880)) +- Conversion factor fixes in Stock Entry ([#23407](https://github.com/frappe/erpnext/pull/23407)) +- Total calculations for multi-currency RCM invoices ([#23072](https://github.com/frappe/erpnext/pull/23072)) +- Show accounts in financial statements upto level 20 ([#23718](https://github.com/frappe/erpnext/pull/23718)) +- Consolidated financial statement sums values into wrong parent ([#23288](https://github.com/frappe/erpnext/pull/23288)) +- Set SLA variance in seconds for Duration fieldtype ([#23765](https://github.com/frappe/erpnext/pull/23765)) +- Added missing reports on selling desk ([#23548](https://github.com/frappe/erpnext/pull/23548)) +- Fixed heading in the mobile view ([#23145](https://github.com/frappe/erpnext/pull/23145)) +- Misleading filters on Item tax Template Link field ([#22918](https://github.com/frappe/erpnext/pull/22918)) +- Do not consider opening entries for TDS calculation ([#23597](https://github.com/frappe/erpnext/pull/23597)) +- Attendance calendar map fix ([#23245](https://github.com/frappe/erpnext/pull/23245)) +- Post cancellation accounting entry on posting date instead of current ([#23361](https://github.com/frappe/erpnext/pull/23361)) +- Set Customer only if Contact is present ([#23704](https://github.com/frappe/erpnext/pull/23704)) +- Add Delivery Note Count in Sales Invoice Dashboard ([#23161](https://github.com/frappe/erpnext/pull/23161)) +- Breadcrumbs for Maintenance Visit and Schedule ([#23369](https://github.com/frappe/erpnext/pull/23369)) +- Raise Error on over receipt/consumption for sub-contracted PR ([#23195](https://github.com/frappe/erpnext/pull/23195)) +- Validate if company not set in the Payment Entry ([#23419](https://github.com/frappe/erpnext/pull/23419)) +- Ignore company and bank account doctype while deleting company transactions ([#22953](https://github.com/frappe/erpnext/pull/22953)) +- Sales funnel data is inconsistent ([#23110](https://github.com/frappe/erpnext/pull/23110)) +- Credit Limit Email not working ([#23059](https://github.com/frappe/erpnext/pull/23059)) +- Add Company in list fields to fetch for Expense Claim ([#23007](https://github.com/frappe/erpnext/pull/23007)) +- Issue form cleaned up and renamed Minutes to First Response field ([#23066](https://github.com/frappe/erpnext/pull/23066)) +- Quotation lost reason options fix ([#22814](https://github.com/frappe/erpnext/pull/22814)) +- Tax amounts in HSN Wise Outward summary ([#23076](https://github.com/frappe/erpnext/pull/23076)) +- Patient Appointment not able to save ([#23434](https://github.com/frappe/erpnext/pull/23434)) +- Removed Working Hours field from Company ([#23009](https://github.com/frappe/erpnext/pull/23009)) +- Added check-in time validation in the Inpatient Record - Transfer ([#22958](https://github.com/frappe/erpnext/pull/22958)) +- Handle Blank from/to range in Numeric Item Attribute ([#23483](https://github.com/frappe/erpnext/pull/23483)) +- Sequence Matcher error in Bank Reconciliation ([#23539](https://github.com/frappe/erpnext/pull/23539)) +- Fixed Conversion Factor rate for the BOM Exploded Item ([#23151](https://github.com/frappe/erpnext/pull/23151)) +- Payment Schedule not fetching ([#23476](https://github.com/frappe/erpnext/pull/23476)) +- Validate if removed Item Attributes exist in variant items ([#22911](https://github.com/frappe/erpnext/pull/22911)) +- Set default billing address for purchase documents ([#22950](https://github.com/frappe/erpnext/pull/22950)) +- Added help link in navbar settings ([#22943](https://github.com/frappe/erpnext/pull/22943)) +- Apply TDS on Purchase Invoice creation from Purchase Order and Purchase Receipt ([#23282](https://github.com/frappe/erpnext/pull/23282)) +- Education Module fixes ([#23714](https://github.com/frappe/erpnext/pull/23714)) +- Filter out cancelled entries in customer ledger summary ([#23205](https://github.com/frappe/erpnext/pull/23205)) +- Fiscal Year and Tax Rates for Italy ([#23623](https://github.com/frappe/erpnext/pull/23623)) +- Production Plan incorrect Work Order qty ([#23264](https://github.com/frappe/erpnext/pull/23264)) +- Added new filters in the Batch-wise Balance History report ([#23676](https://github.com/frappe/erpnext/pull/23676)) +- Update state code and union territory for Daman and Diu ([#22988](https://github.com/frappe/erpnext/pull/22988)) +- Set Stock UOM in item while creating Material Request from Stock Entry ([#23436](https://github.com/frappe/erpnext/pull/23436)) +- Sales Order to Purchase Order flow improvement ([#23357](https://github.com/frappe/erpnext/pull/23357)) +- Student Admission and Student Applicant fixes ([#23515](https://github.com/frappe/erpnext/pull/23515)) +- Loan disbursement amount validation ([#24000](https://github.com/frappe/erpnext/pull/24000)) +- Making company address read-only in delivery note ([#23890](https://github.com/frappe/erpnext/pull/23890)) +- BOM stock report color showing always red ([#23994](https://github.com/frappe/erpnext/pull/23994)) +- Added filter for customer field in Issue ([#24051](https://github.com/frappe/erpnext/pull/24051)) +- Added project link in timesheet form ([#23764](https://github.com/frappe/erpnext/pull/23764)) +- Update integrations desk page ([#23767](https://github.com/frappe/erpnext/pull/23767)) +- Place of supply change on address change ([#23941](https://github.com/frappe/erpnext/pull/23941)) +- TDS calculation, skip invoices with "Apply Tax Withholding Amount" has disabled ([#23672](https://github.com/frappe/erpnext/pull/23672)) +- Auto fetch serial nos with modified conversion factor ([#23854](https://github.com/frappe/erpnext/pull/23854)) +- Default cost center in item master not set in stock entry ([#23877](https://github.com/frappe/erpnext/pull/23877)) +- Incorrect de-link serial no and batch ([#23947](https://github.com/frappe/erpnext/pull/23947)) +- Accounting for internal transfer invoices within same company ([#24021](https://github.com/frappe/erpnext/pull/24021)) +- Multiple pricing rule with margin type as Percentage is not working ([#24205](https://github.com/frappe/erpnext/pull/24205)) +- Added Purchase Order to Global Search ([#24055](https://github.com/frappe/erpnext/pull/24055)) +- Cannot expand row in update items dialog ([#23839](https://github.com/frappe/erpnext/pull/23839)) +- Maintain stock can't be changed it there is product bundle ([#23989](https://github.com/frappe/erpnext/pull/23989)) +- SO to PO Mapping Issue ([#23820](https://github.com/frappe/erpnext/pull/23820)) +- Asset with value zero doesn't show up in fixed asset register ([#24091](https://github.com/frappe/erpnext/pull/24091)) +- Cannot save customer email & phone ([#23797](https://github.com/frappe/erpnext/pull/23797)) +- Incorrect balance value in stock balance report ([#24048](https://github.com/frappe/erpnext/pull/24048)) +- Payment Terms not fetched in Purchase Invoice from Purchase Receipt ([#23735](https://github.com/frappe/erpnext/pull/23735)) +- Fix for LMS Sign Up link ([#23743](https://github.com/frappe/erpnext/pull/23743)) +- Incorrect stock quantity if 'Allow Multiple Material Consumption… ([#24116](https://github.com/frappe/erpnext/pull/24116)) +- Added wrong absent days calculation in salary slip ([#23897](https://github.com/frappe/erpnext/pull/23897)) +- Purchase receipt to purchase invoice bill date mapping ([#23967](https://github.com/frappe/erpnext/pull/23967)) +- Overriding po ([#24022](https://github.com/frappe/erpnext/pull/24022)) +- Do not cancel reference document on Quality Inspection cancellation ([#24198](https://github.com/frappe/erpnext/pull/24198)) +- Get formatted value in 'taxes' print template ([#24035](https://github.com/frappe/erpnext/pull/24035)) +- Don't overrule Item Price via Pricing Rule Rate if 0 ([#23636](https://github.com/frappe/erpnext/pull/23636)) +- Job card error handling for operations field ([#23991](https://github.com/frappe/erpnext/pull/23991)) +- Validation for journal entry with 0 debit and credit values ([#23975](https://github.com/frappe/erpnext/pull/23975)) +- Check if customer exists in product listing ([#24030](https://github.com/frappe/erpnext/pull/24030)) +- Asset finance book posting date fix ([#23778](https://github.com/frappe/erpnext/pull/23778)) +- Same source and target tables in Status Updater's update query ([#24110](https://github.com/frappe/erpnext/pull/24110)) +- Asset finance book depreciation posting date fix ([#23833](https://github.com/frappe/erpnext/pull/23833)) +- Ignore exception during leave ledger creation from patch ([#24005](https://github.com/frappe/erpnext/pull/24005)) +- Added link of bank reconciliation and clearance in accounting desk page ([#23850](https://github.com/frappe/erpnext/pull/23850)) +- Sales invoice add button from sales order dashboard ([#24077](https://github.com/frappe/erpnext/pull/24077)) +- Incorrect calculation for consumed qty for subcontract item ([#23257](https://github.com/frappe/erpnext/pull/23257)) +- Incorrect required_qty in Production Planning Report ([#24074](https://github.com/frappe/erpnext/pull/24074)) +- Email digest user not found ([#23949](https://github.com/frappe/erpnext/pull/23949)) +- Delete Receive at Warehouse entry on cancellation of Send to War… ([#24115](https://github.com/frappe/erpnext/pull/24115)) +- Added TDS Payable account number and an error message ([#24065](https://github.com/frappe/erpnext/pull/24065)) +- Override field_map for job card gantt ([#24155](https://github.com/frappe/erpnext/pull/24155)) +- Old shopify order syncing date ([#23990](https://github.com/frappe/erpnext/pull/23990)) +- Shipping chanrges not sync in erpnext from shopify ([#24114](https://github.com/frappe/erpnext/pull/24114)) +- GSTR B2C report ([#24039](https://github.com/frappe/erpnext/pull/24039)) +- Ignore cancelled entries in stock balance report ([#23757](https://github.com/frappe/erpnext/pull/23757)) +- Stock ageing report not working ([#23923](https://github.com/frappe/erpnext/pull/23923)) +- Incorrect assign to in Maintenance Schedule ([#23831](https://github.com/frappe/erpnext/pull/23831)) +- Improve UX of DATEV report ([#23892](https://github.com/frappe/erpnext/pull/23892)) +- Set SLA variance in seconds for Duration fieldtype ([#23765](https://github.com/frappe/erpnext/pull/23765)) +- dDouble exception in payroll ([#24078](https://github.com/frappe/erpnext/pull/24078)) +- Make asset dashboard charts public ([#23751](https://github.com/frappe/erpnext/pull/23751)) +- Don't copy terms and discount from SO to PO ([#23903](https://github.com/frappe/erpnext/pull/23903)) +- Ignore doctypes on company transaction delete ([#23864](https://github.com/frappe/erpnext/pull/23864)) +- Error handling in Upload Attendance ([#23907](https://github.com/frappe/erpnext/pull/23907)) +- Tax template update on customer address change ([#24160](https://github.com/frappe/erpnext/pull/24160)) +- Not able to save bom ([#23910](https://github.com/frappe/erpnext/pull/23910)) +- Enable Allow Auto Repeat for standard doctypes having auto_repeat field ([#23776](https://github.com/frappe/erpnext/pull/23776)) +- Place of Supply fix in Sales Invoices ([#23785](https://github.com/frappe/erpnext/pull/23785)) +- Opening invoices in GSTR-1 report ([#24117](https://github.com/frappe/erpnext/pull/24117)) +- Partial serial no return issue ([#24208](https://github.com/frappe/erpnext/pull/24208)) +- Import taxjar globally in the taxjar_integration module ([#24027](https://github.com/frappe/erpnext/pull/24027)) +- Payroll attendance error ([#23887](https://github.com/frappe/erpnext/pull/23887)) +- Loan application link on creating loan ([#23937](https://github.com/frappe/erpnext/pull/23937)) +- POS item search includes non stock items ([#23914](https://github.com/frappe/erpnext/pull/23914)) +- Paid amount in Sales Invoice POS return resets to 0 ([#24057](https://github.com/frappe/erpnext/pull/24057)) +- Fiscal year can be shorter than 12 months ([#23838](https://github.com/frappe/erpnext/pull/23838)) +- Loan repayment type option remove ([#23582](https://github.com/frappe/erpnext/pull/23582)) +- Item wise tax calculation ([#23744](https://github.com/frappe/erpnext/pull/23744)) +- Enabling track changes for stock settings ([#23982](https://github.com/frappe/erpnext/pull/23982)) +- Added link of bank reconciliation and clearance in accounting desk page ([#23809](https://github.com/frappe/erpnext/pull/23809)) +- Location data on Asset to use command(make_demo) ([#23825](https://github.com/frappe/erpnext/pull/23825)) +- Handle Account and Item None not found in Opening Invoice Creation Tool ([#23559](https://github.com/frappe/erpnext/pull/23559)) +- Multiple subcontracting issues ([#23662](https://github.com/frappe/erpnext/pull/23662)) +- Sequence id override with workstation column ([#23810](https://github.com/frappe/erpnext/pull/23810)) +- Leave policy dashboard fix and roles ([#24170](https://github.com/frappe/erpnext/pull/24170)) +- Scan barcode does not update barcode item field in sales order ([#24090](https://github.com/frappe/erpnext/pull/24090)) +- Item price duplicate checking ([#23408](https://github.com/frappe/erpnext/pull/23408)) +- Tax template update on supplier change for India ([#24060](https://github.com/frappe/erpnext/pull/24060)) +- Consumed qty logic for subcontracted raw materials ([#23314](https://github.com/frappe/erpnext/pull/23314)) +- Finance book not getting added in journal Entry of asset value adjustment ([#24100](https://github.com/frappe/erpnext/pull/24100)) +- Set proper state code in ewaybill JSON when GST category is SEZ ([#23953](https://github.com/frappe/erpnext/pull/23953)) +- Copying po no when mapping doc ([#23729](https://github.com/frappe/erpnext/pull/23729)) +- Duplicate items validation for POS Invoice when allow multiple items is disabled ([#23896](https://github.com/frappe/erpnext/pull/23896)) +- Do not allow Company as accounting dimension ([#23749](https://github.com/frappe/erpnext/pull/23749)) +- Validation for duplicate Tax Category ([#23978](https://github.com/frappe/erpnext/pull/23978)) +- Therapy plan and session fixes ([#23817](https://github.com/frappe/erpnext/pull/23817)) +- Pricing rule with transaction not working for additional product ([#24053](https://github.com/frappe/erpnext/pull/24053)) +- Inpatient Medication Order and Entry fixes ([#23799](https://github.com/frappe/erpnext/pull/23799)) +- Avoid using SQL query to get fiscal year dates ([#24050](https://github.com/frappe/erpnext/pull/24050)) +- Auto Statewise gst tax template ([#23832](https://github.com/frappe/erpnext/pull/23832)) +- On save sequence id column override with workstation ([#23812](https://github.com/frappe/erpnext/pull/23812)) +- Multiple pricing rules are not working on selling side ([#22711](https://github.com/frappe/erpnext/pull/22711)) +- Salary slip popup error ([#24192](https://github.com/frappe/erpnext/pull/24192)) +- Multiple pricing rule with margin type as Percentage is not working ([#24204](https://github.com/frappe/erpnext/pull/24204)) +- Allow statistical component in salary structure. ([#24424](https://github.com/frappe/erpnext/pull/24424)) +- Set current asset value before calculating difference amount ([#24119](https://github.com/frappe/erpnext/pull/24119)) +- To use Stock UoM in BOM Stock Report ([#24339](https://github.com/frappe/erpnext/pull/24339)) +- Accounting entries of asset when submitting purchase receipt ([#24191](https://github.com/frappe/erpnext/pull/24191)) +- Batch/Serial Selector for Scanned Batched Item ([#24338](https://github.com/frappe/erpnext/pull/24338)) +- Link timesheets with corresponding projects ([#24346](https://github.com/frappe/erpnext/pull/24346)) +- Material request wrong status issue ([#24019](https://github.com/frappe/erpnext/pull/24019)) +- UX issues in e-invoicing ([#24358](https://github.com/frappe/erpnext/pull/24358)) +- Company Wise Valuation Rate for RM in BOM ([#24324](https://github.com/frappe/erpnext/pull/24324)) +- Stock ageing should not take cancelled stock entries. ([#24437](https://github.com/frappe/erpnext/pull/24437)) +- Partial loan security unpledging ([#24252](https://github.com/frappe/erpnext/pull/24252)) +- Asset depreciation ledger ([#24226](https://github.com/frappe/erpnext/pull/24226)) +- Back Update from QC based on Batch No ([#24329](https://github.com/frappe/erpnext/pull/24329)) +- Fix for not having fiscal year while creating new company ([#24130](https://github.com/frappe/erpnext/pull/24130)) +- E-invoice print format not showing other charges ([#24474](https://github.com/frappe/erpnext/pull/24474)) +- Tax template update on customer address change ([#24146](https://github.com/frappe/erpnext/pull/24146)) +- Do not manufacture same serial no multiple times ([#24164](https://github.com/frappe/erpnext/pull/24164)) +- Ignore group cost center validation for period closing voucher ([#24375](https://github.com/frappe/erpnext/pull/24375)) +- Partial serial no return issue ([#24207](https://github.com/frappe/erpnext/pull/24207)) +- GSTR-1 double entry issue ([#24376](https://github.com/frappe/erpnext/pull/24376)) +- Not able to create dunning from sales invoice ([#24349](https://github.com/frappe/erpnext/pull/24349)) +- Set company in leave allocation and leave ledger entry ([#24296](https://github.com/frappe/erpnext/pull/24296)) +- Allow leave policy assignment to be canceled. ([#24265](https://github.com/frappe/erpnext/pull/24265)) +- Removed all day event from shift assignment calendar ([#24397](https://github.com/frappe/erpnext/pull/24397)) +- Tax calculation on salary slip for the first month ([#24272](https://github.com/frappe/erpnext/pull/24272)) +- Validate tax template for tax category ([#24402](https://github.com/frappe/erpnext/pull/24402)) +- Numeric/Non-numeric QI UX ([#24517](https://github.com/frappe/erpnext/pull/24517)) +- Finished good produced qty validation ([#24220](https://github.com/frappe/erpnext/pull/24220)) +- Incorrect serial no in the subcontracted purchase receipt ([#24354](https://github.com/frappe/erpnext/pull/24354)) +- Don't validate warehouse values between Material Request and Stock Entry ([#24294](https://github.com/frappe/erpnext/pull/24294)) +- Don't cancel job card if manufacturing entry has made ([#24063](https://github.com/frappe/erpnext/pull/24063)) +- Subscription prepaid date validation ([#24356](https://github.com/frappe/erpnext/pull/24356)) +- Payment Period based on invoice date report fix/refactor ([#24378](https://github.com/frappe/erpnext/pull/24378)) +- Drop ship partial order fixed ([#24072](https://github.com/frappe/erpnext/pull/24072)) +- Payment entry multi-currency issue ([#24332](https://github.com/frappe/erpnext/pull/24332)) +- Multiple pricing rule issue ([#24515](https://github.com/frappe/erpnext/pull/24515)) +- Last purchase rate not updating when voucher cancelled if only one voucher is present ([#24322](https://github.com/frappe/erpnext/pull/24322)) +- Do not cancel reference document on Quality Inspection cancellation ([#24197](https://github.com/frappe/erpnext/pull/24197)) +- Refactored fetching & validating address from erpnext rather than gst portal ([#24297](https://github.com/frappe/erpnext/pull/24297)) +- Opportunity Status fix ([#22944](https://github.com/frappe/erpnext/pull/22944)) +- Fixed stock and account balance syncing ([#24644](https://github.com/frappe/erpnext/pull/24644)) +- Fixed incorrect stock ledger qty in the stock ledger report and bin ([#24649](https://github.com/frappe/erpnext/pull/24649)) +- Fixed Consolidated Financial Statement report ([#24580](https://github.com/frappe/erpnext/pull/24580)) +- Repost incompleted backdated transactions ([#24991](https://github.com/frappe/erpnext/pull/24991)) +- Unequal debit and credit issue on RCM Invoice ([#24838](https://github.com/frappe/erpnext/pull/24838)) +- Period list for exponential smoothing forecasting report ([#24983](https://github.com/frappe/erpnext/pull/24983)) +- POS Opening Entry with empty balance detail rows ([#24891](https://github.com/frappe/erpnext/pull/24891)) +- Use account_name only in consolidated report ([#24840](https://github.com/frappe/erpnext/pull/24840)) +- Validation of job card in stock entry ([#24882](https://github.com/frappe/erpnext/pull/24882)) +- Incorrect Nil Exempt and Non GST amount in GSTR3B report ([#24918](https://github.com/frappe/erpnext/pull/24918)) +- TDS check getting checked after reload ([#24973](https://github.com/frappe/erpnext/pull/24973)) +- Membership and Donation API fixes ([#24900](https://github.com/frappe/erpnext/pull/24900)) +- Allow zero valuation in stock reconciliation ([#24985](https://github.com/frappe/erpnext/pull/24985)) +- Simplified logic for additional salary ([#24907](https://github.com/frappe/erpnext/pull/24907)) +- Allow to select item code in batch naming ([#24825](https://github.com/frappe/erpnext/pull/24825)) +- Membership renewal validation (#24963) ([#24964](https://github.com/frappe/erpnext/pull/24964)) +
\ No newline at end of file From c5347c4a34434c4d313aad8e824cb7ddcc910150 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Thu, 1 Apr 2021 19:52:07 +0530 Subject: [PATCH 395/449] fix: get_route_options_for_new_doc for project --- erpnext/projects/doctype/project/project.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/projects/doctype/project/project.js b/erpnext/projects/doctype/project/project.js index 077011ace0..c5265e23c0 100644 --- a/erpnext/projects/doctype/project/project.js +++ b/erpnext/projects/doctype/project/project.js @@ -18,8 +18,8 @@ frappe.ui.form.on("Project", { }; }, onload: function (frm) { - var so = frappe.meta.get_docfield("Project", "sales_order"); - so.get_route_options_for_new_doc = function (field) { + const so = frm.get_docfield("sales_order"); + so.get_route_options_for_new_doc = () => { if (frm.is_new()) return; return { "customer": frm.doc.customer, From c01b2caaa3eb144735f2519bb59c9848bdd944be Mon Sep 17 00:00:00 2001 From: Jannat Patel <31363128+pateljannat@users.noreply.github.com> Date: Thu, 1 Apr 2021 20:48:51 +0530 Subject: [PATCH 396/449] fix: serial no refresh issue (#25129) --- erpnext/public/js/controllers/transaction.js | 32 ++++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index d2512e7f43..d1fc37930f 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -737,28 +737,34 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ this.frm.trigger("item_code", cdt, cdn); } else { - var valid_serial_nos = []; - var serialnos = []; // Replacing all occurences of comma with carriage return item.serial_no = item.serial_no.replace(/,/g, '\n'); - serialnos = item.serial_no.split("\n"); - for (var i = 0; i < serialnos.length; i++) { - if (serialnos[i] != "") { - valid_serial_nos.push(serialnos[i]); - } - } item.conversion_factor = item.conversion_factor || 1; - refresh_field("serial_no", item.name, item.parentfield); - if(!doc.is_return && cint(user_defaults.set_qty_in_transactions_based_on_serial_no_input)) { - frappe.model.set_value(item.doctype, item.name, - "qty", valid_serial_nos.length / item.conversion_factor); - frappe.model.set_value(item.doctype, item.name, "stock_qty", valid_serial_nos.length); + if (!doc.is_return && cint(frappe.user_defaults.set_qty_in_transactions_based_on_serial_no_input)) { + setTimeout(() => { + me.update_qty(cdt, cdn); + }, 10000); } } } }, + update_qty: function(cdt, cdn) { + var valid_serial_nos = []; + var serialnos = []; + var item = frappe.get_doc(cdt, cdn); + serialnos = item.serial_no.split("\n"); + for (var i = 0; i < serialnos.length; i++) { + if (serialnos[i] != "") { + valid_serial_nos.push(serialnos[i]); + } + } + frappe.model.set_value(item.doctype, item.name, + "qty", valid_serial_nos.length / item.conversion_factor); + frappe.model.set_value(item.doctype, item.name, "stock_qty", valid_serial_nos.length); + }, + validate: function() { this.calculate_taxes_and_totals(false); }, From f9b9298a6d248badfe1455223fa7d19b703c185b Mon Sep 17 00:00:00 2001 From: Saurabh Date: Thu, 1 Apr 2021 21:59:35 +0530 Subject: [PATCH 397/449] fix: reload doc in patch (#25144) --- .../v13_0/check_is_income_tax_component.py | 55 ++++++++++--------- .../v13_0/update_vehicle_no_reqd_condition.py | 1 + 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/erpnext/patches/v13_0/check_is_income_tax_component.py b/erpnext/patches/v13_0/check_is_income_tax_component.py index 9ad48e23b7..c92d52dcec 100644 --- a/erpnext/patches/v13_0/check_is_income_tax_component.py +++ b/erpnext/patches/v13_0/check_is_income_tax_component.py @@ -8,36 +8,39 @@ from erpnext.regional.india.setup import setup def execute(): - doctypes = ['salary_component', - 'Employee Tax Exemption Declaration', - 'Employee Tax Exemption Proof Submission', - 'Employee Tax Exemption Declaration Category', - 'Employee Tax Exemption Proof Submission Detail' - ] + doctypes = ['salary_component', + 'Employee Tax Exemption Declaration', + 'Employee Tax Exemption Proof Submission', + 'Employee Tax Exemption Declaration Category', + 'Employee Tax Exemption Proof Submission Detail', + 'gratuity_rule', + 'gratuity_rule_slab', + 'gratuity_applicable_component' + ] - for doctype in doctypes: - frappe.reload_doc('Payroll', 'doctype', doctype) + for doctype in doctypes: + frappe.reload_doc('Payroll', 'doctype', doctype) - reports = ['Professional Tax Deductions', 'Provident Fund Deductions'] - for report in reports: - frappe.reload_doc('Regional', 'Report', report) - frappe.reload_doc('Regional', 'Report', report) + reports = ['Professional Tax Deductions', 'Provident Fund Deductions'] + for report in reports: + frappe.reload_doc('Regional', 'Report', report) + frappe.reload_doc('Regional', 'Report', report) - if erpnext.get_region() == "India": - setup(patch=True) + if erpnext.get_region() == "India": + setup(patch=True) - if frappe.db.exists("Salary Component", "Income Tax"): - frappe.db.set_value("Salary Component", "Income Tax", "is_income_tax_component", 1) - if frappe.db.exists("Salary Component", "TDS"): - frappe.db.set_value("Salary Component", "TDS", "is_income_tax_component", 1) + if frappe.db.exists("Salary Component", "Income Tax"): + frappe.db.set_value("Salary Component", "Income Tax", "is_income_tax_component", 1) + if frappe.db.exists("Salary Component", "TDS"): + frappe.db.set_value("Salary Component", "TDS", "is_income_tax_component", 1) - components = frappe.db.sql("select name from `tabSalary Component` where variable_based_on_taxable_salary = 1", as_dict=1) - for component in components: - frappe.db.set_value("Salary Component", component.name, "is_income_tax_component", 1) + components = frappe.db.sql("select name from `tabSalary Component` where variable_based_on_taxable_salary = 1", as_dict=1) + for component in components: + frappe.db.set_value("Salary Component", component.name, "is_income_tax_component", 1) - if erpnext.get_region() == "India": - if frappe.db.exists("Salary Component", "Provident Fund"): - frappe.db.set_value("Salary Component", "Provident Fund", "component_type", "Provident Fund") - if frappe.db.exists("Salary Component", "Professional Tax"): - frappe.db.set_value("Salary Component", "Professional Tax", "component_type", "Professional Tax") \ No newline at end of file + if erpnext.get_region() == "India": + if frappe.db.exists("Salary Component", "Provident Fund"): + frappe.db.set_value("Salary Component", "Provident Fund", "component_type", "Provident Fund") + if frappe.db.exists("Salary Component", "Professional Tax"): + frappe.db.set_value("Salary Component", "Professional Tax", "component_type", "Professional Tax") \ No newline at end of file diff --git a/erpnext/patches/v13_0/update_vehicle_no_reqd_condition.py b/erpnext/patches/v13_0/update_vehicle_no_reqd_condition.py index c26cddbe4e..01a4ae04ad 100644 --- a/erpnext/patches/v13_0/update_vehicle_no_reqd_condition.py +++ b/erpnext/patches/v13_0/update_vehicle_no_reqd_condition.py @@ -1,6 +1,7 @@ import frappe def execute(): + frappe.reload_doc('custom', 'doctype', 'custom_field') company = frappe.get_all('Company', filters = {'country': 'India'}) if not company: return From 87dea3923bce7cf5c452db47bf16811901e9bd37 Mon Sep 17 00:00:00 2001 From: Anuja Pawar <60467153+Anuja-pawar@users.noreply.github.com> Date: Thu, 1 Apr 2021 22:05:08 +0530 Subject: [PATCH 398/449] fix: Picked Qty conversion from Stock Qty to Qty while creating DN from Pick List (#25106) * fix: picked qty from Stock Qty to Qty in DN * fix: suggested changes and added test * fix: sider changes * fix: sider changes --- erpnext/stock/doctype/pick_list/pick_list.py | 2 +- .../stock/doctype/pick_list/test_pick_list.py | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index 0da57b734b..7d206cb4a9 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -345,7 +345,7 @@ def create_delivery_note(source_name, target_doc=None): if dn_item: dn_item.warehouse = location.warehouse - dn_item.qty = location.picked_qty + dn_item.qty = flt(location.picked_qty) / (flt(location.conversion_factor) or 1) dn_item.batch_no = location.batch_no dn_item.serial_no = location.serial_no diff --git a/erpnext/stock/doctype/pick_list/test_pick_list.py b/erpnext/stock/doctype/pick_list/test_pick_list.py index 8ea7f89dc4..a762e9763e 100644 --- a/erpnext/stock/doctype/pick_list/test_pick_list.py +++ b/erpnext/stock/doctype/pick_list/test_pick_list.py @@ -9,6 +9,7 @@ test_dependencies = ['Item', 'Sales Invoice', 'Stock Entry', 'Batch'] from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt from erpnext.stock.doctype.item.test_item import create_item +from erpnext.stock.doctype.pick_list.pick_list import create_delivery_note from erpnext.stock.doctype.stock_reconciliation.stock_reconciliation \ import EmptyStockReconciliationItemsError @@ -291,6 +292,61 @@ class TestPickList(unittest.TestCase): self.assertEqual(pick_list.locations[1].qty, 5) self.assertEqual(pick_list.locations[1].sales_order_item, sales_order.items[0].name) + def test_pick_list_for_items_with_multiple_UOM(self): + purchase_receipt = make_purchase_receipt(item_code="_Test Item", qty=10) + purchase_receipt.submit() + + sales_order = frappe.get_doc({ + 'doctype': 'Sales Order', + 'customer': '_Test Customer', + 'company': '_Test Company', + 'items': [{ + 'item_code': '_Test Item', + 'qty': 1, + 'conversion_factor': 5, + 'delivery_date': frappe.utils.today() + }, { + 'item_code': '_Test Item', + 'qty': 1, + 'conversion_factor': 1, + 'delivery_date': frappe.utils.today() + }], + }).insert() + sales_order.submit() + + pick_list = frappe.get_doc({ + 'doctype': 'Pick List', + 'company': '_Test Company', + 'customer': '_Test Customer', + 'items_based_on': 'Sales Order', + 'locations': [{ + 'item_code': '_Test Item', + 'qty': 1, + 'stock_qty': 5, + 'conversion_factor': 5, + 'sales_order': sales_order.name, + 'sales_order_item': sales_order.items[0].name , + }, { + 'item_code': '_Test Item', + 'qty': 1, + 'stock_qty': 1, + 'conversion_factor': 1, + 'sales_order': sales_order.name, + 'sales_order_item': sales_order.items[1].name , + }] + }) + pick_list.set_item_locations() + pick_list.submit() + + delivery_note = create_delivery_note(pick_list.name) + + self.assertEqual(pick_list.locations[0].qty, delivery_note.items[0].qty) + self.assertEqual(pick_list.locations[1].qty, delivery_note.items[1].qty) + self.assertEqual(sales_order.items[0].conversion_factor, delivery_note.items[0].conversion_factor) + + pick_list.cancel() + sales_order.cancel() + purchase_receipt.cancel() # def test_pick_list_skips_items_in_expired_batch(self): # pass From e7b3047eca0722938900444582e1bf22d24e5b15 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Thu, 1 Apr 2021 22:59:28 +0530 Subject: [PATCH 399/449] chore: Bump version to v13.0.0 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 150033bae6..026c243c6d 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0-beta.14' +__version__ = '13.0.0' def get_default_company(user=None): '''Get default company for user''' From 9896907565e74e8957856eca32e9a0208221c30f Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 2 Apr 2021 00:27:08 +0530 Subject: [PATCH 400/449] fix: incorrect incoming rate for the sales return --- .../controllers/sales_and_purchase_return.py | 17 ++++++++++++++++- erpnext/controllers/selling_controller.py | 6 ++++-- erpnext/stock/stock_ledger.py | 3 ++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index de61b35316..5f759b43bc 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import frappe, erpnext from frappe import _ from frappe.model.meta import get_field_precision +from erpnext.stock.utils import get_incoming_rate from frappe.utils import flt, get_datetime, format_datetime class StockOverReturnError(frappe.ValidationError): pass @@ -389,10 +390,24 @@ def make_return_doc(doctype, source_name, target_doc=None): return doclist -def get_rate_for_return(voucher_type, voucher_no, item_code, return_against=None, item_row=None, voucher_detail_no=None): +def get_rate_for_return(voucher_type, voucher_no, item_code, return_against=None, + item_row=None, voucher_detail_no=None, sle=None): if not return_against: return_against = frappe.get_cached_value(voucher_type, voucher_no, "return_against") + if not return_against and voucher_type == 'Sales Invoice' and sle: + return get_incoming_rate({ + "item_code": sle.item_code, + "warehouse": sle.warehouse, + "posting_date": sle.get('posting_date'), + "posting_time": sle.get('posting_time'), + "qty": sle.actual_qty, + "serial_no": sle.get('serial_no'), + "company": sle.company, + "voucher_type": sle.voucher_type, + "voucher_no": sle.voucher_no + }, raise_error_if_no_rate=False) + return_against_item_field = get_return_against_item_fields(voucher_type) filters = get_filters(voucher_type, voucher_no, voucher_detail_no, diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index edc40c430a..54156f379c 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -311,14 +311,16 @@ class SellingController(StockController): items = self.get("items") + (self.get("packed_items") or []) for d in items: - if not cint(self.get("is_return")): + if not self.get("return_against"): # Get incoming rate based on original item cost based on valuation method + qty = flt(d.get('stock_qty') or d.get('actual_qty')) + d.incoming_rate = get_incoming_rate({ "item_code": d.item_code, "warehouse": d.warehouse, "posting_date": self.get('posting_date') or self.get('transaction_date'), "posting_time": self.get('posting_time') or nowtime(), - "qty": -1 * flt(d.get('stock_qty') or d.get('actual_qty')), + "qty": qty if cint(self.get("is_return")) else (-1 * qty), "serial_no": d.get('serial_no'), "company": self.company, "voucher_type": self.doctype, diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 121c51cf6a..df5f16fd41 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -372,7 +372,8 @@ class update_entries_after(object): elif sle.voucher_type in ("Purchase Receipt", "Purchase Invoice", "Delivery Note", "Sales Invoice"): if frappe.get_cached_value(sle.voucher_type, sle.voucher_no, "is_return"): from erpnext.controllers.sales_and_purchase_return import get_rate_for_return # don't move this import to top - rate = get_rate_for_return(sle.voucher_type, sle.voucher_no, sle.item_code, voucher_detail_no=sle.voucher_detail_no) + rate = get_rate_for_return(sle.voucher_type, sle.voucher_no, sle.item_code, + voucher_detail_no=sle.voucher_detail_no, sle = sle) else: if sle.voucher_type in ("Purchase Receipt", "Purchase Invoice"): rate_field = "valuation_rate" From e41d48c7deeb228cb7d1bfd2604f1d0e48db8a80 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 2 Apr 2021 13:21:08 +0530 Subject: [PATCH 401/449] fix: disable auto naming of customer during import --- erpnext/selling/doctype/customer/customer.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 96b3fa4ccd..49ca9423e8 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -38,11 +38,19 @@ class Customer(TransactionBase): set_name_by_naming_series(self) def get_customer_name(self): - if frappe.db.get_value("Customer", self.customer_name): + + if frappe.db.get_value("Customer", self.customer_name) and not frappe.flags.in_import: count = frappe.db.sql("""select ifnull(MAX(CAST(SUBSTRING_INDEX(name, ' ', -1) AS UNSIGNED)), 0) from tabCustomer where name like %s""", "%{0} - %".format(self.customer_name), as_list=1)[0][0] count = cint(count) + 1 - return "{0} - {1}".format(self.customer_name, cstr(count)) + + new_customer_name = "{0} - {1}".format(self.customer_name, cstr(count)) + + msgprint(_("Changed customer name to '{}' as '{}' already exists.") + .format(new_customer_name, self.customer_name), + title=_("Note"), indicator="yellow") + + return new_customer_name return self.customer_name From 8b829711fc5feb91adbc235aebf3a2ff9b59ff43 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Sat, 3 Apr 2021 14:20:30 +0530 Subject: [PATCH 402/449] fix: incorrect batch picked in subcontracted purchase receipt --- erpnext/controllers/buying_controller.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 219d5295c3..b686dc026c 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -6,6 +6,7 @@ import frappe from frappe import _, msgprint from frappe.utils import flt,cint, cstr, getdate from six import iteritems +from collections import OrderedDict from erpnext.accounts.party import get_party_details from erpnext.stock.get_item_details import get_conversion_factor from erpnext.buying.utils import validate_for_items, update_last_purchase_rate @@ -391,10 +392,12 @@ class BuyingController(StockController): batches_qty = get_batches_with_qty(raw_material.rm_item_code, raw_material.main_item_code, qty, transferred_batch_qty_map, backflushed_batch_qty_map, item.purchase_order) + for batch_data in batches_qty: qty = batch_data['qty'] raw_material.batch_no = batch_data['batch'] - self.append_raw_material_to_be_backflushed(item, raw_material, qty) + if qty > 0: + self.append_raw_material_to_be_backflushed(item, raw_material, qty) else: self.append_raw_material_to_be_backflushed(item, raw_material, qty) @@ -1056,7 +1059,7 @@ def get_transferred_batch_qty_map(purchase_order, fg_item): for batch_data in transferred_batches: key = ((batch_data.item_code, fg_item) if batch_data.subcontracted_item else (batch_data.item_code, purchase_order)) - transferred_batch_qty_map.setdefault(key, {}) + transferred_batch_qty_map.setdefault(key, OrderedDict()) transferred_batch_qty_map[key][batch_data.batch_no] = batch_data.qty return transferred_batch_qty_map @@ -1109,8 +1112,14 @@ def get_batches_with_qty(item_code, fg_item, required_qty, transferred_batch_qty if available_qty >= required_qty: available_batches.append({'batch': batch, 'qty': required_qty}) break - else: + elif available_qty != 0: available_batches.append({'batch': batch, 'qty': available_qty}) required_qty -= available_qty + for row in available_batches: + if backflushed_batches.get(row.get('batch'), 0) > 0: + backflushed_batches[row.get('batch')] += row.get('qty') + else: + backflushed_batches[row.get('batch')] = row.get('qty') + return available_batches From aa809ceffef679fa8c12472f5dc51fb734c7438c Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 7 Apr 2021 10:57:46 +0530 Subject: [PATCH 403/449] fix: Patch fixes for v13 upgrade (#25220) --- .../workspace/accounting/accounting.json | 10 ++++ erpnext/patches.txt | 1 + .../v13_0/create_uae_pos_invoice_fields.py | 4 ++ .../fix_non_unique_represents_company.py | 8 +++ ..._history_settings_for_standard_doctypes.py | 2 + erpnext/patches/v13_0/setup_uae_vat_fields.py | 4 ++ erpnext/regional/germany/setup.py | 15 +++++- erpnext/regional/india/setup.py | 13 ++--- erpnext/regional/report/datev/datev.json | 49 ++++++++----------- 9 files changed, 71 insertions(+), 35 deletions(-) create mode 100644 erpnext/patches/v13_0/fix_non_unique_represents_company.py diff --git a/erpnext/accounts/workspace/accounting/accounting.json b/erpnext/accounts/workspace/accounting/accounting.json index fadb66535f..9ffa481c1c 100644 --- a/erpnext/accounts/workspace/accounting/accounting.json +++ b/erpnext/accounts/workspace/accounting/accounting.json @@ -443,6 +443,16 @@ "onboard": 0, "type": "Link" }, + { + "dependencies": "GL Entry", + "hidden": 0, + "is_query_report": 1, + "label": "UAE VAT 201", + "link_to": "UAE VAT 201", + "link_type": "Report", + "onboard": 0, + "type": "Link" + }, { "hidden": 0, "is_query_report": 0, diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 59058a4cf6..09d4b2290c 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -761,3 +761,4 @@ erpnext.patches.v13_0.setup_fields_for_80g_certificate_and_donation erpnext.patches.v13_0.rename_membership_settings_to_non_profit_settings erpnext.patches.v13_0.setup_gratuity_rule_for_india_and_uae erpnext.patches.v13_0.setup_uae_vat_fields +erpnext.patches.v13_0.fix_non_unique_represents_company diff --git a/erpnext/patches/v13_0/create_uae_pos_invoice_fields.py b/erpnext/patches/v13_0/create_uae_pos_invoice_fields.py index 48d5cb4cc8..59b2e49b26 100644 --- a/erpnext/patches/v13_0/create_uae_pos_invoice_fields.py +++ b/erpnext/patches/v13_0/create_uae_pos_invoice_fields.py @@ -11,4 +11,8 @@ def execute(): if not company: return + + frappe.reload_doc('accounts', 'doctype', 'pos_invoice') + frappe.reload_doc('accounts', 'doctype', 'pos_invoice_item') + make_custom_fields() \ No newline at end of file diff --git a/erpnext/patches/v13_0/fix_non_unique_represents_company.py b/erpnext/patches/v13_0/fix_non_unique_represents_company.py new file mode 100644 index 0000000000..61dc824dd4 --- /dev/null +++ b/erpnext/patches/v13_0/fix_non_unique_represents_company.py @@ -0,0 +1,8 @@ +import frappe + +def execute(): + frappe.db.sql(""" + update tabCustomer + set represents_company = NULL + where represents_company = '' + """) \ No newline at end of file diff --git a/erpnext/patches/v13_0/setup_patient_history_settings_for_standard_doctypes.py b/erpnext/patches/v13_0/setup_patient_history_settings_for_standard_doctypes.py index de08aa26b3..7ec470c740 100644 --- a/erpnext/patches/v13_0/setup_patient_history_settings_for_standard_doctypes.py +++ b/erpnext/patches/v13_0/setup_patient_history_settings_for_standard_doctypes.py @@ -6,6 +6,8 @@ def execute(): if "Healthcare" not in frappe.get_active_domains(): return + frappe.reload_doc("healthcare", "doctype", "Inpatient Medication Order") + frappe.reload_doc("healthcare", "doctype", "Therapy Session") frappe.reload_doc("healthcare", "doctype", "Patient History Settings") frappe.reload_doc("healthcare", "doctype", "Patient History Standard Document Type") frappe.reload_doc("healthcare", "doctype", "Patient History Custom Document Type") diff --git a/erpnext/patches/v13_0/setup_uae_vat_fields.py b/erpnext/patches/v13_0/setup_uae_vat_fields.py index ee55bb8996..1830bab02b 100644 --- a/erpnext/patches/v13_0/setup_uae_vat_fields.py +++ b/erpnext/patches/v13_0/setup_uae_vat_fields.py @@ -9,4 +9,8 @@ def execute(): if not company: return + frappe.reload_doc('regional', 'report', 'uae_vat_201') + frappe.reload_doc('regional', 'doctype', 'uae_vat_settings') + frappe.reload_doc('regional', 'doctype', 'uae_vat_account') + setup() diff --git a/erpnext/regional/germany/setup.py b/erpnext/regional/germany/setup.py index d6047e863c..ac1f543488 100644 --- a/erpnext/regional/germany/setup.py +++ b/erpnext/regional/germany/setup.py @@ -3,4 +3,17 @@ import frappe def setup(company=None, patch=True): - pass + add_custom_roles_for_reports() + + +def add_custom_roles_for_reports(): + """Add Access Control to UAE VAT 201.""" + if not frappe.db.get_value('Custom Role', dict(report='DATEV')): + frappe.get_doc(dict( + doctype='Custom Role', + report='DATEV', + roles= [ + dict(role='Accounts User'), + dict(role='Accounts Manager') + ] + )).insert() \ No newline at end of file diff --git a/erpnext/regional/india/setup.py b/erpnext/regional/india/setup.py index f7689cfa19..d573425678 100644 --- a/erpnext/regional/india/setup.py +++ b/erpnext/regional/india/setup.py @@ -12,14 +12,14 @@ from erpnext.accounts.utils import get_fiscal_year, FiscalYearError from frappe.utils import today def setup(company=None, patch=True): - setup_company_independent_fixtures() + setup_company_independent_fixtures(patch=patch) if not patch: make_fixtures(company) # TODO: for all countries -def setup_company_independent_fixtures(): +def setup_company_independent_fixtures(patch=False): make_custom_fields() - make_property_setters() + make_property_setters(patch=patch) add_permissions() add_custom_roles_for_reports() frappe.enqueue('erpnext.regional.india.setup.add_hsn_sac_codes', now=frappe.flags.in_test) @@ -112,10 +112,11 @@ def add_print_formats(): frappe.db.set_value("Print Format", "GST Tax Invoice", "disabled", 0) frappe.db.set_value("Print Format", "GST E-Invoice", "disabled", 0) -def make_property_setters(): +def make_property_setters(patch=False): # GST rules do not allow for an invoice no. bigger than 16 characters - make_property_setter('Sales Invoice', 'naming_series', 'options', 'SINV-.YY.-\nSRET-.YY.-', '') - make_property_setter('Purchase Invoice', 'naming_series', 'options', 'PINV-.YY.-\nPRET-.YY.-', '') + if not patch: + make_property_setter('Sales Invoice', 'naming_series', 'options', 'SINV-.YY.-\nSRET-.YY.-', '') + make_property_setter('Purchase Invoice', 'naming_series', 'options', 'PINV-.YY.-\nPRET-.YY.-', '') def make_custom_fields(update=True): hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC', diff --git a/erpnext/regional/report/datev/datev.json b/erpnext/regional/report/datev/datev.json index 80a866cbf5..94e3960ead 100644 --- a/erpnext/regional/report/datev/datev.json +++ b/erpnext/regional/report/datev/datev.json @@ -1,29 +1,22 @@ { - "add_total_row": 0, - "apply_user_permissions": 0, - "creation": "2019-04-24 08:45:16.650129", - "disabled": 0, - "icon": "octicon octicon-repo-pull", - "color": "#4CB944", - "docstatus": 0, - "doctype": "Report", - "idx": 0, - "is_standard": "Yes", - "module": "Regional", - "name": "DATEV", - "owner": "Administrator", - "ref_doctype": "GL Entry", - "report_name": "DATEV", - "report_type": "Script Report", - "roles": [ - { - "role": "Accounts User" - }, - { - "role": "Accounts Manager" - }, - { - "role": "Auditor" - } - ] -} + "add_total_row": 0, + "columns": [], + "creation": "2019-04-24 08:45:16.650129", + "disable_prepared_report": 0, + "disabled": 0, + "docstatus": 0, + "doctype": "Report", + "filters": [], + "idx": 0, + "is_standard": "Yes", + "modified": "2021-04-06 12:23:00.379517", + "modified_by": "Administrator", + "module": "Regional", + "name": "DATEV", + "owner": "Administrator", + "prepared_report": 0, + "ref_doctype": "GL Entry", + "report_name": "DATEV", + "report_type": "Script Report", + "roles": [] +} \ No newline at end of file From 547fd31a37af08461e618d5585f7f7e6602b4be8 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 7 Apr 2021 11:33:40 +0550 Subject: [PATCH 404/449] bumped to version 13.0.1 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 026c243c6d..d2e58701c8 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.0' +__version__ = '13.0.1' def get_default_company(user=None): '''Get default company for user''' From c39720db501c298c8993a4976984f71afc08eb6f Mon Sep 17 00:00:00 2001 From: Walstan Baptista <38958184+walstanb@users.noreply.github.com> Date: Wed, 7 Apr 2021 11:51:22 +0530 Subject: [PATCH 405/449] fix: frappe.whitelist for doc methods (#25231) --- erpnext/payroll/doctype/payroll_entry/payroll_entry.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py index b520cdabdc..1a6a53438d 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py @@ -183,6 +183,7 @@ class PayrollEntry(Document): """, (ss_status, self.start_date, self.end_date, self.name, self.salary_slip_based_on_timesheet), as_dict=as_dict) return ss_list + @frappe.whitelist() def submit_salary_slips(self): self.check_permission('write') ss_list = self.get_sal_slip_list(ss_status=0) @@ -405,6 +406,7 @@ class PayrollEntry(Document): self.update(get_start_end_dates(self.payroll_frequency, self.start_date or self.posting_date, self.company)) + @frappe.whitelist() def validate_employee_attendance(self): employees_to_mark_attendance = [] days_in_payroll, days_holiday, days_attendance_marked = 0, 0, 0 From bda4c5cc5298c0a5833cd423ee2156f7a15dd198 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 12 Apr 2021 16:09:55 +0530 Subject: [PATCH 406/449] fix: update scheduler check tim --- .../doctype/repost_item_valuation/repost_item_valuation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py index a75db1ac86..a9556514f5 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -126,7 +126,7 @@ def repost_entries(): check_if_stock_and_account_balance_synced(today(), d.name) def get_repost_item_valuation_entries(): - date = add_to_date(today(), hours=-12) + date = add_to_date(today(), hours=-3) return frappe.db.sql(""" SELECT name from `tabRepost Item Valuation` WHERE status != 'Completed' and creation <= %s and docstatus = 1 From bffe933c226bb5d0587ca55e265cebecf8e8d8ee Mon Sep 17 00:00:00 2001 From: Andy Zhu Date: Mon, 12 Apr 2021 22:49:26 +1200 Subject: [PATCH 407/449] Fix: attempts to add overrides function Overrides parent_fieldname in outer form to all child rows's fieldname --- erpnext/public/js/utils.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index e7c7d11b0d..8fe38d91ea 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -291,17 +291,16 @@ $.extend(erpnext.utils, { return options[0]; } }, - copy_parent_value_in_all_row: function(doc, dt, dn, table_fieldname, fieldname, parent_fieldname) { - var d = locals[dt][dn]; - if(d[parent_fieldname]){ - var cl = doc[table_fieldname] || []; - for(var i = 0; i < cl.length; i++) { + overrides_parent_value_in_all_rows: function(doc, dt, dn, table_fieldname, fieldname, parent_fieldname) { + let d = locals[dt][dn]; + if(doc[parent_fieldname]){ + let cl = doc[table_fieldname] || []; + for(let i = 0; i < cl.length; i++) { cl[i][fieldname] = doc[parent_fieldname]; } + frappe.refresh_field(table_fieldname); } - refresh_field(table_fieldname); }, - create_new_doc: function (doctype, update_fields) { frappe.model.with_doctype(doctype, function() { var new_doc = frappe.model.get_new_doc(doctype); From 6a014d12c1594cfccb4c2713cba7f5936010e2cb Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 12 Apr 2021 20:21:27 +0530 Subject: [PATCH 408/449] fix(stock_ledger): round off values near to zero --- erpnext/stock/stock_ledger.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 121c51cf6a..a9e2f77490 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -603,7 +603,7 @@ class update_entries_after(object): batch = self.wh_data.stock_queue[index] if qty_to_pop >= batch[0]: # consume current batch - qty_to_pop = qty_to_pop - batch[0] + qty_to_pop = _round_off_if_near_zero(qty_to_pop - batch[0]) self.wh_data.stock_queue.pop(index) if not self.wh_data.stock_queue and qty_to_pop: # stock finished, qty still remains to be withdrawn @@ -617,8 +617,8 @@ class update_entries_after(object): batch[0] = batch[0] - qty_to_pop qty_to_pop = 0 - stock_value = sum((flt(batch[0]) * flt(batch[1]) for batch in self.wh_data.stock_queue)) - stock_qty = sum((flt(batch[0]) for batch in self.wh_data.stock_queue)) + stock_value = _round_off_if_near_zero(sum((flt(batch[0]) * flt(batch[1]) for batch in self.wh_data.stock_queue))) + stock_qty = _round_off_if_near_zero(sum((flt(batch[0]) for batch in self.wh_data.stock_queue))) if stock_qty: self.wh_data.valuation_rate = stock_value / flt(stock_qty) @@ -857,3 +857,12 @@ def get_future_sle_with_negative_qty(args): order by timestamp(posting_date, posting_time) asc limit 1 """, args, as_dict=1) + +def _round_off_if_near_zero(number: float, precision: int = 6) -> float: + """ Rounds off the number to zero only if number is close to zero for decimal + specified in precision. Precision defaults to 6. + """ + if flt(number) < (1.0 / (10**precision)): + return 0 + + return flt(number) From dbb76a7d0080ce0bab5e4e087c2923872b9d4949 Mon Sep 17 00:00:00 2001 From: Saqib Date: Tue, 13 Apr 2021 18:49:03 +0530 Subject: [PATCH 409/449] fix(e-invoicing): validations & tax calculation fixes (#25314) * fix: GST on freight charge in e-invoicing * feat(india): bulk e-invoice generation (#24969) * fix: cannot fetch e invoice settings * fix: patch condition (#25301) * fix: patch condition * fix: except einvoice loading error seperately * fix: json.loads error Co-authored-by: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> --- .../sales_invoice/regional/india_list.js | 147 +++- erpnext/hooks.py | 5 +- erpnext/patches.txt | 6 +- .../add_company_link_to_einvoice_settings.py | 16 + .../v12_0/add_einvoice_status_field.py | 69 ++ ...add_einvoice_summary_report_permissions.py | 18 + .../v12_0/create_taxable_value_field.py | 18 + .../update_vehicle_no_reqd_condition.py | 0 .../e_invoice_settings.json | 10 +- .../e_invoice_user/e_invoice_user.json | 11 +- erpnext/regional/india/e_invoice/einvoice.js | 54 +- erpnext/regional/india/e_invoice/utils.py | 648 +++++++++++++----- erpnext/regional/india/setup.py | 37 +- erpnext/regional/india/utils.py | 60 +- .../report/e_invoice_summary/__init__.py | 0 .../e_invoice_summary/e_invoice_summary.js | 55 ++ .../e_invoice_summary/e_invoice_summary.json | 28 + .../e_invoice_summary/e_invoice_summary.py | 106 +++ 18 files changed, 1046 insertions(+), 242 deletions(-) create mode 100644 erpnext/patches/v12_0/add_company_link_to_einvoice_settings.py create mode 100644 erpnext/patches/v12_0/add_einvoice_status_field.py create mode 100644 erpnext/patches/v12_0/add_einvoice_summary_report_permissions.py create mode 100644 erpnext/patches/v12_0/create_taxable_value_field.py rename erpnext/patches/{v13_0 => v12_0}/update_vehicle_no_reqd_condition.py (100%) create mode 100644 erpnext/regional/report/e_invoice_summary/__init__.py create mode 100644 erpnext/regional/report/e_invoice_summary/e_invoice_summary.js create mode 100644 erpnext/regional/report/e_invoice_summary/e_invoice_summary.json create mode 100644 erpnext/regional/report/e_invoice_summary/e_invoice_summary.py diff --git a/erpnext/accounts/doctype/sales_invoice/regional/india_list.js b/erpnext/accounts/doctype/sales_invoice/regional/india_list.js index 3e1c5228ea..ada665a0ca 100644 --- a/erpnext/accounts/doctype/sales_invoice/regional/india_list.js +++ b/erpnext/accounts/doctype/sales_invoice/regional/india_list.js @@ -1,14 +1,14 @@ var globalOnload = frappe.listview_settings['Sales Invoice'].onload; -frappe.listview_settings['Sales Invoice'].onload = function (doclist) { +frappe.listview_settings['Sales Invoice'].onload = function (list_view) { // Provision in case onload event is added to sales_invoice.js in future if (globalOnload) { - globalOnload(doclist); + globalOnload(list_view); } const action = () => { - const selected_docs = doclist.get_checked_items(); - const docnames = doclist.get_checked_items(true); + const selected_docs = list_view.get_checked_items(); + const docnames = list_view.get_checked_items(true); for (let doc of selected_docs) { if (doc.docstatus !== 1) { @@ -19,7 +19,7 @@ frappe.listview_settings['Sales Invoice'].onload = function (doclist) { frappe.call({ method: 'erpnext.regional.india.utils.generate_ewb_json', args: { - 'dt': doclist.doctype, + 'dt': list_view.doctype, 'dn': docnames }, callback: function(r) { @@ -35,5 +35,140 @@ frappe.listview_settings['Sales Invoice'].onload = function (doclist) { }); }; - doclist.page.add_actions_menu_item(__('Generate E-Way Bill JSON'), action, false); + list_view.page.add_actions_menu_item(__('Generate E-Way Bill JSON'), action, false); + + const generate_irns = () => { + const docnames = list_view.get_checked_items(true); + if (docnames && docnames.length) { + frappe.call({ + method: 'erpnext.regional.india.e_invoice.utils.generate_einvoices', + args: { docnames }, + freeze: true, + freeze_message: __('Generating E-Invoices...') + }); + } else { + frappe.msgprint({ + message: __('Please select at least one sales invoice to generate IRN'), + title: __('No Invoice Selected'), + indicator: 'red' + }); + } + }; + + const cancel_irns = () => { + const docnames = list_view.get_checked_items(true); + + const fields = [ + { + "label": "Reason", + "fieldname": "reason", + "fieldtype": "Select", + "reqd": 1, + "default": "1-Duplicate", + "options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"] + }, + { + "label": "Remark", + "fieldname": "remark", + "fieldtype": "Data", + "reqd": 1 + } + ]; + + const d = new frappe.ui.Dialog({ + title: __("Cancel IRN"), + fields: fields, + primary_action: function() { + const data = d.get_values(); + frappe.call({ + method: 'erpnext.regional.india.e_invoice.utils.cancel_irns', + args: { + doctype: list_view.doctype, + docnames, + reason: data.reason.split('-')[0], + remark: data.remark + }, + freeze: true, + freeze_message: __('Cancelling E-Invoices...'), + }); + d.hide(); + }, + primary_action_label: __('Submit') + }); + d.show(); + }; + + let einvoicing_enabled = false; + frappe.db.get_single_value("E Invoice Settings", "enable").then(enabled => { + einvoicing_enabled = enabled; + }); + + list_view.$result.on("change", "input[type=checkbox]", () => { + if (einvoicing_enabled) { + const docnames = list_view.get_checked_items(true); + // show/hide e-invoicing actions when no sales invoices are checked + if (docnames && docnames.length) { + // prevent adding actions twice if e-invoicing action group already exists + if (list_view.page.get_inner_group_button(__('E-Invoicing')).length == 0) { + list_view.page.add_inner_button(__('Generate IRNs'), generate_irns, __('E-Invoicing')); + list_view.page.add_inner_button(__('Cancel IRNs'), cancel_irns, __('E-Invoicing')); + } + } else { + list_view.page.remove_inner_button(__('Generate IRNs'), __('E-Invoicing')); + list_view.page.remove_inner_button(__('Cancel IRNs'), __('E-Invoicing')); + } + } + }); + + frappe.realtime.on("bulk_einvoice_generation_complete", (data) => { + const { failures, user, invoices } = data; + + if (invoices.length != failures.length) { + frappe.msgprint({ + message: __('{0} e-invoices generated successfully', [invoices.length]), + title: __('Bulk E-Invoice Generation Complete'), + indicator: 'orange' + }); + } + + if (failures && failures.length && user == frappe.session.user) { + let message = ` + Failed to generate IRNs for following ${failures.length} sales invoices: +
    + ${failures.map(d => `
  • ${d.docname}
  • `).join('')} +
+ `; + frappe.msgprint({ + message: message, + title: __('Bulk E-Invoice Generation Complete'), + indicator: 'orange' + }); + } + }); + + frappe.realtime.on("bulk_einvoice_cancellation_complete", (data) => { + const { failures, user, invoices } = data; + + if (invoices.length != failures.length) { + frappe.msgprint({ + message: __('{0} e-invoices cancelled successfully', [invoices.length]), + title: __('Bulk E-Invoice Cancellation Complete'), + indicator: 'orange' + }); + } + + if (failures && failures.length && user == frappe.session.user) { + let message = ` + Failed to cancel IRNs for following ${failures.length} sales invoices: +
    + ${failures.map(d => `
  • ${d.docname}
  • `).join('')} +
+ `; + frappe.msgprint({ + message: message, + title: __('Bulk E-Invoice Cancellation Complete'), + indicator: 'orange' + }); + } + }); }; \ No newline at end of file diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 9b9a0dae2e..5d091ddfbc 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -256,7 +256,10 @@ doc_events = { "erpnext.regional.italy.utils.sales_invoice_on_cancel", "erpnext.erpnext_integrations.taxjar_integration.delete_transaction" ], - "on_trash": "erpnext.regional.check_deletion_permission" + "on_trash": "erpnext.regional.check_deletion_permission", + "validate": [ + "erpnext.regional.india.utils.update_taxable_values" + ] }, "Purchase Invoice": { "validate": [ diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 09d4b2290c..6d5b4264fb 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -756,9 +756,13 @@ erpnext.patches.v13_0.update_payment_terms_outstanding erpnext.patches.v12_0.add_state_code_for_ladakh erpnext.patches.v13_0.item_reposting_for_incorrect_sl_and_gl erpnext.patches.v13_0.delete_old_bank_reconciliation_doctypes -erpnext.patches.v13_0.update_vehicle_no_reqd_condition +erpnext.patches.v12_0.update_vehicle_no_reqd_condition +erpnext.patches.v12_0.add_einvoice_status_field #2021-03-17 +erpnext.patches.v12_0.add_einvoice_summary_report_permissions erpnext.patches.v13_0.setup_fields_for_80g_certificate_and_donation erpnext.patches.v13_0.rename_membership_settings_to_non_profit_settings erpnext.patches.v13_0.setup_gratuity_rule_for_india_and_uae erpnext.patches.v13_0.setup_uae_vat_fields erpnext.patches.v13_0.fix_non_unique_represents_company +erpnext.patches.v12_0.create_taxable_value_field +erpnext.patches.v12_0.add_company_link_to_einvoice_settings diff --git a/erpnext/patches/v12_0/add_company_link_to_einvoice_settings.py b/erpnext/patches/v12_0/add_company_link_to_einvoice_settings.py new file mode 100644 index 0000000000..b6bd5fa311 --- /dev/null +++ b/erpnext/patches/v12_0/add_company_link_to_einvoice_settings.py @@ -0,0 +1,16 @@ +from __future__ import unicode_literals +import frappe + +def execute(): + company = frappe.get_all('Company', filters = {'country': 'India'}) + if not company or not frappe.db.count('E Invoice User'): + return + + frappe.reload_doc("regional", "doctype", "e_invoice_user") + for creds in frappe.db.get_all('E Invoice User', fields=['name', 'gstin']): + company_name = frappe.db.sql(""" + select dl.link_name from `tabAddress` a, `tabDynamic Link` dl + where a.gstin = %s and dl.parent = a.name and dl.link_doctype = 'Company' + """, (creds.get('gstin'))) + if company_name and len(company_name) > 0: + frappe.db.set_value('E Invoice User', creds.get('name'), 'company', company_name[0][0]) \ No newline at end of file diff --git a/erpnext/patches/v12_0/add_einvoice_status_field.py b/erpnext/patches/v12_0/add_einvoice_status_field.py new file mode 100644 index 0000000000..387e88588d --- /dev/null +++ b/erpnext/patches/v12_0/add_einvoice_status_field.py @@ -0,0 +1,69 @@ +from __future__ import unicode_literals +import json +import frappe +from frappe.custom.doctype.custom_field.custom_field import create_custom_fields + +def execute(): + company = frappe.get_all('Company', filters = {'country': 'India'}) + if not company: + return + + # move hidden einvoice fields to a different section + custom_fields = { + 'Sales Invoice': [ + dict(fieldname='einvoice_section', label='E-Invoice Fields', fieldtype='Section Break', insert_after='gst_vehicle_type', + print_hide=1, hidden=1), + + dict(fieldname='ack_no', label='Ack. No.', fieldtype='Data', read_only=1, hidden=1, insert_after='einvoice_section', + no_copy=1, print_hide=1), + + dict(fieldname='ack_date', label='Ack. Date', fieldtype='Data', read_only=1, hidden=1, insert_after='ack_no', no_copy=1, print_hide=1), + + dict(fieldname='irn_cancel_date', label='Cancel Date', fieldtype='Data', read_only=1, hidden=1, insert_after='ack_date', + no_copy=1, print_hide=1), + + dict(fieldname='signed_einvoice', label='Signed E-Invoice', fieldtype='Code', options='JSON', hidden=1, insert_after='irn_cancel_date', + no_copy=1, print_hide=1, read_only=1), + + dict(fieldname='signed_qr_code', label='Signed QRCode', fieldtype='Code', options='JSON', hidden=1, insert_after='signed_einvoice', + no_copy=1, print_hide=1, read_only=1), + + dict(fieldname='qrcode_image', label='QRCode', fieldtype='Attach Image', hidden=1, insert_after='signed_qr_code', + no_copy=1, print_hide=1, read_only=1), + + dict(fieldname='einvoice_status', label='E-Invoice Status', fieldtype='Select', insert_after='qrcode_image', + options='\nPending\nGenerated\nCancelled\nFailed', default=None, hidden=1, no_copy=1, print_hide=1, read_only=1), + + dict(fieldname='failure_description', label='E-Invoice Failure Description', fieldtype='Code', options='JSON', + hidden=1, insert_after='einvoice_status', no_copy=1, print_hide=1, read_only=1) + ] + } + create_custom_fields(custom_fields, update=True) + + if frappe.db.exists('E Invoice Settings') and frappe.db.get_single_value('E Invoice Settings', 'enable'): + frappe.db.sql(''' + UPDATE `tabSales Invoice` SET einvoice_status = 'Pending' + WHERE + posting_date >= '2021-04-01' + AND ifnull(irn, '') = '' + AND ifnull(`billing_address_gstin`, '') != ifnull(`company_gstin`, '') + AND ifnull(gst_category, '') in ('Registered Regular', 'SEZ', 'Overseas', 'Deemed Export') + ''') + + # set appropriate statuses + frappe.db.sql('''UPDATE `tabSales Invoice` SET einvoice_status = 'Generated' + WHERE ifnull(irn, '') != '' AND ifnull(irn_cancelled, 0) = 0''') + + frappe.db.sql('''UPDATE `tabSales Invoice` SET einvoice_status = 'Cancelled' + WHERE ifnull(irn_cancelled, 0) = 1''') + + # set correct acknowledgement in e-invoices + einvoices = frappe.get_all('Sales Invoice', {'irn': ['is', 'set']}, ['name', 'signed_einvoice']) + + if einvoices: + for inv in einvoices: + signed_einvoice = inv.get('signed_einvoice') + if signed_einvoice: + signed_einvoice = json.loads(signed_einvoice) + frappe.db.set_value('Sales Invoice', inv.get('name'), 'ack_no', signed_einvoice.get('AckNo'), update_modified=False) + frappe.db.set_value('Sales Invoice', inv.get('name'), 'ack_date', signed_einvoice.get('AckDt'), update_modified=False) \ No newline at end of file diff --git a/erpnext/patches/v12_0/add_einvoice_summary_report_permissions.py b/erpnext/patches/v12_0/add_einvoice_summary_report_permissions.py new file mode 100644 index 0000000000..bf8f566d32 --- /dev/null +++ b/erpnext/patches/v12_0/add_einvoice_summary_report_permissions.py @@ -0,0 +1,18 @@ +from __future__ import unicode_literals +import frappe + +def execute(): + company = frappe.get_all('Company', filters = {'country': 'India'}) + if not company: + return + + if frappe.db.exists('Report', 'E-Invoice Summary') and \ + not frappe.db.get_value('Custom Role', dict(report='E-Invoice Summary')): + frappe.get_doc(dict( + doctype='Custom Role', + report='E-Invoice Summary', + roles= [ + dict(role='Accounts User'), + dict(role='Accounts Manager') + ] + )).insert() \ No newline at end of file diff --git a/erpnext/patches/v12_0/create_taxable_value_field.py b/erpnext/patches/v12_0/create_taxable_value_field.py new file mode 100644 index 0000000000..a0c9fcf4cb --- /dev/null +++ b/erpnext/patches/v12_0/create_taxable_value_field.py @@ -0,0 +1,18 @@ +from __future__ import unicode_literals +import frappe +from frappe.custom.doctype.custom_field.custom_field import create_custom_fields + +def execute(): + company = frappe.get_all('Company', filters = {'country': 'India'}) + if not company: + return + + custom_fields = { + 'Sales Invoice Item': [ + dict(fieldname='taxable_value', label='Taxable Value', + fieldtype='Currency', insert_after='base_net_amount', hidden=1, options="Company:company:default_currency", + print_hide=1) + ] + } + + create_custom_fields(custom_fields, update=True) \ No newline at end of file diff --git a/erpnext/patches/v13_0/update_vehicle_no_reqd_condition.py b/erpnext/patches/v12_0/update_vehicle_no_reqd_condition.py similarity index 100% rename from erpnext/patches/v13_0/update_vehicle_no_reqd_condition.py rename to erpnext/patches/v12_0/update_vehicle_no_reqd_condition.py diff --git a/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.json b/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.json index db8bda75bf..68ed3391d0 100644 --- a/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.json +++ b/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.json @@ -8,6 +8,7 @@ "enable", "section_break_2", "sandbox_mode", + "applicable_from", "credentials", "auth_token", "token_expiry" @@ -48,12 +49,19 @@ "fieldname": "sandbox_mode", "fieldtype": "Check", "label": "Sandbox Mode" + }, + { + "fieldname": "applicable_from", + "fieldtype": "Date", + "in_list_view": 1, + "label": "Applicable From", + "reqd": 1 } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-01-13 12:04:49.449199", + "modified": "2021-03-30 12:26:25.538294", "modified_by": "Administrator", "module": "Regional", "name": "E Invoice Settings", diff --git a/erpnext/regional/doctype/e_invoice_user/e_invoice_user.json b/erpnext/regional/doctype/e_invoice_user/e_invoice_user.json index dd9d99773a..a65b1ca7ca 100644 --- a/erpnext/regional/doctype/e_invoice_user/e_invoice_user.json +++ b/erpnext/regional/doctype/e_invoice_user/e_invoice_user.json @@ -5,6 +5,7 @@ "editable_grid": 1, "engine": "InnoDB", "field_order": [ + "company", "gstin", "username", "password" @@ -30,12 +31,20 @@ "in_list_view": 1, "label": "Password", "reqd": 1 + }, + { + "fieldname": "company", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Company", + "options": "Company", + "reqd": 1 } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2020-12-22 15:10:53.466205", + "modified": "2021-03-22 12:16:56.365616", "modified_by": "Administrator", "module": "Regional", "name": "E Invoice User", diff --git a/erpnext/regional/india/e_invoice/einvoice.js b/erpnext/regional/india/e_invoice/einvoice.js index 48dc70638f..8d682beec3 100644 --- a/erpnext/regional/india/e_invoice/einvoice.js +++ b/erpnext/regional/india/e_invoice/einvoice.js @@ -1,13 +1,13 @@ erpnext.setup_einvoice_actions = (doctype) => { frappe.ui.form.on(doctype, { async refresh(frm) { - const { message } = await frappe.db.get_value("E Invoice Settings", "E Invoice Settings", "enable"); - const einvoicing_enabled = cint(message.enable); - const supply_type = frm.doc.gst_category; - const valid_supply_type = ['Registered Regular', 'SEZ', 'Overseas', 'Deemed Export'].includes(supply_type); - const company_transaction = frm.doc.billing_address_gstin == frm.doc.company_gstin; + const res = await frappe.call({ + method: 'erpnext.regional.india.e_invoice.utils.validate_eligibility', + args: { doc: frm.doc } + }); + const invoice_eligible = res.message; - if (cint(einvoicing_enabled) == 0 || !valid_supply_type || company_transaction) return; + if (!invoice_eligible) return; const { doctype, irn, irn_cancelled, ewaybill, eway_bill_cancelled, name, __unsaved } = frm.doc; @@ -110,45 +110,25 @@ erpnext.setup_einvoice_actions = (doctype) => { } if (irn && ewaybill && !irn_cancelled && !eway_bill_cancelled) { - const fields = [ - { - "label": "Reason", - "fieldname": "reason", - "fieldtype": "Select", - "reqd": 1, - "default": "1-Duplicate", - "options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"] - }, - { - "label": "Remark", - "fieldname": "remark", - "fieldtype": "Data", - "reqd": 1 - } - ]; const action = () => { - const d = new frappe.ui.Dialog({ - title: __('Cancel E-Way Bill'), - fields: fields, + let message = __('Cancellation of e-way bill is currently not supported. '); + message += '

'; + message += __('You must first use the portal to cancel the e-way bill and then update the cancelled status in the ERPNext system.'); + + frappe.msgprint({ + title: __('Update E-Way Bill Cancelled Status?'), + message: message, + indicator: 'orange', primary_action: function() { - const data = d.get_values(); frappe.call({ method: 'erpnext.regional.india.e_invoice.utils.cancel_eway_bill', - args: { - doctype, - docname: name, - eway_bill: ewaybill, - reason: data.reason.split('-')[0], - remark: data.remark - }, + args: { doctype, docname: name }, freeze: true, - callback: () => frm.reload_doc() || d.hide(), - error: () => d.hide() + callback: () => frm.reload_doc() }); }, - primary_action_label: __('Submit') + primary_action_label: __('Yes') }); - d.show(); }; add_custom_button(__("Cancel E-Way Bill"), action); } diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 6267635f60..baec796b75 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -15,18 +15,43 @@ import traceback import io from frappe import _, bold from pyqrcode import create as qrcreate +from frappe.utils.background_jobs import enqueue +from frappe.utils.scheduler import is_scheduler_inactive +from frappe.core.page.background_jobs.background_jobs import get_info from frappe.integrations.utils import make_post_request, make_get_request from erpnext.regional.india.utils import get_gst_accounts, get_place_of_supply -from frappe.utils.data import cstr, cint, format_date, flt, time_diff_in_seconds, now_datetime, add_to_date, get_link_to_form +from frappe.utils.data import cstr, cint, format_date, flt, time_diff_in_seconds, now_datetime, add_to_date, get_link_to_form, getdate, time_diff_in_hours + +@frappe.whitelist() +def validate_eligibility(doc): + if isinstance(doc, six.string_types): + doc = json.loads(doc) + + invalid_doctype = doc.get('doctype') != 'Sales Invoice' + if invalid_doctype: + return False + + einvoicing_enabled = cint(frappe.db.get_single_value('E Invoice Settings', 'enable')) + if not einvoicing_enabled: + return False + + einvoicing_eligible_from = frappe.db.get_single_value('E Invoice Settings', 'applicable_from') or '2021-04-01' + if getdate(doc.get('posting_date')) < getdate(einvoicing_eligible_from): + return False -def validate_einvoice_fields(doc): - einvoicing_enabled = cint(frappe.db.get_value('E Invoice Settings', 'E Invoice Settings', 'enable')) - invalid_doctype = doc.doctype != 'Sales Invoice' invalid_supply_type = doc.get('gst_category') not in ['Registered Regular', 'SEZ', 'Overseas', 'Deemed Export'] company_transaction = doc.get('billing_address_gstin') == doc.get('company_gstin') no_taxes_applied = not doc.get('taxes') - - if not einvoicing_enabled or invalid_doctype or invalid_supply_type or company_transaction or no_taxes_applied: + + if invalid_supply_type or company_transaction or no_taxes_applied: + return False + + return True + +def validate_einvoice_fields(doc): + invoice_eligible = validate_eligibility(doc) + + if not invoice_eligible: return if doc.docstatus == 0 and doc._action == 'save': @@ -35,6 +60,8 @@ def validate_einvoice_fields(doc): if len(doc.name) > 16: raise_document_name_too_long_error() + doc.einvoice_status = 'Pending' + elif doc.docstatus == 1 and doc._action == 'submit' and not doc.irn: frappe.throw(_('You must generate IRN before submitting the document.'), title=_('Missing IRN')) @@ -76,6 +103,9 @@ def get_transaction_details(invoice): )) def get_doc_details(invoice): + if getdate(invoice.posting_date) < getdate('2021-01-01'): + frappe.throw(_('IRN generation is not allowed for invoices dated before 1st Jan 2021'), title=_('Not Allowed')) + invoice_type = 'CRN' if invoice.is_return else 'INV' invoice_name = invoice.name @@ -87,53 +117,38 @@ def get_doc_details(invoice): invoice_date=invoice_date )) -def get_party_details(address_name): - d = frappe.get_all('Address', filters={'name': address_name}, fields=['*'])[0] - - if (not d.gstin - or not d.city - or not d.pincode - or not d.address_title - or not d.address_line1 - or not d.gst_state_number): +def validate_address_fields(address, is_shipping_address): + if ((not address.gstin and not is_shipping_address) + or not address.city + or not address.pincode + or not address.address_title + or not address.address_line1 + or not address.gst_state_number): frappe.throw( - msg=_('Address lines, city, pincode, gstin is mandatory for address {}. Please set them and try again.').format( - get_link_to_form('Address', address_name) - ), + msg=_('Address Lines, City, Pincode, GSTIN are mandatory for address {}. Please set them and try again.').format(address.name), title=_('Missing Address Fields') ) - if d.gst_state_number == 97: - # according to einvoice standard - pincode = 999999 +def get_party_details(address_name, is_shipping_address=False): + addr = frappe.get_doc('Address', address_name) + + validate_address_fields(addr, is_shipping_address) - return frappe._dict(dict( - gstin=d.gstin, - legal_name=sanitize_for_json(d.address_title), - location=sanitize_for_json(d.city), - pincode=d.pincode, - state_code=d.gst_state_number, - address_line1=sanitize_for_json(d.address_line1), - address_line2=sanitize_for_json(d.address_line2) + if addr.gst_state_number == 97: + # according to einvoice standard + addr.pincode = 999999 + + party_address_details = frappe._dict(dict( + legal_name=sanitize_for_json(addr.address_title), + location=sanitize_for_json(addr.city), + pincode=addr.pincode, gstin=addr.gstin, + state_code=addr.gst_state_number, + address_line1=sanitize_for_json(addr.address_line1), + address_line2=sanitize_for_json(addr.address_line2) )) -def get_gstin_details(gstin): - if not hasattr(frappe.local, 'gstin_cache'): - frappe.local.gstin_cache = {} - - key = gstin - details = frappe.local.gstin_cache.get(key) - if details: - return details - - details = frappe.cache().hget('gstin_cache', key) - if details: - frappe.local.gstin_cache[key] = details - return details - - if not details: - return GSPConnector.get_gstin_details(gstin) + return party_address_details def get_overseas_address_details(address_name): address_title, address_line1, address_line2, city = frappe.db.get_value( @@ -169,10 +184,15 @@ def get_item_list(invoice): item.description = sanitize_for_json(d.item_name) item.qty = abs(item.qty) - item.discount_amount = 0 - item.unit_rate = abs(item.base_net_amount / item.qty) - item.gross_amount = abs(item.base_net_amount) - item.taxable_value = abs(item.base_net_amount) + + if invoice.apply_discount_on == 'Net Total' and invoice.discount_amount: + item.discount_amount = abs(item.base_amount - item.base_net_amount) + else: + item.discount_amount = 0 + + item.unit_rate = abs((abs(item.taxable_value) - item.discount_amount)/ item.qty) + item.gross_amount = abs(item.taxable_value) + item.discount_amount + item.taxable_value = abs(item.taxable_value) item.batch_expiry_date = frappe.db.get_value('Batch', d.batch_no, 'expiry_date') if d.batch_no else None item.batch_expiry_date = format_date(item.batch_expiry_date, 'dd/mm/yyyy') if item.batch_expiry_date else None @@ -205,11 +225,11 @@ def update_item_taxes(invoice, item): is_applicable = t.tax_amount and t.account_head in gst_accounts_list if is_applicable: # this contains item wise tax rate & tax amount (incl. discount) - item_tax_detail = json.loads(t.item_wise_tax_detail).get(item.item_code) + item_tax_detail = json.loads(t.item_wise_tax_detail).get(item.item_code or item.item_name) item_tax_rate = item_tax_detail[0] # item tax amount excluding discount amount - item_tax_amount = (item_tax_rate / 100) * item.base_net_amount + item_tax_amount = (item_tax_rate / 100) * item.taxable_value if t.account_head in gst_accounts.cess_account: item_tax_amount_after_discount = item_tax_detail[1] @@ -223,6 +243,9 @@ def update_item_taxes(invoice, item): if t.account_head in gst_accounts[f'{tax_type}_account']: item.tax_rate += item_tax_rate item[f'{tax_type}_amount'] += abs(item_tax_amount) + else: + # TODO: other charges per item + pass return item @@ -230,10 +253,14 @@ def get_invoice_value_details(invoice): invoice_value_details = frappe._dict(dict()) if invoice.apply_discount_on == 'Net Total' and invoice.discount_amount: - invoice_value_details.base_total = abs(invoice.base_total) - invoice_value_details.invoice_discount_amt = abs(invoice.base_discount_amount) + # Discount already applied on net total which means on items + invoice_value_details.base_total = abs(sum([i.taxable_value for i in invoice.get('items')])) + invoice_value_details.invoice_discount_amt = 0 + elif invoice.apply_discount_on == 'Grand Total' and invoice.discount_amount: + invoice_value_details.invoice_discount_amt = invoice.base_discount_amount + invoice_value_details.base_total = abs(sum([i.taxable_value for i in invoice.get('items')])) else: - invoice_value_details.base_total = abs(invoice.base_net_total) + invoice_value_details.base_total = abs(sum([i.taxable_value for i in invoice.get('items')])) # since tax already considers discount amount invoice_value_details.invoice_discount_amt = 0 @@ -254,7 +281,11 @@ def update_invoice_taxes(invoice, invoice_value_details): invoice_value_details.total_igst_amt = 0 invoice_value_details.total_cess_amt = 0 invoice_value_details.total_other_charges = 0 + considered_rows = [] + for t in invoice.taxes: + tax_amount = t.base_tax_amount if (invoice.apply_discount_on == 'Grand Total' and invoice.discount_amount) \ + else t.base_tax_amount_after_discount_amount if t.account_head in gst_accounts_list: if t.account_head in gst_accounts.cess_account: # using after discount amt since item also uses after discount amt for cess calc @@ -262,12 +293,26 @@ def update_invoice_taxes(invoice, invoice_value_details): for tax_type in ['igst', 'cgst', 'sgst']: if t.account_head in gst_accounts[f'{tax_type}_account']: - invoice_value_details[f'total_{tax_type}_amt'] += abs(t.base_tax_amount_after_discount_amount) + + invoice_value_details[f'total_{tax_type}_amt'] += abs(tax_amount) + update_other_charges(t, invoice_value_details, gst_accounts_list, invoice, considered_rows) else: - invoice_value_details.total_other_charges += abs(t.base_tax_amount_after_discount_amount) + invoice_value_details.total_other_charges += abs(tax_amount) return invoice_value_details +def update_other_charges(tax_row, invoice_value_details, gst_accounts_list, invoice, considered_rows): + prev_row_id = cint(tax_row.row_id) - 1 + if tax_row.account_head in gst_accounts_list and prev_row_id not in considered_rows: + if tax_row.charge_type == 'On Previous Row Amount': + amount = invoice.get('taxes')[prev_row_id].tax_amount_after_discount_amount + invoice_value_details.total_other_charges -= abs(amount) + considered_rows.append(prev_row_id) + if tax_row.charge_type == 'On Previous Row Total': + amount = invoice.get('taxes')[prev_row_id].base_total - invoice.base_net_total + invoice_value_details.total_other_charges -= abs(amount) + considered_rows.append(prev_row_id) + def get_payment_details(invoice): payee_name = invoice.company mode_of_payment = ', '.join([d.mode_of_payment for d in invoice.payments]) @@ -280,6 +325,10 @@ def get_payment_details(invoice): )) def get_return_doc_reference(invoice): + if not invoice.return_against: + frappe.throw(_('For generating IRN, reference to the original invoice is mandatory for a credit note. Please set {} field to generate e-invoice.') + .format(frappe.bold('Return Against')), title=_('Missing Field')) + invoice_date = frappe.db.get_value('Sales Invoice', invoice.return_against, 'posting_date') return frappe._dict(dict( invoice_name=invoice.return_against, invoice_date=format_date(invoice_date, 'dd/mm/yyyy') @@ -287,7 +336,11 @@ def get_return_doc_reference(invoice): def get_eway_bill_details(invoice): if invoice.is_return: - frappe.throw(_('E-Way Bill cannot be generated for Credit Notes & Debit Notes'), title=_('E Invoice Validation Failed')) + frappe.throw(_('E-Way Bill cannot be generated for Credit Notes & Debit Notes. Please clear fields in the Transporter Section of the invoice.'), + title=_('Invalid Fields')) + + if not invoice.distance: + frappe.throw(_('Distance is mandatory for generating e-way bill for an e-invoice.'), title=_('Missing Field')) mode_of_transport = { '': '', 'Road': '1', 'Air': '2', 'Rail': '3', 'Ship': '4' } vehicle_type = { 'Regular': 'R', 'Over Dimensional Cargo (ODC)': 'O' } @@ -305,9 +358,15 @@ def get_eway_bill_details(invoice): def validate_mandatory_fields(invoice): if not invoice.company_address: - frappe.throw(_('Company Address is mandatory to fetch company GSTIN details.'), title=_('Missing Fields')) + frappe.throw( + _('Company Address is mandatory to fetch company GSTIN details. Please set Company Address and try again.'), + title=_('Missing Fields') + ) if not invoice.customer_address: - frappe.throw(_('Customer Address is mandatory to fetch customer GSTIN details.'), title=_('Missing Fields')) + frappe.throw( + _('Customer Address is mandatory to fetch customer GSTIN details. Please set Company Address and try again.'), + title=_('Missing Fields') + ) if not frappe.db.get_value('Address', invoice.company_address, 'gstin'): frappe.throw( _('GSTIN is mandatory to fetch company GSTIN details. Please enter GSTIN in selected company address.'), @@ -319,6 +378,39 @@ def validate_mandatory_fields(invoice): title=_('Missing Fields') ) +def validate_totals(einvoice): + item_list = einvoice['ItemList'] + value_details = einvoice['ValDtls'] + + total_item_ass_value = 0 + total_item_cgst_value = 0 + total_item_sgst_value = 0 + total_item_igst_value = 0 + total_item_value = 0 + for item in item_list: + total_item_ass_value += flt(item['AssAmt']) + total_item_cgst_value += flt(item['CgstAmt']) + total_item_sgst_value += flt(item['SgstAmt']) + total_item_igst_value += flt(item['IgstAmt']) + total_item_value += flt(item['TotItemVal']) + + if abs(flt(item['AssAmt']) * flt(item['GstRt']) / 100) - (flt(item['CgstAmt']) + flt(item['SgstAmt']) + flt(item['IgstAmt'])) > 1: + frappe.throw(_('Row #{}: GST rate is invalid. Please remove tax rows with zero tax amount from taxes table.').format(item.idx)) + + if abs(flt(value_details['AssVal']) - total_item_ass_value) > 1: + frappe.throw(_('Total Taxable Value of the items is not equal to the Invoice Net Total. Please check item taxes / discounts for any correction.')) + + if abs(flt(value_details['TotInvVal']) + flt(value_details['Discount']) - total_item_value) > 1: + frappe.throw(_('Total Value of the items is not equal to the Invoice Grand Total. Please check item taxes / discounts for any correction.')) + + calculated_invoice_value = \ + flt(value_details['AssVal']) + flt(value_details['CgstVal']) \ + + flt(value_details['SgstVal']) + flt(value_details['IgstVal']) \ + + flt(value_details['OthChrg']) - flt(value_details['Discount']) + + if abs(flt(value_details['TotInvVal']) - calculated_invoice_value) > 1: + frappe.throw(_('Total Item Value + Taxes - Discount is not equal to the Invoice Grand Total. Please check taxes / discounts for any correction.')) + def make_einvoice(invoice): validate_mandatory_fields(invoice) @@ -334,24 +426,30 @@ def make_einvoice(invoice): buyer_details = get_overseas_address_details(invoice.customer_address) else: buyer_details = get_party_details(invoice.customer_address) - place_of_supply = get_place_of_supply(invoice, invoice.doctype) or sanitize_for_json(invoice.billing_address_gstin) - place_of_supply = place_of_supply[:2] + place_of_supply = get_place_of_supply(invoice, invoice.doctype) + if place_of_supply: + place_of_supply = place_of_supply.split('-')[0] + else: + place_of_supply = sanitize_for_json(invoice.billing_address_gstin)[:2] buyer_details.update(dict(place_of_supply=place_of_supply)) + seller_details.update(dict(legal_name=invoice.company)) + buyer_details.update(dict(legal_name=invoice.customer_name or invoice.customer)) + shipping_details = payment_details = prev_doc_details = eway_bill_details = frappe._dict({}) if invoice.shipping_address_name and invoice.customer_address != invoice.shipping_address_name: if invoice.gst_category == 'Overseas': shipping_details = get_overseas_address_details(invoice.shipping_address_name) else: - shipping_details = get_party_details(invoice.shipping_address_name) + shipping_details = get_party_details(invoice.shipping_address_name, is_shipping_address=True) if invoice.is_pos and invoice.base_paid_amount: payment_details = get_payment_details(invoice) - if invoice.is_return and invoice.return_against: + if invoice.is_return: prev_doc_details = get_return_doc_reference(invoice) - if invoice.transporter: + if invoice.transporter and flt(invoice.distance) and not invoice.is_return: eway_bill_details = get_eway_bill_details(invoice) # not yet implemented @@ -364,18 +462,73 @@ def make_einvoice(invoice): period_details=period_details, prev_doc_details=prev_doc_details, export_details=export_details, eway_bill_details=eway_bill_details ) - einvoice = safe_json_load(einvoice) - validations = json.loads(read_json('einv_validation')) - errors = validate_einvoice(validations, einvoice) - if errors: - message = "\n".join([ - "E Invoice: ", json.dumps(einvoice, indent=4), - "-" * 50, - "Errors: ", json.dumps(errors, indent=4) - ]) - frappe.log_error(title="E Invoice Validation Failed", message=message) - frappe.throw(errors, title=_('E Invoice Validation Failed'), as_list=1) + try: + einvoice = safe_json_load(einvoice) + einvoice = santize_einvoice_fields(einvoice) + except Exception: + show_link_to_error_log(invoice, einvoice) + + validate_totals(einvoice) + + return einvoice + +def show_link_to_error_log(invoice, einvoice): + err_log = log_error(einvoice) + link_to_error_log = get_link_to_form('Error Log', err_log.name, 'Error Log') + frappe.throw( + _('An error occurred while creating e-invoice for {}. Please check {} for more information.').format( + invoice.name, link_to_error_log), + title=_('E Invoice Creation Failed') + ) + +def log_error(data=None): + if isinstance(data, six.string_types): + data = json.loads(data) + + seperator = "--" * 50 + err_tb = traceback.format_exc() + err_msg = str(sys.exc_info()[1]) + data = json.dumps(data, indent=4) + + message = "\n".join([ + "Error", err_msg, seperator, + "Data:", data, seperator, + "Exception:", err_tb + ]) + frappe.log_error(title=_('E Invoice Request Failed'), message=message) + +def santize_einvoice_fields(einvoice): + int_fields = ["Pin","Distance","CrDay"] + float_fields = ["Qty","FreeQty","UnitPrice","TotAmt","Discount","PreTaxVal","AssAmt","GstRt","IgstAmt","CgstAmt","SgstAmt","CesRt","CesAmt","CesNonAdvlAmt","StateCesRt","StateCesAmt","StateCesNonAdvlAmt","OthChrg","TotItemVal","AssVal","CgstVal","SgstVal","IgstVal","CesVal","StCesVal","Discount","OthChrg","RndOffAmt","TotInvVal","TotInvValFc","PaidAmt","PaymtDue","ExpDuty",] + copy = einvoice.copy() + for key, value in copy.items(): + if isinstance(value, list): + for idx, d in enumerate(value): + santized_dict = santize_einvoice_fields(d) + if santized_dict: + einvoice[key][idx] = santized_dict + else: + einvoice[key].pop(idx) + + if not einvoice[key]: + einvoice.pop(key, None) + + elif isinstance(value, dict): + santized_dict = santize_einvoice_fields(value) + if santized_dict: + einvoice[key] = santized_dict + else: + einvoice.pop(key, None) + + elif not value or value == "None": + einvoice.pop(key, None) + + elif key in float_fields: + einvoice[key] = flt(value, 2) + + elif key in int_fields: + einvoice[key] = cint(value) return einvoice @@ -391,70 +544,22 @@ def safe_json_load(json_string): snippet = json_string[start:end] frappe.throw(_("Error in input data. Please check for any special characters near following input:
{}").format(snippet)) -def validate_einvoice(validations, einvoice, errors=[]): - for fieldname, field_validation in validations.items(): - value = einvoice.get(fieldname, None) - if not value or value == "None": - # remove keys with empty values - einvoice.pop(fieldname, None) - continue - - value_type = field_validation.get("type").lower() - if value_type in ['object', 'array']: - child_validations = field_validation.get('properties') - - if isinstance(value, list): - for d in value: - validate_einvoice(child_validations, d, errors) - if not d: - # remove empty dicts - einvoice.pop(fieldname, None) - else: - validate_einvoice(child_validations, value, errors) - if not value: - # remove empty dicts - einvoice.pop(fieldname, None) - continue - - # convert to int or str - if value_type == 'string': - einvoice[fieldname] = str(value) - elif value_type == 'number': - is_integer = '.' not in str(field_validation.get('maximum')) - precision = 3 if '.999' in str(field_validation.get('maximum')) else 2 - einvoice[fieldname] = flt(value, precision) if not is_integer else cint(value) - value = einvoice[fieldname] - - max_length = field_validation.get('maxLength') - minimum = flt(field_validation.get('minimum')) - maximum = flt(field_validation.get('maximum')) - pattern_str = field_validation.get('pattern') - pattern = re.compile(pattern_str or '') - - label = field_validation.get('description') or fieldname - - if value_type == 'string' and len(value) > max_length: - errors.append(_('{} should not exceed {} characters').format(label, max_length)) - if value_type == 'number' and (value > maximum or value < minimum): - errors.append(_('{} {} should be between {} and {}').format(label, value, minimum, maximum)) - if pattern_str and not pattern.match(value): - errors.append(field_validation.get('validationMsg')) - - return errors - -class RequestFailed(Exception): pass +class RequestFailed(Exception): + pass +class CancellationNotAllowed(Exception): + pass class GSPConnector(): def __init__(self, doctype=None, docname=None): - self.e_invoice_settings = frappe.get_cached_doc('E Invoice Settings') - sandbox_mode = self.e_invoice_settings.sandbox_mode + self.doctype = doctype + self.docname = docname - self.invoice = frappe.get_cached_doc(doctype, docname) if doctype and docname else None - self.credentials = self.get_credentials() + self.set_invoice() + self.set_credentials() # authenticate url is same for sandbox & live self.authenticate_url = 'https://gsp.adaequare.com/gsp/authenticate?grant_type=token' - self.base_url = 'https://gsp.adaequare.com' if not sandbox_mode else 'https://gsp.adaequare.com/test' + self.base_url = 'https://gsp.adaequare.com' if not self.e_invoice_settings.sandbox_mode else 'https://gsp.adaequare.com/test' self.cancel_irn_url = self.base_url + '/enriched/ei/api/invoice/cancel' self.irn_details_url = self.base_url + '/enriched/ei/api/invoice/irn' @@ -463,18 +568,29 @@ class GSPConnector(): self.cancel_ewaybill_url = self.base_url + '/enriched/ewb/ewayapi?action=CANEWB' self.generate_ewaybill_url = self.base_url + '/enriched/ei/api/ewaybill' - def get_credentials(self): + def set_invoice(self): + self.invoice = None + if self.doctype and self.docname: + self.invoice = frappe.get_cached_doc(self.doctype, self.docname) + + def set_credentials(self): + self.e_invoice_settings = frappe.get_cached_doc('E Invoice Settings') + + if not self.e_invoice_settings.enable: + frappe.throw(_("E-Invoicing is disabled. Please enable it from {} to generate e-invoices.").format(get_link_to_form("E Invoice Settings", "E Invoice Settings"))) + if self.invoice: gstin = self.get_seller_gstin() - if not self.e_invoice_settings.enable: - frappe.throw(_("E-Invoicing is disabled. Please enable it from {} to generate e-invoices.").format(get_link_to_form("E Invoice Settings", "E Invoice Settings"))) - credentials = next(d for d in self.e_invoice_settings.credentials if d.gstin == gstin) + credentials_for_gstin = [d for d in self.e_invoice_settings.credentials if d.gstin == gstin] + if credentials_for_gstin: + self.credentials = credentials_for_gstin[0] + else: + frappe.throw(_('Cannot find e-invoicing credentials for selected Company GSTIN. Please check E-Invoice Settings')) else: - credentials = self.e_invoice_settings.credentials[0] if self.e_invoice_settings.credentials else None - return credentials + self.credentials = self.e_invoice_settings.credentials[0] if self.e_invoice_settings.credentials else None def get_seller_gstin(self): - gstin = self.invoice.company_gstin or frappe.db.get_value('Address', self.invoice.company_address, 'gstin') + gstin = frappe.db.get_value('Address', self.invoice.company_address, 'gstin') if not gstin: frappe.throw(_('Cannot retrieve Company GSTIN. Please select company address with valid GSTIN.')) return gstin @@ -522,7 +638,7 @@ class GSPConnector(): self.e_invoice_settings.reload() except Exception: - self.log_error(res) + log_error(res) self.raise_error(True) def get_headers(self): @@ -544,14 +660,14 @@ class GSPConnector(): if res.get('success'): return res.get('result') else: - self.log_error(res) + log_error(res) raise RequestFailed except RequestFailed: self.raise_error() except Exception: - self.log_error() + log_error() self.raise_error(True) @staticmethod def get_gstin_details(gstin): @@ -568,12 +684,13 @@ class GSPConnector(): return details def generate_irn(self): - headers = self.get_headers() - einvoice = make_einvoice(self.invoice) - data = json.dumps(einvoice, indent=4) - + data = {} try: + headers = self.get_headers() + einvoice = make_einvoice(self.invoice) + data = json.dumps(einvoice, indent=4) res = self.make_request('post', self.generate_irn_url, headers, data) + if res.get('success'): self.set_einvoice_data(res.get('result')) @@ -593,12 +710,36 @@ class GSPConnector(): except RequestFailed: errors = self.sanitize_error_message(res.get('message')) + self.set_failed_status(errors=errors) self.raise_error(errors=errors) - except Exception: - self.log_error(data) + except Exception as e: + self.set_failed_status(errors=str(e)) + log_error(data) self.raise_error(True) + @staticmethod + def bulk_generate_irn(invoices): + gsp_connector = GSPConnector() + gsp_connector.doctype = 'Sales Invoice' + + failed = [] + + for invoice in invoices: + try: + gsp_connector.docname = invoice + gsp_connector.set_invoice() + gsp_connector.set_credentials() + gsp_connector.generate_irn() + + except Exception as e: + failed.append({ + 'docname': invoice, + 'message': str(e) + }) + + return failed + def get_irn_details(self, irn): headers = self.get_headers() @@ -615,21 +756,30 @@ class GSPConnector(): self.raise_error(errors=errors) except Exception: - self.log_error() + log_error() self.raise_error(True) def cancel_irn(self, irn, reason, remark): - headers = self.get_headers() - data = json.dumps({ - 'Irn': irn, - 'Cnlrsn': reason, - 'Cnlrem': remark - }, indent=4) - + data, res = {}, {} try: + # validate cancellation + if time_diff_in_hours(now_datetime(), self.invoice.ack_date) > 24: + frappe.throw(_('E-Invoice cannot be cancelled after 24 hours of IRN generation.'), title=_('Not Allowed'), exc=CancellationNotAllowed) + if not irn: + frappe.throw(_('IRN not found. You must generate IRN before cancelling.'), title=_('Not Allowed'), exc=CancellationNotAllowed) + + headers = self.get_headers() + data = json.dumps({ + 'Irn': irn, + 'Cnlrsn': reason, + 'Cnlrem': remark + }, indent=4) + res = self.make_request('post', self.cancel_irn_url, headers, data) - if res.get('success'): + if res.get('success') or '9999' in res.get('message'): self.invoice.irn_cancelled = 1 + self.invoice.irn_cancel_date = res.get('result')['CancelDate'] if res.get('result') else "" + self.invoice.einvoice_status = 'Cancelled' self.invoice.flags.updater_reference = { 'doctype': self.invoice.doctype, 'docname': self.invoice.name, @@ -642,11 +792,41 @@ class GSPConnector(): except RequestFailed: errors = self.sanitize_error_message(res.get('message')) + self.set_failed_status(errors=errors) self.raise_error(errors=errors) - except Exception: - self.log_error(data) + except CancellationNotAllowed as e: + self.set_failed_status(errors=str(e)) + self.raise_error(errors=str(e)) + + except Exception as e: + self.set_failed_status(errors=str(e)) + log_error(data) self.raise_error(True) + + @staticmethod + def bulk_cancel_irn(invoices, reason, remark): + gsp_connector = GSPConnector() + gsp_connector.doctype = 'Sales Invoice' + + failed = [] + + for invoice in invoices: + try: + gsp_connector.docname = invoice + gsp_connector.set_invoice() + gsp_connector.set_credentials() + irn = gsp_connector.invoice.irn + gsp_connector.cancel_irn(irn, reason, remark) + + except Exception as e: + failed.append({ + 'docname': invoice, + 'message': str(e) + }) + + return failed + def generate_eway_bill(self, **kwargs): args = frappe._dict(kwargs) @@ -685,7 +865,7 @@ class GSPConnector(): self.raise_error(errors=errors) except Exception: - self.log_error(data) + log_error(data) self.raise_error(True) def cancel_eway_bill(self, eway_bill, reason, remark): @@ -717,7 +897,7 @@ class GSPConnector(): self.raise_error(errors=errors) except Exception: - self.log_error(data) + log_error(data) self.raise_error(True) def sanitize_error_message(self, message): @@ -732,6 +912,9 @@ class GSPConnector(): ] then we trim down the message by looping over errors ''' + if not message: + return [] + errors = re.findall(': [^:]+', message) for idx, e in enumerate(errors): # remove colons @@ -743,22 +926,6 @@ class GSPConnector(): return errors - def log_error(self, data={}): - if not isinstance(data, dict): - data = json.loads(data) - - seperator = "--" * 50 - err_tb = traceback.format_exc() - err_msg = str(sys.exc_info()[1]) - data = json.dumps(data, indent=4) - - message = "\n".join([ - "Error", err_msg, seperator, - "Data:", data, seperator, - "Exception:", err_tb - ]) - frappe.log_error(title=_('E Invoice Request Failed'), message=message) - def raise_error(self, raise_exception=False, errors=[]): title = _('E Invoice Request Failed') if errors: @@ -779,7 +946,10 @@ class GSPConnector(): self.invoice.irn = res.get('Irn') self.invoice.ewaybill = res.get('EwbNo') self.invoice.signed_einvoice = dec_signed_invoice + self.invoice.ack_no = res.get('AckNo') + self.invoice.ack_date = res.get('AckDt') self.invoice.signed_qr_code = res.get('SignedQRCode') + self.invoice.einvoice_status = 'Generated' self.attach_qrcode_image() @@ -815,6 +985,17 @@ class GSPConnector(): self.invoice.flags.ignore_validate = True self.invoice.save() + def set_failed_status(self, errors=None): + frappe.db.rollback() + self.invoice.einvoice_status = 'Failed' + self.invoice.failure_description = self.get_failure_message(errors) if errors else "" + self.update_invoice() + frappe.db.commit() + + def get_failure_message(self, errors): + if isinstance(errors, list): + errors = ', '.join(errors) + return errors def sanitize_for_json(string): """Escape JSON specific characters from a string.""" @@ -844,5 +1025,114 @@ def generate_eway_bill(doctype, docname, **kwargs): @frappe.whitelist() def cancel_eway_bill(doctype, docname, eway_bill, reason, remark): - gsp_connector = GSPConnector(doctype, docname) - gsp_connector.cancel_eway_bill(eway_bill, reason, remark) + # TODO: uncomment when eway_bill api from Adequare is enabled + # gsp_connector = GSPConnector(doctype, docname) + # gsp_connector.cancel_eway_bill(eway_bill, reason, remark) + + # update cancelled status only, to be able to cancel irn next + frappe.db.set_value(doctype, docname, 'eway_bill_cancelled', 1) + +@frappe.whitelist() +def generate_einvoices(docnames): + docnames = json.loads(docnames) or [] + + if len(docnames) < 10: + failures = GSPConnector.bulk_generate_irn(docnames) + frappe.local.message_log = [] + + if failures: + show_bulk_action_failure_message(failures) + + success = len(docnames) - len(failures) + frappe.msgprint( + _('{} e-invoices generated successfully').format(success), + title=_('Bulk E-Invoice Generation Complete') + ) + + else: + enqueue_bulk_action(schedule_bulk_generate_irn, docnames=docnames) + +def schedule_bulk_generate_irn(docnames): + failures = GSPConnector.bulk_generate_irn(docnames) + frappe.local.message_log = [] + + frappe.publish_realtime("bulk_einvoice_generation_complete", { + "user": frappe.session.user, + "failures": failures, + "invoices": docnames + }) + +def show_bulk_action_failure_message(failures): + for doc in failures: + docname = '
{0}'.format(doc.get('docname')) + message = doc.get('message').replace("'", '"') + if message[0] == '[': + errors = json.loads(message) + error_list = ''.join(['
  • {}
  • '.format(err) for err in errors]) + message = '''{} has following errors:
    +
      {}
    '''.format(docname, error_list) + else: + message = '{} - {}'.format(docname, message) + + frappe.msgprint( + message, + title=_('Bulk E-Invoice Generation Complete'), + indicator='red' + ) + +@frappe.whitelist() +def cancel_irns(docnames, reason, remark): + docnames = json.loads(docnames) or [] + + if len(docnames) < 10: + failures = GSPConnector.bulk_cancel_irn(docnames, reason, remark) + frappe.local.message_log = [] + + if failures: + show_bulk_action_failure_message(failures) + + success = len(docnames) - len(failures) + frappe.msgprint( + _('{} e-invoices cancelled successfully').format(success), + title=_('Bulk E-Invoice Cancellation Complete') + ) + else: + enqueue_bulk_action(schedule_bulk_cancel_irn, docnames=docnames, reason=reason, remark=remark) + +def schedule_bulk_cancel_irn(docnames, reason, remark): + failures = GSPConnector.bulk_cancel_irn(docnames, reason, remark) + frappe.local.message_log = [] + + frappe.publish_realtime("bulk_einvoice_cancellation_complete", { + "user": frappe.session.user, + "failures": failures, + "invoices": docnames + }) + +def enqueue_bulk_action(job, **kwargs): + check_scheduler_status() + + enqueue( + job, + **kwargs, + queue="long", + timeout=10000, + event="processing_bulk_einvoice_action", + now=frappe.conf.developer_mode or frappe.flags.in_test, + ) + + if job == schedule_bulk_generate_irn: + msg = _('E-Invoices will be generated in a background process.') + else: + msg = _('E-Invoices will be cancelled in a background process.') + + frappe.msgprint(msg, alert=1) + +def check_scheduler_status(): + if is_scheduler_inactive() and not frappe.flags.in_test: + frappe.throw(_("Scheduler is inactive. Cannot enqueue job."), title=_("Scheduler Inactive")) + +def job_already_enqueued(job_name): + enqueued_jobs = [d.get("job_name") for d in get_info()] + if job_name in enqueued_jobs: + return True \ No newline at end of file diff --git a/erpnext/regional/india/setup.py b/erpnext/regional/india/setup.py index d573425678..3440202a2b 100644 --- a/erpnext/regional/india/setup.py +++ b/erpnext/regional/india/setup.py @@ -51,7 +51,7 @@ def create_hsn_codes(data, code_field): def add_custom_roles_for_reports(): for report_name in ('GST Sales Register', 'GST Purchase Register', - 'GST Itemised Sales Register', 'GST Itemised Purchase Register', 'Eway Bill'): + 'GST Itemised Sales Register', 'GST Itemised Purchase Register', 'Eway Bill', 'E-Invoice Summary'): if not frappe.db.get_value('Custom Role', dict(report=report_name)): frappe.get_doc(dict( @@ -128,6 +128,9 @@ def make_custom_fields(update=True): is_non_gst = dict(fieldname='is_non_gst', label='Is Non GST', fieldtype='Check', fetch_from='item_code.is_non_gst', insert_after='is_nil_exempt', print_hide=1) + taxable_value = dict(fieldname='taxable_value', label='Taxable Value', + fieldtype='Currency', insert_after='base_net_amount', hidden=1, options="Company:company:default_currency", + print_hide=1) purchase_invoice_gst_category = [ dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break', @@ -409,21 +412,37 @@ def make_custom_fields(update=True): dict(fieldname='irn', label='IRN', fieldtype='Data', read_only=1, insert_after='customer', no_copy=1, print_hide=1, depends_on='eval:in_list(["Registered Regular", "SEZ", "Overseas", "Deemed Export"], doc.gst_category) && doc.irn_cancelled === 0'), - dict(fieldname='ack_no', label='Ack. No.', fieldtype='Data', read_only=1, hidden=1, insert_after='irn', no_copy=1, print_hide=1), - - dict(fieldname='ack_date', label='Ack. Date', fieldtype='Data', read_only=1, hidden=1, insert_after='ack_no', no_copy=1, print_hide=1), - dict(fieldname='irn_cancelled', label='IRN Cancelled', fieldtype='Check', no_copy=1, print_hide=1, depends_on='eval:(doc.irn_cancelled === 1)', read_only=1, allow_on_submit=1, insert_after='customer'), dict(fieldname='eway_bill_cancelled', label='E-Way Bill Cancelled', fieldtype='Check', no_copy=1, print_hide=1, depends_on='eval:(doc.eway_bill_cancelled === 1)', read_only=1, allow_on_submit=1, insert_after='customer'), - dict(fieldname='signed_einvoice', fieldtype='Code', options='JSON', hidden=1, no_copy=1, print_hide=1, read_only=1), + dict(fieldname='einvoice_section', label='E-Invoice Fields', fieldtype='Section Break', insert_after='gst_vehicle_type', + print_hide=1, hidden=1), + + dict(fieldname='ack_no', label='Ack. No.', fieldtype='Data', read_only=1, hidden=1, insert_after='einvoice_section', + no_copy=1, print_hide=1), + + dict(fieldname='ack_date', label='Ack. Date', fieldtype='Data', read_only=1, hidden=1, insert_after='ack_no', no_copy=1, print_hide=1), - dict(fieldname='signed_qr_code', fieldtype='Code', options='JSON', hidden=1, no_copy=1, print_hide=1, read_only=1), + dict(fieldname='irn_cancel_date', label='Cancel Date', fieldtype='Data', read_only=1, hidden=1, insert_after='ack_date', + no_copy=1, print_hide=1), - dict(fieldname='qrcode_image', label='QRCode', fieldtype='Attach Image', hidden=1, no_copy=1, print_hide=1, read_only=1) + dict(fieldname='signed_einvoice', label='Signed E-Invoice', fieldtype='Code', options='JSON', hidden=1, insert_after='irn_cancel_date', + no_copy=1, print_hide=1, read_only=1), + + dict(fieldname='signed_qr_code', label='Signed QRCode', fieldtype='Code', options='JSON', hidden=1, insert_after='signed_einvoice', + no_copy=1, print_hide=1, read_only=1), + + dict(fieldname='qrcode_image', label='QRCode', fieldtype='Attach Image', hidden=1, insert_after='signed_qr_code', + no_copy=1, print_hide=1, read_only=1), + + dict(fieldname='einvoice_status', label='E-Invoice Status', fieldtype='Select', insert_after='qrcode_image', + options='\nPending\nGenerated\nCancelled\nFailed', default=None, hidden=1, no_copy=1, print_hide=1, read_only=1), + + dict(fieldname='failure_description', label='E-Invoice Failure Description', fieldtype='Code', options='JSON', + hidden=1, insert_after='einvoice_status', no_copy=1, print_hide=1, read_only=1) ] custom_fields = { @@ -454,7 +473,7 @@ def make_custom_fields(update=True): 'Supplier Quotation Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], 'Sales Order Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], 'Delivery Note Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], - 'Sales Invoice Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], + 'Sales Invoice Item': [hsn_sac_field, nil_rated_exempt, is_non_gst, taxable_value], 'Purchase Order Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], 'Purchase Receipt Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], 'Purchase Invoice Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index ddcedd5e4f..9d23369fc4 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import frappe, re, json from frappe import _ import erpnext -from frappe.utils import cstr, flt, date_diff, nowdate, round_based_on_smallest_currency_fraction, money_in_words, getdate +from frappe.utils import cstr, flt, cint, date_diff, nowdate, round_based_on_smallest_currency_fraction, money_in_words, getdate from erpnext.regional.india import states, state_numbers from erpnext.controllers.taxes_and_totals import get_itemised_tax, get_itemised_taxable_amount from erpnext.controllers.accounts_controller import get_taxes_and_charges @@ -41,24 +41,25 @@ def validate_gstin_for_india(doc, method): return if len(doc.gstin) != 15: - frappe.throw(_("Invalid GSTIN! A GSTIN must have 15 characters.")) + frappe.throw(_("A GSTIN must have 15 characters."), title=_("Invalid GSTIN")) if gst_category and gst_category == 'UIN Holders': if not GSTIN_UIN_FORMAT.match(doc.gstin): - frappe.throw(_("Invalid GSTIN! The input you've entered doesn't match the GSTIN format for UIN Holders or Non-Resident OIDAR Service Providers")) + frappe.throw(_("The input you've entered doesn't match the GSTIN format for UIN Holders or Non-Resident OIDAR Service Providers"), + title=_("Invalid GSTIN")) else: if not GSTIN_FORMAT.match(doc.gstin): - frappe.throw(_("Invalid GSTIN! The input you've entered doesn't match the format of GSTIN.")) + frappe.throw(_("The input you've entered doesn't match the format of GSTIN."), title=_("Invalid GSTIN")) validate_gstin_check_digit(doc.gstin) set_gst_state_and_state_number(doc) if not doc.gst_state: - frappe.throw(_("Please Enter GST state")) + frappe.throw(_("Please enter GST state"), title=_("Invalid State")) if doc.gst_state_number != doc.gstin[:2]: - frappe.throw(_("Invalid GSTIN! First 2 digits of GSTIN should match with State number {0}.") - .format(doc.gst_state_number)) + frappe.throw(_("First 2 digits of GSTIN should match with State number {0}.") + .format(doc.gst_state_number), title=_("Invalid GSTIN")) def validate_pan_for_india(doc, method): if doc.get('country') != 'India' or not doc.pan: @@ -830,3 +831,48 @@ def get_regional_round_off_accounts(company, account_list): account_list.extend(gst_account_list) return account_list + +def update_taxable_values(doc, method): + country = frappe.get_cached_value('Company', doc.company, 'country') + + if country != 'India': + return + + gst_accounts = get_gst_accounts(doc.company) + + # Only considering sgst account to avoid inflating taxable value + gst_account_list = gst_accounts.get('sgst_account', []) + gst_accounts.get('sgst_account', []) \ + + gst_accounts.get('igst_account', []) + + additional_taxes = 0 + total_charges = 0 + item_count = 0 + considered_rows = [] + + for tax in doc.get('taxes'): + prev_row_id = cint(tax.row_id) - 1 + if tax.account_head in gst_account_list and prev_row_id not in considered_rows: + if tax.charge_type == 'On Previous Row Amount': + additional_taxes += doc.get('taxes')[prev_row_id].tax_amount_after_discount_amount + considered_rows.append(prev_row_id) + if tax.charge_type == 'On Previous Row Total': + additional_taxes += doc.get('taxes')[prev_row_id].base_total - doc.base_net_total + considered_rows.append(prev_row_id) + + for item in doc.get('items'): + if doc.apply_discount_on == 'Grand Total' and doc.discount_amount: + proportionate_value = item.base_amount if doc.base_total else item.qty + total_value = doc.base_total if doc.base_total else doc.total_qty + else: + proportionate_value = item.base_net_amount if doc.base_net_total else item.qty + total_value = doc.base_net_total if doc.base_net_total else doc.total_qty + + applicable_charges = flt(flt(proportionate_value * (flt(additional_taxes) / flt(total_value)), + item.precision('taxable_value'))) + item.taxable_value = applicable_charges + proportionate_value + total_charges += applicable_charges + item_count += 1 + + if total_charges != additional_taxes: + diff = additional_taxes - total_charges + doc.get('items')[item_count - 1].taxable_value += diff diff --git a/erpnext/regional/report/e_invoice_summary/__init__.py b/erpnext/regional/report/e_invoice_summary/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/regional/report/e_invoice_summary/e_invoice_summary.js b/erpnext/regional/report/e_invoice_summary/e_invoice_summary.js new file mode 100644 index 0000000000..4713217d83 --- /dev/null +++ b/erpnext/regional/report/e_invoice_summary/e_invoice_summary.js @@ -0,0 +1,55 @@ +// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt +/* eslint-disable */ + +frappe.query_reports["E-Invoice Summary"] = { + "filters": [ + { + "fieldtype": "Link", + "options": "Company", + "reqd": 1, + "fieldname": "company", + "label": __("Company"), + "default": frappe.defaults.get_user_default("Company"), + }, + { + "fieldtype": "Link", + "options": "Customer", + "fieldname": "customer", + "label": __("Customer") + }, + { + "fieldtype": "Date", + "reqd": 1, + "fieldname": "from_date", + "label": __("From Date"), + "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), + }, + { + "fieldtype": "Date", + "reqd": 1, + "fieldname": "to_date", + "label": __("To Date"), + "default": frappe.datetime.get_today(), + }, + { + "fieldtype": "Select", + "fieldname": "status", + "label": __("Status"), + "options": "\nPending\nGenerated\nCancelled\nFailed" + } + ], + + "formatter": function (value, row, column, data, default_formatter) { + value = default_formatter(value, row, column, data); + + if (column.fieldname == "einvoice_status" && value) { + if (value == 'Pending') value = `${value}`; + else if (value == 'Generated') value = `${value}`; + else if (value == 'Cancelled') value = `${value}`; + else if (value == 'Failed') value = `${value}`; + } + + return value; + } +}; diff --git a/erpnext/regional/report/e_invoice_summary/e_invoice_summary.json b/erpnext/regional/report/e_invoice_summary/e_invoice_summary.json new file mode 100644 index 0000000000..4deb073a53 --- /dev/null +++ b/erpnext/regional/report/e_invoice_summary/e_invoice_summary.json @@ -0,0 +1,28 @@ +{ + "add_total_row": 0, + "columns": [], + "creation": "2021-03-12 11:23:37.312294", + "disable_prepared_report": 0, + "disabled": 0, + "docstatus": 0, + "doctype": "Report", + "filters": [], + "idx": 0, + "is_standard": "Yes", + "json": "{}", + "letter_head": "Logo", + "modified": "2021-03-12 12:36:48.689413", + "modified_by": "Administrator", + "module": "Regional", + "name": "E-Invoice Summary", + "owner": "Administrator", + "prepared_report": 0, + "ref_doctype": "Sales Invoice", + "report_name": "E-Invoice Summary", + "report_type": "Script Report", + "roles": [ + { + "role": "Administrator" + } + ] +} \ No newline at end of file diff --git a/erpnext/regional/report/e_invoice_summary/e_invoice_summary.py b/erpnext/regional/report/e_invoice_summary/e_invoice_summary.py new file mode 100644 index 0000000000..47acf291a3 --- /dev/null +++ b/erpnext/regional/report/e_invoice_summary/e_invoice_summary.py @@ -0,0 +1,106 @@ +# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe import _ + +def execute(filters=None): + validate_filters(filters) + + columns = get_columns() + data = get_data(filters) + + return columns, data + +def validate_filters(filters={}): + filters = frappe._dict(filters) + + if not filters.company: + frappe.throw(_('{} is mandatory for generating E-Invoice Summary Report').format(_('Company')), title=_('Invalid Filter')) + if filters.company: + # validate if company has e-invoicing enabled + pass + if not filters.from_date or not filters.to_date: + frappe.throw(_('From Date & To Date is mandatory for generating E-Invoice Summary Report'), title=_('Invalid Filter')) + if filters.from_date > filters.to_date: + frappe.throw(_('From Date must be before To Date'), title=_('Invalid Filter')) + +def get_data(filters={}): + query_filters = { + 'posting_date': ['between', [filters.from_date, filters.to_date]], + 'einvoice_status': ['is', 'set'], + 'company': filters.company + } + if filters.customer: + query_filters['customer'] = filters.customer + if filters.status: + query_filters['einvoice_status'] = filters.status + + data = frappe.get_all( + 'Sales Invoice', + filters=query_filters, + fields=[d.get('fieldname') for d in get_columns()] + ) + + return data + +def get_columns(): + return [ + { + "fieldtype": "Date", + "fieldname": "posting_date", + "label": _("Posting Date"), + "width": 0 + }, + { + "fieldtype": "Link", + "fieldname": "name", + "label": _("Sales Invoice"), + "options": "Sales Invoice", + "width": 140 + }, + { + "fieldtype": "Data", + "fieldname": "einvoice_status", + "label": _("Status"), + "width": 100 + }, + { + "fieldtype": "Link", + "fieldname": "customer", + "options": "Customer", + "label": _("Customer") + }, + { + "fieldtype": "Check", + "fieldname": "is_return", + "label": _("Is Return"), + "width": 85 + }, + { + "fieldtype": "Data", + "fieldname": "ack_no", + "label": "Ack. No.", + "width": 145 + }, + { + "fieldtype": "Data", + "fieldname": "ack_date", + "label": "Ack. Date", + "width": 165 + }, + { + "fieldtype": "Data", + "fieldname": "irn", + "label": _("IRN No."), + "width": 250 + }, + { + "fieldtype": "Currency", + "options": "Company:company:default_currency", + "fieldname": "base_grand_total", + "label": _("Grand Total"), + "width": 120 + } + ] \ No newline at end of file From 03635fb0c4805fda016c4b6a4cacd10473fdd863 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 18 Jan 2021 15:06:35 +0530 Subject: [PATCH 410/449] feat: ESS User --- erpnext/patches.txt | 1 + .../v13_0/make_non_standard_user_type.py | 8 +++ erpnext/setup/install.py | 69 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 erpnext/patches/v13_0/make_non_standard_user_type.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 14f1ab84d6..108495613e 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -771,3 +771,4 @@ erpnext.patches.v12_0.add_gst_category_in_delivery_note erpnext.patches.v12_0.purchase_receipt_status erpnext.patches.v13_0.fix_non_unique_represents_company erpnext.patches.v12_0.add_document_type_field_for_italy_einvoicing +erpnext.patches.v13_0.make_non_standard_user_type #12-03-2020 diff --git a/erpnext/patches/v13_0/make_non_standard_user_type.py b/erpnext/patches/v13_0/make_non_standard_user_type.py new file mode 100644 index 0000000000..e2388f114c --- /dev/null +++ b/erpnext/patches/v13_0/make_non_standard_user_type.py @@ -0,0 +1,8 @@ +# Copyright (c) 2019, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +from erpnext.setup.install import add_non_standard_user_types + +def execute(): + add_non_standard_user_types() \ No newline at end of file diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py index 82f191d0b7..b269c5e0b2 100644 --- a/erpnext/setup/install.py +++ b/erpnext/setup/install.py @@ -8,9 +8,11 @@ from erpnext.accounts.doctype.cash_flow_mapper.default_cash_flow_mapper import D from .default_success_action import get_default_success_action from frappe import _ from frappe.utils import cint +from frappe.installer import update_site_config from frappe.desk.page.setup_wizard.setup_wizard import add_all_roles_to from frappe.custom.doctype.custom_field.custom_field import create_custom_field from erpnext.setup.default_energy_point_rules import get_default_energy_point_rules +from six import iteritems default_mail_footer = """
    Sent via ERPNext
    """ @@ -29,6 +31,7 @@ def after_install(): add_company_to_session_defaults() add_standard_navbar_items() add_app_name() + add_non_standard_user_types() frappe.db.commit() @@ -164,3 +167,69 @@ def add_standard_navbar_items(): def add_app_name(): frappe.db.set_value('System Settings', None, 'app_name', 'ERPNext') + +def add_non_standard_user_types(): + user_types = get_user_types_data() + + user_type_limit = {} + for user_type, data in iteritems(user_types): + user_type_limit.setdefault(frappe.scrub(user_type), 10) + + update_site_config('user_type_doctype_limit', user_type_limit) + + for user_type, data in iteritems(user_types): + create_custom_role(data) + create_user_type(user_type, data) + +def get_user_types_data(): + return { + 'ESS User': { + 'role': 'ESS User', + 'apply_user_permission_on': 'Employee', + 'user_id_field': 'user_id', + 'doctypes': { + 'Salary Slip': ['read'], + 'Employee': ['read', 'write'], + 'Timesheet': ['read', 'write', 'create'], + 'Expense Claim': ['read', 'write', 'create'], + 'Leave Application': ['read', 'write', 'create'], + 'Attendance Request': ['read', 'write', 'create'], + 'Compensatory Leave Request': ['read', 'write', 'create'], + 'Employee Tax Exemption Declaration': ['read', 'write', 'create'], + 'Employee Tax Exemption Proof Submission': ['read', 'write', 'create'], + } + } + } + +def create_custom_role(data): + if data.get('role') and not frappe.db.exists('Role', data.get('role')): + frappe.get_doc({ + 'doctype': 'Role', + 'role_name': data.get('role'), + 'desk_access': 1, + 'is_custom': 1 + }).insert(ignore_permissions=True) + +def create_user_type(user_type, data): + if frappe.db.exists('User Type', user_type): + doc = frappe.get_cached_doc('User Type', user_type) + doc.user_doctypes = [] + else: + doc = frappe.new_doc('User Type') + doc.update({ + 'name': user_type, + 'role': data.get('role'), + 'user_id_field': data.get('user_id_field'), + 'apply_user_permission_on': data.get('apply_user_permission_on') + }) + + create_role_permissions_for_doctype(doc, data) + doc.save(ignore_permissions=True) + +def create_role_permissions_for_doctype(doc, data): + for doctype, perms in iteritems(data.get('doctypes')): + args = {'document_type': doctype} + for perm in perms: + args[perm] = 1 + + doc.append('user_doctypes', args) From 610ccd4c0322c40fa11dec8e8bbaccbd834d3220 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 16 Mar 2021 00:39:10 +0530 Subject: [PATCH 411/449] fix: modified permission --- erpnext/patches.txt | 2 +- erpnext/setup/install.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 108495613e..44ec1ff37c 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -771,4 +771,4 @@ erpnext.patches.v12_0.add_gst_category_in_delivery_note erpnext.patches.v12_0.purchase_receipt_status erpnext.patches.v13_0.fix_non_unique_represents_company erpnext.patches.v12_0.add_document_type_field_for_italy_einvoicing -erpnext.patches.v13_0.make_non_standard_user_type #12-03-2020 +erpnext.patches.v13_0.make_non_standard_user_type #31-03-2020 diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py index b269c5e0b2..09cba8b4d0 100644 --- a/erpnext/setup/install.py +++ b/erpnext/setup/install.py @@ -183,20 +183,20 @@ def add_non_standard_user_types(): def get_user_types_data(): return { - 'ESS User': { - 'role': 'ESS User', + 'Employee Self Service': { + 'role': 'Employee Self Service', 'apply_user_permission_on': 'Employee', 'user_id_field': 'user_id', 'doctypes': { 'Salary Slip': ['read'], 'Employee': ['read', 'write'], - 'Timesheet': ['read', 'write', 'create'], - 'Expense Claim': ['read', 'write', 'create'], - 'Leave Application': ['read', 'write', 'create'], - 'Attendance Request': ['read', 'write', 'create'], - 'Compensatory Leave Request': ['read', 'write', 'create'], - 'Employee Tax Exemption Declaration': ['read', 'write', 'create'], - 'Employee Tax Exemption Proof Submission': ['read', 'write', 'create'], + 'Expense Claim': ['read', 'write', 'create', 'delete'], + 'Leave Application': ['read', 'write', 'create', 'delete'], + 'Attendance Request': ['read', 'write', 'create', 'delete'], + 'Compensatory Leave Request': ['read', 'write', 'create', 'delete'], + 'Employee Tax Exemption Declaration': ['read', 'write', 'create', 'delete'], + 'Employee Tax Exemption Proof Submission': ['read', 'write', 'create', 'delete'], + 'Timesheet': ['read', 'write', 'create', 'delete', 'submit', 'cancel', 'amend'] } } } From a8f78fabfd46cc42309cc6b8b414afc0739b6595 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 13 Apr 2021 18:43:57 +0530 Subject: [PATCH 412/449] fix: patch failing while migrating from v7 to v13 --- erpnext/hooks.py | 2 ++ erpnext/patches.txt | 2 +- .../patches/v13_0/make_non_standard_user_type.py | 16 ++++++++++++++++ erpnext/setup/install.py | 12 ++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 98d5966264..bb6cd8bdc2 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -307,6 +307,8 @@ auto_cancel_exempted_doctypes= [ "Inpatient Medication Entry" ] +after_migrate = ["erpnext.setup.install.update_select_perm_after_install"] + scheduler_events = { "cron": { "0/30 * * * *": [ diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 44ec1ff37c..7098a24043 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -771,4 +771,4 @@ erpnext.patches.v12_0.add_gst_category_in_delivery_note erpnext.patches.v12_0.purchase_receipt_status erpnext.patches.v13_0.fix_non_unique_represents_company erpnext.patches.v12_0.add_document_type_field_for_italy_einvoicing -erpnext.patches.v13_0.make_non_standard_user_type #31-03-2020 +erpnext.patches.v13_0.make_non_standard_user_type #13-04-2021 \ No newline at end of file diff --git a/erpnext/patches/v13_0/make_non_standard_user_type.py b/erpnext/patches/v13_0/make_non_standard_user_type.py index e2388f114c..a9d7883d40 100644 --- a/erpnext/patches/v13_0/make_non_standard_user_type.py +++ b/erpnext/patches/v13_0/make_non_standard_user_type.py @@ -2,7 +2,23 @@ # License: GNU General Public License v3. See license.txt from __future__ import unicode_literals +import frappe +from six import iteritems from erpnext.setup.install import add_non_standard_user_types def execute(): + doctype_dict = { + 'projects': ['Timesheet'], + 'payroll': ['Salary Slip', 'Employee Tax Exemption Declaration', 'Employee Tax Exemption Proof Submission'], + 'hr': ['Employee', 'Expense Claim', 'Leave Application', 'Attendance Request', 'Compensatory Leave Request'] + } + + for module, doctypes in iteritems(doctype_dict): + for doctype in doctypes: + frappe.reload_doc(module, 'doctype', doctype) + + + frappe.flags.ignore_select_perm = True + frappe.flags.update_select_perm_after_migrate = True + add_non_standard_user_types() \ No newline at end of file diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py index 09cba8b4d0..c7220cbc07 100644 --- a/erpnext/setup/install.py +++ b/erpnext/setup/install.py @@ -233,3 +233,15 @@ def create_role_permissions_for_doctype(doc, data): args[perm] = 1 doc.append('user_doctypes', args) + +def update_select_perm_after_install(): + if not frappe.flags.update_select_perm_after_migrate: + return + + frappe.flags.ignore_select_perm = False + for row in frappe.get_all('User Type', filters= {'is_standard': 0}): + print('Updating user type :- ', row.name) + doc = frappe.get_doc('User Type', row.name) + doc.save() + + frappe.flags.update_select_perm_after_migrate = False From ce6c3b5b748a1c46620832e2b51d085b2ef59bf5 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Tue, 13 Apr 2021 20:55:52 +0530 Subject: [PATCH 413/449] fix: incorrect incoming rate for the sales return (#25306) --- .../controllers/sales_and_purchase_return.py | 17 ++++++++++++++++- erpnext/controllers/selling_controller.py | 6 ++++-- erpnext/stock/stock_ledger.py | 3 ++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index de61b35316..5f759b43bc 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import frappe, erpnext from frappe import _ from frappe.model.meta import get_field_precision +from erpnext.stock.utils import get_incoming_rate from frappe.utils import flt, get_datetime, format_datetime class StockOverReturnError(frappe.ValidationError): pass @@ -389,10 +390,24 @@ def make_return_doc(doctype, source_name, target_doc=None): return doclist -def get_rate_for_return(voucher_type, voucher_no, item_code, return_against=None, item_row=None, voucher_detail_no=None): +def get_rate_for_return(voucher_type, voucher_no, item_code, return_against=None, + item_row=None, voucher_detail_no=None, sle=None): if not return_against: return_against = frappe.get_cached_value(voucher_type, voucher_no, "return_against") + if not return_against and voucher_type == 'Sales Invoice' and sle: + return get_incoming_rate({ + "item_code": sle.item_code, + "warehouse": sle.warehouse, + "posting_date": sle.get('posting_date'), + "posting_time": sle.get('posting_time'), + "qty": sle.actual_qty, + "serial_no": sle.get('serial_no'), + "company": sle.company, + "voucher_type": sle.voucher_type, + "voucher_no": sle.voucher_no + }, raise_error_if_no_rate=False) + return_against_item_field = get_return_against_item_fields(voucher_type) filters = get_filters(voucher_type, voucher_no, voucher_detail_no, diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index fb52c1f6ca..6d921625b7 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -311,14 +311,16 @@ class SellingController(StockController): items = self.get("items") + (self.get("packed_items") or []) for d in items: - if not cint(self.get("is_return")): + if not self.get("return_against"): # Get incoming rate based on original item cost based on valuation method + qty = flt(d.get('stock_qty') or d.get('actual_qty')) + d.incoming_rate = get_incoming_rate({ "item_code": d.item_code, "warehouse": d.warehouse, "posting_date": self.get('posting_date') or self.get('transaction_date'), "posting_time": self.get('posting_time') or nowtime(), - "qty": -1 * flt(d.get('stock_qty') or d.get('actual_qty')), + "qty": qty if cint(self.get("is_return")) else (-1 * qty), "serial_no": d.get('serial_no'), "company": self.company, "voucher_type": self.doctype, diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 121c51cf6a..df5f16fd41 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -372,7 +372,8 @@ class update_entries_after(object): elif sle.voucher_type in ("Purchase Receipt", "Purchase Invoice", "Delivery Note", "Sales Invoice"): if frappe.get_cached_value(sle.voucher_type, sle.voucher_no, "is_return"): from erpnext.controllers.sales_and_purchase_return import get_rate_for_return # don't move this import to top - rate = get_rate_for_return(sle.voucher_type, sle.voucher_no, sle.item_code, voucher_detail_no=sle.voucher_detail_no) + rate = get_rate_for_return(sle.voucher_type, sle.voucher_no, sle.item_code, + voucher_detail_no=sle.voucher_detail_no, sle = sle) else: if sle.voucher_type in ("Purchase Receipt", "Purchase Invoice"): rate_field = "valuation_rate" From ece4c16d8f498ffcc354f1b002f55c5e64dc98ce Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 14 Apr 2021 12:53:13 +0530 Subject: [PATCH 414/449] chore: Added change log --- erpnext/change_log/v13/v13.0.2.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 erpnext/change_log/v13/v13.0.2.md diff --git a/erpnext/change_log/v13/v13.0.2.md b/erpnext/change_log/v13/v13.0.2.md new file mode 100644 index 0000000000..2bfbdfcc5d --- /dev/null +++ b/erpnext/change_log/v13/v13.0.2.md @@ -0,0 +1,7 @@ +## Version 13.0.2 Release Notes + +### Fixes +- fix: frappe.whitelist for doc methods ([#25231](https://github.com/frappe/erpnext/pull/25231)) +- fix: incorrect incoming rate for the sales return ([#25306](https://github.com/frappe/erpnext/pull/25306)) +- fix(e-invoicing): validations & tax calculation fixes ([#25314](https://github.com/frappe/erpnext/pull/25314)) +- fix: update scheduler check time ([#25295](https://github.com/frappe/erpnext/pull/25295)) \ No newline at end of file From 88b3c525339638c263977b28377b799d60c27fa5 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 14 Apr 2021 13:13:53 +0550 Subject: [PATCH 415/449] bumped to version 13.0.2 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index d2e58701c8..1a5a0fa275 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '13.0.1' +__version__ = '13.0.2' def get_default_company(user=None): '''Get default company for user''' From 8798f3080837d3f7e4ebf1e41801aa112f2e064e Mon Sep 17 00:00:00 2001 From: Saqib Date: Wed, 14 Apr 2021 15:05:33 +0530 Subject: [PATCH 416/449] fix: pos print receipt (#25328) --- .../selling/page/point_of_sale/pos_past_order_summary.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/selling/page/point_of_sale/pos_past_order_summary.js b/erpnext/selling/page/point_of_sale/pos_past_order_summary.js index a5a739cff9..acf4eb371f 100644 --- a/erpnext/selling/page/point_of_sale/pos_past_order_summary.js +++ b/erpnext/selling/page/point_of_sale/pos_past_order_summary.js @@ -204,11 +204,11 @@ erpnext.PointOfSale.PastOrderSummary = class { print_receipt() { const frm = this.events.get_frm(); frappe.utils.print( - frm.doctype, - frm.docname, + this.doc.doctype, + this.doc.name, frm.pos_print_format, - frm.doc.letter_head, - frm.doc.language || frappe.boot.lang + this.doc.letter_head, + this.doc.language || frappe.boot.lang ); } From d4fd1038dc73f2f5321cb28a42d5d8ac14731f15 Mon Sep 17 00:00:00 2001 From: Saqib Date: Wed, 14 Apr 2021 15:07:10 +0530 Subject: [PATCH 417/449] fix: pos print receipt (#25329) From c4565651ff79e6880086830341494e4b77d1e3a7 Mon Sep 17 00:00:00 2001 From: Ganga Manoj Date: Wed, 14 Apr 2021 17:11:36 +0530 Subject: [PATCH 418/449] fix: Let Administrator delete company transactions (#25300) Co-authored-by: Nabin Hait --- erpnext/setup/doctype/company/delete_company_transactions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/setup/doctype/company/delete_company_transactions.py b/erpnext/setup/doctype/company/delete_company_transactions.py index 933ed3cf32..8367a257ea 100644 --- a/erpnext/setup/doctype/company/delete_company_transactions.py +++ b/erpnext/setup/doctype/company/delete_company_transactions.py @@ -15,7 +15,7 @@ def delete_company_transactions(company_name): frappe.only_for("System Manager") doc = frappe.get_doc("Company", company_name) - if frappe.session.user != doc.owner: + if frappe.session.user != doc.owner and frappe.session.user != 'Administrator': frappe.throw(_("Transactions can only be deleted by the creator of the Company"), frappe.PermissionError) From 24e45163d5fa7a86ffd26639258fc1a24ccb5329 Mon Sep 17 00:00:00 2001 From: Marica Date: Wed, 14 Apr 2021 18:53:15 +0530 Subject: [PATCH 419/449] fix: Sider --- erpnext/public/js/utils.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index 8fe38d91ea..fd98f17ac1 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -292,10 +292,9 @@ $.extend(erpnext.utils, { } }, overrides_parent_value_in_all_rows: function(doc, dt, dn, table_fieldname, fieldname, parent_fieldname) { - let d = locals[dt][dn]; - if(doc[parent_fieldname]){ + if (doc[parent_fieldname]) { let cl = doc[table_fieldname] || []; - for(let i = 0; i < cl.length; i++) { + for (let i = 0; i < cl.length; i++) { cl[i][fieldname] = doc[parent_fieldname]; } frappe.refresh_field(table_fieldname); From 593071bd53c65ebbe3ebde477cd6283b73d9f32c Mon Sep 17 00:00:00 2001 From: Saqib Date: Thu, 15 Apr 2021 14:12:11 +0530 Subject: [PATCH 420/449] fix: currency symbol in bank transaction list view (#25336) --- .../doctype/bank_transaction/bank_transaction.json | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction.json b/erpnext/accounts/doctype/bank_transaction/bank_transaction.json index 69ee4971cd..88aa7ef8b5 100644 --- a/erpnext/accounts/doctype/bank_transaction/bank_transaction.json +++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction.json @@ -175,22 +175,24 @@ }, { "fieldname": "deposit", - "oldfieldname": "debit", "fieldtype": "Currency", "in_list_view": 1, - "label": "Deposit" + "label": "Deposit", + "oldfieldname": "debit", + "options": "currency" }, { "fieldname": "withdrawal", - "oldfieldname": "credit", "fieldtype": "Currency", "in_list_view": 1, - "label": "Withdrawal" + "label": "Withdrawal", + "oldfieldname": "credit", + "options": "currency" } ], "is_submittable": 1, "links": [], - "modified": "2020-12-30 19:40:54.221070", + "modified": "2021-04-14 17:31:58.963529", "modified_by": "Administrator", "module": "Accounts", "name": "Bank Transaction", From c50fbc689737800f2cb1e78786f31f2dbedd3ba9 Mon Sep 17 00:00:00 2001 From: Sun Howwrongbum Date: Thu, 15 Apr 2021 14:52:13 +0530 Subject: [PATCH 421/449] fix: list lookup with undefined variable (#25210) Co-authored-by: Ankush Menat --- erpnext/public/js/utils/serial_no_batch_selector.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/public/js/utils/serial_no_batch_selector.js b/erpnext/public/js/utils/serial_no_batch_selector.js index d49a8138fb..3333d569a7 100644 --- a/erpnext/public/js/utils/serial_no_batch_selector.js +++ b/erpnext/public/js/utils/serial_no_batch_selector.js @@ -353,9 +353,9 @@ erpnext.SerialNoBatchSelector = Class.extend({ return row.on_grid_fields_dict.batch_no.get_value(); } }); - if (selected_batches.includes(val)) { + if (selected_batches.includes(batch_no)) { this.set_value(""); - frappe.throw(__('Batch {0} already selected.', [val])); + frappe.throw(__('Batch {0} already selected.', [batch_no])); } if (me.warehouse_details.name) { From 39b1cd827a5e3ba04c29189426e5f85f7fe77daf Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 15 Apr 2021 18:54:29 +0530 Subject: [PATCH 422/449] fix: Additional Salary component amount not getting set (#25355) --- erpnext/payroll/doctype/salary_slip/salary_slip.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index 539f2c56d3..afdf081ac8 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -633,6 +633,8 @@ class SalarySlip(TransactionBase): if additional_salary: component_row.default_amount = 0 + component_row.additional_amount = amount + component_row.additional_salary = additional_salary.name component_row.deduct_full_tax_on_selected_payroll_date = \ additional_salary.deduct_full_tax_on_selected_payroll_date else: From 597bb8be184778748980ef453c7c48119317ff2f Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Thu, 15 Apr 2021 20:32:45 +0530 Subject: [PATCH 423/449] fix: remove pickup_to, pickup_from and get_pickup_time relies on server-side validation instead js controller --- erpnext/stock/doctype/shipment/shipment.js | 37 ---------------------- 1 file changed, 37 deletions(-) diff --git a/erpnext/stock/doctype/shipment/shipment.js b/erpnext/stock/doctype/shipment/shipment.js index 7af16af898..ce2906ecbe 100644 --- a/erpnext/stock/doctype/shipment/shipment.js +++ b/erpnext/stock/doctype/shipment/shipment.js @@ -363,43 +363,6 @@ frappe.ui.form.on('Shipment', { if (frm.doc.pickup_date < frappe.datetime.get_today()) { frappe.throw(__("Pickup Date cannot be before this day")); } - if (frm.doc.pickup_date == frappe.datetime.get_today()) { - var pickup_time = frm.events.get_pickup_time(frm); - frm.set_value("pickup_from", pickup_time); - frm.trigger('set_pickup_to_time'); - } - }, - pickup_from: function(frm) { - var pickup_time = frm.events.get_pickup_time(frm); - if (frm.doc.pickup_from && frm.doc.pickup_date == frappe.datetime.get_today()) { - let current_hour = pickup_time.split(':')[0]; - let current_min = pickup_time.split(':')[1]; - let pickup_hour = frm.doc.pickup_from.split(':')[0]; - let pickup_min = frm.doc.pickup_from.split(':')[1]; - if (pickup_hour < current_hour || (pickup_hour == current_hour && pickup_min < current_min)) { - frm.set_value("pickup_from", pickup_time); - frappe.throw(__("Pickup Time cannot be in the past")); - } - } - frm.trigger('set_pickup_to_time'); - }, - get_pickup_time: function() { - let current_hour = new Date().getHours(); - let current_min = new Date().toLocaleString('en-US', {minute: 'numeric'}); - if (current_min < 30) { - current_min = '30'; - } else { - current_min = '00'; - current_hour = Number(current_hour)+1; - } - let pickup_time = current_hour +':'+ current_min; - return pickup_time; - }, - set_pickup_to_time: function(frm) { - let pickup_to_hour = Number(frm.doc.pickup_from.split(':')[0])+5; - let pickup_to_min = frm.doc.pickup_from.split(':')[1]; - let pickup_to = pickup_to_hour +':'+ pickup_to_min; - frm.set_value("pickup_to", pickup_to); }, clear_pickup_fields: function(frm) { let fields = ["pickup_address_name", "pickup_contact_name", "pickup_address", "pickup_contact", "pickup_contact_email", "pickup_contact_person"]; From 6179cc1311df15ea0459ec7c9a8e65e2b2d3086d Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Thu, 15 Apr 2021 20:36:28 +0530 Subject: [PATCH 424/449] fix: make pickup_to and pickup_from mandatory fields --- erpnext/stock/doctype/shipment/shipment.json | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/erpnext/stock/doctype/shipment/shipment.json b/erpnext/stock/doctype/shipment/shipment.json index 76c331c5c2..a33cbc288c 100644 --- a/erpnext/stock/doctype/shipment/shipment.json +++ b/erpnext/stock/doctype/shipment/shipment.json @@ -275,14 +275,16 @@ "default": "09:00", "fieldname": "pickup_from", "fieldtype": "Time", - "label": "Pickup from" + "label": "Pickup from", + "reqd": 1 }, { "allow_on_submit": 1, "default": "17:00", "fieldname": "pickup_to", "fieldtype": "Time", - "label": "Pickup to" + "label": "Pickup to", + "reqd": 1 }, { "fieldname": "column_break_36", @@ -431,7 +433,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-12-25 15:02:34.891976", + "modified": "2021-04-13 17:14:18.181818", "modified_by": "Administrator", "module": "Stock", "name": "Shipment", @@ -469,4 +471,4 @@ "sort_field": "modified", "sort_order": "DESC", "track_changes": 1 -} \ No newline at end of file +} From c0db286dc1572d591a9a6c7c70620ffebfbd28d2 Mon Sep 17 00:00:00 2001 From: Afshan <33727827+AfshanKhan@users.noreply.github.com> Date: Thu, 15 Apr 2021 23:48:25 +0530 Subject: [PATCH 425/449] fix: filter for employees in salary slip (#25360) --- erpnext/payroll/doctype/salary_slip/salary_slip.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.js b/erpnext/payroll/doctype/salary_slip/salary_slip.js index a0ddd39ca2..5258f3aff9 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.js +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.js @@ -40,7 +40,9 @@ frappe.ui.form.on("Salary Slip", { frm.set_query("employee", function() { return { query: "erpnext.controllers.queries.employee_query", - filters: frm.doc.company + filters: { + company: frm.doc.company + } }; }); }, From 9d9c256e70ebf00c493f5131179700c3a17e4404 Mon Sep 17 00:00:00 2001 From: Anupam Date: Fri, 16 Apr 2021 00:11:40 +0530 Subject: [PATCH 426/449] feat: added Disable Rounded Total in sales transactions --- .../doctype/sales_invoice/sales_invoice.json | 14 +++++++++++++- .../selling/doctype/sales_order/sales_order.json | 14 +++++++++++++- .../stock/doctype/delivery_note/delivery_note.json | 14 +++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index d382386a32..c6c67b4ddc 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -118,6 +118,7 @@ "in_words", "total_advance", "outstanding_amount", + "disable_rounded_total", "advances_section", "allocate_advances_automatically", "get_advances", @@ -1109,6 +1110,7 @@ "reqd": 1 }, { + "depends_on": "eval:!doc.disable_rounded_total", "fieldname": "base_rounding_adjustment", "fieldtype": "Currency", "hide_days": 1, @@ -1120,6 +1122,7 @@ "read_only": 1 }, { + "depends_on": "eval:!doc.disable_rounded_total", "fieldname": "base_rounded_total", "fieldtype": "Currency", "hide_days": 1, @@ -1168,6 +1171,7 @@ "reqd": 1 }, { + "depends_on": "eval:!doc.disable_rounded_total", "fieldname": "rounding_adjustment", "fieldtype": "Currency", "hide_days": 1, @@ -1180,6 +1184,7 @@ }, { "bold": 1, + "depends_on": "eval:!doc.disable_rounded_total", "fieldname": "rounded_total", "fieldtype": "Currency", "hide_days": 1, @@ -1945,6 +1950,13 @@ "fieldtype": "Link", "label": "Set Target Warehouse", "options": "Warehouse" + }, + { + "default": "0", + "depends_on": "grand_total", + "fieldname": "disable_rounded_total", + "fieldtype": "Check", + "label": "Disable Rounded Total" } ], "icon": "fa fa-file-text", @@ -1957,7 +1969,7 @@ "link_fieldname": "consolidated_invoice" } ], - "modified": "2021-03-31 15:42:26.261540", + "modified": "2021-04-15 23:57:58.766651", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", diff --git a/erpnext/selling/doctype/sales_order/sales_order.json b/erpnext/selling/doctype/sales_order/sales_order.json index 0a5c6651ba..762b6f1d6c 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.json +++ b/erpnext/selling/doctype/sales_order/sales_order.json @@ -98,6 +98,7 @@ "rounded_total", "in_words", "advance_paid", + "disable_rounded_total", "packing_list", "packed_items", "payment_schedule_section", @@ -901,6 +902,7 @@ "width": "150px" }, { + "depends_on": "eval:!doc.disable_rounded_total", "fieldname": "base_rounding_adjustment", "fieldtype": "Currency", "hide_days": 1, @@ -912,6 +914,7 @@ "read_only": 1 }, { + "depends_on": "eval:!doc.disable_rounded_total", "fieldname": "base_rounded_total", "fieldtype": "Currency", "hide_days": 1, @@ -961,6 +964,7 @@ "width": "150px" }, { + "depends_on": "eval:!doc.disable_rounded_total", "fieldname": "rounding_adjustment", "fieldtype": "Currency", "hide_days": 1, @@ -973,6 +977,7 @@ }, { "bold": 1, + "depends_on": "eval:!doc.disable_rounded_total", "fieldname": "rounded_total", "fieldtype": "Currency", "hide_days": 1, @@ -1474,13 +1479,20 @@ "label": "Represents Company", "options": "Company", "read_only": 1 + }, + { + "default": "0", + "depends_on": "grand_total", + "fieldname": "disable_rounded_total", + "fieldtype": "Check", + "label": "Disable Rounded Total" } ], "icon": "fa fa-file-text", "idx": 105, "is_submittable": 1, "links": [], - "modified": "2021-01-20 23:40:39.929296", + "modified": "2021-04-15 23:55:13.439068", "modified_by": "Administrator", "module": "Selling", "name": "Sales Order", diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.json b/erpnext/stock/doctype/delivery_note/delivery_note.json index f595aade91..280fde158f 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.json +++ b/erpnext/stock/doctype/delivery_note/delivery_note.json @@ -99,6 +99,7 @@ "rounding_adjustment", "rounded_total", "in_words", + "disable_rounded_total", "terms_section_break", "tc_name", "terms", @@ -768,6 +769,7 @@ "width": "150px" }, { + "depends_on": "eval:!doc.disable_rounded_total", "fieldname": "base_rounding_adjustment", "fieldtype": "Currency", "label": "Rounding Adjustment (Company Currency)", @@ -777,6 +779,7 @@ "read_only": 1 }, { + "depends_on": "eval:!doc.disable_rounded_total", "fieldname": "base_rounded_total", "fieldtype": "Currency", "label": "Rounded Total (Company Currency)", @@ -819,6 +822,7 @@ "width": "150px" }, { + "depends_on": "eval:!doc.disable_rounded_total", "fieldname": "rounding_adjustment", "fieldtype": "Currency", "label": "Rounding Adjustment", @@ -829,6 +833,7 @@ }, { "bold": 1, + "depends_on": "eval:!doc.disable_rounded_total", "fieldname": "rounded_total", "fieldtype": "Currency", "label": "Rounded Total", @@ -1271,13 +1276,20 @@ "label": "Represents Company", "options": "Company", "read_only": 1 + }, + { + "default": "0", + "depends_on": "grand_total", + "fieldname": "disable_rounded_total", + "fieldtype": "Check", + "label": "Disable Rounded Total" } ], "icon": "fa fa-truck", "idx": 146, "is_submittable": 1, "links": [], - "modified": "2020-12-26 17:07:59.194403", + "modified": "2021-04-15 23:55:49.620641", "modified_by": "Administrator", "module": "Stock", "name": "Delivery Note", From b1aad63a9910367fecab17efb1193453db717a88 Mon Sep 17 00:00:00 2001 From: Jannat Patel <31363128+pateljannat@users.noreply.github.com> Date: Fri, 16 Apr 2021 16:08:22 +0530 Subject: [PATCH 427/449] fix: leave policy in leave allocation (#25334) Co-authored-by: Rucha Mahabal --- erpnext/hr/doctype/leave_allocation/leave_allocation.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.json b/erpnext/hr/doctype/leave_allocation/leave_allocation.json index 3a300c0d63..ae02c512c2 100644 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.json +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.json @@ -218,8 +218,7 @@ "fieldname": "leave_policy_assignment", "fieldtype": "Link", "label": "Leave Policy Assignment", - "options": "Leave Policy Assignment", - "read_only": 1 + "options": "Leave Policy Assignment" }, { "fetch_from": "employee.company", @@ -236,7 +235,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2021-01-04 18:46:13.184104", + "modified": "2021-04-14 15:28:26.335104", "modified_by": "Administrator", "module": "HR", "name": "Leave Allocation", From ede339f80bf514c8f7e5372be3e91567d063b26a Mon Sep 17 00:00:00 2001 From: Marica Date: Fri, 16 Apr 2021 18:42:54 +0530 Subject: [PATCH 428/449] fix: Serial No not updated correctly via Inter Company Stock Transfer (#25006) * fix: Serial No not updated correctly via Inter Company Stock Transfer * chore: Added More Test Cases for inter company Serial Transfer * fix: Test for serial no duplication - fixed serial no test - made errors more meaningful on serial no validation * fix: Stock Reco Test Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> --- .../purchase_receipt/test_purchase_receipt.py | 1 + erpnext/stock/doctype/serial_no/serial_no.py | 33 ++++- .../stock/doctype/serial_no/test_serial_no.py | 129 +++++++++++++++++- .../stock_reconciliation.py | 2 +- .../test_stock_reconciliation.py | 4 +- 5 files changed, 159 insertions(+), 10 deletions(-) diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 7f0c3fa801..16eea24f84 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -582,6 +582,7 @@ class TestPurchaseReceipt(unittest.TestCase): serial_no=serial_no, basic_rate=100, do_not_submit=True) se.submit() + se.cancel() dn.cancel() pr1.cancel() diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py index c8d8ca9e17..c02dd2e518 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.py +++ b/erpnext/stock/doctype/serial_no/serial_no.py @@ -14,6 +14,7 @@ from frappe import _, ValidationError from erpnext.controllers.stock_controller import StockController from six import string_types from six.moves import map + class SerialNoCannotCreateDirectError(ValidationError): pass class SerialNoCannotCannotChangeError(ValidationError): pass class SerialNoNotRequiredError(ValidationError): pass @@ -322,11 +323,35 @@ def validate_serial_no(sle, item_det): frappe.throw(_("Serial Nos Required for Serialized Item {0}").format(sle.item_code), SerialNoRequiredError) elif serial_nos: + # SLE is being cancelled and has serial nos for serial_no in serial_nos: - sr = frappe.db.get_value("Serial No", serial_no, ["name", "warehouse"], as_dict=1) - if sr and cint(sle.actual_qty) < 0 and sr.warehouse != sle.warehouse: - frappe.throw(_("Cannot cancel {0} {1} because Serial No {2} does not belong to the warehouse {3}") - .format(sle.voucher_type, sle.voucher_no, serial_no, sle.warehouse)) + check_serial_no_validity_on_cancel(serial_no, sle) + +def check_serial_no_validity_on_cancel(serial_no, sle): + sr = frappe.db.get_value("Serial No", serial_no, ["name", "warehouse", "company", "status"], as_dict=1) + sr_link = frappe.utils.get_link_to_form("Serial No", serial_no) + doc_link = frappe.utils.get_link_to_form(sle.voucher_type, sle.voucher_no) + actual_qty = cint(sle.actual_qty) + is_stock_reco = sle.voucher_type == "Stock Reconciliation" + msg = None + + if sr and (actual_qty < 0 or is_stock_reco) and sr.warehouse != sle.warehouse: + # receipt(inward) is being cancelled + msg = _("Cannot cancel {0} {1} as Serial No {2} does not belong to the warehouse {3}").format( + sle.voucher_type, doc_link, sr_link, frappe.bold(sle.warehouse)) + elif sr and actual_qty > 0 and not is_stock_reco: + # delivery is being cancelled, check for warehouse. + if sr.warehouse: + # serial no is active in another warehouse/company. + msg = _("Cannot cancel {0} {1} as Serial No {2} is active in warehouse {3}").format( + sle.voucher_type, doc_link, sr_link, frappe.bold(sr.warehouse)) + elif sr.company != sle.company and sr.status == "Delivered": + # serial no is inactive (allowed) or delivered from another company (block). + msg = _("Cannot cancel {0} {1} as Serial No {2} does not belong to the company {3}").format( + sle.voucher_type, doc_link, sr_link, frappe.bold(sle.company)) + + if msg: + frappe.throw(msg, title=_("Cannot cancel")) def validate_material_transfer_entry(sle_doc): sle_doc.update({ diff --git a/erpnext/stock/doctype/serial_no/test_serial_no.py b/erpnext/stock/doctype/serial_no/test_serial_no.py index ed70790b2c..cde7fe07c6 100644 --- a/erpnext/stock/doctype/serial_no/test_serial_no.py +++ b/erpnext/stock/doctype/serial_no/test_serial_no.py @@ -40,16 +40,139 @@ class TestSerialNo(unittest.TestCase): se = make_serialized_item(target_warehouse="_Test Warehouse - _TC") serial_nos = get_serial_nos(se.get("items")[0].serial_no) - create_delivery_note(item_code="_Test Serialized Item With Series", qty=1, serial_no=serial_nos[0]) + dn = create_delivery_note(item_code="_Test Serialized Item With Series", qty=1, serial_no=serial_nos[0]) + + serial_no = frappe.get_doc("Serial No", serial_nos[0]) + + # check Serial No details after delivery + self.assertEqual(serial_no.status, "Delivered") + self.assertEqual(serial_no.warehouse, None) + self.assertEqual(serial_no.company, "_Test Company") + self.assertEqual(serial_no.delivery_document_type, "Delivery Note") + self.assertEqual(serial_no.delivery_document_no, dn.name) wh = create_warehouse("_Test Warehouse", company="_Test Company 1") - make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1, serial_no=serial_nos[0], + pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1, serial_no=serial_nos[0], company="_Test Company 1", warehouse=wh) - serial_no = frappe.db.get_value("Serial No", serial_nos[0], ["warehouse", "company"], as_dict=1) + serial_no.reload() + # check Serial No details after purchase in second company + self.assertEqual(serial_no.status, "Active") self.assertEqual(serial_no.warehouse, wh) self.assertEqual(serial_no.company, "_Test Company 1") + self.assertEqual(serial_no.purchase_document_type, "Purchase Receipt") + self.assertEqual(serial_no.purchase_document_no, pr.name) + + def test_inter_company_transfer_intermediate_cancellation(self): + """ + Receive into and Deliver Serial No from one company. + Then Receive into and Deliver from second company. + Try to cancel intermediate receipts/deliveries to test if it is blocked. + """ + se = make_serialized_item(target_warehouse="_Test Warehouse - _TC") + serial_nos = get_serial_nos(se.get("items")[0].serial_no) + + sn_doc = frappe.get_doc("Serial No", serial_nos[0]) + + # check Serial No details after purchase in first company + self.assertEqual(sn_doc.status, "Active") + self.assertEqual(sn_doc.company, "_Test Company") + self.assertEqual(sn_doc.warehouse, "_Test Warehouse - _TC") + self.assertEqual(sn_doc.purchase_document_no, se.name) + + dn = create_delivery_note(item_code="_Test Serialized Item With Series", + qty=1, serial_no=serial_nos[0]) + sn_doc.reload() + # check Serial No details after delivery from **first** company + self.assertEqual(sn_doc.status, "Delivered") + self.assertEqual(sn_doc.company, "_Test Company") + self.assertEqual(sn_doc.warehouse, None) + self.assertEqual(sn_doc.delivery_document_no, dn.name) + + # try cancelling the first Serial No Receipt, even though it is delivered + # block cancellation is Serial No is out of the warehouse + self.assertRaises(frappe.ValidationError, se.cancel) + + # receive serial no in second company + wh = create_warehouse("_Test Warehouse", company="_Test Company 1") + pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", + qty=1, serial_no=serial_nos[0], company="_Test Company 1", warehouse=wh) + sn_doc.reload() + + self.assertEqual(sn_doc.warehouse, wh) + # try cancelling the delivery from the first company + # block cancellation as Serial No belongs to different company + self.assertRaises(frappe.ValidationError, dn.cancel) + + # deliver from second company + dn_2 = create_delivery_note(item_code="_Test Serialized Item With Series", + qty=1, serial_no=serial_nos[0], company="_Test Company 1", warehouse=wh) + sn_doc.reload() + + # check Serial No details after delivery from **second** company + self.assertEqual(sn_doc.status, "Delivered") + self.assertEqual(sn_doc.company, "_Test Company 1") + self.assertEqual(sn_doc.warehouse, None) + self.assertEqual(sn_doc.delivery_document_no, dn_2.name) + + # cannot cancel any intermediate document before last Delivery Note + self.assertRaises(frappe.ValidationError, se.cancel) + self.assertRaises(frappe.ValidationError, dn.cancel) + self.assertRaises(frappe.ValidationError, pr.cancel) + + def test_inter_company_transfer_fallback_on_cancel(self): + """ + Test Serial No state changes on cancellation. + If Delivery cancelled, it should fall back on last Receipt in the same company. + If Receipt is cancelled, it should be Inactive in the same company. + """ + # Receipt in **first** company + se = make_serialized_item(target_warehouse="_Test Warehouse - _TC") + serial_nos = get_serial_nos(se.get("items")[0].serial_no) + sn_doc = frappe.get_doc("Serial No", serial_nos[0]) + + # Delivery from first company + dn = create_delivery_note(item_code="_Test Serialized Item With Series", + qty=1, serial_no=serial_nos[0]) + + # Receipt in **second** company + wh = create_warehouse("_Test Warehouse", company="_Test Company 1") + pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", + qty=1, serial_no=serial_nos[0], company="_Test Company 1", warehouse=wh) + + # Delivery from second company + dn_2 = create_delivery_note(item_code="_Test Serialized Item With Series", + qty=1, serial_no=serial_nos[0], company="_Test Company 1", warehouse=wh) + sn_doc.reload() + + self.assertEqual(sn_doc.status, "Delivered") + self.assertEqual(sn_doc.company, "_Test Company 1") + self.assertEqual(sn_doc.delivery_document_no, dn_2.name) + + dn_2.cancel() + sn_doc.reload() + # Fallback on Purchase Receipt if Delivery is cancelled + self.assertEqual(sn_doc.status, "Active") + self.assertEqual(sn_doc.company, "_Test Company 1") + self.assertEqual(sn_doc.warehouse, wh) + self.assertEqual(sn_doc.purchase_document_no, pr.name) + + pr.cancel() + sn_doc.reload() + # Inactive in same company if Receipt cancelled + self.assertEqual(sn_doc.status, "Inactive") + self.assertEqual(sn_doc.company, "_Test Company 1") + self.assertEqual(sn_doc.warehouse, None) + + dn.cancel() + sn_doc.reload() + # Fallback on Purchase Receipt in FIRST company if + # Delivery from FIRST company is cancelled + self.assertEqual(sn_doc.status, "Active") + self.assertEqual(sn_doc.company, "_Test Company") + self.assertEqual(sn_doc.warehouse, "_Test Warehouse - _TC") + self.assertEqual(sn_doc.purchase_document_no, se.name) def tearDown(self): frappe.db.rollback() \ No newline at end of file diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index b452e96c5e..1396f19d3f 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -398,7 +398,7 @@ class StockReconciliation(StockController): merge_similar_entries = {} for d in sl_entries: - if not d.serial_no or d.actual_qty < 0: + if not d.serial_no or flt(d.get("actual_qty")) < 0: new_sl_entries.append(d) continue diff --git a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index 6690c6a606..36380b838b 100644 --- a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -32,7 +32,7 @@ class TestStockReconciliation(unittest.TestCase): company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company') # [[qty, valuation_rate, posting_date, # posting_time, expected_stock_value, bin_qty, bin_valuation]] - + input_data = [ [50, 1000, "2012-12-26", "12:00"], [25, 900, "2012-12-26", "12:00"], @@ -86,7 +86,7 @@ class TestStockReconciliation(unittest.TestCase): se1.cancel() def test_get_items(self): - create_warehouse("_Test Warehouse Group 1", + create_warehouse("_Test Warehouse Group 1", {"is_group": 1, "company": "_Test Company", "parent_warehouse": "All Warehouses - _TC"}) create_warehouse("_Test Warehouse Ledger 1", {"is_group": 0, "parent_warehouse": "_Test Warehouse Group 1 - _TC", "company": "_Test Company"}) From adf974810d03b40ad282197bd77c1513b77ef91e Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 16 Apr 2021 21:15:50 +0530 Subject: [PATCH 429/449] fix: equality check instead of assignment in cart --- erpnext/shopping_cart/cart.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py index 8515db3300..56afe95efd 100644 --- a/erpnext/shopping_cart/cart.py +++ b/erpnext/shopping_cart/cart.py @@ -230,12 +230,12 @@ def update_cart_address(address_type, address_name): if address_type.lower() == "billing": quotation.customer_address = address_name quotation.address_display = address_display - quotation.shipping_address_name == quotation.shipping_address_name or address_name + quotation.shipping_address_name = quotation.shipping_address_name or address_name address_doc = next((doc for doc in get_billing_addresses() if doc["name"] == address_name), None) elif address_type.lower() == "shipping": quotation.shipping_address_name = address_name quotation.shipping_address = address_display - quotation.customer_address == quotation.customer_address or address_name + quotation.customer_address = quotation.customer_address or address_name address_doc = next((doc for doc in get_shipping_addresses() if doc["name"] == address_name), None) apply_cart_settings(quotation=quotation) From 67e647232cf289858d1aa3dbea8fe94d5ba746d2 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 16 Apr 2021 21:44:49 +0530 Subject: [PATCH 430/449] ci(semgrep): Add semgrep testing (#24871) Adds semgrep testing in CI. Refer to: - https://github.com/frappe/frappe/pull/12524 - https://github.com/frappe/frappe/pull/12577 --- .github/helper/semgrep_rules/README.md | 38 +++++++++++ .../semgrep_rules/frappe_correctness.py | 28 +++++++++ .../semgrep_rules/frappe_correctness.yml | 56 +++++++++++++++++ .github/helper/semgrep_rules/security.py | 6 ++ .github/helper/semgrep_rules/security.yml | 25 ++++++++ .github/helper/semgrep_rules/translate.js | 37 +++++++++++ .github/helper/semgrep_rules/translate.py | 53 ++++++++++++++++ .github/helper/semgrep_rules/translate.yml | 63 +++++++++++++++++++ .github/helper/semgrep_rules/ux.py | 31 +++++++++ .github/helper/semgrep_rules/ux.yml | 15 +++++ .github/workflows/semgrep.yml | 24 +++++++ 11 files changed, 376 insertions(+) create mode 100644 .github/helper/semgrep_rules/README.md create mode 100644 .github/helper/semgrep_rules/frappe_correctness.py create mode 100644 .github/helper/semgrep_rules/frappe_correctness.yml create mode 100644 .github/helper/semgrep_rules/security.py create mode 100644 .github/helper/semgrep_rules/security.yml create mode 100644 .github/helper/semgrep_rules/translate.js create mode 100644 .github/helper/semgrep_rules/translate.py create mode 100644 .github/helper/semgrep_rules/translate.yml create mode 100644 .github/helper/semgrep_rules/ux.py create mode 100644 .github/helper/semgrep_rules/ux.yml create mode 100644 .github/workflows/semgrep.yml diff --git a/.github/helper/semgrep_rules/README.md b/.github/helper/semgrep_rules/README.md new file mode 100644 index 0000000000..670d8d280f --- /dev/null +++ b/.github/helper/semgrep_rules/README.md @@ -0,0 +1,38 @@ +# Semgrep linting + +## What is semgrep? +Semgrep or "semantic grep" is language agnostic static analysis tool. In simple terms semgrep is syntax-aware `grep`, so unlike regex it doesn't get confused by different ways of writing same thing or whitespaces or code split in multiple lines etc. + +Example: + +To check if a translate function is using f-string or not the regex would be `r"_\(\s*f[\"']"` while equivalent rule in semgrep would be `_(f"...")`. As semgrep knows grammer of language it takes care of unnecessary whitespace, type of quotation marks etc. + +You can read more such examples in `.github/helper/semgrep_rules` directory. + +# Why/when to use this? +We want to maintain quality of contributions, at the same time remembering all the good practices can be pain to deal with while evaluating contributions. Using semgrep if you can translate "best practice" into a rule then it can automate the task for us. + +## Running locally + +Install semgrep using homebrew `brew install semgrep` or pip `pip install semgrep`. + +To run locally use following command: + +`semgrep --config=.github/helper/semgrep_rules [file/folder names]` + +## Testing +semgrep allows testing the tests. Refer to this page: https://semgrep.dev/docs/writing-rules/testing-rules/ + +When writing new rules you should write few positive and few negative cases as shown in the guide and current tests. + +To run current tests: `semgrep --test --test-ignore-todo .github/helper/semgrep_rules` + + +## Reference + +If you are new to Semgrep read following pages to get started on writing/modifying rules: + +- https://semgrep.dev/docs/getting-started/ +- https://semgrep.dev/docs/writing-rules/rule-syntax +- https://semgrep.dev/docs/writing-rules/pattern-examples/ +- https://semgrep.dev/docs/writing-rules/rule-ideas/#common-use-cases diff --git a/.github/helper/semgrep_rules/frappe_correctness.py b/.github/helper/semgrep_rules/frappe_correctness.py new file mode 100644 index 0000000000..4798b927f8 --- /dev/null +++ b/.github/helper/semgrep_rules/frappe_correctness.py @@ -0,0 +1,28 @@ +import frappe +from frappe import _, flt + +from frappe.model.document import Document + + +def on_submit(self): + if self.value_of_goods == 0: + frappe.throw(_('Value of goods cannot be 0')) + # ruleid: frappe-modifying-after-submit + self.status = 'Submitted' + +def on_submit(self): + if flt(self.per_billed) < 100: + self.update_billing_status() + else: + # todook: frappe-modifying-after-submit + self.status = "Completed" + self.db_set("status", "Completed") + +class TestDoc(Document): + pass + + def validate(self): + #ruleid: frappe-modifying-child-tables-while-iterating + for item in self.child_table: + if item.value < 0: + self.remove(item) diff --git a/.github/helper/semgrep_rules/frappe_correctness.yml b/.github/helper/semgrep_rules/frappe_correctness.yml new file mode 100644 index 0000000000..394abbf74d --- /dev/null +++ b/.github/helper/semgrep_rules/frappe_correctness.yml @@ -0,0 +1,56 @@ +# This file specifies rules for correctness according to how frappe doctype data model works. + +rules: +- id: frappe-modifying-after-submit + patterns: + - pattern: self.$ATTR = ... + - pattern-inside: | + def on_submit(self, ...): + ... + message: | + Doctype modified after submission. Please check if modification of self.$ATTR is commited to database. + languages: [python] + severity: ERROR + +- id: frappe-print-function-in-doctypes + pattern: print(...) + message: | + Did you mean to leave this print statement in? Consider using msgprint or logger instead of print statement. + languages: [python] + severity: WARNING + paths: + exclude: + - test_*.py + include: + - "*/**/doctype/*" + +- id: frappe-modifying-child-tables-while-iterating + pattern-either: + - pattern: | + for $ROW in self.$TABLE: + ... + self.remove(...) + - pattern: | + for $ROW in self.$TABLE: + ... + self.append(...) + message: | + Child table being modified while iterating on it. + languages: [python] + severity: ERROR + paths: + include: + - "*/**/doctype/*" + +- id: frappe-same-key-assigned-twice + pattern-either: + - pattern: | + {..., $X: $A, ..., $X: $B, ...} + - pattern: | + dict(..., ($X, $A), ..., ($X, $B), ...) + - pattern: | + _dict(..., ($X, $A), ..., ($X, $B), ...) + message: | + key `$X` is uselessly assigned twice. This could be a potential bug. + languages: [python] + severity: ERROR diff --git a/.github/helper/semgrep_rules/security.py b/.github/helper/semgrep_rules/security.py new file mode 100644 index 0000000000..f477d7c176 --- /dev/null +++ b/.github/helper/semgrep_rules/security.py @@ -0,0 +1,6 @@ +def function_name(input): + # ruleid: frappe-codeinjection-eval + eval(input) + +# ok: frappe-codeinjection-eval +eval("1 + 1") diff --git a/.github/helper/semgrep_rules/security.yml b/.github/helper/semgrep_rules/security.yml new file mode 100644 index 0000000000..5a5098bf50 --- /dev/null +++ b/.github/helper/semgrep_rules/security.yml @@ -0,0 +1,25 @@ +rules: +- id: frappe-codeinjection-eval + patterns: + - pattern-not: eval("...") + - pattern: eval(...) + message: | + Detected the use of eval(). eval() can be dangerous if used to evaluate + dynamic content. Avoid it or use safe_eval(). + languages: [python] + severity: ERROR + +- id: frappe-sqli-format-strings + patterns: + - pattern-inside: | + @frappe.whitelist() + def $FUNC(...): + ... + - pattern-either: + - pattern: frappe.db.sql("..." % ...) + - pattern: frappe.db.sql(f"...", ...) + - pattern: frappe.db.sql("...".format(...), ...) + message: | + Detected use of raw string formatting for SQL queries. This can lead to sql injection vulnerabilities. Refer security guidelines - https://github.com/frappe/erpnext/wiki/Code-Security-Guidelines + languages: [python] + severity: WARNING diff --git a/.github/helper/semgrep_rules/translate.js b/.github/helper/semgrep_rules/translate.js new file mode 100644 index 0000000000..7b92fe2dff --- /dev/null +++ b/.github/helper/semgrep_rules/translate.js @@ -0,0 +1,37 @@ +// ruleid: frappe-translation-empty-string +__("") +// ruleid: frappe-translation-empty-string +__('') + +// ok: frappe-translation-js-formatting +__('Welcome {0}, get started with ERPNext in just a few clicks.', [full_name]); + +// ruleid: frappe-translation-js-formatting +__(`Welcome ${full_name}, get started with ERPNext in just a few clicks.`); + +// ok: frappe-translation-js-formatting +__('This is fine'); + + +// ok: frappe-translation-trailing-spaces +__('This is fine'); + +// ruleid: frappe-translation-trailing-spaces +__(' this is not ok '); +// ruleid: frappe-translation-trailing-spaces +__('this is not ok '); +// ruleid: frappe-translation-trailing-spaces +__(' this is not ok'); + +// ok: frappe-translation-js-splitting +__('You have {0} subscribers in your mailing list.', [subscribers.length]) + +// todoruleid: frappe-translation-js-splitting +__('You have') + subscribers.length + __('subscribers in your mailing list.') + +// ruleid: frappe-translation-js-splitting +__('You have' + 'subscribers in your mailing list.') + +// ruleid: frappe-translation-js-splitting +__('You have {0} subscribers' + + 'in your mailing list', [subscribers.length]) diff --git a/.github/helper/semgrep_rules/translate.py b/.github/helper/semgrep_rules/translate.py new file mode 100644 index 0000000000..bd6cd9126c --- /dev/null +++ b/.github/helper/semgrep_rules/translate.py @@ -0,0 +1,53 @@ +# Examples taken from https://frappeframework.com/docs/user/en/translations +# This file is used for testing the tests. + +from frappe import _ + +full_name = "Jon Doe" +# ok: frappe-translation-python-formatting +_('Welcome {0}, get started with ERPNext in just a few clicks.').format(full_name) + +# ruleid: frappe-translation-python-formatting +_('Welcome %s, get started with ERPNext in just a few clicks.' % full_name) +# ruleid: frappe-translation-python-formatting +_('Welcome %(name)s, get started with ERPNext in just a few clicks.' % {'name': full_name}) + +# ruleid: frappe-translation-python-formatting +_('Welcome {0}, get started with ERPNext in just a few clicks.'.format(full_name)) + + +subscribers = ["Jon", "Doe"] +# ok: frappe-translation-python-formatting +_('You have {0} subscribers in your mailing list.').format(len(subscribers)) + +# ruleid: frappe-translation-python-splitting +_('You have') + len(subscribers) + _('subscribers in your mailing list.') + +# ruleid: frappe-translation-python-splitting +_('You have {0} subscribers \ + in your mailing list').format(len(subscribers)) + +# ok: frappe-translation-python-splitting +_('You have {0} subscribers') \ + + 'in your mailing list' + +# ruleid: frappe-translation-trailing-spaces +msg = _(" You have {0} pending invoice ") +# ruleid: frappe-translation-trailing-spaces +msg = _("You have {0} pending invoice ") +# ruleid: frappe-translation-trailing-spaces +msg = _(" You have {0} pending invoice") + +# ok: frappe-translation-trailing-spaces +msg = ' ' + _("You have {0} pending invoices") + ' ' + +# ruleid: frappe-translation-python-formatting +_(f"can not format like this - {subscribers}") +# ruleid: frappe-translation-python-splitting +_(f"what" + f"this is also not cool") + + +# ruleid: frappe-translation-empty-string +_("") +# ruleid: frappe-translation-empty-string +_('') diff --git a/.github/helper/semgrep_rules/translate.yml b/.github/helper/semgrep_rules/translate.yml new file mode 100644 index 0000000000..3737da5a7e --- /dev/null +++ b/.github/helper/semgrep_rules/translate.yml @@ -0,0 +1,63 @@ +rules: +- id: frappe-translation-empty-string + pattern-either: + - pattern: _("") + - pattern: __("") + message: | + Empty string is useless for translation. + Please refer: https://frappeframework.com/docs/user/en/translations + languages: [python, javascript, json] + severity: ERROR + +- id: frappe-translation-trailing-spaces + pattern-either: + - pattern: _("=~/(^[ \t]+|[ \t]+$)/") + - pattern: __("=~/(^[ \t]+|[ \t]+$)/") + message: | + Trailing or leading whitespace not allowed in translate strings. + Please refer: https://frappeframework.com/docs/user/en/translations + languages: [python, javascript, json] + severity: ERROR + +- id: frappe-translation-python-formatting + pattern-either: + - pattern: _("..." % ...) + - pattern: _("...".format(...)) + - pattern: _(f"...") + message: | + Only positional formatters are allowed and formatting should not be done before translating. + Please refer: https://frappeframework.com/docs/user/en/translations + languages: [python] + severity: ERROR + +- id: frappe-translation-js-formatting + patterns: + - pattern: __(`...`) + - pattern-not: __("...") + message: | + Template strings are not allowed for text formatting. + Please refer: https://frappeframework.com/docs/user/en/translations + languages: [javascript, json] + severity: ERROR + +- id: frappe-translation-python-splitting + pattern-either: + - pattern: _(...) + ... + _(...) + - pattern: _("..." + "...") + - pattern-regex: '_\([^\)]*\\\s*' + message: | + Do not split strings inside translate function. Do not concatenate using translate functions. + Please refer: https://frappeframework.com/docs/user/en/translations + languages: [python] + severity: ERROR + +- id: frappe-translation-js-splitting + pattern-either: + - pattern-regex: '__\([^\)]*[\+\\]\s*' + - pattern: __('...' + '...') + - pattern: __('...') + __('...') + message: | + Do not split strings inside translate function. Do not concatenate using translate functions. + Please refer: https://frappeframework.com/docs/user/en/translations + languages: [javascript, json] + severity: ERROR diff --git a/.github/helper/semgrep_rules/ux.py b/.github/helper/semgrep_rules/ux.py new file mode 100644 index 0000000000..4a74457435 --- /dev/null +++ b/.github/helper/semgrep_rules/ux.py @@ -0,0 +1,31 @@ +import frappe +from frappe import msgprint, throw, _ + + +# ruleid: frappe-missing-translate-function +throw("Error Occured") + +# ruleid: frappe-missing-translate-function +frappe.throw("Error Occured") + +# ruleid: frappe-missing-translate-function +frappe.msgprint("Useful message") + +# ruleid: frappe-missing-translate-function +msgprint("Useful message") + + +# ok: frappe-missing-translate-function +translatedmessage = _("Hello") + +# ok: frappe-missing-translate-function +throw(translatedmessage) + +# ok: frappe-missing-translate-function +msgprint(translatedmessage) + +# ok: frappe-missing-translate-function +msgprint(_("Helpful message")) + +# ok: frappe-missing-translate-function +frappe.throw(_("Error occured")) diff --git a/.github/helper/semgrep_rules/ux.yml b/.github/helper/semgrep_rules/ux.yml new file mode 100644 index 0000000000..ed06a6a80c --- /dev/null +++ b/.github/helper/semgrep_rules/ux.yml @@ -0,0 +1,15 @@ +rules: +- id: frappe-missing-translate-function + pattern-either: + - patterns: + - pattern: frappe.msgprint("...", ...) + - pattern-not: frappe.msgprint(_("..."), ...) + - pattern-not: frappe.msgprint(__("..."), ...) + - patterns: + - pattern: frappe.throw("...", ...) + - pattern-not: frappe.throw(_("..."), ...) + - pattern-not: frappe.throw(__("..."), ...) + message: | + All user facing text must be wrapped in translate function. Please refer to translation documentation. https://frappeframework.com/docs/user/en/guides/basics/translations + languages: [python, javascript, json] + severity: ERROR diff --git a/.github/workflows/semgrep.yml b/.github/workflows/semgrep.yml new file mode 100644 index 0000000000..df08263236 --- /dev/null +++ b/.github/workflows/semgrep.yml @@ -0,0 +1,24 @@ +name: Semgrep + +on: + pull_request: + branches: + - develop +jobs: + semgrep: + name: Frappe Linter + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup python3 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Run semgrep + run: | + python -m pip install -q semgrep + git fetch origin $GITHUB_BASE_REF:$GITHUB_BASE_REF -q + files=$(git diff --name-only --diff-filter=d $GITHUB_BASE_REF) + [[ -d .github/helper/semgrep_rules ]] && semgrep --severity ERROR --config=.github/helper/semgrep_rules --quiet --error $files + semgrep --config="r/python.lang.correctness" --quiet --error $files + [[ -d .github/helper/semgrep_rules ]] && semgrep --severity WARNING --severity INFO --config=.github/helper/semgrep_rules --quiet $files From d6be154ac27dcc69655213a0770610d81e438327 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 16 Apr 2021 22:08:44 +0530 Subject: [PATCH 431/449] fix: implicit string concatenation (#25371) * fix: implicit string concatenations * chore: rerun healthcare patch for company fields --- .../accounts/doctype/promotional_scheme/promotional_scheme.py | 4 ++-- erpnext/patches.txt | 2 +- .../patches/v13_0/set_company_field_in_healthcare_doctypes.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py b/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py index 523e9ee08a..7d9302382f 100644 --- a/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py +++ b/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py @@ -9,7 +9,7 @@ from frappe.utils import cstr from frappe.model.naming import make_autoname from frappe.model.document import Document -pricing_rule_fields = ['apply_on', 'mixed_conditions', 'is_cumulative', 'other_item_code', 'other_item_group' +pricing_rule_fields = ['apply_on', 'mixed_conditions', 'is_cumulative', 'other_item_code', 'other_item_group', 'apply_rule_on_other', 'other_brand', 'selling', 'buying', 'applicable_for', 'valid_from', 'valid_upto', 'customer', 'customer_group', 'territory', 'sales_partner', 'campaign', 'supplier', 'supplier_group', 'company', 'currency', 'apply_multiple_pricing_rules'] @@ -111,4 +111,4 @@ def get_args_for_pricing_rule(doc): for d in pricing_rule_fields: args[d] = doc.get(d) - return args \ No newline at end of file + return args diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 1f800889c7..112f6d8a83 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -693,7 +693,7 @@ execute:frappe.reload_doctype('Dashboard') execute:frappe.reload_doc('desk', 'doctype', 'number_card_link') execute:frappe.delete_doc_if_exists('Dashboard', 'Accounts') erpnext.patches.v13_0.update_actual_start_and_end_date_in_wo -erpnext.patches.v13_0.set_company_field_in_healthcare_doctypes #2020-05-25 +erpnext.patches.v13_0.set_company_field_in_healthcare_doctypes #2021-04-16 erpnext.patches.v12_0.update_bom_in_so_mr execute:frappe.delete_doc("Report", "Department Analytics") execute:frappe.rename_doc("Desk Page", "Loan Management", "Loan", force=True) diff --git a/erpnext/patches/v13_0/set_company_field_in_healthcare_doctypes.py b/erpnext/patches/v13_0/set_company_field_in_healthcare_doctypes.py index be5e30f307..a5b93f6307 100644 --- a/erpnext/patches/v13_0/set_company_field_in_healthcare_doctypes.py +++ b/erpnext/patches/v13_0/set_company_field_in_healthcare_doctypes.py @@ -3,7 +3,7 @@ import frappe def execute(): company = frappe.db.get_single_value('Global Defaults', 'default_company') - doctypes = ['Clinical Procedure', 'Inpatient Record', 'Lab Test', 'Sample Collection' 'Patient Appointment', 'Patient Encounter', 'Vital Signs', 'Therapy Session', 'Therapy Plan', 'Patient Assessment'] + doctypes = ['Clinical Procedure', 'Inpatient Record', 'Lab Test', 'Sample Collection', 'Patient Appointment', 'Patient Encounter', 'Vital Signs', 'Therapy Session', 'Therapy Plan', 'Patient Assessment'] for entry in doctypes: if frappe.db.exists('DocType', entry): frappe.reload_doc('Healthcare', 'doctype', entry) From 18c7815a1b313c10cedf4135b51ecaeaa5c76bb7 Mon Sep 17 00:00:00 2001 From: Saqib Date: Sat, 17 Apr 2021 15:37:40 +0530 Subject: [PATCH 432/449] fix: presentation currency in statement of accounts (#25367) --- .../process_statement_of_accounts.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html index e1ddeff61f..94ae79a0c6 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html +++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html @@ -38,22 +38,22 @@ {% endif %} - {{ frappe.utils.fmt_money(row.debit, filters.presentation_currency) }} + {{ frappe.utils.fmt_money(row.debit, currency=filters.presentation_currency) }} - {{ frappe.utils.fmt_money(row.credit, filters.presentation_currency) }} + {{ frappe.utils.fmt_money(row.credit, currency=filters.presentation_currency) }} {% else %} {{ frappe.format(row.account, {fieldtype: "Link"}) or " " }} - {{ row.account and frappe.utils.fmt_money(row.debit, filters.presentation_currency) }} + {{ row.account and frappe.utils.fmt_money(row.debit, currency=filters.presentation_currency) }} - {{ row.account and frappe.utils.fmt_money(row.credit, filters.presentation_currency) }} + {{ row.account and frappe.utils.fmt_money(row.credit, currency=filters.presentation_currency) }} {% endif %} - {{ frappe.utils.fmt_money(row.balance, filters.presentation_currency) }} + {{ frappe.utils.fmt_money(row.balance, currency=filters.presentation_currency) }} {% endfor %} From 75e13f7bb662d903dca2a4038ed489333604e34c Mon Sep 17 00:00:00 2001 From: Saqib Date: Sat, 17 Apr 2021 15:38:47 +0530 Subject: [PATCH 433/449] fix(e-invoicing): add company validation for e-invoicing (#25348) Co-authored-by: Nabin Hait --- .../doctype/sales_invoice/test_sales_invoice.py | 15 +++++++++++++-- erpnext/regional/india/e_invoice/utils.py | 7 ++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 4a6f9d1d6a..9059d0b040 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -1879,7 +1879,17 @@ class TestSalesInvoice(unittest.TestCase): def test_einvoice_submission_without_irn(self): # init - frappe.db.set_value('E Invoice Settings', 'E Invoice Settings', 'enable', 1) + einvoice_settings = frappe.get_doc('E Invoice Settings') + einvoice_settings.enable = 1 + einvoice_settings.applicable_from = nowdate() + einvoice_settings.append('credentials', { + 'company': '_Test Company', + 'gstin': '27AAECE4835E1ZR', + 'username': 'test', + 'password': 'test' + }) + einvoice_settings.save() + country = frappe.flags.country frappe.flags.country = 'India' @@ -1890,7 +1900,8 @@ class TestSalesInvoice(unittest.TestCase): si.submit() # reset - frappe.db.set_value('E Invoice Settings', 'E Invoice Settings', 'enable', 0) + einvoice_settings = frappe.get_doc('E Invoice Settings') + einvoice_settings.enable = 0 frappe.flags.country = country def test_einvoice_json(self): diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 59c098c1ca..1d3cb661dd 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -38,12 +38,13 @@ def validate_eligibility(doc): einvoicing_eligible_from = frappe.db.get_single_value('E Invoice Settings', 'applicable_from') or '2021-04-01' if getdate(doc.get('posting_date')) < getdate(einvoicing_eligible_from): return False - + + invalid_company = not frappe.db.get_value('E Invoice User', { 'company': doc.get('company') }) invalid_supply_type = doc.get('gst_category') not in ['Registered Regular', 'SEZ', 'Overseas', 'Deemed Export'] company_transaction = doc.get('billing_address_gstin') == doc.get('company_gstin') no_taxes_applied = not doc.get('taxes') - if invalid_supply_type or company_transaction or no_taxes_applied: + if invalid_company or invalid_supply_type or company_transaction or no_taxes_applied: return False return True @@ -400,7 +401,7 @@ def validate_totals(einvoice): if abs(flt(value_details['AssVal']) - total_item_ass_value) > 1: frappe.throw(_('Total Taxable Value of the items is not equal to the Invoice Net Total. Please check item taxes / discounts for any correction.')) - if abs(flt(value_details['TotInvVal']) + flt(value_details['Discount']) - total_item_value) > 1: + if abs(flt(value_details['TotInvVal']) + flt(value_details['Discount']) - flt(value_details['OthChrg']) - total_item_value) > 1: frappe.throw(_('Total Value of the items is not equal to the Invoice Grand Total. Please check item taxes / discounts for any correction.')) calculated_invoice_value = \ From dedf2c1b61a8f31fb8da831e2c2a96611bacaa35 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sat, 17 Apr 2021 14:57:57 +0530 Subject: [PATCH 434/449] fix: remove duplicate keys from dictionaries --- erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 1 - erpnext/controllers/stock_controller.py | 1 - erpnext/manufacturing/dashboard_fixtures.py | 4 +--- .../manufacturing/doctype/production_plan/production_plan.py | 1 - erpnext/regional/report/gstr_1/gstr_1.py | 2 +- erpnext/stock/get_item_details.py | 2 -- erpnext/utilities/activation.py | 1 - 7 files changed, 2 insertions(+), 10 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 3c91dccaa7..a731e79574 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -46,7 +46,6 @@ class SalesInvoice(SellingController): 'target_parent_dt': 'Sales Order', 'target_parent_field': 'per_billed', 'source_field': 'amount', - 'join_field': 'so_detail', 'percent_join_field': 'sales_order', 'status_field': 'billing_status', 'keyword': 'Billed', diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 20499579ca..34f7b27e00 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -117,7 +117,6 @@ class StockController(AccountsController): "account": expense_account, "against": warehouse_account[sle.warehouse]["account"], "cost_center": item_row.cost_center, - "project": item_row.project or self.get('project'), "remarks": self.get("remarks") or "Accounting Entry for Stock", "credit": flt(sle.stock_value_difference, precision), "project": item_row.get("project") or self.get("project"), diff --git a/erpnext/manufacturing/dashboard_fixtures.py b/erpnext/manufacturing/dashboard_fixtures.py index 0e9a21c026..7ba43d6471 100644 --- a/erpnext/manufacturing/dashboard_fixtures.py +++ b/erpnext/manufacturing/dashboard_fixtures.py @@ -43,7 +43,6 @@ def get_charts(): return [{ "doctype": "Dashboard Chart", "based_on": "modified", - "time_interval": "Yearly", "chart_type": "Sum", "chart_name": _("Produced Quantity"), "name": "Produced Quantity", @@ -60,7 +59,6 @@ def get_charts(): }, { "doctype": "Dashboard Chart", "based_on": "creation", - "time_interval": "Yearly", "chart_type": "Sum", "chart_name": _("Completed Operation"), "name": "Completed Operation", @@ -238,4 +236,4 @@ def get_number_cards(): "label": _("Monthly Quality Inspections"), "show_percentage_stats": 1, "stats_time_interval": "Weekly" - }] \ No newline at end of file + }] diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index cef2d8be7a..e7c83ac050 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -561,7 +561,6 @@ def get_material_request_items(row, sales_order, company, 'item_name': row.item_name, 'quantity': required_qty, 'required_bom_qty': total_qty, - 'description': row.description, 'stock_uom': row.get("stock_uom"), 'warehouse': warehouse or row.get('source_warehouse') \ or row.get('default_warehouse') or item_group_defaults.get("default_warehouse"), diff --git a/erpnext/regional/report/gstr_1/gstr_1.py b/erpnext/regional/report/gstr_1/gstr_1.py index 75076231c0..b637fb47b3 100644 --- a/erpnext/regional/report/gstr_1/gstr_1.py +++ b/erpnext/regional/report/gstr_1/gstr_1.py @@ -561,7 +561,7 @@ def get_json(filters, report_name, data): fp = "%02d%s" % (getdate(filters["to_date"]).month, getdate(filters["to_date"]).year) - gst_json = {"gstin": "", "version": "GST2.2.9", + gst_json = {"version": "GST2.2.9", "hash": "hash", "gstin": gstin, "fp": fp} res = {} diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index aaf14a535e..dedfe1d79b 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -309,8 +309,6 @@ def get_basic_details(args, item, overwrite_warehouse=True): "update_stock": args.get("update_stock") if args.get('doctype') in ['Sales Invoice', 'Purchase Invoice'] else 0, "delivered_by_supplier": item.delivered_by_supplier if args.get("doctype") in ["Sales Order", "Sales Invoice"] else 0, "is_fixed_asset": item.is_fixed_asset, - "weight_per_unit":item.weight_per_unit, - "weight_uom":item.weight_uom, "last_purchase_rate": item.last_purchase_rate if args.get("doctype") in ["Purchase Order"] else 0, "transaction_date": args.get("transaction_date"), "against_blanket_order": args.get("against_blanket_order"), diff --git a/erpnext/utilities/activation.py b/erpnext/utilities/activation.py index 7b17c8c464..50c4b255ce 100644 --- a/erpnext/utilities/activation.py +++ b/erpnext/utilities/activation.py @@ -18,7 +18,6 @@ def get_level(): "Delivery Note": 5, "Employee": 3, "Instructor": 5, - "Instructor": 5, "Issue": 5, "Item": 5, "Journal Entry": 3, From ad6a2657aee99b2d56afba99eca55bb09ef4f3d9 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sat, 17 Apr 2021 16:50:02 +0530 Subject: [PATCH 435/449] chore: minor translation fixes --- erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 6 +++--- erpnext/controllers/stock_controller.py | 2 +- .../doctype/production_plan/production_plan.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index a731e79574..4461f29fe3 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -275,7 +275,7 @@ class SalesInvoice(SellingController): pluck="pos_closing_entry" ) if pos_closing_entry: - msg = _("To cancel a {} you need to cancel the POS Closing Entry {}. ").format( + msg = _("To cancel a {} you need to cancel the POS Closing Entry {}.").format( frappe.bold("Consolidated Sales Invoice"), get_link_to_form("POS Closing Entry", pos_closing_entry[0]) ) @@ -548,12 +548,12 @@ class SalesInvoice(SellingController): frappe.throw(_("Debit To is required"), title=_("Account Missing")) if account.report_type != "Balance Sheet": - msg = _("Please ensure {} account is a Balance Sheet account. ").format(frappe.bold("Debit To")) + msg = _("Please ensure {} account is a Balance Sheet account.").format(frappe.bold("Debit To")) + " " msg += _("You can change the parent account to a Balance Sheet account or select a different account.") frappe.throw(msg, title=_("Invalid Account")) if self.customer and account.account_type != "Receivable": - msg = _("Please ensure {} account is a Receivable account. ").format(frappe.bold("Debit To")) + msg = _("Please ensure {} account is a Receivable account.").format(frappe.bold("Debit To")) + " " msg += _("Change the account type to Receivable or select a different account.") frappe.throw(msg, title=_("Invalid Account")) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 34f7b27e00..b14c274515 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -482,7 +482,7 @@ class StockController(AccountsController): ) message += "

    " rule_link = frappe.utils.get_link_to_form("Putaway Rule", rule) - message += _(" Please adjust the qty or edit {0} to proceed.").format(rule_link) + message += _("Please adjust the qty or edit {0} to proceed.").format(rule_link) return message def repost_future_sle_and_gle(self): diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index e7c83ac050..a3e23a6897 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -765,7 +765,7 @@ def get_items_for_material_requests(doc, warehouses=None): to_enable = frappe.bold(_("Ignore Existing Projected Quantity")) warehouse = frappe.bold(doc.get('for_warehouse')) message = _("As there are sufficient raw materials, Material Request is not required for Warehouse {0}.").format(warehouse) + "

    " - message += _(" If you still want to proceed, please enable {0}.").format(to_enable) + message += _("If you still want to proceed, please enable {0}.").format(to_enable) frappe.msgprint(message, title=_("Note")) From 9229ee1745d864656ddee0b216a33078b7a932c6 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sat, 17 Apr 2021 15:41:10 +0530 Subject: [PATCH 436/449] fix: update shipment status in database Caught by semgrep rule: https://github.com/frappe/erpnext/blob/develop/.github/helper/semgrep_rules/frappe_correctness.yml#L4 --- erpnext/stock/doctype/shipment/shipment.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/shipment/shipment.py b/erpnext/stock/doctype/shipment/shipment.py index 4697a7b323..01fcee4cac 100644 --- a/erpnext/stock/doctype/shipment/shipment.py +++ b/erpnext/stock/doctype/shipment/shipment.py @@ -23,10 +23,10 @@ class Shipment(Document): frappe.throw(_('Please enter Shipment Parcel information')) if self.value_of_goods == 0: frappe.throw(_('Value of goods cannot be 0')) - self.status = 'Submitted' + self.db_set('status', 'Submitted') def on_cancel(self): - self.status = 'Cancelled' + self.db_set('status', 'Cancelled') def validate_weight(self): for parcel in self.shipment_parcel: From e972ceb79840783f3947a1856551d477154ec4be Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sat, 17 Apr 2021 15:42:03 +0530 Subject: [PATCH 437/449] fix: patch for updating shipment status --- erpnext/patches.txt | 1 + erpnext/patches/v13_0/update_shipment_status.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 erpnext/patches/v13_0/update_shipment_status.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 112f6d8a83..620cc5be62 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -772,3 +772,4 @@ erpnext.patches.v12_0.purchase_receipt_status erpnext.patches.v13_0.fix_non_unique_represents_company erpnext.patches.v12_0.add_document_type_field_for_italy_einvoicing erpnext.patches.v13_0.make_non_standard_user_type #13-04-2021 +erpnext.patches.v13_0.update_shipment_status diff --git a/erpnext/patches/v13_0/update_shipment_status.py b/erpnext/patches/v13_0/update_shipment_status.py new file mode 100644 index 0000000000..c425599e26 --- /dev/null +++ b/erpnext/patches/v13_0/update_shipment_status.py @@ -0,0 +1,14 @@ +import frappe + +def execute(): + frappe.reload_doc("stock", "doctype", "shipment") + + # update submitted status + frappe.db.sql("""UPDATE `tabShipment` + SET status = "Submitted" + WHERE status = "Draft" AND docstatus = 1""") + + # update cancelled status + frappe.db.sql("""UPDATE `tabShipment` + SET status = "Cancelled" + WHERE status = "Draft" AND docstatus = 2""") From c28fcba77964edb57609fee17b0470638596e5a3 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sat, 17 Apr 2021 15:47:34 +0530 Subject: [PATCH 438/449] ci(semgrep): add correctness rule for on_cancel Changes done to doctype object in `on_submit` are not commited to database. Add rule to catch similar bugs. --- .../semgrep_rules/frappe_correctness.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/helper/semgrep_rules/frappe_correctness.yml b/.github/helper/semgrep_rules/frappe_correctness.yml index 394abbf74d..54df062480 100644 --- a/.github/helper/semgrep_rules/frappe_correctness.yml +++ b/.github/helper/semgrep_rules/frappe_correctness.yml @@ -7,11 +7,29 @@ rules: - pattern-inside: | def on_submit(self, ...): ... + - metavariable-regex: + metavariable: '$ATTR' + # this is negative look-ahead, add more attrs to ignore like (ignore|ignore_this_too|ignore_me) + regex: '^(?!status_updater)(.*)$' message: | Doctype modified after submission. Please check if modification of self.$ATTR is commited to database. languages: [python] severity: ERROR +- id: frappe-modifying-after-cancel + patterns: + - pattern: self.$ATTR = ... + - pattern-inside: | + def on_cancel(self, ...): + ... + - metavariable-regex: + metavariable: '$ATTR' + regex: '^(?!ignore_linked_doctypes|status_updater)(.*)$' + message: | + Doctype modified after cancellation. Please check if modification of self.$ATTR is commited to database. + languages: [python] + severity: ERROR + - id: frappe-print-function-in-doctypes pattern: print(...) message: | From 80d44cada4248946ed6e0cc8e61b09d2612b1547 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Sun, 18 Apr 2021 18:33:34 +0200 Subject: [PATCH 439/449] fix: remove is_default from country wise tax --- erpnext/setup/setup_wizard/data/country_wise_tax.json | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/erpnext/setup/setup_wizard/data/country_wise_tax.json b/erpnext/setup/setup_wizard/data/country_wise_tax.json index 6305442ef2..5876488033 100644 --- a/erpnext/setup/setup_wizard/data/country_wise_tax.json +++ b/erpnext/setup/setup_wizard/data/country_wise_tax.json @@ -486,7 +486,6 @@ "sales_tax_templates": [ { "title": "Umsatzsteuer 19%", - "is_default": 1, "taxes": [ { "account_head": { @@ -513,7 +512,6 @@ "purchase_tax_templates": [ { "title": "Abziehbare Vorsteuer 19%", - "is_default": 1, "taxes": [ { "account_head": { @@ -567,7 +565,6 @@ "sales_tax_templates": [ { "title": "Umsatzsteuer 19%", - "is_default": 1, "taxes": [ { "account_head": { @@ -594,7 +591,6 @@ "purchase_tax_templates": [ { "title": "Abziehbare Vorsteuer 19%", - "is_default": 1, "taxes": [ { "account_head": { @@ -625,7 +621,6 @@ "sales_tax_templates": [ { "title": "Umsatzsteuer 19%", - "is_default": 1, "taxes": [ { "account_head": { @@ -652,7 +647,6 @@ "purchase_tax_templates": [ { "title": "Abziehbare Vorsteuer 19%", - "is_default": 1, "taxes": [ { "account_head": { @@ -683,7 +677,6 @@ "sales_tax_templates": [ { "title": "Umsatzsteuer 19%", - "is_default": 1, "taxes": [ { "account_head": { @@ -708,7 +701,6 @@ "purchase_tax_templates": [ { "title": "Abziehbare Vorsteuer 19%", - "is_default": 1, "taxes": [ { "account_head": { @@ -829,7 +821,6 @@ "item_tax_templates": [ { "title": "In State GST", - "is_default": 1, "taxes": [ { "tax_type": { @@ -893,7 +884,6 @@ "*": [ { "title": "In State GST", - "is_default": 1, "taxes": [ { "account_head": { From e78253152916ef8a16a467445d670dcd03bd6c83 Mon Sep 17 00:00:00 2001 From: Saqib Date: Mon, 19 Apr 2021 10:15:51 +0530 Subject: [PATCH 440/449] fix: Apply single transaction threshold on net_total instead of supplier credit amount (#25243) * fix: Apply single transaction threshold on net_total instead of supplier credit amount * fix: Apply single transaction threshold on net_total instead of supplier credit amount * fix: test Co-authored-by: Nabin Hait --- .../tax_withholding_category.py | 2 +- .../test_tax_withholding_category.py | 44 ------------------- 2 files changed, 1 insertion(+), 45 deletions(-) diff --git a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py index 961bdb147f..09db7fee2b 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py @@ -251,7 +251,7 @@ def get_tds_amount(ldc, parties, inv, tax_details, fiscal_year_details, tax_dedu threshold = tax_details.get('threshold', 0) cumulative_threshold = tax_details.get('cumulative_threshold', 0) - if ((threshold and supp_credit_amt >= threshold) or (cumulative_threshold and supp_credit_amt >= cumulative_threshold)): + if ((threshold and inv.net_total >= threshold) or (cumulative_threshold and supp_credit_amt >= cumulative_threshold)): if ldc and is_valid_certificate( ldc.valid_from, ldc.valid_upto, inv.posting_date, tax_deducted, diff --git a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py index dd3b49aa04..0cea7612dd 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py @@ -87,50 +87,6 @@ class TestTaxWithholdingCategory(unittest.TestCase): for d in invoices: d.cancel() - def test_single_threshold_tds_with_previous_vouchers(self): - invoices = [] - frappe.db.set_value("Supplier", "Test TDS Supplier2", "tax_withholding_category", "Single Threshold TDS") - pi = create_purchase_invoice(supplier="Test TDS Supplier2") - pi.submit() - invoices.append(pi) - - pi = create_purchase_invoice(supplier="Test TDS Supplier2") - pi.submit() - invoices.append(pi) - - self.assertEqual(pi.taxes_and_charges_deducted, 2000) - self.assertEqual(pi.grand_total, 8000) - - # delete invoices to avoid clashing - for d in invoices: - d.cancel() - - def test_single_threshold_tds_with_previous_vouchers_and_no_tds(self): - invoices = [] - doc = create_supplier(supplier_name = "Test TDS Supplier ABC", - tax_withholding_category="Single Threshold TDS") - supplier = doc.name - - pi = create_purchase_invoice(supplier=supplier) - pi.submit() - invoices.append(pi) - - # TDS not applied - pi = create_purchase_invoice(supplier=supplier, do_not_apply_tds=True) - pi.submit() - invoices.append(pi) - - pi = create_purchase_invoice(supplier=supplier) - pi.submit() - invoices.append(pi) - - self.assertEqual(pi.taxes_and_charges_deducted, 2000) - self.assertEqual(pi.grand_total, 8000) - - # delete invoices to avoid clashing - for d in invoices: - d.cancel() - def test_cumulative_threshold_tcs(self): frappe.db.set_value("Customer", "Test TCS Customer", "tax_withholding_category", "Cumulative Threshold TCS") invoices = [] From 7eac4a250d1d156859f9c0d18a0f45c8bcc5215d Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 19 Apr 2021 10:33:39 +0530 Subject: [PATCH 441/449] fix: functions using mutable defaults (#25370) --- erpnext/controllers/queries.py | 4 +++- erpnext/controllers/status_updater.py | 4 +++- .../doctype/bom_update_tool/bom_update_tool.py | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index c0c13153de..bc1ac5ea06 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -713,7 +713,9 @@ def get_tax_template(doctype, txt, searchfield, start, page_len, filters): return [(d,) for d in set(taxes)] -def get_fields(doctype, fields=[]): +def get_fields(doctype, fields=None): + if fields is None: + fields = [] meta = frappe.get_meta(doctype) fields.extend(meta.get_search_fields()) diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py index 0987d0985e..cdb6d244a6 100644 --- a/erpnext/controllers/status_updater.py +++ b/erpnext/controllers/status_updater.py @@ -371,10 +371,12 @@ class StatusUpdater(Document): ref_doc.db_set("per_billed", per_billed) ref_doc.set_status(update=True) -def get_allowance_for(item_code, item_allowance={}, global_qty_allowance=None, global_amount_allowance=None, qty_or_amount="qty"): +def get_allowance_for(item_code, item_allowance=None, global_qty_allowance=None, global_amount_allowance=None, qty_or_amount="qty"): """ Returns the allowance for the item, if not set, returns global allowance """ + if item_allowance is None: + item_allowance = {} if qty_or_amount == "qty": if item_allowance.get(item_code, frappe._dict()).get("qty"): return item_allowance[item_code].qty, item_allowance, global_qty_allowance, global_amount_allowance diff --git a/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py b/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py index 742d18c4cd..8fbcd4ea1d 100644 --- a/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py +++ b/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py @@ -53,7 +53,9 @@ class BOMUpdateTool(Document): rate=%s, amount=stock_qty*%s where bom_no = %s and docstatus < 2 and parenttype='BOM'""", (self.new_bom, unit_cost, unit_cost, self.current_bom)) - def get_parent_boms(self, bom, bom_list=[]): + def get_parent_boms(self, bom, bom_list=None): + if bom_list is None: + bom_list = [] data = frappe.db.sql("""SELECT DISTINCT parent FROM `tabBOM Item` WHERE bom_no = %s AND docstatus < 2 AND parenttype='BOM'""", bom) @@ -106,4 +108,4 @@ def update_cost(): for bom in bom_list: frappe.get_doc("BOM", bom).update_cost(update_parent=False, from_child_bom=True) - frappe.db.auto_commit_on_many_writes = 0 \ No newline at end of file + frappe.db.auto_commit_on_many_writes = 0 From dcdd3bebbe3db01ee2987843d4bd4ca72cd913e5 Mon Sep 17 00:00:00 2001 From: Jannat Patel <31363128+pateljannat@users.noreply.github.com> Date: Mon, 19 Apr 2021 10:36:40 +0530 Subject: [PATCH 442/449] feat: Timer in LMS Quiz (#24246) * feat: new fields in quiz doctypes * feat: timer in lms quiz * fix: variable initialisation * fix: context, exception fix * fix:sider * fix:sider * fix: indentation * fix: timer * fix: sider * fix: return value and format * fix: show time taken only after all attempts are over * fix: sider Co-authored-by: pateljannat Co-authored-by: Marica --- .../course_enrollment/course_enrollment.py | 5 +- erpnext/education/doctype/quiz/quiz.json | 25 +- .../doctype/quiz_activity/quiz_activity.json | 423 ++---------------- erpnext/education/doctype/student/student.py | 2 +- erpnext/education/utils.py | 33 +- erpnext/public/js/education/lms/quiz.js | 72 ++- erpnext/www/lms/content.html | 55 ++- erpnext/www/lms/index.html | 12 +- erpnext/www/lms/topic.py | 2 +- 9 files changed, 218 insertions(+), 411 deletions(-) diff --git a/erpnext/education/doctype/course_enrollment/course_enrollment.py b/erpnext/education/doctype/course_enrollment/course_enrollment.py index f7aa6e9fc1..2b3acf1b93 100644 --- a/erpnext/education/doctype/course_enrollment/course_enrollment.py +++ b/erpnext/education/doctype/course_enrollment/course_enrollment.py @@ -41,7 +41,7 @@ class CourseEnrollment(Document): frappe.throw(_("Student is already enrolled via Course Enrollment {0}").format( get_link_to_form("Course Enrollment", enrollment)), title=_('Duplicate Entry')) - def add_quiz_activity(self, quiz_name, quiz_response, answers, score, status): + def add_quiz_activity(self, quiz_name, quiz_response, answers, score, status, time_taken): result = {k: ('Correct' if v else 'Wrong') for k,v in answers.items()} result_data = [] for key in answers: @@ -66,7 +66,8 @@ class CourseEnrollment(Document): "activity_date": frappe.utils.datetime.datetime.now(), "result": result_data, "score": score, - "status": status + "status": status, + "time_taken": time_taken }).insert(ignore_permissions = True) def add_activity(self, content_type, content): diff --git a/erpnext/education/doctype/quiz/quiz.json b/erpnext/education/doctype/quiz/quiz.json index 569c281f4c..16d7d7e4bf 100644 --- a/erpnext/education/doctype/quiz/quiz.json +++ b/erpnext/education/doctype/quiz/quiz.json @@ -1,4 +1,5 @@ { + "actions": [], "allow_import": 1, "allow_rename": 1, "autoname": "field:title", @@ -12,7 +13,10 @@ "quiz_configuration_section", "passing_score", "max_attempts", - "grading_basis" + "grading_basis", + "column_break_7", + "is_time_bound", + "duration" ], "fields": [ { @@ -58,9 +62,26 @@ "fieldtype": "Select", "label": "Grading Basis", "options": "Latest Highest Score\nLatest Attempt" + }, + { + "default": "0", + "fieldname": "is_time_bound", + "fieldtype": "Check", + "label": "Is Time-Bound" + }, + { + "depends_on": "is_time_bound", + "fieldname": "duration", + "fieldtype": "Duration", + "label": "Duration" + }, + { + "fieldname": "column_break_7", + "fieldtype": "Column Break" } ], - "modified": "2019-06-12 12:23:57.020508", + "links": [], + "modified": "2020-12-24 15:41:35.043262", "modified_by": "Administrator", "module": "Education", "name": "Quiz", diff --git a/erpnext/education/doctype/quiz_activity/quiz_activity.json b/erpnext/education/doctype/quiz_activity/quiz_activity.json index e78db42f7d..742c88754a 100644 --- a/erpnext/education/doctype/quiz_activity/quiz_activity.json +++ b/erpnext/education/doctype/quiz_activity/quiz_activity.json @@ -1,490 +1,163 @@ { - "allow_copy": 0, - "allow_events_in_timeline": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, + "actions": [], "autoname": "format:EDU-QA-{YYYY}-{#####}", "beta": 1, "creation": "2018-10-15 15:48:40.482821", - "custom": 0, - "docstatus": 0, "doctype": "DocType", - "document_type": "", "editable_grid": 1, "engine": "InnoDB", + "field_order": [ + "enrollment", + "student", + "column_break_3", + "course", + "section_break_5", + "quiz", + "column_break_7", + "status", + "section_break_9", + "result", + "section_break_11", + "activity_date", + "score", + "column_break_14", + "time_taken" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "enrollment", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Enrollment", - "length": 0, - "no_copy": 0, "options": "Course Enrollment", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 1, - "translatable": 0, - "unique": 0 + "set_only_once": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fetch_from": "enrollment.student", "fieldname": "student", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, "label": "Student", - "length": 0, - "no_copy": 0, "options": "Student", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "read_only": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "column_break_3", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Column Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fetch_from": "enrollment.course", "fieldname": "course", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Course", - "length": 0, - "no_copy": 0, "options": "Course", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 1, - "translatable": 0, - "unique": 0 + "set_only_once": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "section_break_5", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Section Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "quiz", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, "label": "Quiz", - "length": 0, - "no_copy": 0, "options": "Quiz", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 1, - "translatable": 0, - "unique": 0 + "set_only_once": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "column_break_7", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Column Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "status", "fieldtype": "Select", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Status", - "length": 0, - "no_copy": 0, "options": "\nPass\nFail", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "read_only": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "section_break_9", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Section Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "result", "fieldtype": "Table", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Result", - "length": 0, - "no_copy": 0, "options": "Quiz Result", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 1, - "translatable": 0, - "unique": 0 + "set_only_once": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "activity_date", "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Activity Date", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 1, - "translatable": 0, - "unique": 0 + "set_only_once": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "score", "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, "label": "Score", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 1, - "translatable": 0, - "unique": 0 + "set_only_once": 1 + }, + { + "fieldname": "time_taken", + "fieldtype": "Duration", + "label": "Time Taken", + "set_only_once": 1 + }, + { + "fieldname": "section_break_11", + "fieldtype": "Section Break" + }, + { + "fieldname": "column_break_14", + "fieldtype": "Column Break" } ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 0, - "max_attachments": 0, - "modified": "2018-11-25 19:05:52.434437", + "links": [], + "modified": "2020-12-24 15:41:20.085380", "modified_by": "Administrator", "module": "Education", "name": "Quiz Activity", - "name_case": "", "owner": "Administrator", "permissions": [ { - "amend": 0, - "cancel": 0, "create": 1, "delete": 1, "email": 1, "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, "print": 1, "read": 1, "report": 1, "role": "Academics User", - "set_user_permissions": 0, "share": 1, - "submit": 0, "write": 1 }, { - "amend": 0, - "cancel": 0, "create": 1, "delete": 1, "email": 1, "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, "print": 1, "read": 1, "report": 1, "role": "LMS User", - "set_user_permissions": 0, "share": 1, - "submit": 0, "write": 1 }, { - "amend": 0, - "cancel": 0, - "create": 0, - "delete": 0, "email": 1, "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, "print": 1, "read": 1, "report": 1, "role": "Instructor", - "set_user_permissions": 0, - "share": 1, - "submit": 0, - "write": 0 + "share": 1 } ], "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, "sort_field": "modified", "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0, - "track_views": 0 + "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/education/doctype/student/student.py b/erpnext/education/doctype/student/student.py index 81626f1918..2dc0f634f0 100644 --- a/erpnext/education/doctype/student/student.py +++ b/erpnext/education/doctype/student/student.py @@ -114,7 +114,7 @@ class Student(Document): status = check_content_completion(content.name, content.doctype, course_enrollment_name) progress.append({'content': content.name, 'content_type': content.doctype, 'is_complete': status}) elif content.doctype == 'Quiz': - status, score, result = check_quiz_completion(content, course_enrollment_name) + status, score, result, time_taken = check_quiz_completion(content, course_enrollment_name) progress.append({'content': content.name, 'content_type': content.doctype, 'is_complete': status, 'score': score, 'result': result}) return progress diff --git a/erpnext/education/utils.py b/erpnext/education/utils.py index cffc3960a0..8f51fef847 100644 --- a/erpnext/education/utils.py +++ b/erpnext/education/utils.py @@ -194,7 +194,7 @@ def add_activity(course, content_type, content, program): return enrollment.add_activity(content_type, content) @frappe.whitelist() -def evaluate_quiz(quiz_response, quiz_name, course, program): +def evaluate_quiz(quiz_response, quiz_name, course, program, time_taken): import json student = get_current_student() @@ -209,7 +209,7 @@ def evaluate_quiz(quiz_response, quiz_name, course, program): if student: enrollment = get_or_create_course_enrollment(course, program) if quiz.allowed_attempt(enrollment, quiz_name): - enrollment.add_quiz_activity(quiz_name, quiz_response, result, score, status) + enrollment.add_quiz_activity(quiz_name, quiz_response, result, score, status, time_taken) return {'result': result, 'score': score, 'status': status} else: return None @@ -219,8 +219,9 @@ def get_quiz(quiz_name, course): try: quiz = frappe.get_doc("Quiz", quiz_name) questions = quiz.get_questions() + duration = quiz.duration except: - frappe.throw(_("Quiz {0} does not exist").format(quiz_name)) + frappe.throw(_("Quiz {0} does not exist").format(quiz_name), frappe.DoesNotExistError) return None questions = [{ @@ -232,12 +233,20 @@ def get_quiz(quiz_name, course): } for question in questions] if has_super_access(): - return {'questions': questions, 'activity': None} + return { + 'questions': questions, + 'activity': None, + 'duration':duration + } student = get_current_student() course_enrollment = get_enrollment("course", course, student.name) - status, score, result = check_quiz_completion(quiz, course_enrollment) - return {'questions': questions, 'activity': {'is_complete': status, 'score': score, 'result': result}} + status, score, result, time_taken = check_quiz_completion(quiz, course_enrollment) + return { + 'questions': questions, + 'activity': {'is_complete': status, 'score': score, 'result': result, 'time_taken': time_taken}, + 'duration': quiz.duration + } def get_topic_progress(topic, course_name, program): """ @@ -361,15 +370,23 @@ def check_content_completion(content_name, content_type, enrollment_name): return False def check_quiz_completion(quiz, enrollment_name): - attempts = frappe.get_all("Quiz Activity", filters={'enrollment': enrollment_name, 'quiz': quiz.name}, fields=["name", "activity_date", "score", "status"]) + attempts = frappe.get_all("Quiz Activity", + filters={ + 'enrollment': enrollment_name, + 'quiz': quiz.name + }, + fields=["name", "activity_date", "score", "status", "time_taken"] + ) status = False if quiz.max_attempts == 0 else bool(len(attempts) >= quiz.max_attempts) score = None result = None + time_taken = None if attempts: if quiz.grading_basis == 'Last Highest Score': attempts = sorted(attempts, key = lambda i: int(i.score), reverse=True) score = attempts[0]['score'] result = attempts[0]['status'] + time_taken = attempts[0]['time_taken'] if result == 'Pass': status = True - return status, score, result \ No newline at end of file + return status, score, result, time_taken \ No newline at end of file diff --git a/erpnext/public/js/education/lms/quiz.js b/erpnext/public/js/education/lms/quiz.js index 4a9d1e34e6..32fa4ab1ec 100644 --- a/erpnext/public/js/education/lms/quiz.js +++ b/erpnext/public/js/education/lms/quiz.js @@ -20,6 +20,16 @@ class Quiz { } make(data) { + if (data.duration) { + const timer_display = document.createElement("div"); + timer_display.classList.add("lms-timer", "float-right", "font-weight-bold"); + document.getElementsByClassName("lms-title")[0].appendChild(timer_display); + if (!data.activity || (data.activity && !data.activity.is_complete)) { + this.initialiseTimer(data.duration); + this.is_time_bound = true; + this.time_taken = 0; + } + } data.questions.forEach(question_data => { let question_wrapper = document.createElement('div'); let question = new Question({ @@ -37,12 +47,51 @@ class Quiz { indicator = 'green' message = 'You have already cleared the quiz.' } - + if (data.activity.time_taken) { + this.calculate_and_display_time(data.activity.time_taken, "Time Taken - "); + } this.set_quiz_footer(message, indicator, data.activity.score) } else { this.make_actions(); } + window.addEventListener('beforeunload', (event) => { + event.preventDefault(); + event.returnValue = ''; + }); + } + + initialiseTimer(duration) { + this.time_left = duration; + var self = this; + var old_diff; + this.calculate_and_display_time(this.time_left, "Time Left - "); + this.start_time = new Date().getTime(); + this.timer = setInterval(function () { + var diff = (new Date().getTime() - self.start_time)/1000; + var variation = old_diff ? diff - old_diff : diff; + old_diff = diff; + self.time_left -= variation; + self.time_taken += variation; + self.calculate_and_display_time(self.time_left, "Time Left - "); + if (self.time_left <= 0) { + clearInterval(self.timer); + self.time_taken -= 1; + self.submit(); + } + }, 1000); + } + + calculate_and_display_time(second, text) { + var timer_display = document.getElementsByClassName("lms-timer")[0]; + var hours = this.append_zero(Math.floor(second / 3600)); + var minutes = this.append_zero(Math.floor(second % 3600 / 60)); + var seconds = this.append_zero(Math.ceil(second % 3600 % 60)); + timer_display.innerText = text + hours + ":" + minutes + ":" + seconds; + } + + append_zero(time) { + return time > 9 ? time : "0" + time; } make_actions() { @@ -57,6 +106,10 @@ class Quiz { } submit() { + if (this.is_time_bound) { + clearInterval(this.timer); + $(".lms-timer").text(""); + } this.submit_btn.innerText = 'Evaluating..' this.submit_btn.disabled = true this.disable() @@ -64,7 +117,8 @@ class Quiz { quiz_name: this.name, quiz_response: this.get_selected(), course: this.course, - program: this.program + program: this.program, + time_taken: this.is_time_bound ? this.time_taken : "" }).then(res => { this.submit_btn.remove() if (!res.message) { @@ -157,7 +211,7 @@ class Question { return input; } - let make_label = function(name, value) { + let make_label = function (name, value) { let label = document.createElement('label'); label.classList.add('form-check-label'); label.htmlFor = name; @@ -166,14 +220,14 @@ class Question { } let make_option = function (wrapper, option) { - let option_div = document.createElement('div') - option_div.classList.add('form-check', 'pb-1') + let option_div = document.createElement('div'); + option_div.classList.add('form-check', 'pb-1'); let input = make_input(option.name, option.option); let label = make_label(option.name, option.option); - option_div.appendChild(input) - option_div.appendChild(label) - wrapper.appendChild(option_div) - return {input: input, ...option} + option_div.appendChild(input); + option_div.appendChild(label); + wrapper.appendChild(option_div); + return { input: input, ...option }; } let options_wrapper = document.createElement('div') diff --git a/erpnext/www/lms/content.html b/erpnext/www/lms/content.html index dc9b6d80fb..15afb097b9 100644 --- a/erpnext/www/lms/content.html +++ b/erpnext/www/lms/content.html @@ -62,7 +62,7 @@ {{_('Back to Course')}}
    -
    +

    {{ content.name }} ({{ position + 1 }}/{{length}})

    {% endmacro %} @@ -169,14 +169,51 @@ const next_url = '/lms/course?name={{ course }}&program={{ program }}' {% endif %} frappe.ready(() => { - const quiz = new Quiz(document.getElementById('quiz-wrapper'), { - name: '{{ content.name }}', - course: '{{ course }}', - program: '{{ program }}', - quiz_exit_button: quiz_exit_button, - next_url: next_url - }) - window.quiz = quiz; + {% if content.is_time_bound %} + var duration = get_duration("{{content.duration}}") + var d = frappe.msgprint({ + title: __('Important Notice'), + indicator: "red", + message: __(`This is a Time-Bound Quiz.

    + A timer for ${duration} will start, once you click on Proceed.

    + If you fail to submit before the time is up, the Quiz will be submitted automatically.`), + primary_action: { + label: __("Proceed"), + action: () => { + create_quiz(); + d.hide(); + } + }, + secondary_action: { + action: () => { + d.hide(); + window.location.href = "/lms/course?name={{ course }}&program={{ program }}"; + }, + label: __("Go Back"), + } + }); + {% else %} + create_quiz(); + {% endif %} + function create_quiz() { + const quiz = new Quiz(document.getElementById('quiz-wrapper'), { + name: '{{ content.name }}', + course: '{{ course }}', + program: '{{ program }}', + quiz_exit_button: quiz_exit_button, + next_url: next_url + }) + window.quiz = quiz; + } + function get_duration(seconds){ + var hours = append_zero(Math.floor(seconds / 3600)); + var minutes = append_zero(Math.floor(seconds % 3600 / 60)); + var seconds = append_zero(Math.floor(seconds % 3600 % 60)); + return `${hours}:${minutes}:${seconds}`; + } + function append_zero(time) { + return time > 9 ? time : "0" + time; + } }) {% endif %} diff --git a/erpnext/www/lms/index.html b/erpnext/www/lms/index.html index 7b239acd56..c1e96205eb 100644 --- a/erpnext/www/lms/index.html +++ b/erpnext/www/lms/index.html @@ -42,7 +42,9 @@

    {{ education_settings.portal_title }}

    -

    {{ education_settings.description }}

    + {% if education_settings.description %} +

    {{ education_settings.description }}

    + {% endif %}

    {% if frappe.session.user == 'Guest' %} {{_('Sign Up')}} @@ -51,13 +53,15 @@

    - {% for program in featured_programs %} - {{ program_card(program.program, program.has_access) }} - {% endfor %} {% if featured_programs %} + {% for program in featured_programs %} + {{ program_card(program.program, program.has_access) }} + {% endfor %} {% for n in range( (3 - (featured_programs|length)) %3) %} {{ null_card() }} {% endfor %} + {% else %} +

    You have not enrolled in any program. Contact your Instructor.

    {% endif %}
    diff --git a/erpnext/www/lms/topic.py b/erpnext/www/lms/topic.py index f75ae8e9b6..8abbc72e91 100644 --- a/erpnext/www/lms/topic.py +++ b/erpnext/www/lms/topic.py @@ -35,7 +35,7 @@ def get_contents(topic, course, program): progress.append({'content': content, 'content_type': content.doctype, 'completed': status}) elif content.doctype == 'Quiz': if student: - status, score, result = utils.check_quiz_completion(content, course_enrollment.name) + status, score, result, time_taken = utils.check_quiz_completion(content, course_enrollment.name) else: status = False score = None From e8bc912ffcafeccfd41c8944f6ac053a68d9ac56 Mon Sep 17 00:00:00 2001 From: Marica Date: Mon, 19 Apr 2021 11:05:21 +0530 Subject: [PATCH 443/449] perf: Fetching exchange rate on every line item slows down PO (#25345) * fix: Dont fetch exchange rates for each line item once fetched at parent ` * perf: Use price list conversion rate from parent - If price list conversion rate exists in args already from earlier call, use that - `get_price_list_currency_and_exchange_rate` wont be called for each child row Co-authored-by: Nabin Hait --- erpnext/public/js/controllers/transaction.js | 2 ++ erpnext/stock/get_item_details.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 6c2144d6cb..a0398e718f 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1103,6 +1103,8 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ to_currency: to_currency, args: args }, + freeze: true, + freeze_message: __("Fetching exchange rates ..."), callback: function(r) { callback(flt(r.message)); } diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index dedfe1d79b..1a61f30b9a 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -609,8 +609,12 @@ def get_price_list_rate(args, item_doc, out): meta = frappe.get_meta(args.parenttype or args.doctype) if meta.get_field("currency") or args.get('currency'): - pl_details = get_price_list_currency_and_exchange_rate(args) - args.update(pl_details) + if not args.get("price_list_currency") or not args.get("plc_conversion_rate"): + # if currency and plc_conversion_rate exist then + # `get_price_list_currency_and_exchange_rate` has already been called + pl_details = get_price_list_currency_and_exchange_rate(args) + args.update(pl_details) + if meta.get_field("currency"): validate_conversion_rate(args, meta) @@ -1000,6 +1004,8 @@ def apply_price_list(args, as_doc=False): args = process_args(args) parent = get_price_list_currency_and_exchange_rate(args) + args.update(parent) + children = [] if "items" in args: @@ -1064,7 +1070,7 @@ def get_price_list_currency_and_exchange_rate(args): return frappe._dict({ "price_list_currency": price_list_currency, "price_list_uom_dependant": price_list_uom_dependant, - "plc_conversion_rate": plc_conversion_rate + "plc_conversion_rate": plc_conversion_rate or 1 }) @frappe.whitelist() From 9c9907cf8e26ea65d330f1fec07d01afa2038017 Mon Sep 17 00:00:00 2001 From: Afshan <33727827+AfshanKhan@users.noreply.github.com> Date: Mon, 19 Apr 2021 11:48:28 +0530 Subject: [PATCH 444/449] fix: available employee for selection (#25377) * fix: available employee for selection * fix: available employee for selection fix: available employee for selection --- .../doctype/payroll_entry/payroll_entry.js | 4 + .../doctype/payroll_entry/payroll_entry.py | 153 ++++++++++-------- 2 files changed, 88 insertions(+), 69 deletions(-) diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.js b/erpnext/payroll/doctype/payroll_entry/payroll_entry.js index 85bb651af7..f2892600d1 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.js +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.js @@ -151,6 +151,10 @@ frappe.ui.form.on('Payroll Entry', { filters['company'] = frm.doc.company; filters['start_date'] = frm.doc.start_date; filters['end_date'] = frm.doc.end_date; + filters['salary_slip_based_on_timesheet'] = frm.doc.salary_slip_based_on_timesheet; + filters['payroll_frequency'] = frm.doc.payroll_frequency; + filters['payroll_payable_account'] = frm.doc.payroll_payable_account; + filters['currency'] = frm.doc.currency; if (frm.doc.department) { filters['department'] = frm.doc.department; diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py index 4c9469e277..3953b463f1 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py @@ -52,49 +52,32 @@ class PayrollEntry(Document): Returns list of active employees based on selected criteria and for which salary structure exists """ - cond = self.get_filter_condition() - cond += self.get_joining_relieving_condition() + self.check_mandatory() + filters = self.make_filters() + cond = get_filter_condition(filters) + cond += get_joining_relieving_condition(self.start_date, self.end_date) condition = '' if self.payroll_frequency: condition = """and payroll_frequency = '%(payroll_frequency)s'"""% {"payroll_frequency": self.payroll_frequency} - sal_struct = frappe.db.sql_list(""" - select - name from `tabSalary Structure` - where - docstatus = 1 and - is_active = 'Yes' - and company = %(company)s - and currency = %(currency)s and - ifnull(salary_slip_based_on_timesheet,0) = %(salary_slip_based_on_timesheet)s - {condition}""".format(condition=condition), - {"company": self.company, "currency": self.currency, "salary_slip_based_on_timesheet":self.salary_slip_based_on_timesheet}) - + sal_struct = get_sal_struct(self.company, self.currency, self.salary_slip_based_on_timesheet, condition) if sal_struct: cond += "and t2.salary_structure IN %(sal_struct)s " cond += "and t2.payroll_payable_account = %(payroll_payable_account)s " cond += "and %(from_date)s >= t2.from_date" - emp_list = frappe.db.sql(""" - select - distinct t1.name as employee, t1.employee_name, t1.department, t1.designation - from - `tabEmployee` t1, `tabSalary Structure Assignment` t2 - where - t1.name = t2.employee - and t2.docstatus = 1 - %s order by t2.from_date desc - """ % cond, {"sal_struct": tuple(sal_struct), "from_date": self.end_date, "payroll_payable_account": self.payroll_payable_account}, as_dict=True) - - emp_list = self.remove_payrolled_employees(emp_list) + emp_list = get_emp_list(sal_struct, cond, self.end_date, self.payroll_payable_account) + emp_list = remove_payrolled_employees(emp_list, self.start_date, self.end_date) return emp_list - def remove_payrolled_employees(self, emp_list): - for employee_details in emp_list: - if frappe.db.exists("Salary Slip", {"employee": employee_details.employee, "start_date": self.start_date, "end_date": self.end_date, "docstatus": 1}): - emp_list.remove(employee_details) + def make_filters(self): + filters = frappe._dict() + filters['company'] = self.company + filters['branch'] = self.branch + filters['department'] = self.department + filters['designation'] = self.designation - return emp_list + return filters @frappe.whitelist() def fill_employee_details(self): @@ -122,23 +105,6 @@ class PayrollEntry(Document): if self.validate_attendance: return self.validate_employee_attendance() - def get_filter_condition(self): - self.check_mandatory() - - cond = '' - for f in ['company', 'branch', 'department', 'designation']: - if self.get(f): - cond += " and t1." + f + " = " + frappe.db.escape(self.get(f)) - - return cond - - def get_joining_relieving_condition(self): - cond = """ - and ifnull(t1.date_of_joining, '0000-00-00') <= '%(end_date)s' - and ifnull(t1.relieving_date, '2199-12-31') >= '%(start_date)s' - """ % {"start_date": self.start_date, "end_date": self.end_date} - return cond - def check_mandatory(self): for fieldname in ['company', 'start_date', 'end_date']: if not self.get(fieldname): @@ -451,6 +417,53 @@ class PayrollEntry(Document): marked_days = attendances[0][0] return marked_days +def get_sal_struct(company, currency, salary_slip_based_on_timesheet, condition): + return frappe.db.sql_list(""" + select + name from `tabSalary Structure` + where + docstatus = 1 and + is_active = 'Yes' + and company = %(company)s + and currency = %(currency)s and + ifnull(salary_slip_based_on_timesheet,0) = %(salary_slip_based_on_timesheet)s + {condition}""".format(condition=condition), + {"company": company, "currency": currency, "salary_slip_based_on_timesheet": salary_slip_based_on_timesheet}) + +def get_filter_condition(filters): + cond = '' + for f in ['company', 'branch', 'department', 'designation']: + if filters.get(f): + cond += " and t1." + f + " = " + frappe.db.escape(filters.get(f)) + + return cond + +def get_joining_relieving_condition(start_date, end_date): + cond = """ + and ifnull(t1.date_of_joining, '0000-00-00') <= '%(end_date)s' + and ifnull(t1.relieving_date, '2199-12-31') >= '%(start_date)s' + """ % {"start_date": start_date, "end_date": end_date} + return cond + +def get_emp_list(sal_struct, cond, end_date, payroll_payable_account): + return frappe.db.sql(""" + select + distinct t1.name as employee, t1.employee_name, t1.department, t1.designation + from + `tabEmployee` t1, `tabSalary Structure Assignment` t2 + where + t1.name = t2.employee + and t2.docstatus = 1 + %s order by t2.from_date desc + """ % cond, {"sal_struct": tuple(sal_struct), "from_date": end_date, "payroll_payable_account": payroll_payable_account}, as_dict=True) + +def remove_payrolled_employees(emp_list, start_date, end_date): + for employee_details in emp_list: + if frappe.db.exists("Salary Slip", {"employee": employee_details.employee, "start_date": start_date, "end_date": end_date, "docstatus": 1}): + emp_list.remove(employee_details) + + return emp_list + @frappe.whitelist() def get_start_end_dates(payroll_frequency, start_date=None, company=None): '''Returns dict of start and end dates for given payroll frequency based on start_date''' @@ -639,39 +652,41 @@ def get_payroll_entries_for_jv(doctype, txt, searchfield, start, page_len, filte 'start': start, 'page_len': page_len }) -def get_employee_with_existing_salary_slip(start_date, end_date, company): - return frappe.db.sql_list(""" - select employee from `tabSalary Slip` - where - (start_date between %(start_date)s and %(end_date)s - or - end_date between %(start_date)s and %(end_date)s - or - %(start_date)s between start_date and end_date) - and company = %(company)s - and docstatus = 1 - """, {'start_date': start_date, 'end_date': end_date, 'company': company}) +def get_employee_list(filters): + cond = get_filter_condition(filters) + cond += get_joining_relieving_condition(filters.start_date, filters.end_date) + condition = """and payroll_frequency = '%(payroll_frequency)s'"""% {"payroll_frequency": filters.payroll_frequency} + sal_struct = get_sal_struct(filters.company, filters.currency, filters.salary_slip_based_on_timesheet, condition) + if sal_struct: + cond += "and t2.salary_structure IN %(sal_struct)s " + cond += "and t2.payroll_payable_account = %(payroll_payable_account)s " + cond += "and %(from_date)s >= t2.from_date" + emp_list = get_emp_list(sal_struct, cond, filters.end_date, filters.payroll_payable_account) + emp_list = remove_payrolled_employees(emp_list, filters.start_date, filters.end_date) + return emp_list @frappe.whitelist() @frappe.validate_and_sanitize_search_inputs def employee_query(doctype, txt, searchfield, start, page_len, filters): filters = frappe._dict(filters) conditions = [] - exclude_employees = [] + include_employees = [] emp_cond = '' if filters.start_date and filters.end_date: - employee_list = get_employee_with_existing_salary_slip(filters.start_date, filters.end_date, filters.company) + employee_list = get_employee_list(filters) emp = filters.get('employees') + include_employees = [employee.employee for employee in employee_list if employee.employee not in emp] filters.pop('start_date') filters.pop('end_date') + filters.pop('salary_slip_based_on_timesheet') + filters.pop('payroll_frequency') + filters.pop('payroll_payable_account') + filters.pop('currency') if filters.employees is not None: filters.pop('employees') - if employee_list: - exclude_employees.extend(employee_list) - if emp: - exclude_employees.extend(emp) - if exclude_employees: - emp_cond += 'and employee not in %(exclude_employees)s' + + if include_employees: + emp_cond += 'and employee in %(include_employees)s' return frappe.db.sql("""select name, employee_name from `tabEmployee` where status = 'Active' @@ -695,4 +710,4 @@ def employee_query(doctype, txt, searchfield, start, page_len, filters): '_txt': txt.replace("%", ""), 'start': start, 'page_len': page_len, - 'exclude_employees': exclude_employees}) + 'include_employees': include_employees}) From 6c88ab07c779de864a88d9c073a1092b696f51c8 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 19 Apr 2021 11:51:46 +0530 Subject: [PATCH 445/449] fix: commit leave_allocation change to db (#25382) --- .../compensatory_leave_request/compensatory_leave_request.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/hr/doctype/compensatory_leave_request/compensatory_leave_request.py b/erpnext/hr/doctype/compensatory_leave_request/compensatory_leave_request.py index aa5a67f40c..a6fe429be1 100644 --- a/erpnext/hr/doctype/compensatory_leave_request/compensatory_leave_request.py +++ b/erpnext/hr/doctype/compensatory_leave_request/compensatory_leave_request.py @@ -66,7 +66,7 @@ class CompensatoryLeaveRequest(Document): else: leave_allocation = self.create_leave_allocation(leave_period, date_difference) - self.leave_allocation=leave_allocation.name + self.db_set("leave_allocation", leave_allocation.name) else: frappe.throw(_("There is no leave period in between {0} and {1}").format(format_date(self.work_from_date), format_date(self.work_end_date))) @@ -124,4 +124,4 @@ class CompensatoryLeaveRequest(Document): )) allocation.insert(ignore_permissions=True) allocation.submit() - return allocation \ No newline at end of file + return allocation From ac8a467b0a5694a86a992d3c8e1b14b362e19a57 Mon Sep 17 00:00:00 2001 From: Alan <2.alan.tom@gmail.com> Date: Mon, 19 Apr 2021 12:38:25 +0530 Subject: [PATCH 446/449] fix: exclude spurious Stock Entry Types from 'consumed' calculation (#25352) * fix: exclude spurious 'Stock Entry Type's from 'consumed' calculation * fix: filter using purpose, make requested changes Co-authored-by: Ankush Menat --- .../itemwise_recommended_reorder_level.py | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.py b/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.py index 5df3fa8067..2f70523264 100644 --- a/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.py +++ b/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.py @@ -55,19 +55,31 @@ def get_item_info(filters): def get_consumed_items(condition): + purpose_to_exclude = [ + "Material Transfer for Manufacture", + "Material Transfer", + "Send to Subcontractor" + ] + + condition += """ + and ( + purpose is NULL + or purpose not in ({}) + ) + """.format(', '.join([f"'{p}'" for p in purpose_to_exclude])) + condition = condition.replace("posting_date", "sle.posting_date") + consumed_items = frappe.db.sql(""" select item_code, abs(sum(actual_qty)) as consumed_qty - from `tabStock Ledger Entry` - where actual_qty < 0 + from `tabStock Ledger Entry` as sle left join `tabStock Entry` as se + on sle.voucher_no = se.name + where + actual_qty < 0 and voucher_type not in ('Delivery Note', 'Sales Invoice') %s - group by item_code - """ % condition, as_dict=1) - - consumed_items_map = {} - for item in consumed_items: - consumed_items_map.setdefault(item.item_code, item.consumed_qty) + group by item_code""" % condition, as_dict=1) + consumed_items_map = {item.item_code : item.consumed_qty for item in consumed_items} return consumed_items_map def get_delivered_items(condition): From 119b27b97f8cd2092c8e915e5283dbd26876d1ce Mon Sep 17 00:00:00 2001 From: Jannat Patel <31363128+pateljannat@users.noreply.github.com> Date: Mon, 19 Apr 2021 12:46:14 +0530 Subject: [PATCH 447/449] feat: Delayed Tasks Summary (#25024) * feat: delayed deliverables summary * fix: sider * fix: renamed to delayed tasks * fix: renamed test * fix: test * fix: sider * fix: dates, validations and chart * fix: space and column width * feat: Sort tasks by descending order of delay Co-authored-by: Rucha Mahabal --- erpnext/projects/doctype/task/task.json | 15 +- erpnext/projects/doctype/task/task.py | 5 + .../report/delayed_tasks_summary/__init__.py | 0 .../delayed_tasks_summary.js | 41 ++++++ .../delayed_tasks_summary.json | 29 ++++ .../delayed_tasks_summary.py | 133 ++++++++++++++++++ .../test_delayed_tasks_summary.py | 54 +++++++ .../projects/workspace/projects/projects.json | 13 +- 8 files changed, 286 insertions(+), 4 deletions(-) create mode 100644 erpnext/projects/report/delayed_tasks_summary/__init__.py create mode 100644 erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.js create mode 100644 erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.json create mode 100644 erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.py create mode 100644 erpnext/projects/report/delayed_tasks_summary/test_delayed_tasks_summary.py diff --git a/erpnext/projects/doctype/task/task.json b/erpnext/projects/doctype/task/task.json index 160cc5812f..ef4740d9ee 100644 --- a/erpnext/projects/doctype/task/task.json +++ b/erpnext/projects/doctype/task/task.json @@ -11,15 +11,16 @@ "project", "issue", "type", + "color", "is_group", "is_template", "column_break0", "status", "priority", "task_weight", - "completed_by", - "color", "parent_task", + "completed_by", + "completed_on", "sb_timeline", "exp_start_date", "expected_time", @@ -358,6 +359,7 @@ "read_only": 1 }, { + "depends_on": "eval: doc.status == \"Completed\"", "fieldname": "completed_by", "fieldtype": "Link", "label": "Completed By", @@ -381,6 +383,13 @@ "fieldname": "duration", "fieldtype": "Int", "label": "Duration (Days)" + }, + { + "depends_on": "eval: doc.status == \"Completed\"", + "fieldname": "completed_on", + "fieldtype": "Date", + "label": "Completed On", + "mandatory_depends_on": "eval: doc.status == \"Completed\"" } ], "icon": "fa fa-check", @@ -388,7 +397,7 @@ "is_tree": 1, "links": [], "max_attachments": 5, - "modified": "2020-12-28 11:32:58.714991", + "modified": "2021-04-16 12:46:51.556741", "modified_by": "Administrator", "module": "Projects", "name": "Task", diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py index 855ff5f83e..d1583f1473 100755 --- a/erpnext/projects/doctype/task/task.py +++ b/erpnext/projects/doctype/task/task.py @@ -36,6 +36,7 @@ class Task(NestedSet): self.validate_status() self.update_depends_on() self.validate_dependencies_for_template_task() + self.validate_completed_on() def validate_dates(self): if self.exp_start_date and self.exp_end_date and getdate(self.exp_start_date) > getdate(self.exp_end_date): @@ -100,6 +101,10 @@ class Task(NestedSet): dependent_task_format = """{0}""".format(task.task) frappe.throw(_("Dependent Task {0} is not a Template Task").format(dependent_task_format)) + def validate_completed_on(self): + if self.completed_on and getdate(self.completed_on) > getdate(): + frappe.throw(_("Completed On cannot be greater than Today")) + def update_depends_on(self): depends_on_tasks = self.depends_on_tasks or "" for d in self.depends_on: diff --git a/erpnext/projects/report/delayed_tasks_summary/__init__.py b/erpnext/projects/report/delayed_tasks_summary/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.js b/erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.js new file mode 100644 index 0000000000..5aa44c0a8c --- /dev/null +++ b/erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.js @@ -0,0 +1,41 @@ +// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt +/* eslint-disable */ + +frappe.query_reports["Delayed Tasks Summary"] = { + "filters": [ + { + "fieldname": "from_date", + "label": __("From Date"), + "fieldtype": "Date" + }, + { + "fieldname": "to_date", + "label": __("To Date"), + "fieldtype": "Date" + }, + { + "fieldname": "priority", + "label": __("Priority"), + "fieldtype": "Select", + "options": ["", "Low", "Medium", "High", "Urgent"] + }, + { + "fieldname": "status", + "label": __("Status"), + "fieldtype": "Select", + "options": ["", "Open", "Working","Pending Review","Overdue","Completed"] + }, + ], + "formatter": function(value, row, column, data, default_formatter) { + value = default_formatter(value, row, column, data); + if (column.id == "delay") { + if (data["delay"] > 0) { + value = `

    ${value}

    `; + } else { + value = `

    ${value}

    `; + } + } + return value + } +}; diff --git a/erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.json b/erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.json new file mode 100644 index 0000000000..100c422433 --- /dev/null +++ b/erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.json @@ -0,0 +1,29 @@ +{ + "add_total_row": 0, + "columns": [], + "creation": "2021-03-25 15:03:19.857418", + "disable_prepared_report": 0, + "disabled": 0, + "docstatus": 0, + "doctype": "Report", + "filters": [], + "idx": 0, + "is_standard": "Yes", + "modified": "2021-04-15 15:49:35.432486", + "modified_by": "Administrator", + "module": "Projects", + "name": "Delayed Tasks Summary", + "owner": "Administrator", + "prepared_report": 0, + "ref_doctype": "Task", + "report_name": "Delayed Tasks Summary", + "report_type": "Script Report", + "roles": [ + { + "role": "Projects User" + }, + { + "role": "Projects Manager" + } + ] +} \ No newline at end of file diff --git a/erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.py b/erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.py new file mode 100644 index 0000000000..cdabe6487e --- /dev/null +++ b/erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.py @@ -0,0 +1,133 @@ +# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.utils import date_diff, nowdate + +def execute(filters=None): + columns, data = [], [] + data = get_data(filters) + columns = get_columns() + charts = get_chart_data(data) + return columns, data, None, charts + +def get_data(filters): + conditions = get_conditions(filters) + tasks = frappe.get_all("Task", + filters = conditions, + fields = ["name", "subject", "exp_start_date", "exp_end_date", + "status", "priority", "completed_on", "progress"], + order_by="creation" + ) + for task in tasks: + if task.exp_end_date: + if task.completed_on: + task.delay = date_diff(task.completed_on, task.exp_end_date) + elif task.status == "Completed": + # task is completed but completed on is not set (for older tasks) + task.delay = 0 + else: + # task not completed + task.delay = date_diff(nowdate(), task.exp_end_date) + else: + # task has no end date, hence no delay + task.delay = 0 + + # Sort by descending order of delay + tasks.sort(key=lambda x: x["delay"], reverse=True) + return tasks + +def get_conditions(filters): + conditions = frappe._dict() + keys = ["priority", "status"] + for key in keys: + if filters.get(key): + conditions[key] = filters.get(key) + if filters.get("from_date"): + conditions.exp_end_date = [">=", filters.get("from_date")] + if filters.get("to_date"): + conditions.exp_start_date = ["<=", filters.get("to_date")] + return conditions + +def get_chart_data(data): + delay, on_track = 0, 0 + for entry in data: + if entry.get("delay") > 0: + delay = delay + 1 + else: + on_track = on_track + 1 + charts = { + "data": { + "labels": ["On Track", "Delayed"], + "datasets": [ + { + "name": "Delayed", + "values": [on_track, delay] + } + ] + }, + "type": "percentage", + "colors": ["#84D5BA", "#CB4B5F"] + } + return charts + +def get_columns(): + columns = [ + { + "fieldname": "name", + "fieldtype": "Link", + "label": "Task", + "options": "Task", + "width": 150 + }, + { + "fieldname": "subject", + "fieldtype": "Data", + "label": "Subject", + "width": 200 + }, + { + "fieldname": "status", + "fieldtype": "Data", + "label": "Status", + "width": 100 + }, + { + "fieldname": "priority", + "fieldtype": "Data", + "label": "Priority", + "width": 80 + }, + { + "fieldname": "progress", + "fieldtype": "Data", + "label": "Progress (%)", + "width": 120 + }, + { + "fieldname": "exp_start_date", + "fieldtype": "Date", + "label": "Expected Start Date", + "width": 150 + }, + { + "fieldname": "exp_end_date", + "fieldtype": "Date", + "label": "Expected End Date", + "width": 150 + }, + { + "fieldname": "completed_on", + "fieldtype": "Date", + "label": "Actual End Date", + "width": 130 + }, + { + "fieldname": "delay", + "fieldtype": "Data", + "label": "Delay (In Days)", + "width": 120 + } + ] + return columns diff --git a/erpnext/projects/report/delayed_tasks_summary/test_delayed_tasks_summary.py b/erpnext/projects/report/delayed_tasks_summary/test_delayed_tasks_summary.py new file mode 100644 index 0000000000..dbeedb4be9 --- /dev/null +++ b/erpnext/projects/report/delayed_tasks_summary/test_delayed_tasks_summary.py @@ -0,0 +1,54 @@ +from __future__ import unicode_literals +import unittest +import frappe +from frappe.utils import nowdate, add_days, add_months +from erpnext.projects.doctype.task.test_task import create_task +from erpnext.projects.report.delayed_tasks_summary.delayed_tasks_summary import execute + +class TestDelayedTasksSummary(unittest.TestCase): + @classmethod + def setUp(self): + task1 = create_task("_Test Task 98", add_days(nowdate(), -10), nowdate()) + create_task("_Test Task 99", add_days(nowdate(), -10), add_days(nowdate(), -1)) + + task1.status = "Completed" + task1.completed_on = add_days(nowdate(), -1) + task1.save() + + def test_delayed_tasks_summary(self): + filters = frappe._dict({ + "from_date": add_months(nowdate(), -1), + "to_date": nowdate(), + "priority": "Low", + "status": "Open" + }) + expected_data = [ + { + "subject": "_Test Task 99", + "status": "Open", + "priority": "Low", + "delay": 1 + }, + { + "subject": "_Test Task 98", + "status": "Completed", + "priority": "Low", + "delay": -1 + } + ] + report = execute(filters) + data = list(filter(lambda x: x.subject == "_Test Task 99", report[1]))[0] + + for key in ["subject", "status", "priority", "delay"]: + self.assertEqual(expected_data[0].get(key), data.get(key)) + + filters.status = "Completed" + report = execute(filters) + data = list(filter(lambda x: x.subject == "_Test Task 98", report[1]))[0] + + for key in ["subject", "status", "priority", "delay"]: + self.assertEqual(expected_data[1].get(key), data.get(key)) + + def tearDown(self): + for task in ["_Test Task 98", "_Test Task 99"]: + frappe.get_doc("Task", {"subject": task}).delete() \ No newline at end of file diff --git a/erpnext/projects/workspace/projects/projects.json b/erpnext/projects/workspace/projects/projects.json index dbbd7e1458..0ec17029a2 100644 --- a/erpnext/projects/workspace/projects/projects.json +++ b/erpnext/projects/workspace/projects/projects.json @@ -15,6 +15,7 @@ "hide_custom": 0, "icon": "project", "idx": 0, + "is_default": 0, "is_standard": 1, "label": "Projects", "links": [ @@ -148,9 +149,19 @@ "link_type": "Report", "onboard": 0, "type": "Link" + }, + { + "dependencies": "Task", + "hidden": 0, + "is_query_report": 1, + "label": "Delayed Tasks Summary", + "link_to": "Delayed Tasks Summary", + "link_type": "Report", + "onboard": 0, + "type": "Link" } ], - "modified": "2020-12-01 13:38:37.856224", + "modified": "2021-03-26 16:32:00.628561", "modified_by": "Administrator", "module": "Projects", "name": "Projects", From ceba5774be6910d6c48f0f69e3f4adc1345b1b4b Mon Sep 17 00:00:00 2001 From: Rakshith N <36509967+rakshithrddy@users.noreply.github.com> Date: Mon, 19 Apr 2021 13:21:49 +0530 Subject: [PATCH 448/449] fix(pos): special character scanning in point of sale (#25353) Co-authored-by: rakshith.n Co-authored-by: Saqib --- .../page/point_of_sale/pos_item_selector.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/erpnext/selling/page/point_of_sale/pos_item_selector.js b/erpnext/selling/page/point_of_sale/pos_item_selector.js index e0d5b73166..9fb3943b53 100644 --- a/erpnext/selling/page/point_of_sale/pos_item_selector.js +++ b/erpnext/selling/page/point_of_sale/pos_item_selector.js @@ -159,6 +159,31 @@ erpnext.PointOfSale.ItemSelector = class { bind_events() { const me = this; window.onScan = onScan; + + onScan.decodeKeyEvent = function (oEvent) { + var iCode = this._getNormalizedKeyNum(oEvent); + switch (true) { + case iCode >= 48 && iCode <= 90: // numbers and letters + case iCode >= 106 && iCode <= 111: // operations on numeric keypad (+, -, etc.) + case (iCode >= 160 && iCode <= 164) || iCode == 170: // ^ ! # $ * + case iCode >= 186 && iCode <= 194: // (; = , - . / `) + case iCode >= 219 && iCode <= 222: // ([ \ ] ') + if (oEvent.key !== undefined && oEvent.key !== '') { + return oEvent.key; + } + + var sDecoded = String.fromCharCode(iCode); + switch (oEvent.shiftKey) { + case false: sDecoded = sDecoded.toLowerCase(); break; + case true: sDecoded = sDecoded.toUpperCase(); break; + } + return sDecoded; + case iCode >= 96 && iCode <= 105: // numbers on numeric keypad + return 0 + (iCode - 96); + } + return ''; + }; + onScan.attachTo(document, { onScan: (sScancode) => { if (this.search_field && this.$component.is(':visible')) { From cb718fce88e3dd7866980333237cec25b9a72acf Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Mon, 19 Apr 2021 13:25:15 +0530 Subject: [PATCH 449/449] feat: Role to allow over billing, delivery, receipt (#24854) * feat: Role to allow over billing, delivery, receipt * fix: Typo --- .../doctype/accounts_settings/accounts_settings.json | 10 +++++++++- erpnext/controllers/accounts_controller.py | 4 +++- erpnext/controllers/status_updater.py | 10 +++++++--- .../stock/doctype/stock_settings/stock_settings.json | 10 +++++++++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json index a3c29b6d64..e1276e7da3 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json @@ -12,6 +12,7 @@ "frozen_accounts_modifier", "determine_address_tax_category_from", "over_billing_allowance", + "role_allowed_to_over_bill", "column_break_4", "credit_controller", "check_supplier_invoice_uniqueness", @@ -226,6 +227,13 @@ "fieldname": "delete_linked_ledger_entries", "fieldtype": "Check", "label": "Delete Accounting and Stock Ledger Entries on deletion of Transaction" + }, + { + "description": "Users with this role are allowed to over bill above the allowance percentage", + "fieldname": "role_allowed_to_over_bill", + "fieldtype": "Link", + "label": "Role Allowed to Over Bill ", + "options": "Role" } ], "icon": "icon-cog", @@ -233,7 +241,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-01-05 13:04:00.118892", + "modified": "2021-03-11 18:52:05.601996", "modified_by": "Administrator", "module": "Accounts", "name": "Accounts Settings", diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 33fbf1c0b9..d36e7b03f4 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -717,7 +717,9 @@ class AccountsController(TransactionBase): total_billed_amt = abs(total_billed_amt) max_allowed_amt = abs(max_allowed_amt) - if total_billed_amt - max_allowed_amt > 0.01: + role_allowed_to_over_bill = frappe.db.get_single_value('Accounts Settings', 'role_allowed_to_over_bill') + + if total_billed_amt - max_allowed_amt > 0.01 and role_allowed_to_over_bill not in frappe.get_roles(): frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set allowance in Accounts Settings") .format(item.item_code, item.idx, max_allowed_amt)) diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py index cdb6d244a6..5276da9720 100644 --- a/erpnext/controllers/status_updater.py +++ b/erpnext/controllers/status_updater.py @@ -201,10 +201,14 @@ class StatusUpdater(Document): get_allowance_for(item['item_code'], self.item_allowance, self.global_qty_allowance, self.global_amount_allowance, qty_or_amount) - overflow_percent = ((item[args['target_field']] - item[args['target_ref_field']]) / - item[args['target_ref_field']]) * 100 + role_allowed_to_over_deliver_receive = frappe.db.get_single_value('Stock Settings', 'role_allowed_to_over_deliver_receive') + role_allowed_to_over_bill = frappe.db.get_single_value('Accounts Settings', 'role_allowed_to_over_bill') + role = role_allowed_to_over_deliver_receive if qty_or_amount == 'qty' else role_allowed_to_over_bill - if overflow_percent - allowance > 0.01: + overflow_percent = ((item[args['target_field']] - item[args['target_ref_field']]) / + item[args['target_ref_field']]) * 100 + + if overflow_percent - allowance > 0.01 and role not in frappe.get_roles(): item['max_allowed'] = flt(item[args['target_ref_field']] * (100+allowance)/100) item['reduce_by'] = item[args['target_field']] - item['max_allowed'] diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.json b/erpnext/stock/doctype/stock_settings/stock_settings.json index 84af57b48d..f18eabc84b 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.json +++ b/erpnext/stock/doctype/stock_settings/stock_settings.json @@ -13,6 +13,7 @@ "column_break_4", "valuation_method", "over_delivery_receipt_allowance", + "role_allowed_to_over_deliver_receive", "action_if_quality_inspection_is_not_submitted", "show_barcode_field", "clean_description_html", @@ -234,6 +235,13 @@ "fieldname": "disable_serial_no_and_batch_selector", "fieldtype": "Check", "label": "Disable Serial No And Batch Selector" + }, + { + "description": "Users with this role are allowed to over deliver/receive against orders above the allowance percentage", + "fieldname": "role_allowed_to_over_deliver_receive", + "fieldtype": "Link", + "label": "Role Allowed to Over Deliver/Receive", + "options": "Role" } ], "icon": "icon-cog", @@ -241,7 +249,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-01-18 13:15:38.352796", + "modified": "2021-03-11 18:48:14.513055", "modified_by": "Administrator", "module": "Stock", "name": "Stock Settings",