Ejemplo n.º 1
0
    def findQuotesFromCSV(self, csvfile):
        try:
            with open(csvfile, 'r', encoding='utf-8') as f:
                reader = csv.reader(f, dialect="excel-tab")
                extmaterials = []
                for row in reader:
                    try:
                        orderNum = row[0]
                        itemCode = row[1]
                        quantity = float(row[2])
                        unit = row[3]
                        material = Material()
                        material.setItemCode(itemCode)
                        extendedMaterial = ExtMaterials(material)
                        extendedMaterial.setOrderNumber(orderNum)
                        extendedMaterial.setUnit(unit)
                        extendedMaterial.setQuantity(quantity)
                        extmaterials.append(extendedMaterial)

                    except ValueError:
                        logging.info(
                            'There is a wrong data format entry. Please check')
                        continue

                self.rfq.setMaterialList(extmaterials)

            rfq_json = self.rfq.__dict__
            rfq_json['materialList'] = self.rfq.to_json()

            return rfq_json['materialList']

        except IOError as error:
            logging.info(error)
Ejemplo n.º 2
0
    def createQuotefromCSV(self, csvfile):
        try:
            with open(csvfile, 'r', encoding='utf-8') as f:
                reader = csv.reader(f, dialect="excel-tab")
                qtmaterials = []
                for row in reader:
                    try:
                        orderNum = row[0]
                        itemCode = row[1]
                        quantity = float(row[2])
                        unit = row[3]
                        weight = float(row[4])
                        givenweight = float(row[5])
                        unitprice = float(row[6])
                        totalprice = float(row[7])
                        currency = row[8]
                        country = row[9]
                        note = row[10]

                        material = Material()
                        material.setItemCode(itemCode)

                        extended_material = ExtMaterials(material)
                        extended_material.setOrderNumber(orderNum)
                        extended_material.setUnit(unit)
                        extended_material.setQuantity(quantity)

                        quoted_material = QuotedMaterials(extended_material)
                        quoted_material.setTheoreticalWeight(weight)
                        quoted_material.setGivenWeight(givenweight)
                        quoted_material.setUnitPrice(unitprice)
                        quoted_material.setTotalPrice(totalprice)
                        quoted_material.setCurrency(currency)
                        quoted_material.setCountryOrigin(country)
                        quoted_material.setNote(note)

                        qtmaterials.append(quoted_material)

                    except ValueError as error:
                        print(itemCode)
                        print(error)
                        continue

                self.quote.setMaterialList(qtmaterials)

            quote_json = self.quote.__dict__
            quote_json['materialList'] = self.quote.to_json()

            total_materials = len(quote_json['materialList'])
            logging.info('End of Quote creation  \t' + str(total_materials))

            return quote_json

        except IOError as error:
            print("QuoteCreator")
            print(error)
Ejemplo n.º 3
0
    def createMaterial(self, csvfile):
        try:
            with open(csvfile, 'r', encoding='utf-8') as f:
                reader = csv.reader(f, dialect="excel-tab")
                filename = csvfile.split('/')[-1]
                logging.info('Opened file: ' + filename)
                for row in reader:
                    item = row[0]
                    material = Material()
                    material.setItemCode(item)

                    obj_id = material.__dict__
                    self.material_list.append(obj_id)

            return self.material_list

        except IOError as error:
            print(error)
            return self.material_list
Ejemplo n.º 4
0
    def createExtQuotedMaterialsfromCSV(self, csvfile):
        try:
            with open(csvfile, 'r', encoding='utf-8') as f:
                reader = csv.reader(f, dialect="excel-tab")
                qtmaterials = []
                for row in reader:
                    try:
                        orderNum = row[0]
                        itemCode = row[1]
                        quantity = float(row[2])
                        unit = row[3]
                        unitprice = float(row[4])
                        totalprice = float(row[5])
                        currency = row[6]
                        country = row[7]
                        projectId = row[8]
                        updateDate = row[9]

                        material = Material()
                        material.setItemCode(itemCode)
                        material.setDescription("")

                        ext_material = ExtMaterials(material)
                        ext_material.setOrderNumber(orderNum)
                        ext_material.setUnit(unit)
                        ext_material.setQuantity(quantity)

                        quoted_material = QuotedMaterials(ext_material)
                        quoted_material.setTheoreticalWeight(0.0)
                        quoted_material.setGivenWeight(0.0)
                        quoted_material.setUnitPrice(unitprice)
                        quoted_material.setTotalPrice(totalprice)
                        quoted_material.setCurrency(currency)
                        quoted_material.setCountryOrigin(country)
                        quoted_material.setNote("NA")

                        ext_quoted_material = ExtQuotedMaterials(quoted_material)
                        ext_quoted_material.setProjectId(projectId)
                        ext_quoted_material.setUpdateDate(updateDate)
                        ext_quoted_material.setProviderId(self.providerId)
                        ext_quoted_material.setProviderName(self.providerName)
                        ext_quoted_material.setRevision(self.revision)

                        qtmaterials.append(ext_quoted_material)

                    except ValueError as error:
                        print(itemCode)
                        print(error)
                        continue

            quote_json = [ob.__dict__ for ob in qtmaterials]
            logging.info('End of Quote creation  \t' + str(len(qtmaterials)))

            return quote_json

        except IOError as error:
            print("ExtendedQuotedMaterialsCreator")
            print(error)
Ejemplo n.º 5
0
    def editQuotedMaterials(self, quote_form, material_data):
        try:

            material = Material()
            material.setItemCode(material_data['itemcode'])
            material.setDescription(material_data['description'])
            material.setType(material_data['type'])
            material.setCategory(material_data['category'])
            material.setDimensions(material_data['dimensions'])

            ext_material = ExtMaterials(material)
            ext_material.setOrderNumber(material_data['orderNumber'])
            ext_material.setQuantity(material_data['quantity'])
            ext_material.setUnit(material_data['unit'])

            quoted_material = QuotedMaterials(ext_material)
            quoted_material.setUnitPrice(quote_form.cleaned_data['unitPrice'])
            quoted_material.setTotalPrice(
                quote_form.cleaned_data['totalPrice'])

            quote = ExtQuotedMaterials(quoted_material)
            quote.setRevision(quote_form.cleaned_data['revision'])

            quote_json = quote.__dict__

            self.quote_list.append(quote_json)

            return self.quote_list

        except IOError as error:
            logging.info(error)
            return self.quote_list
Ejemplo n.º 6
0
    def editQuotewithMaterials(self, quote_form, material_formset,
                               material_data):
        try:

            quote = Quotes()
            quote.setIntenalCode(quote_form.cleaned_data['internalCode'])
            quote.setExternalCode(quote_form.cleaned_data['externalCode'])
            quote.setProviderCode(quote_form.cleaned_data['providerCode'])
            quote.setReceivedDate(quote_form.cleaned_data['receivedDate'])
            quote.setSentDate(quote_form.cleaned_data['sentDate'])
            quote.setUser(quote_form.cleaned_data['user'])
            quote.setProviderId(quote_form.cleaned_data['providerId'])
            quote.setProviderName(quote_form.cleaned_data['providerName'])
            quote.setContactName(quote_form.cleaned_data['contactName'])
            quote.setIncoterms(quote_form.cleaned_data['incoterms'])
            quote.setNote(quote_form.cleaned_data['note'])
            quote.setEdt(quote_form.cleaned_data['edt'])

            extmaterials = []

            try:
                idx = 0
                for tmp_data in material_formset:

                    itemcode_data = material_data[idx]['itemcode']
                    order_number_data = material_data[idx]['orderNumber']
                    quantity_data = material_data[idx]['quantity']
                    unit_data = material_data[idx]['unit']

                    material = Material()
                    material.setItemCode(itemcode_data)
                    material.setDescription(material_data[idx]['description'])
                    material.setType(material_data[idx]['type'])
                    material.setCategory(material_data[idx]['category'])
                    material.setDimensions(material_data[idx]['dimensions'])

                    ext_material = ExtMaterials(material)
                    ext_material.setOrderNumber(order_number_data)
                    ext_material.setQuantity(quantity_data)
                    ext_material.setUnit(unit_data)

                    mod_material = QuotedMaterials(ext_material)
                    mod_material.setOrderNumber(order_number_data)
                    mod_material.setQuantity(tmp_data.cleaned_data['quantity'])
                    mod_material.setUnit(tmp_data.cleaned_data['unit'])
                    mod_material.setUnitPrice(
                        tmp_data.cleaned_data['unitPrice'])
                    mod_material.setTotalPrice(
                        tmp_data.cleaned_data['totalPrice'])

                    mod_material.setCountryOrigin(
                        material_data[idx]['countryOrigin'])
                    mod_material.setCurrency(material_data[idx]['currency'])
                    mod_material.setTheoreticalWeight(
                        material_data[idx]['theoreticalWeight'])
                    mod_material.setGivenWeight(
                        material_data[idx]['givenWeight'])

                    extmaterials.append(mod_material)

                    idx = idx + 1

            except Exception as ex:
                logging.info(ex)

            quote.setMaterialList(extmaterials)

            quote_json = quote.__dict__
            quote_json['materialList'] = quote.to_json()

            self.quote_list.append(quote_json)

            return self.quote_list

        except IOError as error:
            logging.info(error)
            return self.quote_list
Ejemplo n.º 7
0
    def editRFQwithMaterials(self, form, material_formset, material_data):
        try:
            internalCode = form.cleaned_data['internalCode']
            externalCode = form.cleaned_data['externalCode']
            sender = form.cleaned_data['sender']
            company = form.cleaned_data['company']
            receivedDate = form.cleaned_data['receivedDate']
            note = form.cleaned_data['note']

            rfq = RequestForQuotes()
            rfq.setIntenalCode(internalCode)
            rfq.setExternalCode(externalCode)
            rfq.setSender(sender)
            rfq.setCompany(company)
            rfq.setReceivedDate(receivedDate)
            rfq.setNote(note)

            extmaterials = []

            try:
                idx = 0
                for material in material_formset:

                    itemcode_data = material_data[idx]['itemcode']
                    description_data = material_data[idx]['description']
                    type_data = material_data[idx]['type']
                    dimensions_data = material_data[idx]['dimensions']
                    category_data = material_data[idx]['category']

                    order_number_data = material_data[idx]['orderNumber']

                    temp_material = Material()
                    temp_material.setItemCode(itemcode_data)
                    temp_material.setDescription(description_data)
                    temp_material.setType(type_data)
                    temp_material.setDimensions(dimensions_data)
                    temp_material.setCategory(category_data)

                    mod_material = ExtMaterials(temp_material)
                    mod_material.setOrderNumber(order_number_data)
                    mod_material.setQuantity(material.cleaned_data['quantity'])
                    mod_material.setUnit(material.cleaned_data['unit'])
                    extmaterials.append(mod_material)
                    idx = idx + 1

            except Exception as ex:
                logging.info(ex)

            rfq.setMaterialList(extmaterials)

            rfq_json = rfq.__dict__
            rfq_json['materialList'] = rfq.to_json()

            self.rfq_list.append(rfq_json)

            return self.rfq_list

        except IOError as error:
            logging.info(error)
            return self.rfq_list
Ejemplo n.º 8
0
    def editMaterial(self, form):
        try:
            itemcode = form.cleaned_data['itemcode']
            description = form.cleaned_data['description']
            type = form.cleaned_data['type']
            category = form.cleaned_data['category']
            dimensions = form.cleaned_data['dimensions']

            material = Material()
            material.setItemCode(itemcode)
            material.setDescription(description)
            material.setType(type)
            material.setCategory(category)
            material.setDimensions(dimensions)

            obj_id = material.__dict__
            self.material_list.append(obj_id)

            return self.material_list

        except IOError as error:
            print(error)
            return self.material_list
Ejemplo n.º 9
0
    def createMaterialfromCSV(self, csvfile):
        try:
            fileFilter(csvfile)
            with open(csvfile, 'r', encoding='utf-8') as f:
                reader = csv.reader(f, dialect="excel-tab")
                filename = csvfile.split('/')[-1]
                logging.info('Opened file: ' + filename)
                for row in reader:
                    if row[0] == '':
                        continue
                    item = row[1]
                    dsc = row[2].rstrip().split(',')
                    cat = dsc[0]
                    material = Material()
                    material.setItemCode(item)
                    material.setDescription(','.join(dsc))
                    material.setCategory(cat)
                    result = find_type(dsc)
                    material.setType(result)

                    if result == 'NA':
                        logging.info('No type for  \t' + str(material))
                    result = find_dimensions(dsc)
                    material.setDimensions(result)

                    obj_id = material.__dict__
                    self.material_list.append(obj_id)

                    if result == 'NA':
                        logging.info('No dimensions for  \t' + str(material))

            return self.material_list

        except IOError as error:
            print(error)
            return self.material_list