示例#1
0
    def allocate_leave(self):
        self.validate_values()
        leave_allocated_for = []
        employees = self.get_employees()
        if not employees:
            dataent.throw(_("No employee found"))

        for d in self.get_employees():
            try:
                la = dataent.new_doc('Leave Allocation')
                la.set("__islocal", 1)
                la.employee = cstr(d[0])
                la.employee_name = dataent.db.get_value(
                    'Employee', cstr(d[0]), 'employee_name')
                la.leave_type = self.leave_type
                la.from_date = self.from_date
                la.to_date = self.to_date
                la.carry_forward = cint(self.carry_forward)
                la.new_leaves_allocated = flt(self.no_of_days)
                la.docstatus = 1
                la.save()
                leave_allocated_for.append(d[0])
            except:
                pass
        if leave_allocated_for:
            msgprint(
                _("Leaves Allocated Successfully for {0}").format(
                    comma_and(leave_allocated_for)))
示例#2
0
    def make_material_request(self):
        '''Create Material Requests grouped by Sales Order and Material Request Type'''
        material_request_list = []
        material_request_map = {}

        for item in self.mr_items:
            item_doc = dataent.get_cached_doc('Item', item.item_code)

            # key for Sales Order:Material Request Type
            key = '{}:{}'.format(item.sales_order,
                                 item_doc.default_material_request_type)
            schedule_date = add_days(nowdate(), cint(item_doc.lead_time_days))

            if not key in material_request_map:
                # make a new MR for the combination
                material_request_map[key] = dataent.new_doc("Material Request")
                material_request = material_request_map[key]
                material_request.update({
                    "transaction_date":
                    nowdate(),
                    "status":
                    "Draft",
                    "company":
                    self.company,
                    "requested_by":
                    dataent.session.user,
                    'material_request_type':
                    item_doc.default_material_request_type
                })
                material_request_list.append(material_request)
            else:
                material_request = material_request_map[key]

            # add item
            material_request.append("items", {
             "item_code": item.item_code,
             "qty": item.quantity,
             "schedule_date": schedule_date,
             "warehouse": item.warehouse,
             "sales_order": item.sales_order,
             'production_plan': self.name,
             'material_request_plan_item': item.name,
             "project": dataent.db.get_value("Sales Order", item.sales_order, "project") \
              if item.sales_order else None
            })

        for material_request in material_request_list:
            # submit
            material_request.flags.ignore_permissions = 1
            material_request.run_method("set_missing_values")
            material_request.submit()

        dataent.flags.mute_messages = False

        if material_request_list:
            material_request_list = ["""<a href="#Form/Material Request/{0}">{1}</a>""".format(m.name, m.name) \
             for m in material_request_list]
            msgprint(_("{0} created").format(comma_and(material_request_list)))
        else:
            msgprint(_("No material request created"))
示例#3
0
	def make_fee_records(self):
		from epaas.education.api import get_fee_components
		fee_list = []
		for d in self.fees:
			fee_components = get_fee_components(d.fee_structure)
			if fee_components:
				fees = dataent.new_doc("Fees")
				fees.update({
					"student": self.student,
					"academic_year": self.academic_year,
					"academic_term": d.academic_term,
					"fee_structure": d.fee_structure,
					"program": self.program,
					"due_date": d.due_date,
					"student_name": self.student_name,
					"program_enrollment": self.name,
					"components": fee_components
				})
				
				fees.save()
				fees.submit()
				fee_list.append(fees.name)
		if fee_list:
			fee_list = ["""<a href="#Form/Fees/%s" target="_blank">%s</a>""" % \
				(fee, fee) for fee in fee_list]
			msgprint(_("Fee Records Created - {0}").format(comma_and(fee_list)))
示例#4
0
    def check_email_id_is_unique(self):
        if self.email_id:
            names = dataent.db.sql_list(
                """select name from `tabJob Applicant`
				where email_id=%s and name!=%s and job_title=%s""",
                (self.email_id, self.name, self.job_title))

            if names:
                dataent.throw(
                    _("Email Address must be unique, already exists for {0}").
                    format(comma_and(names)), dataent.DuplicateEntryError)
示例#5
0
    def check_email_id_is_unique(self):
        if self.email_id:
            # validate email is unique
            duplicate_leads = dataent.db.sql_list(
                """select name from tabLead
				where email_id=%s and name!=%s""", (self.email_id, self.name))

            if duplicate_leads:
                dataent.throw(
                    _("Email Address must be unique, already exists for {0}"
                      ).format(comma_and(duplicate_leads)),
                    dataent.DuplicateEntryError)
示例#6
0
    def validate_exchange_rates_exist(self):
        """check if exchange rates exist for all Price List currencies (to company's currency)"""
        company_currency = dataent.get_cached_value('Company', self.company,
                                                    "default_currency")
        if not company_currency:
            msgprint(_("Please specify currency in Company") + ": " +
                     self.company,
                     raise_exception=ShoppingCartSetupError)

        price_list_currency_map = dataent.db.get_values(
            "Price List", [self.price_list], "currency")

        # check if all price lists have a currency
        for price_list, currency in price_list_currency_map.items():
            if not currency:
                dataent.throw(
                    _("Currency is required for Price List {0}").format(
                        price_list))

        expected_to_exist = [
            currency + "-" + company_currency
            for currency in price_list_currency_map.values()
            if currency != company_currency
        ]

        # manqala 20/09/2016: set up selection parameters for query from tabCurrency Exchange
        from_currency = [
            currency for currency in price_list_currency_map.values()
            if currency != company_currency
        ]
        to_currency = company_currency
        # manqala end

        if expected_to_exist:
            # manqala 20/09/2016: modify query so that it uses date in the selection from Currency Exchange.
            # exchange rates defined with date less than the date on which this document is being saved will be selected
            exists = dataent.db.sql_list(
                """select CONCAT(from_currency,'-',to_currency) from `tabCurrency Exchange`
				where from_currency in (%s) and to_currency = "%s" and date <= curdate()"""
                % (", ".join(["%s"] * len(from_currency)), to_currency),
                tuple(from_currency))
            # manqala end

            missing = list(set(expected_to_exist).difference(exists))

            if missing:
                msgprint(_("Missing Currency Exchange Rates for {0}").format(
                    comma_and(missing)),
                         raise_exception=ShoppingCartSetupError)
示例#7
0
    def make_work_order(self):
        wo_list = []
        self.validate_data()
        items_data = self.get_production_items()

        for key, item in items_data.items():
            work_order = self.create_work_order(item)
            if work_order:
                wo_list.append(work_order)

        dataent.flags.mute_messages = False

        if wo_list:
            wo_list = ["""<a href="#Form/Work Order/%s" target="_blank">%s</a>""" % \
             (p, p) for p in wo_list]
            msgprint(_("{0} created").format(comma_and(wo_list)))
        else:
            msgprint(_("No Work Orders created"))
示例#8
0
    def check_nextdoc_docstatus(self):
        # Checks Delivery Note
        submit_dn = dataent.db.sql_list(
            """
			select t1.name
			from `tabDelivery Note` t1,`tabDelivery Note Item` t2
			where t1.name = t2.parent and t2.against_sales_order = %s and t1.docstatus = 1""",
            self.name)

        if submit_dn:
            dataent.throw(
                _("Delivery Notes {0} must be cancelled before cancelling this Sales Order"
                  ).format(comma_and(submit_dn)))

        # Checks Sales Invoice
        submit_rv = dataent.db.sql_list(
            """select t1.name
			from `tabSales Invoice` t1,`tabSales Invoice Item` t2
			where t1.name = t2.parent and t2.sales_order = %s and t1.docstatus = 1""",
            self.name)

        if submit_rv:
            dataent.throw(
                _("Sales Invoice {0} must be cancelled before cancelling this Sales Order"
                  ).format(comma_and(submit_rv)))

        #check maintenance schedule
        submit_ms = dataent.db.sql_list(
            """
			select t1.name
			from `tabMaintenance Schedule` t1, `tabMaintenance Schedule Item` t2
			where t2.parent=t1.name and t2.sales_order = %s and t1.docstatus = 1""",
            self.name)

        if submit_ms:
            dataent.throw(
                _("Maintenance Schedule {0} must be cancelled before cancelling this Sales Order"
                  ).format(comma_and(submit_ms)))

        # check maintenance visit
        submit_mv = dataent.db.sql_list(
            """
			select t1.name
			from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2
			where t2.parent=t1.name and t2.prevdoc_docname = %s and t1.docstatus = 1""",
            self.name)

        if submit_mv:
            dataent.throw(
                _("Maintenance Visit {0} must be cancelled before cancelling this Sales Order"
                  ).format(comma_and(submit_mv)))

        # check work order
        pro_order = dataent.db.sql_list(
            """
			select name
			from `tabWork Order`
			where sales_order = %s and docstatus = 1""", self.name)

        if pro_order:
            dataent.throw(
                _("Work Order {0} must be cancelled before cancelling this Sales Order"
                  ).format(comma_and(pro_order)))