Exemplo n.º 1
0
 def throw_overlap_error(self, d):
     msg = _("Employee {0} has already applied for {1} on {2} : ").format(self.employee,
      d['shift_type'], formatdate(d['date'])) \
      + """ <b><a href="#Form/Shift Assignment/{0}">{0}</a></b>""".format(d["name"])
     dataent.throw(msg, OverlapError)
Exemplo n.º 2
0
 def validate_reference_doctype(self):
     if not dataent.get_meta(
             self.reference_doctype).has_field('auto_repeat'):
         dataent.throw(
             _("Add custom field Auto Repeat in the doctype {0}").format(
                 self.reference_doctype))
Exemplo n.º 3
0
 def validate_dates(self):
     if self.end_date and getdate(self.start_date) > getdate(self.end_date):
         dataent.throw(_("End date must be greater than start date"))
Exemplo n.º 4
0
def get_app_publisher(module):
    app = dataent.local.module_app[scrub(module)]
    if not app:
        dataent.throw(_("App not found"))
    app_publisher = dataent.get_hooks(hook="app_publisher", app_name=app)[0]
    return app_publisher
Exemplo n.º 5
0
def validate_queue(queue, default_queue_list=None):
	if not default_queue_list:
		default_queue_list = list(queue_timeout)

	if queue not in default_queue_list:
		dataent.throw(_("Queue should be one of {0}").format(', '.join(default_queue_list)))
Exemplo n.º 6
0
 def validate_dates(self):
     if getdate(self.start_date) > getdate(self.end_date):
         dataent.throw(_("End Date can not be less than Start Date"))
Exemplo n.º 7
0
	def validate_standard(self):
		if self.is_standard and not dataent.conf.developer_mode:
			dataent.throw(_('Cannot edit Standard Notification. To edit, please disable this and duplicate it'))
Exemplo n.º 8
0
 def validate_name_with_customer_group(self):
     if dataent.db.exists("Customer Group", self.name):
         dataent.throw(
             _("A Customer Group exists with same name please change the Customer name or rename the Customer Group"
               ), dataent.NameError)
Exemplo n.º 9
0
    def create_lead_address_contact(self):
        if self.lead_name:
            # assign lead address to customer (if already not set)
            address_names = dataent.get_all('Dynamic Link',
                                            filters={
                                                "parenttype": "Address",
                                                "link_doctype": "Lead",
                                                "link_name": self.lead_name
                                            },
                                            fields=["parent as name"])

            for address_name in address_names:
                address = dataent.get_doc('Address', address_name.get('name'))
                if not address.has_link('Customer', self.name):
                    address.append(
                        'links',
                        dict(link_doctype='Customer', link_name=self.name))
                    address.save()

            lead = dataent.db.get_value(
                "Lead",
                self.lead_name, [
                    "organization_lead", "lead_name", "email_id", "phone",
                    "mobile_no", "gender", "salutation"
                ],
                as_dict=True)

            if not lead.lead_name:
                dataent.throw(
                    _("Please mention the Lead Name in Lead {0}").format(
                        self.lead_name))

            if lead.organization_lead:
                contact_names = dataent.get_all('Dynamic Link',
                                                filters={
                                                    "parenttype": "Contact",
                                                    "link_doctype": "Lead",
                                                    "link_name": self.lead_name
                                                },
                                                fields=["parent as name"])

                for contact_name in contact_names:
                    contact = dataent.get_doc('Contact',
                                              contact_name.get('name'))
                    if not contact.has_link('Customer', self.name):
                        contact.append(
                            'links',
                            dict(link_doctype='Customer', link_name=self.name))
                        contact.save()

            else:
                lead.lead_name = lead.lead_name.split(" ")
                lead.first_name = lead.lead_name[0]
                lead.last_name = " ".join(lead.lead_name[1:])

                # create contact from lead
                contact = dataent.new_doc('Contact')
                contact.first_name = lead.first_name
                contact.last_name = lead.last_name
                contact.gender = lead.gender
                contact.salutation = lead.salutation
                contact.email_id = lead.email_id
                contact.phone = lead.phone
                contact.mobile_no = lead.mobile_no
                contact.is_primary_contact = 1
                contact.append(
                    'links', dict(link_doctype='Customer',
                                  link_name=self.name))
                contact.flags.ignore_permissions = self.flags.ignore_permissions
                contact.autoname()
                if not dataent.db.exists("Contact", contact.name):
                    contact.insert()
Exemplo n.º 10
0
def validate_fiscal_year(fiscal_year, from_fiscal_year, to_fiscal_year):
    if not fiscal_year.get('year_start_date') and not fiscal_year.get(
            'year_end_date'):
        dataent.throw(_("End Year cannot be before Start Year"))
Exemplo n.º 11
0
 def validate_values(self):
     if not self.weekly_off:
         throw(_("Please select weekly off day"))
Exemplo n.º 12
0
def sales_invoice_validate(doc):
    #Validate company
    if doc.doctype != 'Sales Invoice':
        return

    if not doc.company_address:
        dataent.throw(_("Please set an Address on the Company '%s'" %
                        doc.company),
                      title=_("E-Invoicing Information Missing"))
    else:
        validate_address(doc.company_address)

    company_fiscal_regime = dataent.get_cached_value("Company", doc.company,
                                                     'fiscal_regime')
    if not company_fiscal_regime:
        dataent.throw(
            _("Fiscal Regime is mandatory, kindly set the fiscal regime in the company {0}"
              ).format(doc.company))
    else:
        doc.company_fiscal_regime = company_fiscal_regime

    doc.company_tax_id = dataent.get_cached_value("Company", doc.company,
                                                  'tax_id')
    doc.company_fiscal_code = dataent.get_cached_value("Company", doc.company,
                                                       'fiscal_code')
    if not doc.company_tax_id and not doc.company_fiscal_code:
        dataent.throw(
            _("Please set either the Tax ID or Fiscal Code on Company '%s'" %
              doc.company),
            title=_("E-Invoicing Information Missing"))

    #Validate customer details
    customer = dataent.get_doc("Customer", doc.customer)

    if customer.customer_type == "Individual":
        doc.customer_fiscal_code = customer.fiscal_code
        if not doc.customer_fiscal_code:
            dataent.throw(_("Please set Fiscal Code for the customer '%s'" %
                            doc.customer),
                          title=_("E-Invoicing Information Missing"))
    else:
        if customer.is_public_administration:
            doc.customer_fiscal_code = customer.fiscal_code
            if not doc.customer_fiscal_code:
                dataent.throw(_(
                    "Please set Fiscal Code for the public administration '%s'"
                    % doc.customer),
                              title=_("E-Invoicing Information Missing"))
        else:
            doc.tax_id = customer.tax_id
            if not doc.tax_id:
                dataent.throw(_("Please set Tax ID for the customer '%s'" %
                                doc.customer),
                              title=_("E-Invoicing Information Missing"))

    if not doc.customer_address:
        dataent.throw(_("Please set the Customer Address"),
                      title=_("E-Invoicing Information Missing"))
    else:
        validate_address(doc.customer_address)

    if not len(doc.taxes):
        dataent.throw(
            _("Please set at least one row in the Taxes and Charges Table"),
            title=_("E-Invoicing Information Missing"))
    else:
        for row in doc.taxes:
            if row.rate == 0 and row.tax_amount == 0 and not row.tax_exemption_reason:
                dataent.throw(_(
                    "Row {0}: Please set at Tax Exemption Reason in Sales Taxes and Charges"
                    .format(row.idx)),
                              title=_("E-Invoicing Information Missing"))

    for schedule in doc.payment_schedule:
        if schedule.mode_of_payment and not schedule.mode_of_payment_code:
            schedule.mode_of_payment_code = dataent.get_cached_value(
                'Mode of Payment', schedule.mode_of_payment,
                'mode_of_payment_code')