예제 #1
0
	def test_item_variant_by_manufacturer(self):
		if frappe.db.exists('Item', '_Test Variant Mfg'):
			frappe.delete_doc('Item', '_Test Variant Mfg')
		if frappe.db.exists('Item', '_Test Variant Mfg-1'):
			frappe.delete_doc('Item', '_Test Variant Mfg-1')
		if frappe.db.exists('Manufacturer', 'MSG1'):
			frappe.delete_doc('Manufacturer', 'MSG1')

		template = frappe.get_doc(dict(
			doctype='Item',
			item_code='_Test Variant Mfg',
			has_variant=1,
			item_group='Products',
			variant_based_on='Manufacturer'
		)).insert()

		manufacturer = frappe.get_doc(dict(
			doctype='Manufacturer',
			short_name='MSG1'
		)).insert()

		variant = get_variant(template.name, manufacturer=manufacturer.name)
		self.assertEquals(variant.item_code, '_Test Variant Mfg-1')
		self.assertEquals(variant.description, '_Test Variant Mfg')
		self.assertEquals(variant.get("manufacturers")[0].manufacturer, 'MSG1')
		variant.insert()

		variant = get_variant(template.name, manufacturer=manufacturer.name,
			manufacturer_part_no='007')
		self.assertEquals(variant.item_code, '_Test Variant Mfg-2')
		self.assertEquals(variant.description, '_Test Variant Mfg')
		self.assertEquals(variant.get("manufacturers")[0].manufacturer, 'MSG1')
		self.assertEquals(variant.get("manufacturers")[0].manufacturer_part_no, '007')
예제 #2
0
	def test_item_variant_by_manufacturer(self):
		if frappe.db.exists('Item', '_Test Variant Mfg'):
			frappe.delete_doc('Item', '_Test Variant Mfg')
		if frappe.db.exists('Item', '_Test Variant Mfg-1'):
			frappe.delete_doc('Item', '_Test Variant Mfg-1')
		if frappe.db.exists('Manufacturer', 'MSG1'):
			frappe.delete_doc('Manufacturer', 'MSG1')

		template = frappe.get_doc(dict(
			doctype='Item',
			item_code='_Test Variant Mfg',
			has_variant=1,
			item_group='Products',
			variant_based_on='Manufacturer'
		)).insert()

		manufacturer = frappe.get_doc(dict(
			doctype='Manufacturer',
			short_name='MSG1'
		)).insert()

		variant = get_variant(template.name, manufacturer=manufacturer.name)
		self.assertEquals(variant.item_code, '_Test Variant Mfg-1')
		self.assertEquals(variant.description, '_Test Variant Mfg')
		self.assertEquals(variant.manufacturer, 'MSG1')
		variant.insert()

		variant = get_variant(template.name, manufacturer=manufacturer.name,
			manufacturer_part_no='007')
		self.assertEquals(variant.item_code, '_Test Variant Mfg-2')
		self.assertEquals(variant.description, '_Test Variant Mfg')
		self.assertEquals(variant.manufacturer, 'MSG1')
		self.assertEquals(variant.manufacturer_part_no, '007')
예제 #3
0
def create_variant_item(**filters):
    if not filters.get("item_code") or not filters.get(
            "attr_type") or not filters.get("attr_value"):
        return
    item = frappe.get_doc("Item", filters.get("item_code"))
    if not item.variant_of:
        return
    args = {filters.get('attr_type'): filters.get("attr_value")}
    args = get_variant_attribute_args(item, args)
    variant = get_variant(item.variant_of, args)
    if variant:
        variant = frappe.get_doc("Item", variant)
    else:
        template = check_and_create_attribute(item.variant_of)
        args = update_missing_variant_attrs(item, template, args)
        variant = create_variant(template.name, args)
        size = get_size_from_item(item)
        weight = get_weight_from_item(item)
        variant.valuation_rate = (size * weight * 0.250) + item.valuation_rate
    if filters.get('valuation_rate'):
        variant.valuation_rate = filters.get('valuation_rate')
    variant.ashbee_bar = item.ashbee_bar
    variant.ashbee_weight = item.ashbee_weight
    variant.save()
    return variant
예제 #4
0
 def check_paper(self):
     for new_paper in self.new_papers:
         attributes = new_paper.bf_gsm_deck.strip().split("-")
         if (len(attributes) != 3): continue
         args = {
             "Colour": new_paper.colour,
             "BF": attributes[0],
             "GSM": attributes[1],
             "Deck": attributes[2]
         }
         new_paper.paper = get_variant("PPR", args)
예제 #5
0
	def validate_variant_attributes(self):
		if self.variant_of:
			args = {}
			for d in self.attributes:
				if not d.attribute_value:
					frappe.throw(_("Please specify Attribute Value for attribute {0}").format(d.attribute))
				args[d.attribute] = d.attribute_value

			variant = get_variant(self.variant_of, args, self.name)
			if variant:
				frappe.throw(_("Item variant {0} exists with same attributes")
					.format(variant), ItemVariantExistsError)
예제 #6
0
파일: item.py 프로젝트: venetanji/erpnext
	def validate_variant_attributes(self):
		if self.variant_of:
			args = {}
			for d in self.attributes:
				if not d.attribute_value:
					frappe.throw(_("Please specify Attribute Value for attribute {0}").format(d.attribute))
				args[d.attribute] = d.attribute_value

			variant = get_variant(self.variant_of, args, self.name)
			if variant:
				frappe.throw(_("Item variant {0} exists with same attributes")
					.format(variant), ItemVariantExistsError)			
예제 #7
0
파일: test_item.py 프로젝트: ankush/erpnext
    def test_item_variant_by_manufacturer(self):
        fields = [{
            "field_name": "description"
        }, {
            "field_name": "variant_based_on"
        }]
        set_item_variant_settings(fields)

        if frappe.db.exists("Item", "_Test Variant Mfg"):
            frappe.delete_doc("Item", "_Test Variant Mfg")
        if frappe.db.exists("Item", "_Test Variant Mfg-1"):
            frappe.delete_doc("Item", "_Test Variant Mfg-1")
        if frappe.db.exists("Manufacturer", "MSG1"):
            frappe.delete_doc("Manufacturer", "MSG1")

        template = frappe.get_doc(
            dict(
                doctype="Item",
                item_code="_Test Variant Mfg",
                has_variant=1,
                item_group="Products",
                variant_based_on="Manufacturer",
            )).insert()

        manufacturer = frappe.get_doc(
            dict(doctype="Manufacturer", short_name="MSG1")).insert()

        variant = get_variant(template.name, manufacturer=manufacturer.name)
        self.assertEqual(variant.item_code, "_Test Variant Mfg-1")
        self.assertEqual(variant.description, "_Test Variant Mfg")
        self.assertEqual(variant.manufacturer, "MSG1")
        variant.insert()

        variant = get_variant(template.name,
                              manufacturer=manufacturer.name,
                              manufacturer_part_no="007")
        self.assertEqual(variant.item_code, "_Test Variant Mfg-2")
        self.assertEqual(variant.description, "_Test Variant Mfg")
        self.assertEqual(variant.manufacturer, "MSG1")
        self.assertEqual(variant.manufacturer_part_no, "007")
예제 #8
0
	def validate_variant_attributes(self):
		if self.variant_of:
			args = {}
			for d in self.attributes:
				if not d.attribute_value:
					frappe.throw(_("Please specify Attribute Value for attribute {0}").format(d.attribute))
				args[d.attribute] = d.attribute_value

			if self.variant_of:
				# test this during insert because naming is based on item_code and we cannot use condition like self.name != variant
				variant = get_variant(self.variant_of, args)
				if variant and self.get("__islocal"):
					frappe.throw(_("Item variant {0} exists with same attributes").format(variant), ItemVariantExistsError)
예제 #9
0
	def validate_variant_attributes(self):
		if self.is_new() and self.variant_of and self.variant_based_on == 'Item Attribute':
			args = {}
			for d in self.attributes:
				if cstr(d.attribute_value).strip() == '':
					frappe.throw(_("Please specify Attribute Value for attribute {0}").format(d.attribute))
				args[d.attribute] = d.attribute_value

			variant = get_variant(self.variant_of, args, self.name)
			if variant:
				frappe.throw(_("Item variant {0} exists with same attributes")
					.format(variant), ItemVariantExistsError)

			validate_item_variant_attributes(self, args)
예제 #10
0
def get_finished_variant_item(**filters):
    if not filters.get("item_code") or not filters.get(
            "attr_type") or not filters.get("attr_value"):
        return
    item = frappe.get_doc("Item", filters.get("item_code"))
    if not item.variant_of:
        return
    template = frappe.get_doc("Item", item.variant_of)
    args = update_missing_variant_attrs(
        item, template, {filters.get("attr_type"): filters.get("attr_value")})
    variant = get_variant(item.variant_of, args)
    if variant:
        variant = frappe.get_doc("Item", variant)
        return {'name': variant.name, 'rate': variant.valuation_rate}
예제 #11
0
def create_new_paper(bf_gsm_deck, color):
    attributes = bf_gsm_deck.strip().split("-")
    if (len(attributes) != 3):
        frappe.throw("Argument isn't in the right format(BF-GSM-Deck)")
    args = {
        "Colour": color,
        "BF": attributes[0],
        "GSM": attributes[1],
        "Deck": attributes[2]
    }
    if (get_variant("PPR", args) != None):
        frappe.throw("Paper {0} is already present".format(bf_gsm_deck))
    print("Creating the new paper {0}".format(args))
    paper = create_variant("PPR", args)
    paper.save()
    paper_mgmnt = frappe.get_doc("CM Paper Management", "Paper Management")
    paper_mgmnt.update_paper_rate()
    return paper.name
예제 #12
0
def lancer(groupe):
	if not groupe:
		frappe.msgprint(_("Groupe est invalide"))
		return None
#	try:
	refs = []
	items = frappe.db.get_all("Article Excel",filters={'groupe_article':groupe },fields=['designation_commerciale','oem_simplifie','name','version','generation','modele','groupe_article','oem', 'moog','bosch','mahle','mahle_2','meyle','era','bga','gsp','corteco','magneti_marelli','mann_filtre','clean_filters','hengst_filter','hengst_filter_2','champion'])
	oems = set(i.oem_simplifie for i in items)
	#frappe.msgprint(len(oems) + " oem")
	doc_groupe = frappe.get_doc('Item Group',groupe)
	result = ''
	frappe.msgprint("Operation encours, vous devez laisser la page ouverte")
	for oem in oems:
		#self.titre = "En cours..."
		if not oem:
			continue
		#tpl = tuple([e.name for e in al])
		all_models = frappe.db.get_all('OEM',filters={'oem_simplifie':oem},fields=['name'])
		if all_models and len(all_models) > 0:
			continue
		model = frappe.new_doc('Item')
		#result += doc_groupe.name
		model.has_variants = 1
		model.variant_based_on = 'Manufacturer'
		model.item_code = 'code'
		model.generer_code_interne = 1
		model.item_name =  doc_groupe.name
		model.item_group = doc_groupe.name
		model.is_purchase_item = 1
		model.is_sales_item = 1
		#model.designation_commerciale = oem.designation_commerciale
		model.adresse_magasin = "NA"
		model.nom_generique_long = model.item_name
		#myversions = [v for v in items if v.oem == oem]
		myversions = list(filter(lambda x: x.oem_simplifie == oem,items))
		#frappe.msgprint((oem))
		if myversions:
			model.designation_commerciale = myversions[0].designation_commerciale
		if oem:
			row = model.append('oem')
			row.oem_simplifie=oem
			full_oem = [r for r in items if r.oem_simplifie == oem]
			if full_oem:
				row.oem = full_oem[0].oem
		for version in myversions:
			#frappe.msgprint(str(version.version))
			#ver = frappe.get_doc('Version vehicule',version.version)
			#frappe.msgprint(str(ver))
			if version.version:
				model.append('versions',{
                       		'version_vehicule':version.version
                       		})
			elif version.generation:
				model.append('generation_vehicule_supporte',{
				'generation_vehicule':version.generation
				})
			elif version.modele:
				model.append('modele_vehicule_supporte',{
				'modele_vehicule':version.modele
				})
		model.save()
		#frappe.msgprint(model.name)
		#frappe.db.commit()
		items_oem = frappe.db.get_all('Article Excel',filters={'oem_simplifie':oem},fields=['oem_simplifie','name','bga','version','generation','modele','groupe_article','oem', 'moog','bosch','mahle','meyle','era','gsp','corteco','magneti_marelli','mann_filtre','clean_filters','hengst_filter','hengst_filter_2','mahle_2','champion'])
		#frappe.msgprint(str(len(items_oem)))
		result = ''
		for o in items_oem:
			filters = [o.moog,o.bosch,o.mahle,o.mahle_2,o.meyle,o.era,o.gsp,o .corteco,o.bga,o.magneti_marelli,o.mann_filtre,o.clean_filters,o.hengst_filter,o.hengst_filter_2,o.champion]
			not_null_filters =list([x for x in filters if x is not None and x != ''])
			#frappe.msgprint(' '.join(not_null_filters))
			exist = []
			exist = frappe.db.get_all('Item',filters={'manufacturer_part_no':('in',not_null_filters),'has_variants':0},fields=['name'])
			#frappe.msgprint('items with ref: '+o.oem+' '+str('[%s]' % ', '.join(map(str, exist)))+' n '+str(len(exist)))
			if exist and len(exist) > 0:
				#result += str(' - '.join(exist))
				frappe.delete_doc('Article Excel', o.name)
				continue
			if o.moog:
				#exist = frappe.db.get_all('Item',filters={'manufacturer_part_no':o.moog},fields=['namr'])
				variant1 = get_variant(template=model.name,manufacturer='MOOG',manufacturer_part_no=o.moog)
				variant1.save()
				#frappe.db.commit()
			if o.bosch:
				variant2 = get_variant(template=model.name,manufacturer='BOSCH',manufacturer_part_no=o.bosch)
               	        	variant2.save()
			if o.mahle:
               	        	variant3 = get_variant(template=model.name,manufacturer='MAHLE',manufacturer_part_no=o.mahle)
               	        	variant3.save()
			if o.mahle_2:
                              	variant3 = get_variant(template=model.name,manufacturer='MAHLE',manufacturer_part_no=o.mahle_2)
                           	variant3.save()
			if o.meyle:
               	        	variant4 = get_variant(template=model.name,manufacturer='MEYLE',manufacturer_part_no=o.meyle)
               	        	variant4.save()
			if o.era:
               	        	variant5 = get_variant(template=model.name,manufacturer='ERA',manufacturer_part_no=o.era)
               	        	variant5.save()
			if o.gsp:
               	        	variant6 = get_variant(template=model.name,manufacturer='GSP',manufacturer_part_no=o.gsp)
               	        	variant6.save()
			if o.corteco:
               	        	variant7 = get_variant(template=model.name,manufacturer='CORTECO',manufacturer_part_no=o.corteco)
               	        	variant7.save()
			if o.bga:
               	        	variant8 = get_variant(template=model.name,manufacturer='BGA',manufacturer_part_no=o.bga)
               	        	variant8.save()
			if o.magneti_marelli:
               	        	variant9 = get_variant(template=model.name,manufacturer='MAGNETI MARELLI',manufacturer_part_no=o.magneti_marelli)
               	        	variant9.save()
			if o.mann_filtre:
               	        	variant10 = get_variant(template=model.name,manufacturer='MANN FILTRE',manufacturer_part_no=o.mann_filtre)
               	        	variant10.save()
			if o.clean_filters:
               	        	variant11 = get_variant(template=model.name,manufacturer='CLEAN FILTERS',manufacturer_part_no=o.clean_filters)
               	       		variant11.save()
			if o.hengst_filter:
               	        	variant11 = get_variant(template=model.name,manufacturer='HENGST FILTER',manufacturer_part_no=o.hengst_filter)
               	    		variant11.save()
			if o.hengst_filter_2:
                               	variant11 = get_variant(template=model.name,manufacturer='HENGST FILTER',manufacturer_part_no=o.hengst_filter_2)
                               	variant11.save()
			if o.champion:
               	        	variant11 = get_variant(template=model.name,manufacturer='CHAMPION',manufacturer_part_no=o.champion)
               	        	variant11.save()
			frappe.db.commit()
			frappe.delete_doc('Article Excel', o.name)
			#frappe.db.commit()
		
	frappe.msgprint("OK... operation termine")
	return "Termine "+result