انت مبرمج محترف في البرمجة باستخدام frappe framework ولغة البرمجة paython ولغة البرمجة…
- User
انت مبرمج محترف في البرمجة باستخدام frappe framework ولغة البرمجة paython ولغة البرمجة JavaScrept, وانا اريد مساعدتك , لدي Doctype باسم Agreements ولذي سوف ارسل لك الكود الخاص بملف البايثون وملف الجافاء سكربت الخاص به , يوجد في هذا ال Doctype مجموعة الحقول التاليه : { agreement:Data, amount:Currency, agreement_projects:Table agreement_parties:Table } حيث ان الجدول الفرعي agreement_projects يحتوي على حقل project وهو عباره عن حقل من نوع Link من Doctype ال Project ,وكذالك يحتوي الجدول الفرعي agreement_projects على الحقول الاتيه :{ project_outputs:Link, governorate_location:Link, subdistrict_location:Link, amount:Currency, amount_disbursed:Currency, residual_amount:Currency, } وايضاً يحتوي الجدول الفرعي agreement_parties الحقول الاتيه :{ parties:Link, amount:Currency } , اريد اضافة فلاتر للحقول "governorate_location,subdistrict_location" المتواجدة في الجدول الفرعي agreement_projects مثل ماهو موضح في الكود التالي
frm.set_query("governorate_location", function() { return { filters: { is_group: 1, location_type:"Governorate", } } }); frm.set_query("district_location", function() { return { filters: { parent_location: ['in', seralize_loaction(frm.doc.governorate_location)], location_type:"District", } } });, والان واريد منك انا تخبرني كيف ابداء بارسال محتواء الملفات اليك وماهي الخطوات التي اتبعها للتعامل معك , المخرجات اريد ان تكون مخرجات كود كل ملف بعد التعديل وشرح للتعديلات - Assistant
بالتأكيد، أحب مساعدتك في إجراء التعديلات المطلوبة على الشيفرات الخاصة بك في Frappe Framework. لبدء العمل على هذه المسألة، يمكنك اتباع الخطوات التالية:
الخطوات المقترحة
-
رفع المحتوى: يمكنك نسخه ولصقه هنا مباشرةً. قم بكتابة محتويات ملفات Python وJavaScript الخاصة بـ Doctype Agreements. إذا كانت الملفات كبيرة، يمكنك تلخيص الأجزاء الأساسية فقط.
-
شرح المشكلة: تأكد من توضيح أي تفاصيل إضافية حول كيفية عمل كل جزء من الكود، وكذلك إذا كان لديك أي متطلبات/قيود خاصة.
-
الاستعداد للتعديلات: سأقوم بتحليل الشيفرات البرمجية الخاصة بك، ثم سأزوّدك بالنسخ المعدلة لكود كل ملف مع شرح التعديلات.
ملاحظة حول التعديلات
- في JavaScript، يجب التأكد من أن الفلاتر مُعرفة بشكل صحيح لكل حقل.
- في Python، إذا كان هناك أي عمليات مرتبطة وهذه الفلاتر، يجب أن تأخذ بعين الاعتبار.
- سأعتني بتهيئة الفلاتر المناسبة لـ
governorate_locationوsubdistrict_location.
مثال على كيف يمكنك كتابة المحتوى
# الاتفاقيات.py import frappe from frappe.model.document import Document class Agreements(Document): # الشيفرة الحالية pass -
- User
Copyright (c) 2023, open-alt.com and contributors
For license information, please see license.txt
agreements.py
import frappe from frappe.model.document import Document
class Agreements(Document): def validate(self): self.update_amount_from_parties() self.check_projects_amount() self.check_duplicate_parties() self.check_duplicate_projects()
def update_amount_from_parties(self): total_amount = sum(party.amount for party in self.agreement_parties) self.total_agreement_parties_amount = total_amount def check_projects_amount(self): total_projects_amount = sum(project.amount for project in self.agreement_projects) self.total_agreement_projects_amount = total_projects_amount if total_projects_amount > self.total_agreement_parties_amount: frappe.throw("The total amount of projects cannot exceed the amount of the agreement.") def check_duplicate_parties(self): party_set = set() for party in self.agreement_parties: if party.parties in party_set: frappe.throw(f"The party '{party.parties}' has already been added.") party_set.add(party.parties) def check_duplicate_projects(self): project_set = set() for project in self.agreement_projects: # Establishment of the key set to be verified project_key = (project.project, project.project_outputs, project.governorate_location, project.subdistrict_location) if project_key in project_set: frappe.throw(f"A project with the same details already exists: {project_key}") project_set.add(project_key) - Assistant
شكرًا لمشاركة جزء من كود البايثون. الآن، سأضع الشيفرة الجافا سكريبت لتتمكن من تعديلها وفقًا لمتطلباتك. سيكون من المفيد أن أرى الكود بالكامل لكي أتمكن من تقديم تغييرات دقيقة للفلاتر.
في الوقت الحالي، سأوضح لك كيفية إضافة الفلاتر للحقول
governorate_locationو في الجدول الفرعي . - User
// Copyright (c) 2023, open-alt.com and contributors // For license information, please see license.txt // agreements.js frappe.ui.form.on('Agreements', { // refresh: function(frm) { // // يمكن إضافة أي منطق هنا عند تجديد النموذج إذا لزم الأمر // }, });
// Flatter's designation of fields in agreement_projects frappe.ui.form.on('Agreement Projects', { refresh: function(frm) { frm.set_query("governorate_location", function() { return { filters: { is_group: 1, location_type: "Governorate", } }; }); }, governorate_location: function(frm, cdt, cdn) { frm.set_query("subdistrict_location", function() { const row = locals[cdt][cdn]; return { filters: { parent_location: row.governorate_location, location_type: "District", } }; });
}, subdistrict_location: function(frm, cdt, cdn) { const row = locals[cdt][cdn]; frm.set_query("subdistrict_location", function() { return { filters: { parent_location: row.governorate_location, location_type: "District", } }; }); }});
- Assistant
شكرًا لمشاركة كود JavaScript. سأقوم الآن بمراجعة الكود وتقديم التعديلات اللازمة لضمان عمل الفلاتر بشكل صحيح.
تحليل الكود الحالي
-
تعيين الفلاتر:
- قمت بتعيين فلتر لكل من و . الأمر يبدو جيدًا لكن هناك بعض النقاط يمكن تحسينها.
-