Example #1
0
    def get_calendar_events(self, user_id):
        from core.doctype.event.event import get_events

        events = get_events(self.future_from_date, self.future_to_date)

        html = ""
        if events:
            for i, e in enumerate(events):
                if i >= 10:
                    break
                if e.all_day:
                    html += """<li style='line-height: 200%%'>%s [%s (%s)]</li>""" % (
                        e.subject,
                        datetime_in_user_format(e.starts_on),
                        _("All Day"),
                    )
                else:
                    html += "<li style='line-height: 200%%'>%s [%s - %s]</li>" % (
                        e.subject,
                        datetime_in_user_format(e.starts_on),
                        datetime_in_user_format(e.ends_on),
                    )

        if html:
            return 1, "<h4>Upcoming Calendar Events (max 10):</h4><ul>" + html + "</ul><hr>"
        else:
            return 0, "<p>Calendar Events</p>"
Example #2
0
    def validate_return_reference_doc(self):
        """validate item with reference doc"""
        ref = get_return_doclist_and_details(self.doc.fields)

        if ref.doclist:
            # validate docstatus
            if ref.doclist[0].docstatus != 1:
                webnotes.msgprint(
                    _(ref.doclist[0].doctype) + ' "' + ref.doclist[0].name + '": ' + _("Status should be Submitted"),
                    raise_exception=webnotes.InvalidStatusError,
                )

                # update stock check
            if ref.doclist[0].doctype == "Sales Invoice" and (
                cint(ref.doclist[0].is_pos) != 1 or cint(ref.doclist[0].update_stock) != 1
            ):
                webnotes.msgprint(
                    _(ref.doclist[0].doctype)
                    + ' "'
                    + ref.doclist[0].name
                    + '": '
                    + _("Is POS and Update Stock should be checked."),
                    raise_exception=NotUpdateStockError,
                )

                # posting date check
            ref_posting_datetime = "%s %s" % (
                cstr(ref.doclist[0].posting_date),
                cstr(ref.doclist[0].posting_time) or "00:00:00",
            )
            this_posting_datetime = "%s %s" % (cstr(self.doc.posting_date), cstr(self.doc.posting_time))
            if this_posting_datetime < ref_posting_datetime:
                from webnotes.utils.dateutils import datetime_in_user_format

                webnotes.msgprint(
                    _("Posting Date Time cannot be before") + ": " + datetime_in_user_format(ref_posting_datetime),
                    raise_exception=True,
                )

            stock_items = get_stock_items_for_return(ref.doclist, ref.parentfields)
            already_returned_item_qty = self.get_already_returned_item_qty(ref.fieldname)

            for item in self.doclist.get({"parentfield": "mtn_details"}):
                # validate if item exists in the ref doclist and that it is a stock item
                if item.item_code not in stock_items:
                    msgprint(
                        _("Item")
                        + ': "'
                        + item.item_code
                        + _('" does not exist in ')
                        + ref.doclist[0].doctype
                        + ": "
                        + ref.doclist[0].name,
                        raise_exception=webnotes.DoesNotExistError,
                    )

                    # validate quantity <= ref item's qty - qty already returned
                ref_item = ref.doclist.getone({"item_code": item.item_code})
                returnable_qty = ref_item.qty - flt(already_returned_item_qty.get(item.item_code))
                self.validate_value("transfer_qty", "<=", returnable_qty, item, raise_exception=StockOverReturnError)
Example #3
0
    def validate_return_reference_doc(self):
        """validate item with reference doc"""
        ref = get_return_doclist_and_details(self.doc.fields)

        if ref.doclist:
            # validate docstatus
            if ref.doclist[0].docstatus != 1:
                webnotes.msgprint(_(ref.doclist[0].doctype) + ' "' +
                                  ref.doclist[0].name + '": ' +
                                  _("Status should be Submitted"),
                                  raise_exception=webnotes.InvalidStatusError)

            # update stock check
            if ref.doclist[0].doctype == "Sales Invoice" and cint(
                    ref.doclist[0].update_stock) != 1:
                webnotes.msgprint(_(ref.doclist[0].doctype) + ' "' +
                                  ref.doclist[0].name + '": ' +
                                  _("Update Stock should be checked."),
                                  raise_exception=NotUpdateStockError)

            # posting date check
            ref_posting_datetime = "%s %s" % (cstr(
                ref.doclist[0].posting_date), cstr(ref.doclist[0].posting_time)
                                              or "00:00:00")
            this_posting_datetime = "%s %s" % (cstr(
                self.doc.posting_date), cstr(self.doc.posting_time))
            if this_posting_datetime < ref_posting_datetime:
                from webnotes.utils.dateutils import datetime_in_user_format
                webnotes.msgprint(
                    _("Posting Date Time cannot be before") + ": " +
                    datetime_in_user_format(ref_posting_datetime),
                    raise_exception=True)

            stock_items = get_stock_items_for_return(ref.doclist,
                                                     ref.parentfields)
            already_returned_item_qty = self.get_already_returned_item_qty(
                ref.fieldname)

            for item in self.doclist.get({"parentfield": "mtn_details"}):
                # validate if item exists in the ref doclist and that it is a stock item
                if item.item_code not in stock_items:
                    msgprint(_("Item") + ': "' + item.item_code +
                             _("\" does not exist in ") +
                             ref.doclist[0].doctype + ": " +
                             ref.doclist[0].name,
                             raise_exception=webnotes.DoesNotExistError)

                # validate quantity <= ref item's qty - qty already returned
                ref_item = ref.doclist.getone({"item_code": item.item_code})
                returnable_qty = ref_item.qty - flt(
                    already_returned_item_qty.get(item.item_code))
                self.validate_value("transfer_qty",
                                    "<=",
                                    returnable_qty,
                                    item,
                                    raise_exception=StockOverReturnError)
Example #4
0
	def get_calendar_events(self, user_id):
		from core.doctype.event.event import get_events
		events = get_events(self.future_from_date.strftime("%Y-%m-%d"), self.future_to_date.strftime("%Y-%m-%d"))
		
		html = ""
		if events:
			for i, e in enumerate(events):
				if i>=10:
					break
				if e.all_day:
					html += """<li style='line-height: 200%%'>%s [%s (%s)]</li>""" % \
						(e.subject, datetime_in_user_format(e.starts_on), _("All Day"))
				else:
					html += "<li style='line-height: 200%%'>%s [%s - %s]</li>" % \
						(e.subject, datetime_in_user_format(e.starts_on), datetime_in_user_format(e.ends_on))
		
		if html:
			return 1, "<h4>Upcoming Calendar Events (max 10):</h4><ul>" + html + "</ul><hr>"
		else:
			return 0, "<p>Calendar Events</p>"
Example #5
0
	def validate_return_reference_doc(self):
		"""validate item with reference doc"""
		ref = get_return_doclist_and_details(self.doc.fields)

		if ref.doclist:
			# validate docstatus
			if ref.doclist[0].docstatus != 1:
				webnotes.msgprint(_(ref.doclist[0].doctype) + ' "' + ref.doclist[0].name + '": '
					+ _("Status should be Submitted"), raise_exception=webnotes.InvalidStatusError)

			# update stock check
			if ref.doclist[0].doctype == "Sales Invoice" and cint(ref.doclist[0].update_stock) != 1:
				webnotes.msgprint(_(ref.doclist[0].doctype) + ' "' + ref.doclist[0].name + '": '
					+ _("Update Stock should be checked."),
					raise_exception=NotUpdateStockError)

			# posting date check
			ref_posting_datetime = "%s %s" % (cstr(ref.doclist[0].posting_date),
				cstr(ref.doclist[0].posting_time) or "00:00:00")
			this_posting_datetime = "%s %s" % (cstr(self.doc.posting_date),
				cstr(self.doc.posting_time))
			if this_posting_datetime < ref_posting_datetime:
				from webnotes.utils.dateutils import datetime_in_user_format
				webnotes.msgprint(_("Posting Date Time cannot be before")
					+ ": " + datetime_in_user_format(ref_posting_datetime),
					raise_exception=True)

			stock_items = get_stock_items_for_return(ref.doclist, ref.parentfields)
			already_returned_item_qty = self.get_already_returned_item_qty(ref.fieldname)

			for item in self.doclist.get({"parentfield": "mtn_details"}):
				# validate if item exists in the ref doclist and that it is a stock item
				if item.item_code not in stock_items:
					msgprint(_("Item") + ': "' + item.item_code + _("\" does not exist in ") +
						ref.doclist[0].doctype + ": " + ref.doclist[0].name,
						raise_exception=webnotes.DoesNotExistError)

				# validate quantity <= ref item's qty - qty already returned
				ref_item_qty = sum([flt(d.qty) for d in ref.doclist.get({"item_code": item.item_code})])
				returnable_qty = ref_item_qty - flt(already_returned_item_qty.get(item.item_code))
				if not returnable_qty:
					webnotes.throw("{item}: {item_code} {returned}".format(
						item=_("Item"), item_code=item.item_code,
						returned=_("already returned though some other documents")),
						StockOverReturnError)
				elif item.transfer_qty > returnable_qty:
					webnotes.throw("{item}: {item_code}, {returned}: {qty}".format(
						item=_("Item"), item_code=item.item_code,
						returned=_("Max Returnable Qty"), qty=returnable_qty), StockOverReturnError)