Example #1
0
def name_sales_invoice(doc, action):
    abbr = frappe.get_cached_value('Company', doc.company, 'abbr')
    fy = get_fiscal_year_short_form()
    if doc.is_pos:
        doc.name = parse_naming_series(f'{abbr}POSI{fy}-.######')
    else:
        doc.name = parse_naming_series(f'{abbr}SI{fy}-.######')
Example #2
0
	def test_rename_entries(self):
		je = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 100, submit=True)
		rename_gle_sle_docs()
		naming_series = parse_naming_series(parts=frappe.get_meta("GL Entry").autoname.split(".")[:-1])

		je = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 100, submit=True)

		gl_entries = frappe.get_all("GL Entry",
			fields=["name", "to_rename"],
			filters={"voucher_type": "Journal Entry", "voucher_no": je.name},
			order_by="creation"
		)
		self.assertTrue(all(entry.to_rename == 1 for entry in gl_entries))
		old_naming_series_current_value = frappe.db.sql("SELECT current from tabSeries where name = %s", naming_series)[0][0]

		rename_gle_sle_docs()

		new_gl_entries = frappe.get_all("GL Entry",
			fields=["name", "to_rename"],
			filters={"voucher_type": "Journal Entry", "voucher_no": je.name},
			order_by="creation"
		)
		self.assertTrue(all(entry.to_rename == 0 for entry in new_gl_entries))

		self.assertTrue(all(new.name != old.name for new, old in zip(gl_entries, new_gl_entries)))

		new_naming_series_current_value = frappe.db.sql("SELECT current from tabSeries where name = %s", naming_series)[0][0]
		self.assertEquals(old_naming_series_current_value + 2, new_naming_series_current_value)
Example #3
0
    def parse_naming_series(self, prefix):
        parts = prefix.split('.')
        if parts[-1] == "#" * len(parts[-1]):
            del parts[-1]

        pre = parse_naming_series(parts)
        return pre
Example #4
0
    def parse_naming_series(self):
        parts = self.prefix.split('.')

        # Remove ### from the end of series
        if parts[-1] == "#" * len(parts[-1]):
            del parts[-1]

        prefix = parse_naming_series(parts)
        return prefix
Example #5
0
	def parse_naming_series(self):
		parts = self.prefix.split('.')

		# Remove ### from the end of series
		if parts[-1] == "#" * len(parts[-1]):
			del parts[-1]

		prefix = parse_naming_series(parts)
		return prefix
Example #6
0
    def parse_naming_series_custom(self):
        parts = self.custom_prefix.split('.')
        # If series contain date format like INV.YYYY.MM.#####
        if len(parts) > 2:
            del parts[-1]  # Removed ### from the series
            prefix = parse_naming_series(parts)
        else:
            prefix = parts[0]

        return prefix
	def parse_naming_series(self):
		parts = self.prefix.split('.')
		# If series contain date format like INV.YYYY.MM.#####
		if len(parts) > 2:
			del parts[-1] # Removed ### from the series
			prefix = parse_naming_series(parts)
		else:
			prefix = parts[0]

		return prefix
Example #8
0
	def test_naming_series(self):
		data = ["TEST-", "TEST/17-18/.test_data./.####", "TEST.YYYY.MM.####"]

		for series in data:
			name = make_autoname(series)
			prefix = series

			if ".#" in series:
				prefix = series.rsplit('.',1)[0]

			prefix = parse_naming_series(prefix)
			old_current = frappe.db.get_value('Series', prefix, "current", order_by="name")

			revert_series_if_last(series, name)
			new_current = cint(frappe.db.get_value('Series', prefix, "current", order_by="name"))

			self.assertEqual(cint(old_current) - 1, new_current)
    def apply(self, doc):
        """
		Apply naming rules for the given document. Will set `name` if the rule is matched.
		"""
        if self.conditions:
            if not evaluate_filters(
                    doc, [(self.document_type, d.field, d.condition, d.value)
                          for d in self.conditions]):
                return

        counter = frappe.db.get_value(
            self.doctype, self.name, "counter", for_update=True) or 0
        naming_series = parse_naming_series(self.prefix, doc=doc)

        doc.name = naming_series + ("%0" + str(self.prefix_digits) +
                                    "d") % (counter + 1)
        frappe.db.set_value(self.doctype, self.name, "counter", counter + 1)
Example #10
0
	def test_naming_series(self):
		data = ["TEST-", "TEST/17-18/.test_data./.####", "TEST.YYYY.MM.####"]

		for series in data:
			name = make_autoname(series)
			prefix = series

			if ".#" in series:
				prefix = series.rsplit('.',1)[0]

			prefix = parse_naming_series(prefix)
			old_current = frappe.db.get_value('Series', prefix, "current", order_by="name")

			revert_series_if_last(series, name)
			new_current = cint(frappe.db.get_value('Series', prefix, "current", order_by="name"))

			self.assertEqual(cint(old_current) - 1, new_current)
Example #11
0
def name_pos_invoice(doc, action):
    fy = get_fiscal_year_short_form()
    abbr = frappe.get_cached_value('Company', doc.company, 'abbr')
    doc.name = parse_naming_series(f"{abbr}POI{fy}-.######")
Example #12
0
def name_purchase_receipt(doc, action):
    fy = get_fiscal_year_short_form()
    abbr = frappe.get_cached_value('Company', doc.company, 'abbr')
    doc.name = parse_naming_series(f"{abbr}PR{fy}-.######")
Example #13
0
def name_sales_order(doc, action):
    fy = get_fiscal_year_short_form()
    abbr = frappe.get_cached_value('Company', doc.company, 'abbr')
    doc.name = parse_naming_series(f"{abbr}SO{fy}-.######")