feat: initialize party link for customer & suppliers

This commit is contained in:
Saqib Ansari 2021-08-19 17:55:24 +05:30
parent c60d5523bc
commit dddc29fdc1
5 changed files with 139 additions and 0 deletions

View File

@ -0,0 +1,41 @@
// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.ui.form.on('Party Link', {
refresh: function(frm) {
frm.set_query('party_type', 'links', () => {
return {
filters: {
name: ['in', party_types]
}
};
});
frm.set_query('primary_role', () => {
return {
filters: {
name: ['in', ['Customer', 'Supplier']]
}
};
});
frm.set_query('secondary_role', () => {
let party_types = Object.keys(frappe.boot.party_account_types)
.filter(p => p != frm.doc.primary_role);
return {
filters: {
name: ['in', party_types]
}
};
});
},
primary_role(frm) {
frm.set_value('primary_party', '');
frm.set_value('secondary_role', '');
},
secondary_role(frm) {
frm.set_value('secondary_party', '');
}
});

View File

@ -0,0 +1,78 @@
{
"actions": [],
"autoname": "ACC-PT-LNK-.###.",
"creation": "2021-08-18 21:06:53.027695",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"primary_role",
"secondary_role",
"column_break_2",
"primary_party",
"secondary_party"
],
"fields": [
{
"fieldname": "primary_role",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Primary Role",
"options": "DocType",
"reqd": 1
},
{
"fieldname": "column_break_2",
"fieldtype": "Column Break"
},
{
"depends_on": "primary_role",
"fieldname": "secondary_role",
"fieldtype": "Link",
"label": "Secondary Role",
"mandatory_depends_on": "primary_role",
"options": "DocType"
},
{
"depends_on": "primary_role",
"fieldname": "primary_party",
"fieldtype": "Dynamic Link",
"label": "Primary Party",
"mandatory_depends_on": "primary_role",
"options": "primary_role"
},
{
"depends_on": "secondary_role",
"fieldname": "secondary_party",
"fieldtype": "Dynamic Link",
"label": "Secondary Party",
"mandatory_depends_on": "secondary_role",
"options": "secondary_role"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-08-19 17:53:43.456752",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Party Link",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"title_field": "primary_party",
"track_changes": 1
}

View File

@ -0,0 +1,12 @@
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
import frappe
from frappe import _
from frappe.model.document import Document
class PartyLink(Document):
def validate(self):
if self.primary_role not in ['Customer', 'Supplier']:
frappe.throw(_("Allowed primary roles are 'Customer' and 'Supplier'. Please select one of these roles only."),
title=_("Invalid Primary Role"))

View File

@ -0,0 +1,8 @@
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# import frappe
import unittest
class TestPartyLink(unittest.TestCase):
pass