Exemplo n.º 1
0
	def create_user(self):
		doctype = "User"
		if db.exists(doctype, self.user):
			return

		user = frappe.new_doc(doctype)

		user.update({
			"email": self.user,
			"first_name": self.first_name,
			"last_name": self.last_name,
			"full_name": self.full_name,
			"enabled": 1 if self.status == "Active" else 0,
			"username": self.full_name.replace(" ", "_"),
		})

		new_role = _("Resident")

		if not db.exists("Role", new_role):
			frappe.get_doc({
				"doctype": "Role",
				"role_name": new_role
			}).save(ignore_permissions=True)

		user.add_roles(new_role)
		user.save(ignore_permissions=True)
Exemplo n.º 2
0
    def validate_if_exists(self):
        doctype = self.doctype
        name = self.generate_autoname()

        reversed_name = self.generate_autoname(reversed=True)

        error_message = """
            Se encontró una {doctype} en el sistema que coincide 
            con estos valores: <br>
            <a href="{url_to_form}"><strong>{doctype}</strong>: {name}</a>
        """

        exists = database.exists(doctype, name)
        exists_in_reversed = database.exists(doctype, reversed_name)

        if not exists and not exists_in_reversed:
            return

        if not self.is_new() and self.name == name:
            return

        url_to_form = frappe.utils.get_url_to_form(
            doctype, reversed_name if exists_in_reversed else name)

        frappe.throw(
            error_message.format(
                doctype=doctype,
                url_to_form=url_to_form,
                name=reversed_name if exists_in_reversed else name))
Exemplo n.º 3
0
    def create_customer_if_not_exists(self):
        party_doctype = "Customer"

        filters = {
            "tax_id": self.tax_id,
        }

        doc = frappe.new_doc(party_doctype)

        if db.exists(party_doctype, filters):
            doc = frappe.get_doc(party_doctype, filters)

        doc.update({
            "customer_name": self.full_name,
            "customer_type": "Individual",
            "tax_id": self.tax_id,
            "customer_phones": [],
            "customer_reference": [],
        })

        self.add_customer_numbers(doc)
        self.add_customer_references(doc, "guarantor_1")
        self.add_customer_references(doc, "guarantor_2")
        self.add_customer_references(doc, "guarantor_3")

        self.add_customer_references(doc, "co_debtor", True)

        # let's make sure that the customer saves
        doc.flags.ignore_mandatory = True
        doc.flags.ignore_permissions = True

        self.customer = doc.name

        doc.save()
Exemplo n.º 4
0
    def get_item(source_doc):
        ref_doctype = "Product Assembly"
        ref_docname = source_doc.product_assembly

        doctype = "Item"
        filters = {
            "ref_doctype": ref_doctype,
            "ref_docname": ref_docname,
        }

        errmsg = translate("Item not found for Product Assembly: {}")
        if not database.exists(doctype, filters):
            frappe.throw(errmsg.format(ref_docname))

        item_doc = frappe.get_doc(doctype, filters)

        args = {
            "item_code": item_doc.name,
            "item_name": item_doc.item_name,
            "parent": target_doc.name,
            "parentfield": "items",
            "parenttype": "Quotation",
            "description": source_doc.product_assembly_specification,
            "company": defaults.company,
            "doctype": "Quotation",
            "currency": source_doc.currency,
            "qty": source_doc.qty_to_produce,
            "rate": source_doc.rate_per_unit,
        }

        return get_item_details(args)
Exemplo n.º 5
0
    def generate_hash_and_validate(self):

        # don't validate for compound products
        unique_hash = self.generate_hash()

        doctype = self.doctype
        filters = {
            "unique_hash": unique_hash,
        }

        if not self.is_new():
            filters.update({
                "name": ["!=", self.name]
            })

        exists = cstr(database.exists(doctype, filters))

        url_to_form = frappe.utils.get_url_to_form(doctype, exists)

        err_msg = """
            Ya existe un Producto con las mismas especificaciones
            <br>
            <strong>{doctype}</strong>
            <a href="{url_to_form}">{name}</a>
        """

        if exists and not self.is_compound_product:
            frappe.throw(
                err_msg
                .format(doctype=translate(doctype),
                        url_to_form=url_to_form,
                        name=exists)
            )

        self.unique_hash = unique_hash
Exemplo n.º 6
0
    def update_naming_series(self):
        setter = frappe.new_doc("Property Setter")

        filters = {
            'doc_type': "Sales Invoice",
            'field_name': 'naming_series',
            'doctype_or_field': 'DocField',
            'property': "options",
            'property_type': "Select"
        }

        if database.exists("Property Setter", filters):
            setter = frappe.get_doc("Property Setter", filters)

        series = [""]

        series += self.get_series()

        setter.update({
            'doc_type': "Sales Invoice",
            'field_name': 'naming_series',
            'doctype_or_field': 'DocField',
            'property': "options",
            'property_type': "Select",
            'value': "\n".join(series)
        })

        setter.save()

        database.commit()
Exemplo n.º 7
0
def update_tasks(doc):
    doctype = "Project Template"
    docname = doc.project_template

    if not docname:
        return False

    template = frappe.get_doc(doctype, docname)

    # update tasks from template
    for task in template.tasks:
        doctype = "Task"
        filters = {
            "subject": task.subject,
            "project": doc.name,
            "task_weight": task.task_weight,
        }

        exists = database.exists(doctype, filters)

        if not exists:
            continue

        taskdoc = frappe.get_doc(doctype, filters)

        taskdoc.update({
            "department": doc.department,
            "idx": task.idx,
        })

        taskdoc.flags.ignore_permissions = True
        taskdoc.save()
Exemplo n.º 8
0
    def get_linked_production_order(self):
        doctype = "Production Order"
        filters = {"project_center": self.name}

        if not database.exists(doctype, filters):
            return None

        return frappe.get_value(doctype, filters)
Exemplo n.º 9
0
def get_loan_record(doc):
    import fimax.utils

    doctype = "Loan Record"

    if not db.exists(doctype, doc.name):
        return fimax.utils.create_loan_record(doc)

    return get_doc(doctype, doc.name)
Exemplo n.º 10
0
	def update_status(self):
		doctype = "User"
		if not db.exists(doctype, self.user):
			return

		user = frappe.get_doc(doctype, self.user)
		user.enabled = 1 if self.status == "Active" else 0

		user.save(ignore_permissions=True)
Exemplo n.º 11
0
def add_reqd_custom_fields_in_user():
    if db.exists("Custom Field", "User-dark_theme"):
        return

    from condos import user_custom_fields

    for docdict in user_custom_fields:
        frappe.get_doc(docdict) \
         .save(ignore_permissions=True)
Exemplo n.º 12
0
def get_party_details(party=None,
                      party_type="Customer",
                      ignore_permissions=False):

    if not party:
        return {}

    if not db.exists(party_type, party):
        frappe.throw(_("{0}: {1} does not exists").format(party_type, party))

    return _get_party_details(party, party_type, ignore_permissions)
Exemplo n.º 13
0
def set_creator_object(doc):
    doctype = doc.ref_doctype
    docname = doc.ref_docname

    if doctype and docname:
        if database.exists(doctype, docname):
            creator_doc = get_doc(doctype, docname)

            doc.set_onload("creator", creator_doc)
            doc.set_onload("is_child_creator", False)
    else:
        doc.set_onload("creator", {})

    childdoctype = doc.ref_childtype
    childdocname = doc.ref_childname

    if childdoctype and childdocname:
        if database.exists(childdoctype, childdocname):
            creator_doc = get_doc(childdoctype, childdocname)

            doc.set_onload("creator", creator_doc)
            doc.set_onload("is_child_creator", False)
Exemplo n.º 14
0
def execute():
    core = "DocType"
    doctype = "Paperboard Caliper"

    if not database.exists(core, doctype):
        return False

    database.sql("""
        Update `tab{0}`
            Set caliper_uom = capliper_uom
        Where
            caliper_uom is null
            And capliper_uom is not null
    """.format(doctype))
Exemplo n.º 15
0
def upadte_item_price(item, price_list, per_unit_price):
	if db.exists("Item Price",{"item_code":item,"price_list":price_list}):
		name = db.get_value("Item Price",{"item_code":item,"price_list":price_list},'name')
		db.set_value("Item Price",name,"price_list_rate", per_unit_price)
	else:
		item_price = frappe.new_doc("Item Price")
		item_price.price_list = price_list
		item_price.item_code = item
		item_price.price_list_rate = per_unit_price
		
		item_price.save()
	db.commit()
		
	return "Item Price Updated!"
Exemplo n.º 16
0
def get_item_group_doc(item_group):
    doctype = "Item Group"
    filters = {
        "item_group_name": item_group,
    }

    exists = database.exists(doctype, filters)

    doc = frappe.new_doc(doctype)

    if exists:
        doc = frappe.get_doc(doctype, filters)

    return doc
Exemplo n.º 17
0
        def get_product_features(item_code):
            doctype = "Item"
            name = item_code
            fields = ("ref_doctype", "ref_docname")

            ref_doctype, ref_docname = database.get_value(
                doctype, name, fields)

            if not ref_doctype or not ref_docname \
                    or not database.exists(ref_doctype, ref_docname):
                return []

            doc = frappe.get_doc(ref_doctype, ref_docname)

            options = doc.get_full_product_options()

            return options.split(", ")
Exemplo n.º 18
0
def update_status_to_loan_charges():
    """Update status for each Loan Charge based on the current
				date and the paid amount"""

    for doc in get_valid_loan_charges():

        if not db.exists(doc.doctype, doc.name):
            continue

        # it exists, so then let's get it
        doc = get_doc(doc.doctype, doc.name)

        doc.run_method("update_references", cancel=False)

        doc.run_method("update_status")

        # submit to update the database
        doc.submit()
Exemplo n.º 19
0
def execute():
    doctype = "Paperboard"

    if not database.exists("DocType", doctype):
        return False

    doclist = frappe.get_all(doctype)

    for opts in doclist:
        doc = frappe.get_doc(doctype, opts)

        oldname = doc.name
        newname = doc.title

        if newname == oldname:
            continue

        frappe.rename_doc(doctype, newname, oldname, force=True)
Exemplo n.º 20
0
def get_item_doc(doctype, docname, cdt=None, cdn=None):
    item_doctype = "Item"

    filters = {
        "ref_doctype": doctype,
        "ref_docname": docname,
    }

    if cdt and cdn:
        filters.update({
            "ref_childtype": cdt,
            "ref_childname": cdn,
        })

    if database.exists(item_doctype, filters):
        return get_doc(item_doctype, filters)

    return frappe.new_doc(item_doctype)
Exemplo n.º 21
0
    def validate_if_doc_exists(self):
        item_doc = self.get_item_doc()

        doctype = item_doc.ref_doctype
        name = item_doc.ref_docname

        errmsg = translate("This Item cannot be used as it does "
                           "not have a Product Profile")

        if not doctype or not name:
            frappe.throw(errmsg)

        errmsg = translate(
            "This Item cannot be used as its "
            "references to a Product Profile does not exist anymore")

        if not database.exists(doctype, name):
            frappe.throw(errmsg)
def execute():
    if not database.exists("DocType", "List of Material Detail"):
        return False

    doctype = "List of Material Detail"
    doclist = frappe.get_all(doctype, as_list=True)

    for name, in doclist:
        doc = frappe.get_doc(doctype, name)

        if doc.naming_selection \
                or doc.naming_series:
            continue

        doc.naming_selection = "Naming Series"
        doc.naming_series = "LIST-OF-MATERIAL-DETAIL-"

        doc.db_update()
Exemplo n.º 23
0
    def validate_if_exists(self):
        doctype = self.doctype
        name = self.generate_autoname()

        url_to_form = frappe.utils.get_url_to_form(doctype, name)

        error_message = """
            Se encontró una {doctype} en el sistema que coincide 
            con estos valores: <br>
            <a href="{url_to_form}"><strong>{doctype}</strong>: {name}</a>
        """

        if not database.exists(doctype, name):
            return

        frappe.throw(
            error_message.format(doctype=doctype,
                                 url_to_form=url_to_form,
                                 name=name))
Exemplo n.º 24
0
def add_reqd_roles():
    """adds default roles for the app to run"""

    from condos.controllers.role import create_simple_role

    doctype, role_list = "Role", (
        _("Tenant"),
        _("Leaser"),
        _("Supervisor"),
        _("Employee"),
        _("Maintainer"),
        _("Web User"),
    )

    for role in role_list:
        if db.exists(doctype, role):
            continue

        create_simple_role(role) \
         .save(ignore_permissions=True)
Exemplo n.º 25
0
	def onclick_update_price(self):
		if self.item_price:
			if db.exists("Item Price" ,{ "item_code":self.item_code ,"price_list":self.price_list}):
				item_price = frappe.get_doc("Item Price",{"item_code":self.item_code, "price_list":self.price_list})
				item_price.price_list_rate = self.item_price
				if self.link_to == "Supplier" and self.price_list == "Standard Buying":
					item_price.supplier = self.party
				elif self.link_to == "Customer" and self.price_list == "Standard Selling":
					item_price.customer = self.party
				item_price.save()
			else:
				item_price = frappe.new_doc("Item Price")
				item_price.price_list = self.price_list
				item_price.item_code = self.item_code
				item_price.price_list_rate = self.item_price
				if self.link_to == "Supplier" and self.price_list == "Standard Buying":
					item_price.supplier = self.party
				elif self.link_to == "Customer" and self.price_list == "Standard Selling":
					item_price.customer = self.party
				item_price.save()
			frappe.msgprint("Item Price Updated")
Exemplo n.º 26
0
 def on_submit(self):
     data = frappe.get_list("Item Price", fields='item_code')
     if db.exists("Item Price", {
             "item_code": self.product_name,
             "price_list": self.price_list
     }):
         item_price = frappe.get_doc("Item Price", {
             "item_code": self.product_name,
             "price_list": self.price_list
         })
         item_price.price_list_rate = self.price
         item_price.price_list = self.price_list
         item_price.save()
     else:
         item_price = frappe.new_doc("Item Price")
         item_price.price_list = self.price_list
         item_price.item_code = self.product_name
         item_price.price_list_rate = self.price
         item_price.save()
     frappe.db.commit()
     frappe.msgprint(_("Item Price Updated"))
Exemplo n.º 27
0
    def get_compound_product(self, throw_error=True):
        if not self.is_compound_product:
            if throw_error:
                err_msg = translate(
                    "Product Assembly must be a marked as Compound Product")

                frappe.throw(err_msg)

            return False

        doctype = "Compound Product"
        filters = {
            "product_profile": self.product_profile,
            "product_assembly": self.name,
        }

        if not database.exists(doctype, filters):
            err_msg = translate(
                "A Compound Product linked to this "
                "Product Assembly does not exist")

            frappe.throw(err_msg)

        return frappe.get_doc(doctype, filters)
Exemplo n.º 28
0
        def fetch_default_rate(product_option, option, options):
            doctype = "Product Feature"
            name = product_option
            fieldname = "materials"

            if not database.exists(doctype, name):
                option.rate = 0.0000

                return option.rate

            del options[product_option]

            doc = frappe.get_doc(doctype, name)

            # total = .000
            for supply in doc.get(fieldname):
                doctype = "List of Material Detail"
                name = supply.list_of_material_detail
                fields = ("last_purchase_rate", "qty", "fixed_qty")

                values = frappe \
                    .get_value(doctype, name, fields, as_dict=True)

                # total += flt(values.last_purchase_rate) * flt(values.qty)

                if not name in options:
                    options[name] = pydict(qty=0, rate=.000)

                option = options[name]

                # option.cost_specification = "{}: {}".format(
                #     product_option, name)
                option.cost_specification = cstr(name)
                option.qty = flt(values.qty)
                option.rate = flt(values.last_purchase_rate)
                option.fixed_qty = values.fixed_qty
Exemplo n.º 29
0
    def fetch_product_assembly(self):
        doctype = self.meta \
            .get_field("product_assembly") \
            .options

        docname = self.product_assembly

        if docname:
            product_assembly = frappe \
                .get_doc(doctype, docname)

            if not product_assembly.is_compound_product:
                self.set_assembly_onload(product_assembly)
                return [product_assembly]

            doctype = "Compound Product"
            filters = {
                "enabled": True,
                "product_assembly": self.product_assembly,
            }

            errmsg = \
                translate("The Product you're trying to estimate is marked "
                          "as Compound Product, but no Enabled Compound "
                          "Product template was found")

            if not database.exists(doctype, filters):
                frappe.throw(errmsg)

            product_compound = frappe.get_doc(doctype, filters)

            sub_assemblies = [
                d.get_product_assembly() for d in product_compound.parts
            ]

            self.set_assembly_onload(product_assembly, sub_assemblies)
Exemplo n.º 30
0
def create_report_files(site_name, report_name):
    # users can change the installation path, the operating
    # user or even have multiple benchs running in the same instance.

    # by default it is located at `/home/frappe/frappe-bench`

    # so, lets make sure we get the right path

    # get the base `frappe-bench` path where the system
    # is installed

    _base_path = frappe.utils.get_bench_path()

    # scrub to remove any trailing spaces or if it is a more complex name
    # by more than one word

    # we just want to make sure and do anything we can to guess
    # what the user wants and do it right

    _site_name = frappe.scrub(site_name)

    _sites_path = "/".join([_base_path, "sites"])

    # lets bring all the frappe sites setup on this instance

    _all_sites = frappe.utils \
     .get_sites(sites_path=_sites_path)

    # if the site does not exist in this instance
    # exit and let the user know

    if _site_name not in _all_sites:
        print ("Site {site} does not exist" \
         .format(site=_site_name))
        sys_exit()

    if _site_name != "all":
        _all_sites = [_site_name]

    module_exists = False

    for site in _all_sites:

        # initialize frappe for the current site.
        # reset thread locals `frappe.local`

        frappe.init(site=site, sites_path=_sites_path)

        # connect to site database instance
        # frappe.connect will try to init again
        # this is fine as we don't any other solution by now

        frappe.connect(site=site)

        # we now can import the frappe.db object

        from frappe import db

        # if the report exists in at least one site
        # that could mean we are posibly overriding the content
        # of the controllers

        # so, lets make sure that this never happens
        # if we prove it to be true, we don't want to write to the files
        # this is why we use two loops

        if not db.exists("Report", {
                "report_name": report_name,
        }):
            # mark the flag as true

            module_exists = True

            # and skip this round

        report = frappe.get_doc("Report", report_name)

        report_path = frappe.get_module_path(report.module, "report",
                                             report_name)

        frappe.create_folder(report_path, with_init=True)

        report.create_report_py()

        # lets close the connection and release werkzeug local

        frappe.destroy()