Agri fixes (#12033)
* crop_cycle, moving point in geojson from js to py
* crop fields are fetched into crop_cycle
- fixes #12011
* area is a readonly field
- fixes #11994
* [agri] land unit child geojson bug fixed
* set_intro null if parent field entered, list only group nodes
* minor fixes
diff --git a/erpnext/agriculture/doctype/crop_cycle/crop_cycle.js b/erpnext/agriculture/doctype/crop_cycle/crop_cycle.js
index 98dd056..ae28bb7 100644
--- a/erpnext/agriculture/doctype/crop_cycle/crop_cycle.js
+++ b/erpnext/agriculture/doctype/crop_cycle/crop_cycle.js
@@ -15,7 +15,7 @@
output[doctype].forEach( (analysis_doc) => {
let point_to_be_tested = JSON.parse(analysis_doc.location).features[0].geometry.coordinates;
let poly_of_land = JSON.parse(land_doc.location).features[0].geometry.coordinates[0];
- if (test_analysis_position(point_to_be_tested, poly_of_land)){
+ if (is_in_land_unit(point_to_be_tested, poly_of_land)){
obj_to_append[analysis_doctypes_docs[analysis_doctypes.indexOf(doctype)]].push(analysis_doc.name);
}
});
@@ -28,7 +28,7 @@
}
});
-function test_analysis_position(point, vs) {
+function is_in_land_unit(point, vs) {
// ray-casting algorithm based on
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
diff --git a/erpnext/agriculture/doctype/crop_cycle/crop_cycle.py b/erpnext/agriculture/doctype/crop_cycle/crop_cycle.py
index 8912f59..64e2f9a 100644
--- a/erpnext/agriculture/doctype/crop_cycle/crop_cycle.py
+++ b/erpnext/agriculture/doctype/crop_cycle/crop_cycle.py
@@ -12,6 +12,10 @@
if self.is_new():
crop = frappe.get_doc('Crop', self.crop)
self.create_project(crop.period, crop.agriculture_task)
+ if not self.crop_spacing_uom:
+ self.crop_spacing_uom = crop.crop_spacing_uom
+ if not self.row_spacing_uom:
+ self.row_spacing_uom = crop.row_spacing_uom
if not self.project:
self.project = self.name
for detected_disease in self.detected_disease:
@@ -59,4 +63,19 @@
return ast.literal_eval(doc.location).get('features')[0].get('geometry').get('coordinates')
def get_geometry_type(self, doc):
- return ast.literal_eval(doc.location).get('features')[0].get('geometry').get('type')
\ No newline at end of file
+ return ast.literal_eval(doc.location).get('features')[0].get('geometry').get('type')
+
+ def is_in_land_unit(self, point, vs):
+ x, y = point
+ inside = False
+ j = len(vs)-1
+ i = 0
+ while i < len(vs):
+ xi, yi = vs[i]
+ xj, yj = vs[j]
+ intersect = ((yi > y) != (yj > y)) and (x < (xj - xi) * (y - yi) / (yj - yi) + xi)
+ if intersect:
+ inside = not inside
+ i = j
+ j += 1
+ return inside
\ No newline at end of file
diff --git a/erpnext/agriculture/doctype/land_unit/land_unit.js b/erpnext/agriculture/doctype/land_unit/land_unit.js
index c9ab348..5b40b24 100644
--- a/erpnext/agriculture/doctype/land_unit/land_unit.js
+++ b/erpnext/agriculture/doctype/land_unit/land_unit.js
@@ -9,6 +9,13 @@
setup: function(frm) {
frm.add_fetch("parent_land_unit", "latitude", "latitude");
frm.add_fetch("parent_land_unit", "longitude", "longitude");
+ frm.set_query("parent_land_unit", function() {
+ return {
+ "filters": {
+ "is_group": 1
+ }
+ };
+ });
},
onload_post_render(frm){
@@ -28,4 +35,7 @@
frm.set_intro(null);
}
},
+ parent_land_unit: function(frm) {
+ frm.set_intro(null);
+ },
});
diff --git a/erpnext/agriculture/doctype/land_unit/land_unit.json b/erpnext/agriculture/doctype/land_unit/land_unit.json
index e5f6c0d..94d350f 100644
--- a/erpnext/agriculture/doctype/land_unit/land_unit.json
+++ b/erpnext/agriculture/doctype/land_unit/land_unit.json
@@ -431,7 +431,7 @@
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
- "read_only": 0,
+ "read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
@@ -632,7 +632,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2017-12-13 16:50:18.581137",
+ "modified": "2017-12-14 18:16:15.124188",
"modified_by": "Administrator",
"module": "Agriculture",
"name": "Land Unit",
@@ -680,7 +680,7 @@
"write": 1
}
],
- "quick_entry": 0,
+ "quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
"show_name_in_global_search": 1,
diff --git a/erpnext/agriculture/doctype/land_unit/land_unit.py b/erpnext/agriculture/doctype/land_unit/land_unit.py
index 634cb75..fe683bc 100644
--- a/erpnext/agriculture/doctype/land_unit/land_unit.py
+++ b/erpnext/agriculture/doctype/land_unit/land_unit.py
@@ -10,6 +10,7 @@
from frappe import _
from frappe.utils.nestedset import NestedSet
+from frappe.utils import flt
# from frappe.model.document import Document
RADIUS = 6378137
@@ -39,10 +40,10 @@
else:
features = json.loads(self.get('location')).get('features')
new_area = compute_area(features)
- self.area_difference = new_area - self.area
+ self.area_difference = new_area - flt(self.area)
self.area = new_area
- if self.get('parent'):
+ if self.get('parent_land_unit'):
ancestors = self.get_ancestors()
self_features = self.add_child_property()
self_features = set(self_features)
@@ -118,7 +119,7 @@
layer_area += polygon_area(coords = feature.get('geometry').get('coordinates'))
elif feature.get('geometry').get('type') == 'Point' and feature.get('properties').get('point_type') == 'circle':
layer_area += math.pi * math.pow(feature.get('properties').get('radius'), 2)
- return layer_area
+ return flt(layer_area)
def rad(angle_in_degrees):
return angle_in_degrees*math.pi/180
diff --git a/erpnext/agriculture/doctype/land_unit/land_unit_tree.js b/erpnext/agriculture/doctype/land_unit/land_unit_tree.js
index 0d7a53e..e0d6479 100644
--- a/erpnext/agriculture/doctype/land_unit/land_unit_tree.js
+++ b/erpnext/agriculture/doctype/land_unit/land_unit_tree.js
@@ -8,8 +8,8 @@
click: function(node) {
var lu = frappe.new_doc("Land Unit", {
"parent_land_unit": node.label
- })
+ });
}
}
],
-}
\ No newline at end of file
+};
\ No newline at end of file