Fetch same items multiple times from source doc if all qty not processed
This commit is contained in:
parent
0dab40f4a1
commit
802b4359b5
@ -55,7 +55,8 @@ class Task(Document):
|
|||||||
def update_depends_on(self):
|
def update_depends_on(self):
|
||||||
depends_on_tasks = ""
|
depends_on_tasks = ""
|
||||||
for d in self.depends_on:
|
for d in self.depends_on:
|
||||||
depends_on_tasks += d.task + ","
|
if d.task:
|
||||||
|
depends_on_tasks += d.task + ","
|
||||||
self.depends_on_tasks = depends_on_tasks
|
self.depends_on_tasks = depends_on_tasks
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
|
|||||||
@ -153,22 +153,37 @@ erpnext.utils.map_current_doc = function(opts) {
|
|||||||
frappe.get_meta(items_doctype).fields.forEach(function(d) {
|
frappe.get_meta(items_doctype).fields.forEach(function(d) {
|
||||||
if(d.options===opts.source_doctype) link_fieldname = d.fieldname; });
|
if(d.options===opts.source_doctype) link_fieldname = d.fieldname; });
|
||||||
|
|
||||||
// search in existing items if the source_name is already set
|
// search in existing items if the source_name is already set and full qty fetched
|
||||||
var already_set = false;
|
var already_set = false;
|
||||||
|
var item_qty_map = {};
|
||||||
|
|
||||||
$.each(cur_frm.doc.items, function(i, d) {
|
$.each(cur_frm.doc.items, function(i, d) {
|
||||||
if(d[link_fieldname]==opts.source_name) {
|
if(d[link_fieldname]==opts.source_name) {
|
||||||
already_set = true;
|
already_set = true;
|
||||||
return false;
|
if (item_qty_map[d.item_code])
|
||||||
|
item_qty_map[d.item_code] += flt(d.qty);
|
||||||
|
else
|
||||||
|
item_qty_map[d.item_code] = flt(d.qty);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(already_set) {
|
if(already_set) {
|
||||||
frappe.msgprint(__("You have already selected items from {0} {1}",
|
frappe.model.with_doc(opts.source_doctype, opts.source_name, function(r) {
|
||||||
[opts.source_doctype, opts.source_name]));
|
var source_doc = frappe.model.get_doc(opts.source_doctype, opts.source_name);
|
||||||
return;
|
$.each(source_doc.items || [], function(i, row) {
|
||||||
}
|
if(row.qty > flt(item_qty_map[row.item_code])) {
|
||||||
|
already_set = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
if(already_set) {
|
||||||
|
frappe.msgprint(__("You have already selected items from {0} {1}",
|
||||||
|
[opts.source_doctype, opts.source_name]));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import get_datetime
|
from frappe.utils import getdate
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
class AcademicTerm(Document):
|
class AcademicTerm(Document):
|
||||||
@ -18,16 +18,18 @@ class AcademicTerm(Document):
|
|||||||
self.title = self.academic_year + " ({})".format(self.term_name) if self.term_name else ""
|
self.title = self.academic_year + " ({})".format(self.term_name) if self.term_name else ""
|
||||||
|
|
||||||
#Check that start of academic year is earlier than end of academic year
|
#Check that start of academic year is earlier than end of academic year
|
||||||
if self.term_start_date and self.term_end_date and self.term_start_date > self.term_end_date:
|
if self.term_start_date and self.term_end_date \
|
||||||
|
and getdate(self.term_start_date) > getdate(self.term_end_date):
|
||||||
frappe.throw(_("The Term End Date cannot be earlier than the Term Start Date. Please correct the dates and try again."))
|
frappe.throw(_("The Term End Date cannot be earlier than the Term Start Date. Please correct the dates and try again."))
|
||||||
|
|
||||||
"""Check that the start of the term is not before the start of the academic year and end of term is not after
|
# Check that the start of the term is not before the start of the academic year
|
||||||
the end of the academic year"""
|
# and end of term is not after the end of the academic year"""
|
||||||
|
|
||||||
year = frappe.get_doc("Academic Year",self.academic_year)
|
year = frappe.get_doc("Academic Year",self.academic_year)
|
||||||
if self.term_start_date and get_datetime(year.year_start_date) and (self.term_start_date < get_datetime(year.year_start_date)):
|
if self.term_start_date and getdate(year.year_start_date) and (getdate(self.term_start_date) < getdate(year.year_start_date)):
|
||||||
frappe.throw(_("The Term Start Date cannot be earlier than the Year Start Date of the Academic Year to which the term is linked (Academic Year {}). Please correct the dates and try again.").format(self.academic_year))
|
frappe.throw(_("The Term Start Date cannot be earlier than the Year Start Date of the Academic Year to which the term is linked (Academic Year {}). Please correct the dates and try again.").format(self.academic_year))
|
||||||
|
|
||||||
if self.term_end_date and get_datetime(year.year_end_date) and (self.term_end_date > get_datetime(year.year_end_date)):
|
if self.term_end_date and getdate(year.year_end_date) and (getdate(self.term_end_date) > getdate(year.year_end_date)):
|
||||||
frappe.throw(_("The Term End Date cannot be later than the Year End Date of the Academic Year to which the term is linked (Academic Year {}). Please correct the dates and try again.").format(self.academic_year))
|
frappe.throw(_("The Term End Date cannot be later than the Year End Date of the Academic Year to which the term is linked (Academic Year {}). Please correct the dates and try again.").format(self.academic_year))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user