Exemple #1
0
def attach_file(doctype, docname, filedata):
	if not filedata: return


	fd_json = json.loads(filedata)
	fd_list = list(fd_json["files_data"])

	for fd in fd_list:
		attach_type = frappe.get_value("Tipo de Adjunto", fd["attach_type"], 
			["allow_more_than_one", "max_attacthments"], as_dict=True)

		file_list = frappe.get_list("File", { "file_name": ["like", "{}%".format(fd["filename"].split(".pdf")[0])]})

		if file_list:
			if (not attach_type.allow_more_than_one and len(file_list))\
				or\
			(attach_type.allow_more_than_one and attach_type.max_attacthments 
				and flt(attach_type.max_attacthments) <= len(file_list)):
				frappe.throw("No puede agregar mas adjuntos de este tipo")

			fd["filename"] = fd["filename"].replace(".pdf", "-{}.pdf".format(len(file_list)))
			fd["filename"] = s_sanitize(fd["filename"], upper=False)
		
		filedoc = save_file(fd["filename"], fd["dataurl"], 
			doctype, docname, decode=True, is_private=True)
    def after_rename(self, doctype, old_name, new_name):
        new_item_group_name = frappe.rename_doc(
            "Item Group", self.old_item_name,
            "{0}".format(s_sanitize(self.name, upper=False)))

        self.item_group = new_item_group_name

        self.db_update()
    def get_route(self):
        parent_route = ''

        parent_route = frappe.get_value("Item Group", _item_group, "route")

        item_group_route = pws.api.s_strip("{0}".format(
            s_sanitize(self.name, upper=False)))

        return "{0}/{1}".format(parent_route, item_group_route.lower())
    def create_item_group_if_not_exists(self):
        doc = frappe.new_doc("Item Group")

        item_group = frappe.get_value(
            "Item Group",
            {"item_group_name": s_sanitize(self.name, upper=False)}, ["name"])

        if item_group:
            doc = frappe.get_doc("Item Group", item_group)

        doc.update({
            "parent_item_group": _item_group,
            "item_group_name": s_sanitize(self.name, upper=False),
            "route": self.get_route(),
            "is_group": False
        })

        doc.save()

        # update this object too
        self.item_group = doc.name
        self.parent_item_group = doc.parent_item_group
Exemple #5
0
	def collect_names(self):
		self.item_name = frappe.get_value("Item", self.item, "item_name")		
		if "," in self.item_name:
			arr = self.item_name.split(',', 1)
			
			self.item_name = "{0} ({1}), {2}".format(arr[0], self.project_name, arr[1])
		else:
			self.item_name = "{0} ({1})".format(self.item_name, self.project_name)

		fields = ["project_type", "customer", "item_name", 
			"production_qty"]

		return "{0}: {1} - {2}, Cant. {3}".format(*[
			s_sanitize(self.get(field), upper=False) for field in fields])