def make_child_variant(parent, template_name):
    if print_debug: frappe.logger().debug("***make_child_variant***")

    #mapper selon le noms des attributes
    attribute_map = {}
    child_attributes = get_item_variant_attributes_values(template_name)
    parent_attributes = get_item_variant_attributes_values(parent.item_code)
    for child_attribute in child_attributes:
        for item_attribute in parent_attributes:
            #if child_attribute[0] == item_attribute[0] and item_attribute[3] == 0:
            if child_attribute[0] == item_attribute[0]:
                attribute_map[child_attribute[0]] = child_attribute[0]

    #mapper selon la configuration dans la bd
    attribute_map_bd = get_attribute_mapping(parent.variant_of, template_name)
    if attribute_map_bd:
        attribute_map.update(attribute_map_bd)
    parent_attributes_dict = {i[0]: i[1] for i in parent_attributes}
    args = {}
    for key, value in attribute_map.iteritems():
        att_value = get_attribute_value_mapping(parent.variant_of,
                                                template_name, key, value,
                                                parent_attributes_dict[key])
        args[value] = att_value

    return create_variant_and_submit(template_name, args)
Example #2
0
def make_child_variant(parent, template_name):
    if print_debug: frappe.errprint("make_child_variant:")

    #mapper selon le noms des attributes
    attribute_map = {}
    child_attributes = get_item_variant_attributes_values(template_name)
    parent_attributes = get_item_variant_attributes_values(parent.item_code)
    for child_attribute in child_attributes:
        for item_attribute in parent_attributes:
            if print_debug: frappe.errprint("attribute: " + item_attribute[0])
            if print_debug:
                frappe.errprint("Uninheritable: " + cstr(item_attribute[3]))
            #if child_attribute[0] == item_attribute[0] and item_attribute[3] == 0:
            if child_attribute[0] == item_attribute[0]:
                attribute_map[child_attribute[0]] = child_attribute[0]

    if print_debug: frappe.errprint("parent: " + cstr(parent.variant_of))
    if print_debug: frappe.errprint("template_name: " + cstr(template_name))
    if print_debug: frappe.errprint("attribute_map: " + cstr(attribute_map))
    #mapper selon la configuration dans la bd
    attribute_map_bd = get_attribute_mapping(parent.variant_of, template_name)
    if attribute_map_bd:
        attribute_map.update(attribute_map_bd)
    if print_debug: frappe.errprint("attribute_map: " + cstr(attribute_map))
    if print_debug:
        frappe.errprint("parent_attributes:" + str(parent_attributes))
    parent_attributes_dict = {i[0]: i[1] for i in parent_attributes}
    if print_debug:
        frappe.errprint("parent_attributes_dict:" +
                        str(parent_attributes_dict))
    args = {}
    for key, value in attribute_map.iteritems():
        att_value = get_attribute_value_mapping(parent.variant_of,
                                                template_name, key, value,
                                                parent_attributes_dict[key])
        args[value] = att_value

        if print_debug:
            frappe.errprint("value: " + parent_attributes_dict[key])
        if print_debug: frappe.errprint("value_map: " + att_value)

    # for child_attribute in child_attributes:
    # for item_attribute in parent_attributes:
    # if child_attribute[0] == item_attribute[0]:
    # args[child_attribute[0]] = item_attribute[1]
    if print_debug: frappe.errprint(args)
    return create_variant_and_submit(template_name, args)
def get_hash_code(template_name, attribute_value_list):

    if isinstance(template_name, basestring):
        att_str = template_name
    else:
        att_str = template_name.name
    #att_str = template_name
    attributes = get_item_variant_attributes_values(template_name)

    frappe.errprint("attributes: " + cstr(attributes))
    frappe.errprint("attribute_value_list: " + cstr(attribute_value_list))
    for value in attribute_value_list:
        att_str += value

    bytes = att_str.encode("UTF-8")
    hash_object = hashlib.md5(bytes)
    return hash_object.hexdigest()