Skip to content

Commit

Permalink
Merge f4d628f into a7567f2
Browse files Browse the repository at this point in the history
  • Loading branch information
vishdha committed Sep 16, 2020
2 parents a7567f2 + f4d628f commit 1b5887a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 10 deletions.
44 changes: 41 additions & 3 deletions erpnext/agriculture/doctype/plant_batch/plant_batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ frappe.ui.form.on('Plant Batch', {
obj_to_append: obj_to_append
});
});

frm.set_df_property("untracked_count", "read_only", frm.is_new() ? 0 : 1);
if (!frm.is_new()) {
frm.add_custom_button(__("Split Plant Batch"), () => {
frm.trigger("split_plant_batch");
}, __("Create"));
frm.add_custom_button(__("Plant"), () => {
frappe.model.open_mapped_doc({
method: "erpnext.agriculture.doctype.plant_batch.plant_batch.make_plant",
Expand All @@ -46,8 +49,43 @@ frappe.ui.form.on('Plant Batch', {
});
}, __("Create"));
}

}
},
split_plant_batch: function(frm) {
frappe.prompt([{
fieldname: 'split_count',
label: __('New Batch Qty'),
fieldtype: 'Int',
},
{
fieldname: 'new_batch_id',
label: __('New Batch ID (Optional)'),
fieldtype: 'Data',
}],
(data) => {
if (frm.doc.untracked_count < data.split_count) {
frappe.throw(__("The Split count ({0}) should be less or equal than the untracked quantity ({1})",
[data.split_count, frm.doc.untracked_count]));
}
frappe.call({
method: 'erpnext.agriculture.doctype.plant_batch.plant_batch.split_plant_batch',
args: {
untracked_count: frm.doc.untracked_count,
strain: frm.doc.strain,
start_date: frm.doc.start_date,
location: frm.doc.location,
split_count: data.split_count,
new_batch_id: data.new_batch_id,
reference_name: frm.doc.name
},
callback: (r) => {
frm.refresh();
},
});
},
__('Split Batch'),
__('Split')
);
},
});

function is_in_land_unit(point, vs) {
Expand Down
14 changes: 9 additions & 5 deletions erpnext/agriculture/doctype/plant_batch/plant_batch.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,14 @@
{
"fieldname": "tracked_count",
"fieldtype": "Int",
"label": "Tracked Count"
"label": "Tracked Count",
"read_only": 1
},
{
"fieldname": "packaged_count",
"fieldtype": "Int",
"label": "Packaged Count"
"label": "Packaged Count",
"read_only": 1
},
{
"fieldname": "column_break_37",
Expand All @@ -222,12 +224,14 @@
{
"fieldname": "harvested_count",
"fieldtype": "Int",
"label": "Harvested Count"
"label": "Harvested Count",
"read_only": 1
},
{
"fieldname": "destroyed_count",
"fieldtype": "Int",
"label": "Destroyed Count"
"label": "Destroyed Count",
"read_only": 1
},
{
"description": "The minimum distance between each plant for optimum growth",
Expand All @@ -250,7 +254,7 @@
"options": "Plant Tag"
}
],
"modified": "2020-08-25 07:20:07.654098",
"modified": "2020-09-15 22:57:54.641618",
"modified_by": "Administrator",
"module": "Agriculture",
"name": "Plant Batch",
Expand Down
26 changes: 24 additions & 2 deletions erpnext/agriculture/doctype/plant_batch/plant_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def create_plant_batch_project(self):
if strain.cultivation_task:
self.project = create_project(self.title, self.start_date, strain.period)
create_tasks(strain.cultivation_task, self.project, self.start_date)

def reload_linked_analysis(self):
linked_doctypes = ['Soil Texture', 'Soil Analysis', 'Plant Analysis']
required_fields = ['location', 'name', 'collection_datetime']
Expand Down Expand Up @@ -115,4 +115,26 @@ def make_disease_diagnosis(source_name, target_doc=None):
}
}}, target_doc)

return target_doc
return target_doc

@frappe.whitelist()
def split_plant_batch(strain, start_date, location, split_count, new_batch_id=None, reference_name=None):
"""Split the plant batch into a new plant batch"""
prev_plant_batch = frappe.get_doc('Plant Batch', reference_name)

if prev_plant_batch.untracked_count < int(split_count):
frappe.throw(_("The Split count ({0}) should be less or equal to the untracked quantity ({1})").format(split_count, prev_plant_batch.untracked_count))

plant_batch = frappe.get_doc(
dict(doctype='Plant Batch',
title=new_batch_id,
strain = strain,
start_date = start_date,
untracked_count = split_count,
location = location)
).insert()

prev_plant_batch.untracked_count = prev_plant_batch.untracked_count - int(split_count)
prev_plant_batch.save()

return plant_batch.name

0 comments on commit 1b5887a

Please sign in to comment.