예제 #1
0
def custom_autoname(self, method):
    from frappe.model.naming import getseries
    #Series for Seal Kit = SK, Series for Host Assembly = HA
    if self.ht_product_type == 'Seal Kit':
        self.name = 'SK' + "-" + str(getseries('SK', 5))
    if self.ht_product_type == 'Host Assembly':
        self.name = 'HA' + "-" + str(getseries('HA', 5))
예제 #2
0
    def test_format_autoname(self):
        '''
		Test if braced params are replaced in format autoname
		'''
        doctype = 'ToDo'

        todo_doctype = frappe.get_doc('DocType', doctype)
        todo_doctype.autoname = 'format:TODO-{MM}-{status}-{##}'
        todo_doctype.save()

        description = 'Format'

        todo = frappe.new_doc(doctype)
        todo.description = description
        todo.insert()

        series = getseries('', 2)

        series = str(int(series) - 1)

        if len(series) < 2:
            series = '0' + series

        self.assertEqual(
            todo.name, 'TODO-{month}-{status}-{series}'.format(
                month=now_datetime().strftime('%m'),
                status=todo.status,
                series=series))
예제 #3
0
    def update_customer_address(self, newdn, set_field, abbr):
        # ERPNext
        # frappe.db.sql("""update `tabAddress` set address_title=%(newdn)s
        # 	{set_field} where customer=%(newdn)s"""\
        # 	.format(set_field=set_field), ({"newdn": newdn}))
        """
			rename all the addresses
		"""
        # get all the addresses which needs to be rename
        condn = abbr + "%"
        addresses = frappe.db.sql(
            """SELECT name FROM tabAddress addr WHERE customer='%s' AND name NOT LIKE '%s' ORDER BY name ASC"""
            % (newdn, condn))

        for address in addresses:
            # rename the address
            current_series = abbr + getseries(abbr, 4, '')
            frappe.db.sql(
                """update `tabAddress` set location_id=%(current_series)s, name=%(current_series)s
				{set_field} where name=%(address)s""".format(set_field=set_field),
                ({
                    "newdn": newdn,
                    "current_series": current_series,
                    "address": address
                }))
예제 #4
0
	def test_format_autoname(self):
		'''
		Test if braced params are replaced in format autoname
		'''
		doctype = 'ToDo'

		todo_doctype = frappe.get_doc('DocType', doctype)
		todo_doctype.autoname = 'format:TODO-{MM}-{status}-{##}'
		todo_doctype.save()

		description = 'Format'

		todo = frappe.new_doc(doctype)
		todo.description = description
		todo.insert()

		series = getseries('', 2, doctype)

		series = str(int(series)-1)

		if len(series) < 2:
			series = '0' + series

		self.assertEqual(todo.name, 'TODO-{month}-{status}-{series}'.format(
			month=now_datetime().strftime('%m'), status=todo.status, series=series))
예제 #5
0
    def test_format_autoname(self):
        """
		Test if braced params are replaced in format autoname
		"""
        doctype = "ToDo"

        todo_doctype = frappe.get_doc("DocType", doctype)
        todo_doctype.autoname = "format:TODO-{MM}-{status}-{##}"
        todo_doctype.save()

        description = "Format"

        todo = frappe.new_doc(doctype)
        todo.description = description
        todo.insert()

        series = getseries("", 2)

        series = str(int(series) - 1)

        if len(series) < 2:
            series = "0" + series

        self.assertEqual(
            todo.name,
            "TODO-{month}-{status}-{series}".format(
                month=now_datetime().strftime("%m"),
                status=todo.status,
                series=series),
        )
예제 #6
0
    def test_format_autoname_for_consecutive_week_number(self):
        """
		Test if braced params are replaced for consecutive week number in format autoname
		"""
        doctype = "ToDo"

        todo_doctype = frappe.get_doc("DocType", doctype)
        todo_doctype.autoname = "format:TODO-{WW}-{##}"
        todo_doctype.save()

        description = "Format"

        todo = frappe.new_doc(doctype)
        todo.description = description
        todo.insert()

        series = getseries("", 2)

        series = str(int(series) - 1)

        if len(series) < 2:
            series = "0" + series

        week = determine_consecutive_week_number(now_datetime())

        self.assertEqual(
            todo.name, "TODO-{week}-{series}".format(week=week, series=series))
예제 #7
0
 def autoname(self):
     pref = ""
     if self.type == 'Standard':
         pref += 'STD'
     elif self.type == 'Drawing':
         pref += 'DWG'
     series = get_default_naming_series(self.doctype)
     digits = getseries(series, 3)
     pref += str(digits)
     chk_digit = fn_check_digit(self, pref)
     name = pref + str(chk_digit)
     self.name = name
예제 #8
0
def populate_item_code(self, method):
    from frappe.model.naming import getseries
    parent_group_code = frappe.db.sql(
        """\
			select makwiz_item_group_code from `tabItem Group` where item_group_name = ( select parent_item_group
from `tabItem Group` where item_group_name = %s)""", (self.item_group))
    if (parent_group_code[0][0] == 'C' or parent_group_code[0][0] == 'R'):
        Item_code = str(parent_group_code[0][0]) + str(
            self.makwiz_item_group_code) + str(
                getseries("item_series_number", 4))
    else:
        Item_code = self.item_code

    self.item_code = Item_code
    self.name = self.item_code
예제 #9
0
def validate(self, method):
    # customer code set by user
    # if customer is setting the code, naming series may not follow, and may not be unique
    if self.supplier_code:
        return

    if not self.territory:
        frappe.throw(_("Please select territory"))

    abbr = frappe.db.get_value('Territory',
                               filters={'name': self.territory},
                               fieldname='consoleerp_abbr')
    if not abbr:
        frappe.throw("Define abbreviation for territory")

    # frappe naming module
    from frappe.model.naming import getseries
    # takes key, number of digits as args
    naming_series = "SUPP-" + abbr + "-"
    self.supplier_code = naming_series + getseries(naming_series, 5)