Deepesh Garg
3 years ago
committed by
GitHub
10 changed files with 287 additions and 2 deletions
@ -0,0 +1,33 @@ |
|||
// 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('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', ''); |
|||
} |
|||
}); |
@ -0,0 +1,102 @@ |
|||
{ |
|||
"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-25 20:08:56.761150", |
|||
"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 |
|||
}, |
|||
{ |
|||
"create": 1, |
|||
"delete": 1, |
|||
"email": 1, |
|||
"export": 1, |
|||
"print": 1, |
|||
"read": 1, |
|||
"report": 1, |
|||
"role": "Accounts Manager", |
|||
"share": 1, |
|||
"write": 1 |
|||
}, |
|||
{ |
|||
"create": 1, |
|||
"delete": 1, |
|||
"email": 1, |
|||
"export": 1, |
|||
"print": 1, |
|||
"read": 1, |
|||
"report": 1, |
|||
"role": "Accounts User", |
|||
"share": 1, |
|||
"write": 1 |
|||
} |
|||
], |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC", |
|||
"title_field": "primary_party", |
|||
"track_changes": 1 |
|||
} |
@ -0,0 +1,26 @@ |
|||
# 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")) |
|||
|
|||
existing_party_link = frappe.get_all('Party Link', { |
|||
'primary_party': self.secondary_party |
|||
}, pluck="primary_role") |
|||
if existing_party_link: |
|||
frappe.throw(_('{} {} is already linked with another {}') |
|||
.format(self.secondary_role, self.secondary_party, existing_party_link[0])) |
|||
|
|||
existing_party_link = frappe.get_all('Party Link', { |
|||
'secondary_party': self.primary_party |
|||
}, pluck="primary_role") |
|||
if existing_party_link: |
|||
frappe.throw(_('{} {} is already linked with another {}') |
|||
.format(self.primary_role, self.primary_party, existing_party_link[0])) |
@ -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 |
Loading…
Reference in new issue