Land unit tree (#12072)
* improvise tree structure * remove set intro code * remove all land units dependency * test case corrected
This commit is contained in:
parent
2bca5a98ae
commit
0acf687e20
@ -27,15 +27,4 @@ frappe.ui.form.on('Land Unit', {
|
|||||||
frm.doc.longitude = frm.fields_dict.location.map.getCenter()['lng'];
|
frm.doc.longitude = frm.fields_dict.location.map.getCenter()['lng'];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
refresh: function(frm) {
|
|
||||||
if(!frm.doc.parent_land_unit) {
|
|
||||||
frm.set_read_only();
|
|
||||||
frm.set_intro(__("This is a root land unit and cannot be edited."));
|
|
||||||
} else {
|
|
||||||
frm.set_intro(null);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
parent_land_unit: function(frm) {
|
|
||||||
frm.set_intro(null);
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
@ -32,6 +32,7 @@ class LandUnit(NestedSet):
|
|||||||
ancestor_features[index] = json.loads(feature)
|
ancestor_features[index] = json.loads(feature)
|
||||||
ancestor_doc.set_location_value(features = ancestor_features)
|
ancestor_doc.set_location_value(features = ancestor_features)
|
||||||
ancestor_doc.db_set(fieldname='area', value=ancestor_doc.get('area')-self.get('area'),commit=True)
|
ancestor_doc.db_set(fieldname='area', value=ancestor_doc.get('area')-self.get('area'),commit=True)
|
||||||
|
super(LandUnit, self).on_update()
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
if not self.is_new():
|
if not self.is_new():
|
||||||
@ -79,7 +80,6 @@ class LandUnit(NestedSet):
|
|||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
super(LandUnit, self).on_update()
|
super(LandUnit, self).on_update()
|
||||||
self.validate_one_root()
|
|
||||||
|
|
||||||
def add_child_property(self):
|
def add_child_property(self):
|
||||||
location = self.get('location')
|
location = self.get('location')
|
||||||
@ -164,3 +164,17 @@ def ring_area(coords):
|
|||||||
area = area * RADIUS * RADIUS / 2
|
area = area * RADIUS * RADIUS / 2
|
||||||
return area
|
return area
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_children(doctype, parent, is_root=False):
|
||||||
|
if is_root:
|
||||||
|
parent = ''
|
||||||
|
|
||||||
|
land_units = frappe.db.sql("""select name as value,
|
||||||
|
is_group as expandable
|
||||||
|
from `tabLand Unit`
|
||||||
|
where ifnull(`parent_land_unit`,'') = %s
|
||||||
|
order by name""", (parent), as_dict=1)
|
||||||
|
|
||||||
|
# return nodes
|
||||||
|
return land_units
|
||||||
|
|
@ -1,11 +1,26 @@
|
|||||||
frappe.treeview_settings["Land Unit"] = {
|
frappe.treeview_settings["Land Unit"] = {
|
||||||
|
get_tree_nodes: "erpnext.agriculture.doctype.land_unit.land_unit.get_children",
|
||||||
ignore_fields:["parent_land_unit"],
|
ignore_fields:["parent_land_unit"],
|
||||||
|
get_tree_root: false,
|
||||||
disable_add_node: true,
|
disable_add_node: true,
|
||||||
|
root_label: "All Land Units",
|
||||||
|
onload: function(me) {
|
||||||
|
me.make_tree();
|
||||||
|
},
|
||||||
toolbar: [
|
toolbar: [
|
||||||
{ toggle_btn: true },
|
{ toggle_btn: true },
|
||||||
{
|
{
|
||||||
label:__("Add Child"),
|
label:__("Edit"),
|
||||||
|
condition: function(node) { return (node.label!='All Land Units'); },
|
||||||
click: function(node) {
|
click: function(node) {
|
||||||
|
frappe.set_route('Form', 'Land Unit', node.data.value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label:__("Add Child"),
|
||||||
|
condition: function(node) { return node.expandable; },
|
||||||
|
click: function(node) {
|
||||||
|
if(node.label=='All Land Units') node.label='';
|
||||||
var lu = frappe.new_doc("Land Unit", {
|
var lu = frappe.new_doc("Land Unit", {
|
||||||
"parent_land_unit": node.label
|
"parent_land_unit": node.label
|
||||||
});
|
});
|
||||||
|
@ -12,7 +12,6 @@ QUnit.test("test: Land Unit", function (assert) {
|
|||||||
// insert a new Land Unit
|
// insert a new Land Unit
|
||||||
() => frappe.tests.make('Land Unit', [
|
() => frappe.tests.make('Land Unit', [
|
||||||
// values to be set
|
// values to be set
|
||||||
{parent_land_unit: 'All Land Units'},
|
|
||||||
{land_unit_name: 'Basil Farm'}
|
{land_unit_name: 'Basil Farm'}
|
||||||
]),
|
]),
|
||||||
() => {
|
() => {
|
||||||
|
@ -21,6 +21,6 @@ class TestLandUnit(unittest.TestCase):
|
|||||||
temp['features'][0]['properties']['feature_of'] = land_unit
|
temp['features'][0]['properties']['feature_of'] = land_unit
|
||||||
formatted_land_units.extend(temp['features'])
|
formatted_land_units.extend(temp['features'])
|
||||||
formatted_land_unit_string = str(formatted_land_units)
|
formatted_land_unit_string = str(formatted_land_units)
|
||||||
all_land_units = frappe.get_doc('Land Unit', 'All Land Units')
|
test_land = frappe.get_doc('Land Unit', 'Test Land')
|
||||||
self.assertEquals(formatted_land_unit_string, str(json.loads(all_land_units.get('location'))['features']))
|
self.assertEquals(formatted_land_unit_string, str(json.loads(test_land.get('location'))['features']))
|
||||||
self.assertEquals(area, all_land_units.get('area'))
|
self.assertEquals(area, test_land.get('area'))
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
[
|
[
|
||||||
|
{
|
||||||
|
"doctype": "Land Unit",
|
||||||
|
"land_unit_name": "Test Land",
|
||||||
|
"is_group": 1,
|
||||||
|
"is_container": 1
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Land Unit",
|
"doctype": "Land Unit",
|
||||||
"land_unit_name": "Basil Farm",
|
"land_unit_name": "Basil Farm",
|
||||||
"location": "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"point_type\":\"circle\",\"radius\":884.5625420736483},\"geometry\":{\"type\":\"Point\",\"coordinates\":[72.875834,19.100566]}}]}",
|
"location": "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"point_type\":\"circle\",\"radius\":884.5625420736483},\"geometry\":{\"type\":\"Point\",\"coordinates\":[72.875834,19.100566]}}]}",
|
||||||
"parent_land_unit": "All Land Units",
|
"parent_land_unit": "Test Land",
|
||||||
"parent": "All Land Units",
|
"parent": "Test Land",
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"is_container": 1
|
"is_container": 1
|
||||||
},
|
},
|
||||||
|
@ -4,18 +4,13 @@ from frappe import _
|
|||||||
from erpnext.setup.utils import insert_record
|
from erpnext.setup.utils import insert_record
|
||||||
|
|
||||||
def setup_agriculture():
|
def setup_agriculture():
|
||||||
if frappe.db.exists('Land Unit', 'All Land Units'):
|
if frappe.get_all('Agriculture Analysis Criteria'):
|
||||||
# already setup
|
# already setup
|
||||||
return
|
return
|
||||||
create_agriculture_data()
|
create_agriculture_data()
|
||||||
|
|
||||||
def create_agriculture_data():
|
def create_agriculture_data():
|
||||||
records = [
|
records = [
|
||||||
dict(
|
|
||||||
doctype="Land Unit",
|
|
||||||
land_unit_name="All Land Units",
|
|
||||||
is_group=1,
|
|
||||||
is_container=1),
|
|
||||||
dict(
|
dict(
|
||||||
doctype='Item Group',
|
doctype='Item Group',
|
||||||
item_group_name='Fertilizer',
|
item_group_name='Fertilizer',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user