- 
                Notifications
    
You must be signed in to change notification settings  - Fork 203
 
chore: add type hints to frappe.whitelist function; #3628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 2 commits
8075da2
              ceeefb6
              60b7c2a
              c55602e
              a9593b6
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 
          
            
          
           | 
    @@ -65,7 +65,7 @@ | |||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| class GSTInvoiceManagementSystem(Document): | ||||||||||||||||||||||||||
| @frappe.whitelist() | ||||||||||||||||||||||||||
| def autoreconcile_and_get_data(self): | ||||||||||||||||||||||||||
| def autoreconcile_and_get_data(self) -> dict: | ||||||||||||||||||||||||||
| frappe.has_permission("GST Invoice Management System", "write", throw=True) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| filters = frappe._dict( | ||||||||||||||||||||||||||
| 
          
            
          
           | 
    @@ -142,7 +142,7 @@ def get_pending_actions(self): | |||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| @frappe.whitelist() | ||||||||||||||||||||||||||
| def update_action(self, invoice_names, action): | ||||||||||||||||||||||||||
| def update_action(self, invoice_names: list[str] | str, action: str) -> None: | ||||||||||||||||||||||||||
| frappe.has_permission("GST Invoice Management System", "write", throw=True) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| invoice_names = frappe.parse_json(invoice_names) | ||||||||||||||||||||||||||
| 
          
            
          
           | 
    @@ -181,7 +181,7 @@ def update_action(self, invoice_names, action): | |||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| @frappe.whitelist() | ||||||||||||||||||||||||||
| def get_invoice_details(self, purchase_name, inward_supply_name): | ||||||||||||||||||||||||||
| def get_invoice_details(self, purchase_name: str, inward_supply_name: str) -> dict: | ||||||||||||||||||||||||||
| frappe.has_permission("GST Invoice Management System", "write", throw=True) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| inward_supply = InwardSupply().get_all( | ||||||||||||||||||||||||||
| 
        
          
        
         | 
    @@ -205,7 +205,9 @@ def get_invoice_details(self, purchase_name, inward_supply_name): | |||||||||||||||||||||||||
| return reconciliation_data[0] | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| @frappe.whitelist() | ||||||||||||||||||||||||||
| def link_documents(self, purchase_invoice_name, inward_supply_name, link_doctype): | ||||||||||||||||||||||||||
| def link_documents( | ||||||||||||||||||||||||||
| self, purchase_invoice_name: str, inward_supply_name: str, link_doctype: str | ||||||||||||||||||||||||||
| ) -> None: | ||||||||||||||||||||||||||
| frappe.has_permission("GST Invoice Management System", "write", throw=True) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| purchases, inward_supplies = _link_documents( | ||||||||||||||||||||||||||
| 
        
          
        
         | 
    @@ -215,15 +217,15 @@ def link_documents(self, purchase_invoice_name, inward_supply_name, link_doctype | |||||||||||||||||||||||||
| return self.get_invoice_data(inward_supplies, purchases) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| @frappe.whitelist() | ||||||||||||||||||||||||||
| def unlink_documents(self, data): | ||||||||||||||||||||||||||
| def unlink_documents(self, data: dict | str) -> dict: | ||||||||||||||||||||||||||
| frappe.has_permission("GST Invoice Management System", "write", throw=True) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| purchases, inward_supplies = _unlink_documents(data) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| return self.get_invoice_data(inward_supplies, purchases) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| 
         
      Comment on lines
    
      +220
     to 
      226
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return type mismatch for  This returns  Apply this diff: -    def unlink_documents(self, data: dict | str) -> dict:
+    def unlink_documents(self, data: dict | str) -> list[dict]:📝 Committable suggestion
 
        Suggested change
       
    
 🤖 Prompt for AI Agents | 
||||||||||||||||||||||||||
| @frappe.whitelist() | ||||||||||||||||||||||||||
| def get_link_options(self, doctype, filters): | ||||||||||||||||||||||||||
| def get_link_options(self, doctype, filters: dict) -> list[dict]: | ||||||||||||||||||||||||||
| frappe.has_permission("GST Invoice Management System", "write", throw=True) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| if isinstance(filters, dict): | ||||||||||||||||||||||||||
| 
        
          
        
         | 
    @@ -245,7 +247,7 @@ def get_link_options(self, doctype, filters): | |||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| @frappe.whitelist() | ||||||||||||||||||||||||||
| @otp_handler | ||||||||||||||||||||||||||
| def download_invoices(company_gstin): | ||||||||||||||||||||||||||
| def download_invoices(company_gstin: str) -> None: | ||||||||||||||||||||||||||
| frappe.has_permission("GST Invoice Management System", "write", throw=True) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| TaxpayerBaseAPI(company_gstin).validate_auth_token() | ||||||||||||||||||||||||||
| 
        
          
        
         | 
    @@ -255,7 +257,7 @@ def download_invoices(company_gstin): | |||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| @frappe.whitelist() | ||||||||||||||||||||||||||
| @otp_handler | ||||||||||||||||||||||||||
| def save_invoices(company_gstin): | ||||||||||||||||||||||||||
| def save_invoices(company_gstin: str) -> None: | ||||||||||||||||||||||||||
| frappe.has_permission("GST Invoice Management System", "write", throw=True) | ||||||||||||||||||||||||||
| frappe.has_permission("GST Return Log", "write", throw=True) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| 
        
          
        
         | 
    @@ -264,7 +266,7 @@ def save_invoices(company_gstin): | |||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| @frappe.whitelist() | ||||||||||||||||||||||||||
| @otp_handler | ||||||||||||||||||||||||||
| def reset_invoices(company_gstin): | ||||||||||||||||||||||||||
| def reset_invoices(company_gstin: str) -> None: | ||||||||||||||||||||||||||
| frappe.has_permission("GST Invoice Management System", "write", throw=True) | ||||||||||||||||||||||||||
| frappe.has_permission("GST Return Log", "write", throw=True) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| 
        
          
        
         | 
    @@ -273,7 +275,7 @@ def reset_invoices(company_gstin): | |||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| @frappe.whitelist() | ||||||||||||||||||||||||||
| @otp_handler | ||||||||||||||||||||||||||
| def sync_with_gstn_and_reupload(company_gstin): | ||||||||||||||||||||||||||
| def sync_with_gstn_and_reupload(company_gstin: str) -> None: | ||||||||||||||||||||||||||
| frappe.has_permission("GST Invoice Management System", "write", throw=True) | ||||||||||||||||||||||||||
| frappe.has_permission("GST Return Log", "write", throw=True) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| 
        
          
        
         | 
    @@ -288,7 +290,7 @@ def sync_with_gstn_and_reupload(company_gstin): | |||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| @frappe.whitelist() | ||||||||||||||||||||||||||
| @otp_handler | ||||||||||||||||||||||||||
| def check_action_status(company_gstin, action): | ||||||||||||||||||||||||||
| def check_action_status(company_gstin: str, action: str) -> dict: | ||||||||||||||||||||||||||
| frappe.has_permission("GST Return Log", "write", throw=True) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| ims_log = frappe.get_doc( | ||||||||||||||||||||||||||
| 
        
          
        
         | 
    @@ -300,15 +302,15 @@ def check_action_status(company_gstin, action): | |||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| @frappe.whitelist() | ||||||||||||||||||||||||||
| def download_excel_report(data, doc): | ||||||||||||||||||||||||||
| def download_excel_report(data: str, doc: str) -> None: | ||||||||||||||||||||||||||
| frappe.has_permission("GST Invoice Management System", "export", throw=True) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| build_data = BuildExcelIMS(doc, data) | ||||||||||||||||||||||||||
| build_data.export_data() | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| @frappe.whitelist() | ||||||||||||||||||||||||||
| def get_period_options(company, company_gstin): | ||||||||||||||||||||||||||
| def get_period_options(company: str, company_gstin: str) -> list[str]: | ||||||||||||||||||||||||||
| def format_period(period): | ||||||||||||||||||||||||||
| return period[2:] + period[:2] | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| 
          
            
          
           | 
    ||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Gate mass item updates behind write permission.
This whitelisted endpoint enqueues updates to all Item records matching an HSN—privileged operation. Add an explicit write-permission check on Item before enqueue.
@frappe.whitelist() def update_taxes_in_item_master(taxes: list[dict] | str, hsn_code: str) -> int: + frappe.has_permission("Item", "write", throw=True) frappe.enqueue(update_item_document, taxes=taxes, hsn_code=hsn_code, queue="long") return 1📝 Committable suggestion
🤖 Prompt for AI Agents