From e63dfe4a94a5acf45badae38938955ab99a8ba33 Mon Sep 17 00:00:00 2001 From: Mohammed Irfan Date: Mon, 6 Jul 2026 15:35:49 +0530 Subject: [PATCH] feat: subscription renewal customizations across Quotation, Sales Order, and Sales Invoice - Add Subscription Details section with Subscription Type, Is New Subscription, Subscription Remarks, and Subscription Item child table to Quotation, Sales Order, and Sales Invoice - Add dynamic Old Invoice / Old Proforma Invoice link based on Export checkbox - Enforce mandatory Subscription Type and conditional Old Invoice requirement - Configure read-only controls for Old Invoice and Export on Sales Order and Sales Invoice - Update renewal workflow to mark old document renewed on export Sales Order or domestic Sales Invoice submission - Add client scripts for item filtering and amount syncing --- spollex/doctype_events/quotation.py | 4 + spollex/doctype_events/sales_invoice.py | 11 + spollex/doctype_events/sales_order.py | 11 + spollex/doctype_events/subscription.py | 59 + spollex/fixtures/custom_field.json | 1482 +++++++++++++++++ spollex/hooks.py | 22 +- spollex/public/js/quotation.js | 69 + spollex/public/js/sales_invoice.js | 105 +- spollex/public/js/sales_order.js | 67 + .../doctype/subscription_item/__init__.py | 2 + .../subscription_item/subscription_item.json | 56 + .../subscription_item/subscription_item.py | 7 + 12 files changed, 1857 insertions(+), 38 deletions(-) create mode 100644 spollex/doctype_events/quotation.py create mode 100644 spollex/doctype_events/sales_invoice.py create mode 100644 spollex/doctype_events/sales_order.py create mode 100644 spollex/doctype_events/subscription.py create mode 100644 spollex/public/js/quotation.js create mode 100644 spollex/public/js/sales_order.js create mode 100644 spollex/spollex/doctype/subscription_item/__init__.py create mode 100644 spollex/spollex/doctype/subscription_item/subscription_item.json create mode 100644 spollex/spollex/doctype/subscription_item/subscription_item.py diff --git a/spollex/doctype_events/quotation.py b/spollex/doctype_events/quotation.py new file mode 100644 index 0000000..5c49692 --- /dev/null +++ b/spollex/doctype_events/quotation.py @@ -0,0 +1,4 @@ +# Copyright (c) 2026, 4C Solutions and contributors +# For license information, please see license.txt + +from spollex.doctype_events.subscription import validate_subscription_details diff --git a/spollex/doctype_events/sales_invoice.py b/spollex/doctype_events/sales_invoice.py new file mode 100644 index 0000000..b711da6 --- /dev/null +++ b/spollex/doctype_events/sales_invoice.py @@ -0,0 +1,11 @@ +# Copyright (c) 2026, 4C Solutions and contributors +# For license information, please see license.txt + +from spollex.doctype_events.subscription import ( + validate_subscription_details, + update_renewal_invoice_status, +) + + +def update_renewal_invoice_status_on_submit_cancel(doc, method=None): + update_renewal_invoice_status(doc, method=method, is_export=False) diff --git a/spollex/doctype_events/sales_order.py b/spollex/doctype_events/sales_order.py new file mode 100644 index 0000000..a30540d --- /dev/null +++ b/spollex/doctype_events/sales_order.py @@ -0,0 +1,11 @@ +# Copyright (c) 2026, 4C Solutions and contributors +# For license information, please see license.txt + +from spollex.doctype_events.subscription import ( + validate_subscription_details, + update_renewal_invoice_status, +) + + +def update_renewal_invoice_status_on_submit_cancel(doc, method=None): + update_renewal_invoice_status(doc, method=method, is_export=True) diff --git a/spollex/doctype_events/subscription.py b/spollex/doctype_events/subscription.py new file mode 100644 index 0000000..73b10d2 --- /dev/null +++ b/spollex/doctype_events/subscription.py @@ -0,0 +1,59 @@ +# Copyright (c) 2026, 4C Solutions and contributors +# For license information, please see license.txt + +import frappe +from frappe import _ +from frappe.utils import getdate + + +def validate_subscription_details(doc, method=None): + target_dt = "Sales Order" if doc.get("custom_export") else "Sales Invoice" + doc.custom_old_doctype = target_dt + + is_new = doc.get("custom_is_new_subscription") + if doc.custom_subscription_type in ["AMC", "License"] and not is_new and not doc.get("custom_old_invoice"): + label = _("Old Proforma Invoice") if doc.get("custom_export") else _("Old Invoice") + frappe.throw( + _("{0} is mandatory when Subscription Type is {1}").format(label, doc.custom_subscription_type) + ) + + _sync_subscription_item_amounts(doc) + _validate_subscription_item_dates(doc) + + +def _sync_subscription_item_amounts(doc): + item_codes_in_doc = {item.item_code for item in (doc.items or [])} + item_amount_map = {} + for item in doc.items or []: + if item.item_code: + item_amount_map[item.item_code] = item_amount_map.get(item.item_code, 0) + (item.amount or 0) + + for row in doc.custom_subscription_items or []: + if not row.item_code: + continue + if row.item_code not in item_codes_in_doc: + frappe.throw( + _("Row #{0}: Item {1} in Subscription Items is not present in the Items table.").format( + row.idx, row.item_code + ) + ) + row.amount = item_amount_map.get(row.item_code, 0) + + +def _validate_subscription_item_dates(doc): + for row in doc.custom_subscription_items or []: + if row.from_date and row.to_date and getdate(row.from_date) > getdate(row.to_date): + frappe.throw( + _("Row #{0}: From Date cannot be after To Date in Subscription Items.").format(row.idx) + ) + + +def update_renewal_invoice_status(doc, method=None, is_export=False): + old_invoice = doc.get("custom_old_invoice") + if not old_invoice or bool(doc.get("custom_export")) != is_export: + return + + is_renewed = 1 if method == "on_submit" else 0 + target_dt = doc.get("custom_old_doctype") or ("Sales Order" if is_export else "Sales Invoice") + if frappe.db.exists(target_dt, old_invoice): + frappe.db.set_value(target_dt, old_invoice, "custom_renewed", is_renewed) diff --git a/spollex/fixtures/custom_field.json b/spollex/fixtures/custom_field.json index 624a6e8..1003feb 100644 --- a/spollex/fixtures/custom_field.json +++ b/spollex/fixtures/custom_field.json @@ -1879,5 +1879,1487 @@ "translatable": 0, "unique": 0, "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": "Sales Invoice", + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Quotation", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_old_doctype", + "fieldtype": "Link", + "hidden": 1, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "has_unit_price_items", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Old Invoice DocType", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Quotation-custom_old_doctype", + "no_copy": 0, + "non_negative": 0, + "options": "DocType", + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Quotation", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_old_invoice", + "fieldtype": "Dynamic Link", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_old_doctype", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Old Invoice", + "length": 0, + "link_filters": null, + "mandatory_depends_on": "eval:in_list(['AMC', 'License'], doc.custom_subscription_type) && !doc.custom_is_new_subscription", + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Quotation-custom_old_invoice", + "no_copy": 0, + "non_negative": 0, + "options": "custom_old_doctype", + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Quotation", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_export", + "fieldtype": "Check", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_old_invoice", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Export", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Quotation-custom_export", + "no_copy": 0, + "non_negative": 0, + "options": null, + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Quotation", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_subscription_details_section", + "fieldtype": "Section Break", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "update_auto_repeat_reference", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Subscription Details", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Quotation-custom_subscription_details_section", + "no_copy": 0, + "non_negative": 0, + "options": null, + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": "None", + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Quotation", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_subscription_type", + "fieldtype": "Select", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_subscription_details_section", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Subscription Type", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Quotation-custom_subscription_type", + "no_copy": 0, + "non_negative": 0, + "options": "\nAMC\nLicense\nNone", + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 1, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Quotation", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_is_new_subscription", + "fieldtype": "Check", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_subscription_type", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Is New Subscription", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Quotation-custom_is_new_subscription", + "no_copy": 0, + "non_negative": 0, + "options": null, + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Quotation", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_subscription_items", + "fieldtype": "Table", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_is_new_subscription", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Subscription Items", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Quotation-custom_subscription_items", + "no_copy": 0, + "non_negative": 0, + "options": "Subscription Item", + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Quotation", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_subscription_remarks", + "fieldtype": "Small Text", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_subscription_items", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Subscription Remarks", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Quotation-custom_subscription_remarks", + "no_copy": 0, + "non_negative": 0, + "options": null, + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": "Sales Invoice", + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Order", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_old_doctype", + "fieldtype": "Link", + "hidden": 1, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "has_unit_price_items", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Old Invoice DocType", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Order-custom_old_doctype", + "no_copy": 0, + "non_negative": 0, + "options": "DocType", + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Order", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_old_invoice", + "fieldtype": "Dynamic Link", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_old_doctype", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Old Invoice", + "length": 0, + "link_filters": null, + "mandatory_depends_on": "eval:in_list(['AMC', 'License'], doc.custom_subscription_type) && !doc.custom_is_new_subscription", + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Order-custom_old_invoice", + "no_copy": 0, + "non_negative": 0, + "options": "custom_old_doctype", + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 1, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Order", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_export", + "fieldtype": "Check", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_old_invoice", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Export", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Order-custom_export", + "no_copy": 0, + "non_negative": 0, + "options": null, + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 1, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Order", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_subscription_details_section", + "fieldtype": "Section Break", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "update_auto_repeat_reference", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Subscription Details", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Order-custom_subscription_details_section", + "no_copy": 0, + "non_negative": 0, + "options": null, + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": "None", + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Order", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_subscription_type", + "fieldtype": "Select", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_subscription_details_section", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Subscription Type", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Order-custom_subscription_type", + "no_copy": 0, + "non_negative": 0, + "options": "\nAMC\nLicense\nNone", + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 1, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Order", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_is_new_subscription", + "fieldtype": "Check", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_subscription_type", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Is New Subscription", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Order-custom_is_new_subscription", + "no_copy": 0, + "non_negative": 0, + "options": null, + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Order", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_subscription_items", + "fieldtype": "Table", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_is_new_subscription", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Subscription Items", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Order-custom_subscription_items", + "no_copy": 0, + "non_negative": 0, + "options": "Subscription Item", + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Order", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_subscription_remarks", + "fieldtype": "Small Text", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_subscription_items", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Subscription Remarks", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Order-custom_subscription_remarks", + "no_copy": 0, + "non_negative": 0, + "options": null, + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Order", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_renewed", + "fieldtype": "Check", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_subscription_remarks", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Renewed", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Order-custom_renewed", + "no_copy": 1, + "non_negative": 0, + "options": null, + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 1, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": "Sales Invoice", + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Invoice", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_old_doctype", + "fieldtype": "Link", + "hidden": 1, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "is_debit_note", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Old Invoice DocType", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Invoice-custom_old_doctype", + "no_copy": 0, + "non_negative": 0, + "options": "DocType", + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Invoice", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_old_invoice", + "fieldtype": "Dynamic Link", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_old_doctype", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Old Invoice", + "length": 0, + "link_filters": null, + "mandatory_depends_on": "eval:in_list(['AMC', 'License'], doc.custom_subscription_type) && !doc.custom_is_new_subscription", + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Invoice-custom_old_invoice", + "no_copy": 0, + "non_negative": 0, + "options": "custom_old_doctype", + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 1, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Invoice", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_export", + "fieldtype": "Check", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_old_invoice", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Export", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Invoice-custom_export", + "no_copy": 0, + "non_negative": 0, + "options": null, + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 1, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Invoice", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_subscription_details_section", + "fieldtype": "Section Break", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "update_auto_repeat_reference", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Subscription Details", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Invoice-custom_subscription_details_section", + "no_copy": 0, + "non_negative": 0, + "options": null, + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": "None", + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Invoice", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_subscription_type", + "fieldtype": "Select", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_subscription_details_section", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Subscription Type", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Invoice-custom_subscription_type", + "no_copy": 0, + "non_negative": 0, + "options": "\nAMC\nLicense\nNone", + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 1, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Invoice", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_is_new_subscription", + "fieldtype": "Check", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_subscription_type", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Is New Subscription", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Invoice-custom_is_new_subscription", + "no_copy": 0, + "non_negative": 0, + "options": null, + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Invoice", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_subscription_items", + "fieldtype": "Table", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_is_new_subscription", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Subscription Items", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Invoice-custom_subscription_items", + "no_copy": 0, + "non_negative": 0, + "options": "Subscription Item", + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Invoice", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_subscription_remarks", + "fieldtype": "Small Text", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_subscription_items", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Subscription Remarks", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Invoice-custom_subscription_remarks", + "no_copy": 0, + "non_negative": 0, + "options": null, + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Sales Invoice", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_renewed", + "fieldtype": "Check", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "custom_subscription_remarks", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Renewed", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2026-08-27 15:00:00.000000", + "module": "spollex", + "name": "Sales Invoice-custom_renewed", + "no_copy": 1, + "non_negative": 0, + "options": null, + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 1, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null } ] \ No newline at end of file diff --git a/spollex/hooks.py b/spollex/hooks.py index 0c08945..2b74b42 100644 --- a/spollex/hooks.py +++ b/spollex/hooks.py @@ -53,6 +53,8 @@ # include js in doctype views # doctype_js = {"doctype" : "public/js/doctype.js"} doctype_js = { + "Quotation" : "public/js/quotation.js", + "Sales Order" : "public/js/sales_order.js", "Sales Invoice" : "public/js/sales_invoice.js", "Purchase Invoice" : "public/js/purchase_invoice.js", "Purchase Order" : "public/js/purchase_order.js", @@ -155,13 +157,6 @@ # --------------- # Hook on document methods and events -# doc_events = { -# "*": { -# "on_update": "method", -# "on_cancel": "method", -# "on_trash": "method" -# } -# } doc_events = { "Purchase Invoice": { "on_submit": "spollex.doctype_events.purchase_invoice.create_journal_entry_on_submit", @@ -180,6 +175,19 @@ "Maintenance Visit": { "on_submit": "spollex.doctype_events.maintenance_visit.update_contract_visits", "on_cancel": "spollex.doctype_events.maintenance_visit.update_contract_visits" + }, + "Quotation": { + "validate": "spollex.doctype_events.quotation.validate_subscription_details" + }, + "Sales Order": { + "validate": "spollex.doctype_events.sales_order.validate_subscription_details", + "on_submit": "spollex.doctype_events.sales_order.update_renewal_invoice_status_on_submit_cancel", + "on_cancel": "spollex.doctype_events.sales_order.update_renewal_invoice_status_on_submit_cancel" + }, + "Sales Invoice": { + "validate": "spollex.doctype_events.sales_invoice.validate_subscription_details", + "on_submit": "spollex.doctype_events.sales_invoice.update_renewal_invoice_status_on_submit_cancel", + "on_cancel": "spollex.doctype_events.sales_invoice.update_renewal_invoice_status_on_submit_cancel" } } diff --git a/spollex/public/js/quotation.js b/spollex/public/js/quotation.js new file mode 100644 index 0000000..8dc8de4 --- /dev/null +++ b/spollex/public/js/quotation.js @@ -0,0 +1,69 @@ +frappe.ui.form.on("Quotation", { + onload: function(frm) { + setup_subscription_queries(frm); + update_old_invoice_link(frm); + }, + refresh: function(frm) { + update_old_invoice_link(frm); + }, + custom_export: function(frm) { + update_old_invoice_link(frm); + if (frm.doc.custom_old_invoice) { + frm.set_value("custom_old_invoice", ""); + } + }, + custom_subscription_type: function(frm) { + update_old_invoice_link(frm); + }, + custom_is_new_subscription: function(frm) { + update_old_invoice_link(frm); + }, + before_save: function(frm) { + update_old_invoice_link(frm); + } +}); + +frappe.ui.form.on("Subscription Item", { + item_code: function(frm, cdt, cdn) { + let row = locals[cdt][cdn]; + if (!row.item_code) return; + + let matched_item = (frm.doc.items || []).find(item => item.item_code === row.item_code); + if (matched_item) { + frappe.model.set_value(cdt, cdn, "amount", matched_item.amount); + } else { + frappe.msgprint(__("Item {0} is not present in the items table.", [row.item_code])); + } + } +}); + +function setup_subscription_queries(frm) { + frm.set_query("item_code", "custom_subscription_items", function(doc) { + let items = (doc.items || []).map(item => item.item_code).filter(Boolean); + return { filters: [["Item", "name", "in", items]] }; + }); + + frm.set_query("custom_old_invoice", function(doc) { + let target_dt = doc.custom_export ? "Sales Order" : "Sales Invoice"; + let filters = { + docstatus: 1, + custom_renewed: 0 + }; + let customer = doc.quotation_to === "Customer" ? doc.party_name : (doc.customer || ""); + if (customer) { + filters.customer = customer; + } + return { filters: filters }; + }); +} + +function update_old_invoice_link(frm) { + let target_dt = frm.doc.custom_export ? "Sales Order" : "Sales Invoice"; + let target_label = frm.doc.custom_export ? __("Old Proforma Invoice") : __("Old Invoice"); + + // Only set value on editable drafts to avoid dirtying submitted/existing docs + if (frm.doc.docstatus === 0 && frm.doc.custom_old_doctype !== target_dt) { + frm.set_value("custom_old_doctype", target_dt); + } + frm.set_df_property("custom_old_invoice", "label", target_label); +} diff --git a/spollex/public/js/sales_invoice.js b/spollex/public/js/sales_invoice.js index a4f2ab8..f49e7db 100644 --- a/spollex/public/js/sales_invoice.js +++ b/spollex/public/js/sales_invoice.js @@ -8,12 +8,27 @@ //}); frappe.ui.form.on("Sales Invoice", { - // frm.doc.sales_team.forEach((record) => { - // before_save: function(frm){ - // calculate_commission_rate(frm, record.doctype, record.name); - // }); - // }, + onload: function(frm) { + setup_subscription_queries(frm); + update_old_invoice_link(frm); + }, + custom_export: function(frm) { + update_old_invoice_link(frm); + if (frm.doc.custom_old_invoice) { + frm.set_value("custom_old_invoice", ""); + } + }, + custom_subscription_type: function(frm) { + update_old_invoice_link(frm); + }, + custom_is_new_subscription: function(frm) { + update_old_invoice_link(frm); + }, + before_save: function(frm) { + update_old_invoice_link(frm); + }, refresh: function(frm) { + update_old_invoice_link(frm); if (frm.doc.docstatus === 1 && frm.doc.status != "Paid") { frm.add_custom_button(__("Post Sales Credit Note"), function() { post_sales_credit_note(frm); @@ -22,13 +37,55 @@ frappe.ui.form.on("Sales Invoice", { } }); +frappe.ui.form.on("Subscription Item", { + item_code: function(frm, cdt, cdn) { + let row = locals[cdt][cdn]; + if (!row.item_code) return; + + let matched_item = (frm.doc.items || []).find(item => item.item_code === row.item_code); + if (matched_item) { + frappe.model.set_value(cdt, cdn, "amount", matched_item.amount); + } else { + frappe.msgprint(__("Item {0} is not present in the items table.", [row.item_code])); + } + } +}); + +function setup_subscription_queries(frm) { + frm.set_query("item_code", "custom_subscription_items", function(doc) { + let items = (doc.items || []).map(item => item.item_code).filter(Boolean); + return { filters: [["Item", "name", "in", items]] }; + }); + + frm.set_query("custom_old_invoice", function(doc) { + let target_dt = doc.custom_export ? "Sales Order" : "Sales Invoice"; + return { + filters: { + customer: doc.customer, + docstatus: 1, + custom_renewed: 0 + } + }; + }); +} + +function update_old_invoice_link(frm) { + let target_dt = frm.doc.custom_export ? "Sales Order" : "Sales Invoice"; + let target_label = frm.doc.custom_export ? __("Old Proforma Invoice") : __("Old Invoice"); + + // Only set value on editable drafts to avoid dirtying submitted/existing docs + if (frm.doc.docstatus === 0 && frm.doc.custom_old_doctype !== target_dt) { + frm.set_value("custom_old_doctype", target_dt); + } + frm.set_df_property("custom_old_invoice", "label", target_label); +} + // function calculate_commission_rate(frm, cdt, cdn) { // var sales_person_row = locals[cdt][cdn]; // var total_amount = frm.doc.amount_eligible_for_commission || 0; // var allocated_percentage = sales_person_row.allocated_percentage || 0; // var allocated_amount = (total_amount * allocated_percentage) * 0.01; // var posting_date = frm.doc.posting_date; - // if (allocated_amount) { // frappe.call({ // method: "spollex.overrides.sales_person.fetch_commission_rate", @@ -49,27 +106,13 @@ frappe.ui.form.on("Sales Invoice", { // } let post_sales_credit_note = async function(frm) { - const fields = [ - { - label: 'Rebate Amount', - fieldname: 'rebate_amount', - fieldtype: 'Currency' - }, - { - label: 'Posting Date', - fieldname: 'posting_date', - fieldtype: 'Date', - default: frm.doc.posting_date - }, - { - label: 'Remark', - fieldname: 'remark', - fieldtype: 'Small Text', - } + { label: 'Rebate Amount', fieldname: 'rebate_amount', fieldtype: 'Currency' }, + { label: 'Posting Date', fieldname: 'posting_date', fieldtype: 'Date', default: frm.doc.posting_date }, + { label: 'Remark', fieldname: 'remark', fieldtype: 'Small Text' } ]; - let d = new frappe.ui.Dialog ({ + let d = new frappe.ui.Dialog({ title: "Post Sales Credit Note", fields: fields, primary_action_label: "Create Credit Note", @@ -78,24 +121,24 @@ let post_sales_credit_note = async function(frm) { frappe.call({ method: 'spollex.utils.create_credit_note', args: { - rebate_amount : values.rebate_amount, - posting_date : values.posting_date, + rebate_amount: values.rebate_amount, + posting_date: values.posting_date, remark: values.remark, reference_name: frm.doc.name }, callback: function(response) { if (response.message) { - frappe.msgprint(__("Credit note created successfully")) + frappe.msgprint(__("Credit note created successfully")); } else { - frappe.msgprint(__("Credit note creation failed")) + frappe.msgprint(__("Credit note creation failed")); } d.hide(); } }); } else { - frappe.msgprint(__("The rebate amount cannot exceed the total invoice amount")) + frappe.msgprint(__("The rebate amount cannot exceed the total invoice amount")); } } - }) + }); d.show(); -} \ No newline at end of file +}; diff --git a/spollex/public/js/sales_order.js b/spollex/public/js/sales_order.js new file mode 100644 index 0000000..40d943a --- /dev/null +++ b/spollex/public/js/sales_order.js @@ -0,0 +1,67 @@ +frappe.ui.form.on("Sales Order", { + onload: function(frm) { + setup_subscription_queries(frm); + update_old_invoice_link(frm); + }, + refresh: function(frm) { + update_old_invoice_link(frm); + }, + custom_export: function(frm) { + update_old_invoice_link(frm); + if (frm.doc.custom_old_invoice) { + frm.set_value("custom_old_invoice", ""); + } + }, + custom_subscription_type: function(frm) { + update_old_invoice_link(frm); + }, + custom_is_new_subscription: function(frm) { + update_old_invoice_link(frm); + }, + before_save: function(frm) { + update_old_invoice_link(frm); + } +}); + +frappe.ui.form.on("Subscription Item", { + item_code: function(frm, cdt, cdn) { + let row = locals[cdt][cdn]; + if (!row.item_code) return; + + let matched_item = (frm.doc.items || []).find(item => item.item_code === row.item_code); + if (matched_item) { + frappe.model.set_value(cdt, cdn, "amount", matched_item.amount); + } else { + frappe.msgprint(__("Item {0} is not present in the items table.", [row.item_code])); + } + } +}); + +function setup_subscription_queries(frm) { + frm.set_query("item_code", "custom_subscription_items", function(doc) { + let items = (doc.items || []).map(item => item.item_code).filter(Boolean); + return { filters: [["Item", "name", "in", items]] }; + }); + + frm.set_query("custom_old_invoice", function(doc) { + let target_dt = doc.custom_export ? "Sales Order" : "Sales Invoice"; + return { + filters: { + customer: doc.customer, + docstatus: 1, + custom_renewed: 0 + } + }; + }); +} + +function update_old_invoice_link(frm) { + let target_dt = frm.doc.custom_export ? "Sales Order" : "Sales Invoice"; + let target_label = frm.doc.custom_export ? __("Old Proforma Invoice") : __("Old Invoice"); + + // Only set value on editable drafts to avoid dirtying submitted/existing docs + if (frm.doc.docstatus === 0 && frm.doc.custom_old_doctype !== target_dt) { + frm.set_value("custom_old_doctype", target_dt); + } + frm.set_df_property("custom_old_invoice", "label", target_label); +} diff --git a/spollex/spollex/doctype/subscription_item/__init__.py b/spollex/spollex/doctype/subscription_item/__init__.py new file mode 100644 index 0000000..e682e25 --- /dev/null +++ b/spollex/spollex/doctype/subscription_item/__init__.py @@ -0,0 +1,2 @@ +# Copyright (c) 2026, 4C Solutions and contributors +# For license information, please see license.txt diff --git a/spollex/spollex/doctype/subscription_item/subscription_item.json b/spollex/spollex/doctype/subscription_item/subscription_item.json new file mode 100644 index 0000000..2a389b9 --- /dev/null +++ b/spollex/spollex/doctype/subscription_item/subscription_item.json @@ -0,0 +1,56 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2026-07-04 15:50:00.000000", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "item_code", + "amount", + "from_date", + "to_date" + ], + "fields": [ + { + "fieldname": "item_code", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Item", + "options": "Item", + "reqd": 1 + }, + { + "fieldname": "amount", + "fieldtype": "Currency", + "in_list_view": 1, + "label": "Amount" + }, + { + "fieldname": "from_date", + "fieldtype": "Date", + "in_list_view": 1, + "label": "From Date" + }, + { + "fieldname": "to_date", + "fieldtype": "Date", + "in_list_view": 1, + "label": "To Date" + } + ], + "grid_page_length": 50, + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2026-08-27 12:00:00.000000", + "modified_by": "Administrator", + "module": "spollex", + "name": "Subscription Item", + "owner": "Administrator", + "permissions": [], + "row_format": "Dynamic", + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/spollex/spollex/doctype/subscription_item/subscription_item.py b/spollex/spollex/doctype/subscription_item/subscription_item.py new file mode 100644 index 0000000..c72092a --- /dev/null +++ b/spollex/spollex/doctype/subscription_item/subscription_item.py @@ -0,0 +1,7 @@ +# Copyright (c) 2026, 4C Solutions and contributors +# For license information, please see license.txt + +from frappe.model.document import Document + +class SubscriptionItem(Document): + pass