انت مبرمج محترف في البرمجة باستخدام frappe framework ولغة البرمجة paython ولغة البرمجة…
- User
انت مبرمج محترف في البرمجة باستخدام frappe framework ولغة البرمجة paython ولغة البرمجة JavaScrept, وانا اريد مساعدتك , لدي توثيق لتقرير اريد منك ان تشرح لي هذا التقرير وكيف اقوم بانشائه
- Assistant
بالتأكيد! سأكون سعيدًا بمساعدتك في توضيح كيفية إنشاء التقرير باستخدام Frappe Framework وPython وJavaScript. لكن أحتاج إلى مزيد من التفاصيل حول ما يتضمنه التقرير الذي لديك.
إذا كان لديك توثيق محدد أو بعض النقاط الرئيسية التي تود تغطيتها، يرجى مشاركتها. سأساعدك بعد ذلك في فهم الخطوات اللازمة لإنشاء التقرير. يمكنك أيضًا إخباري عن أي مكونات أو ميزات معينة تريد إضافتها في التقرير.
- User
Report: Cash Collection Ratio Analysis Report Description: A report that calculates the cash collection ratio for specified accounts over a given date range. The report focuses on accounts where the custom field custom_included_in_the_ratio is set to 1 and computes the required ratio using the formula (A × account_ratio), where A represents the net balance calculated as (SUM(debit) - SUM(credit)). This report provides insights into the cash collection efficiency of the selected accounts.
Report Fields: [ {"fieldname": "account_name", "label": "Account", "fieldtype": "Link", "options": "Account", "width": 150}, {"fieldname": "cash_collection_a", "label": "Cash collections (A)", "fieldtype": "float", "width": 200}, {"fieldname": "account_ratio", "label": "Ratio", "fieldtype": "Float", "width": 100}, {"fieldname": "ratio_value", "label": "Ratio Value", "fieldtype": "float", "width": 150}, # A × account_ratio {"fieldname": "branch", "label": "Branch", "fieldtype": "Link", "width": 150, "options": "Branch"}, # A × account_ratio ]
Filters: frappe.query_reports["Total Item Cost + Quantity Sold"] = { "filters": [ { "fieldname": "account", "label": __("Account"), "fieldtype": "Link", "options": "Account", "default": "", "reqd": 0 },
{ "fieldname": "start_date", "label": __("Start Date"), "fieldtype": "Date", "reqd": 1, }, { "fieldname": "end_date", "label": __("End Date"), "fieldtype": "Date", "reqd": 1, }, ]};
Calculations: • Cash Collections (A) = SUM(debit) - SUM(credit) • RatioValue = A × account_ratio
Report Format: • Displays the accounts meeting the condition custom_included_in_the_ratio = 1. • Lists each account's calculated Net Balance (A) and Cash Collection Ratio. • Allows filtering by date range and specific accounts. • Get accounts with transactions from (Sales Invoice, Payment Entry). If the transaction is from PAYMENT ENTRY, the type must be RECEIVE. REQUIRES BACKUP TO WORK
- Assistant
لإنشاء تقرير "تحليل نسبة تحصيل النقد" باستخدام Frappe Framework، يمكنك اتباع الخطوات التالية. سأقوم بتفصيل العمليات الأساسية التي ستحتاج إلى تنفيذها لإنشاء هذا التقرير.
1. إعداد التقرير
تحتاج إلى إنشاء تقرير جديد في Frappe. يمكنك القيام بذلك من خلال إنشاء ملف Python يخصص التقرير داخل تطبيقك. يجب أن يتضمن هذا الملف تعريف التقرير، الحقول، والفلاتر.
2. إنشاء ملف التقرير
في مجلد تطبيقك، أنشئ ملفًا جديدًا في المسار
your_app/report/، وسميهcash_collection_ratio_analysis.py. يجب أن يبدو الشيفرة كالتالي:import frappe from frappe import _ def execute(filters=None): columns = get_columns() data = get_data(filters) return columns, data def get_columns(): return [ {"fieldname": "account_name", "label": _("Account"), "fieldtype": "Link", "options": "Account", "width": 150}, {"fieldname": "cash_collection_a", "label": _("Cash collections (A)"), "fieldtype": "float", "width": 200}, {"fieldname": "account_ratio", "label": _("Ratio"), "fieldtype": "Float", "width": 100}, {"fieldname": "ratio_value", "label": _("Ratio Value"), "fieldtype": "float", "width": 150}, {"fieldname": "branch", "label": _("Branch"), "fieldtype": "Link", "options": "Branch", "width": 150} ] def get_data(filters): conditions = get_conditions(filters) data = [] # الاستعلام للحصول على البيانات accounts = frappe.db.sql(""" SELECT account.name AS account_name, SUM(debit) - SUM(credit) AS cash_collection_a, account.custom_included_in_the_ratio, account.account_ratio, branch.name AS branch FROM `tabAccount` account LEFT JOIN `tabTransaction` t ON t.account = account.name LEFT JOIN `tabBranch` branch ON branch.name = t.branch WHERE account.custom_included_in_the_ratio = 1 AND t.posting_date BETWEEN %(start_date)s AND %(end_date)s GROUP BY account.name """, filters, as_dict=True) for account in accounts: ratio_value = account.cash_collection_a * account.account_ratio if account.account_ratio else 0 data.append({ "account_name": account.account_name, "cash_collection_a": account.cash_collection_a, "account_ratio": account.account_ratio, "ratio_value": ratio_value, "branch": account.branch }) return data def get_conditions(filters): conditions = "" if filters.get("account"): conditions += " AND t.account = %(account)s" return conditions3. إعداد الفلاتر
لكي تعمل الفلاتر بشكل صحيح، يجب تعريفها في ملف JavaScript. انتقل إلى نفس المجلد وأنشئ ملفًا JavaScript بنفس اسم التقرير، على سبيل المثال
cash_collection_ratio_analysis.js:frappe.query_reports["Cash Collection Ratio Analysis"] = { "filters": [ { "fieldname": "account", "label": __("Account"), "fieldtype": "Link", "options": "Account", "default": "", "reqd": 0 }, { "fieldname": "start_date", "label": __("Start Date"), "fieldtype": "Date", "reqd": 1, }, { "fieldname": "end_date", "label": __("End Date"), "fieldtype": "Date", "reqd": 1, }, ] };4. تسجيل التقرير
سجّل التقرير في الـ
hooks.pyالخاص بتطبيقك:app_name = "your_app" app_title = "Your App" app_publisher = "Your Name" app_description = "Your App Description" app_email = "your_email@example.com" app_license = "MIT" # Add your report here fixtures = ["Report"]5. تأكيد العمل
بعد إعداد كل شيء، تأكد من إعادة تشغيل خادم Frappe الخاص بك، ثم انتقل إلى واجهة المستخدم الخاصة بـ Frappe لتأكيد أن التقرير يظهر بشكل صحيح ويمكنك استخدامه مع الفلاتر.
ملخص
في هذا التقرير، قمنا بجعل حساب نسبة تحصيل النقد يتضمن الفلاتر بناءً على تاريخ البدء والانتهاء، بالإضافة إلى الحسابات التي تم تضمينها في النسبة. تأكد من وجود الحقول المخصصة المطلوبة في نموذج "Account".
إذا كان لديك أي استفسارات إضافية أو كنت بحاجة إلى مزيد من التفاصيل، فلا تتردد في طرحها!
- User
App Versions
{ "ebkar_reports": "1.0.0", "erpnext": "14.72.2", "frappe": "14.80.0", "hrms": "14.29.3" }Route
query-report/Cash Collection Ratio AnalysisTraceback
Traceback (most recent call last): File "apps/frappe/frappe/app.py", line 97, in application response = frappe.api.handle() File "apps/frappe/frappe/api.py", line 55, in handle return frappe.handler.handle() File "apps/frappe/frappe/handler.py", line 48, in handle data = execute_cmd(cmd) File "apps/frappe/frappe/handler.py", line 86, in execute_cmd return frappe.call(method, **frappe.form_dict) File "apps/frappe/frappe/__init__.py", line 1619, in call return fn(*args, **newargs) File "apps/frappe/frappe/__init__.py", line 815, in wrapper_fn retval = fn(*args, **get_newargs(fn, kwargs)) File "apps/frappe/frappe/desk/query_report.py", line 242, in run result = generate_report_result(report, filters, user, custom_columns, is_tree, parent_field) File "apps/frappe/frappe/__init__.py", line 815, in wrapper_fn retval = fn(*args, **get_newargs(fn, kwargs)) File "apps/frappe/frappe/desk/query_report.py", line 94, in generate_report_result res = get_report_result(report, filters) or [] File "apps/frappe/frappe/desk/query_report.py", line 75, in get_report_result res = report.execute_script_report(filters) File "apps/frappe/frappe/core/doctype/report/report.py", line 128, in execute_script_report res = self.execute_module(filters) File "apps/frappe/frappe/core/doctype/report/report.py", line 145, in execute_module return frappe.get_attr(method_name)(frappe._dict(filters)) File "apps/ebkar_reports/ebkar_reports/ebkar_reports/report/cash_collection_ratio_analysis/cash_collection_ratio_analysis.py", line 19, in execute accounts = frappe.get_all( File "apps/frappe/frappe/__init__.py", line 1938, in get_all return get_list(doctype, *args, **kwargs) File "apps/frappe/frappe/__init__.py", line 1910, in get_list return frappe.model.db_query.DatabaseQuery(doctype).execute(*args, **kwargs) File "apps/frappe/frappe/model/db_query.py", line 190, in execute result = self.build_and_run() File "apps/frappe/frappe/model/db_query.py", line 231, in build_and_run return frappe.db.sql( File "apps/frappe/frappe/database/database.py", line 244, in sql self._cursor.execute(query, values) File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 153, in execute result = self._query(query) File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 322, in _query conn.query(q) File "env/lib/python3.10/site-packages/pymysql/connections.py", line 563, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "env/lib/python3.10/site-packages/pymysql/connections.py", line 825, in _read_query_result result.read() File "env/lib/python3.10/site-packages/pymysql/connections.py", line 1199, in read first_packet = self.connection._read_packet() File "env/lib/python3.10/site-packages/pymysql/connections.py", line 775, in _read_packet packet.raise_for_error() File "env/lib/python3.10/site-packages/pymysql/protocol.py", line 219, in raise_for_error err.raise_mysql_exception(self._data) File "env/lib/python3.10/site-packages/pymysql/err.py", line 150, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.OperationalError: (1054, "Unknown column 'branch' in 'field list'")Request Data
{ "type": "GET", "args": { "report_name": "Cash Collection Ratio Analysis", "filters": "{\"start_date\":\"2024-10-01\",\"end_date\":\"2024-12-29\"}", "ignore_prepared_report": false, "are_default_filters": false }, "headers": {}, "error_handlers": {}, "url": "/api/method/frappe.desk.query_report.run" }Response Data
{ "exception": "pymysql.err.OperationalError: (1054, \"Unknown column 'branch' in 'field list'\")" } - Assistant
الخطأ الذي تواجهه، والذي يظهر كالتالي:
pymysql.err.OperationalError: (1054, "Unknown column 'branch' in 'field list'")يعني أن الاستعلام الذي تقوم بإجرائه يحاول الوصول إلى عمود (column) يسمى
branchالذي لا يوجد في جدول البيانات المحدد.كيفية حل المشكلة:
-
تحقق من وجود العمود:
- تأكد من أن العمود
branchموجود في جدولTransactionأو في الجداول التي تشارك في الاستعلام. يمكنك ذلك عن طريق مراجعة البنية (schema) لقاعدة البيانات.
- تأكد من أن العمود
-
تعديل الاستعلام:
- إذا كان العمود
branchغير موجود واستمرت الحاجة إلى بيانات الفرع، يجب تعديل السؤال لإزالة أي استدعاء لهذا العمود أو إضافة الجداول المناسبة. - إذا كان هناك جدول مختلف يحتوي على معلومات الفروع (مثل
tabBranch)، تأكد من JOIN هذا الجدول بشكل صحيح.
- إذا كان العمود
نموذج تعديل الاستعلام:
هنا مثال على كيفية تعديل الاستعلام في دالة
get_dataالخاصة بك لإزالة العمودbranchإذا لم يكن موجودًا:def get_data(filters): conditions = get_conditions(filters) data = [] # الاستعلام للحصول على البيانات accounts = frappe.db.sql(""" SELECT account.name AS account_name, SUM(debit) - SUM(credit) AS cash_collection_a, account.custom_included_in_the_ratio, account.account_ratio FROM `tabAccount` account LEFT JOIN `tabTransaction` t ON t.account = account.name WHERE account.custom_included_in_the_ratio = 1 AND t.posting_date BETWEEN %(start_date)s AND %(end_date)s GROUP BY account.name """, filters, as_dict=True) for account in accounts: ratio_value = account.cash_collection_a * account.account_ratio if account.account_ratio else 0 data.append({ "account_name": account.account_name, "cash_collection_a": account.cash_collection_a, "account_ratio": account.account_ratio, "ratio_value": ratio_value, }) return dataإذا كنت بحاجة إلى عمود الفرع:
إذا كنت بحاجة بالفعل إلى استخدام عمود الفرع، تأكد من أن لديك بيانات موجودة في الجداول الصحيحة، وتحقق مما إذا كان يمكنك استخدام استعلام JOIN مناسب.
تحقق من الفلاتر:
إذا كان لديك نوع من الفلاتر يعتمد على قيمة
branch، فتأكد من أن جميع فلاتر التقرير تتناسب مع تصميم قاعدة البيانات.بعد تعديل الاستعلام:
بعد إجراء التعديلات اللازمة، تأكد من إعادة تشغيل خادم Frappe الخاص بك ثم جرب تشغيل التقرير مرة أخرى للتحقق مما إذا كان الخطأ قد تم حله.
-