def get_filters(self):
        from_date = self.from_date
        to_date = self.to_date
        sales_order = self.sales_order
        item_code = self.item_code
        customer = self.customer

        filters = pydict()

        if from_date and to_date:
            filters.expected_start_date = ["Between", [from_date, to_date]]

        if from_date and not to_date:
            filters.expected_start_date = [">=", from_date]

        if not from_date and to_date:
            filters.expected_start_date = ["<=", to_date]

        if sales_order:
            filters.sales_order = sales_order

        if item_code:
            filters.item_code = item_code

        if customer:
            filters.customer = customer

        return filters
Esempio n. 2
0
    def get_full_specifications(self, dont_generate=False):
        if dont_generate:
            return self.full_specifications or self.product_profile

        if not self.is_compound_product:
            full_name = self.get_full_name()

            return "{0}.".format(full_name)

        if self.is_new():
            return ""

        compound_product = self.get_compound_product()

        template = "templates/product_specifications_template.html"

        specs = list()

        for part in compound_product.parts:
            spec = pydict()

            if part.part_name:
                spec.part_name = part.part_name

            spec.qty = part.qty
            spec.description = part.product_specification

            specs.append(spec)

        opts = {
            "product_profile": self.product_profile,
            "specs": specs,
        }

        return frappe.render_template(template, opts)
Esempio n. 3
0
def get_data_to_ask(doc):
    from json import loads
    doc.reload()

    opts = list()

    for childoc in doc.data_to_ask:
        doctype = "Data to Ask"
        name = childoc.data_to_ask

        data_to_ask = frappe.get_doc(doctype, name)

        df = pydict()

        # magic begins
        df.data_to_ask = data_to_ask.data_to_ask

        df.source_doctype = data_to_ask.source_doctype
        df.docname_field = data_to_ask.docname_field
        df.source_docfield = loads(data_to_ask.source_docfield)
        df.target_doctype = data_to_ask.target_doctype
        df.target_fieldname = data_to_ask.target_fieldname

        opts.append(df)

    return frappe.as_json(opts)
        def get_grouped_by_request_type():
            material_groups = pydict()
            for material in self.planning_materials:
                if not material_groups.get(material.request_type):
                    material_groups[material.request_type] = list()

                material_groups.get(material.request_type) \
                    .append(material)

            return material_groups
Esempio n. 5
0
def get_current_item_group_code(parent_item_group):
    filters = pydict(parent_item_group=parent_item_group)

    result = database.sql(
        """
        Select
            Max(item_group_code)
        From
            `tabItem Group`
        Where
            parent_item_group = %(parent_item_group)s
    """, filters)

    return cint(result[0][0])
Esempio n. 6
0
    def set_operations(self, assembly=None):
        self.operations = list()

        if not assembly:
            assembly = self.get_product_assembly()

        errmsg = \
            translate("Product Assembly: {} is marked as a Compound Product "
                      "and it has not operations available. You should "
                      "consider creating individual Production Orders for"
                      "each part.")

        if assembly.is_compound_product:
            frappe.throw(errmsg.format(assembly.name))

        def get_department(option):
            doctype = "Product Feature"
            name = option
            fieldname = "department"
            return database.get_value(doctype, name, fieldname)

        def get_parent_department(option):
            name = get_department(option)

            doctype = "Department"
            fieldname = "parent_department"

            return database.get_value(doctype, name, fieldname)

        def get_work_station(option):
            doctype = "Product Feature"
            name = option
            fieldname = "default_work_station"

            return database.get_value(doctype, name, fieldname)

        options = assembly.get_product_options()

        for option in options.split(", "):
            operation = pydict()

            operation.production_order = self.name
            operation.product_feature = option
            operation.department = get_department(option)
            operation.parent_department = get_parent_department(option)
            operation.work_station = get_work_station(option)

            self.append("operations", operation)
Esempio n. 7
0
    def fetch_cost_estimation_type(self):
        doctype = self.meta \
            .get_field("cost_estimation_type") \
            .options

        docname = self.cost_estimation_type

        cost_estimation_type = pydict()

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

            self.set_last_purchase_rate(cost_estimation_type)

        self.set_onload("cost_estimation_type", cost_estimation_type)
        def add_material(material, feature, project_center):
            from math import ceil

            planning_material = pydict()

            planning_material.item = material.item
            planning_material.item_specs = material.item_name
            planning_material.qty = ceil(material.qty * project_center.qty)
            planning_material.uom = material.uom
            planning_material.warehouse = self.warehouse

            planning_material.request_type = get_default_request_type()
            planning_material.project_center = project_center.project_center
            planning_material.expected_on = get_expected_start_date(
                project_center.project_center)

            self.append("planning_materials", planning_material)
Esempio n. 9
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
Esempio n. 10
0
    def set_assembly_onload(self, product_assembly, sub_assemblies=None):
        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

        is_compound_product = product_assembly.is_compound_product

        errmsg = \
            translate("You've passed a Compound Product as a "
                      "Product Assembly but no Sub Assemblies were passed")

        if is_compound_product and sub_assemblies is None:
            frappe.throw(errmsg)

        options = pydict()
        if is_compound_product:
            assembly_specifications = ", ".join(
                (d.get_full_name() for d in sub_assemblies))

            # assembly_options = ", ".join(
            #     (d.get_product_options() for d in sub_assemblies))

            # group by options
            for sub_assembly in sub_assemblies:
                product_options = sub_assembly.get_product_options()
                for product_option in product_options.split(", "):
                    if not product_option in options:
                        options[product_option] = pydict(qty=0, rate=.000)

                    option = options[product_option]

                    option.qty += 1
                    fetch_default_rate(product_option, option, options)

            assembly_options = list()
            for key in options.keys():
                newdict = options[key]
                newdict.setdefault("cost_specification", key)

                assembly_options.append(newdict)

        else:
            assembly_specifications = product_assembly \
                .get_full_name()

            # assembly_options = product_assembly \
            #     .get_product_options()

            product_options = product_assembly.get_product_options()
            for product_option in product_options.split(", "):
                if not product_option in options:
                    options[product_option] = pydict(qty=0, rate=.000)

                option = options[product_option]

                option.qty += 1
                fetch_default_rate(product_option, option, options)

            assembly_options = list()
            for key in options.keys():
                newdict = options[key]
                newdict.setdefault("cost_specification", key)

                assembly_options.append(newdict)

        final_dimension = product_assembly.dimension

        self.set_onload("product_assembly", product_assembly)

        if is_compound_product:
            self.set_onload("sub_assemblies", sub_assemblies)

        self.set_onload("assembly_specifications", assembly_specifications)

        self.set_onload("assembly_options", assembly_options)

        # # temporary update of product_assembly_specification
        # if not self.product_assembly_specification == assembly_specifications:
        #     self.db_set("product_assembly_specification",
        #                 assembly_specifications, update_modified=False)

        # temporary update of final_dimension
        if not self.final_dimension == final_dimension \
                and not self.is_new():
            self.db_set("final_dimension",
                        final_dimension,
                        update_modified=False)