How customise create of variant value of product under odoo 12? - variant

In the product.template module I added a length / width variant as shown in the following figure enter image description here
I need to: customize creation of values in column «Attribute Values» in form view which External id is product.product_template_only_form_view in odoo 12:
For example: if user enter value in column «attribute Value» value: « *number1 * number2* » or value: « number1 x space number2 space » or value: «space number1 x number2 space » , i need function to trim spaces and set value «number1/number2» in this column!
Other condition: if number1 < number2 then i need to set value in column «attribute Value» like this «number2/number1» because we should have (length > width).
Here is a screenshot for this case: enter image description here

class valuesInherit(models.Model):
_inherit = 'product.template'
#api.depends('attribute_line_ids')
def Change (self):
if self.your_length_field and self.your_length_field:
if if self.your_length_field > if self.your_width_field:
self.result_field = self.your_length_field/ your_length_field
if self.your_length_field and self.your_length_field:
if if self.your_length_field < if self.your_width_field:
self.result_field = your_length_field/ self.your_length_field

Related

Is there a R function (or any way) to color code all numeric values within a single string?

`I successfully manage to color code certain words within a string.
However, I am unable to color code ALL numeric values within that same tring.
I want all the numeric values within the string (example: 1, 2.3, 4, 6.87) to be of the same color (example: blue)
I am all ears to any solution, thank you so much for your help.
`library(tidyverse)
library(crayon)
library(stringr)
library(readr)`
creating the string/vector # ALL GOOD HERE
`text <- tolower(c("Kyste simple inférieur de
56 mm. Aorto-bi-iliaque en
5,9cm. Artères communes de 19mm et
de 87mm. 120mm stable.")) #tolower is removing capital letters#`
individuate words # ALL SEEMS GOOD HERE
`unique_words <- function(x) {
purrr::map(.x = x,
.f = ~ unique(base::strsplit(x = ., split = " ")[[1]],
collapse = " "))
}`
creating a dataframe with crayonized text # ALL SEEMS GOOD HERE
df <- tibble::enframe(unique_words(x = text)) %>% tidyr::unnest() %>%
here you can specify the color/word combinations you need # PROBLEM SEEMS TO BE HERE
`dplyr::mutate(.data = .,
value2 = dplyr::case_when(value == "aorto-bi-iliaque" ~ crayon::green(value),
value == gsub(".*(\\b\\d+\\b).*", "\\1", text) ~ crayon::blue(value), **# Here is where I need help #**
TRUE ~ value)) %>%
dplyr::select(., -value) `
printing the text
`print(cat(df$value2))`
enter image description here This is what it gives me, the word is correctly color coded but all the n`umeric value are still unchanged

How to check string of one column ,and change of string of another column using pandas

I have big csv file, PF sample data like below
Name,value,data
jack,X16206,hi this is X16206
Riti,X1620600,I want to change X16206.
Aadii,X16206,New value is X1620600.
jan,abc700134,something new 20600.
I have a value X16206(alpha-numeric) with 00 added sometimes and sometimes not, in value column and data column
I want to check the string from value column and change the string present in a sentence which is in the data column as 'exact'
expected output:
Name,value,data
jack,X16206,hi this is [exact]
Riti,X1620600,I want to change [exact].
Aadii,X16206,New value is [exact].
jan,abc700134,something new 20600.
what I have tried so far
df1['num'] = np.where(df1['value'].str.len().isin({6,8}), 1, -1)
def myfn2(row):
if row['num']==1:
row['New_data']=row['data'].replace(row['value'],'[exact]')
else:
row['New_data']=row['data']
return row
df1=df1.apply(myfn2,axis=1)
Output I got
Name,value,data,num,New_data
jack,X16206,hi this is X16206,1,hi this is [exact]
Riti,X1620600,I want to change X16206,1,I want to change X16206.
Aadii,X16206,New value is X1620600,1,New value is [exact]00.
jan,abc700134,something new 20600,-1,something new 20600.
Can anyone please help me how to do this?
Try:
import re
def fn(x):
v = re.sub(r"(?<=\d{4})00$", "", x["value"])
return re.sub(r"(" + v + "0?0?)", r"[exact]", x["data"])
df["data"] = df.apply(fn, axis=1)
print(df)
Prints:
Name value data
0 jack X16206 hi this is [exact]
1 Riti X1620600 I want to change [exact].
2 Aadii X16206 New value is [exact].
3 jan abc700134 something new 20600.

How to select a random Entry on a tkinter canvas?

I'm making a simple sudoku generator, and have got 81 different entries (e1, e2, e3, e4 ... etc).
I would like to know if there is any way to select a random entry to insert a number into.
So kind of like this:
num = randint(0, 81)
entry = "e" + str(num)
entry.insert()
With the above code you get an error saying
str object has no attribute 'insert'
which makes sense, but is there any way to 'convert' a string to a variable name?
Thanks in advance.
Store the entries in a list, then use random.choice to pick one of the entries.
entries = []
for i in range 81:
entry = tk.Entry(...)
entries.append(entry)
...
random_entry = random.choice(entries)

Spotfire: How to increment variables to build scoring mechanism?

I'm trying to figure out how I could use variables in Spotfire (online version) to build a scoring mechanism and populate a calculated column with the final result.
I have a couple of values stored in columns that I would use to evaluate and attribute a score like this:
if column1<10 then segment1 = segment1 + 1
if column1>10 then segment2 = segment2+1
...ETC...
In the end each "segment" should have a score and I would like to simply display the name of the segment that has the highest score.
Ex:
Segment1 has a final value of 10
Segment2 has a final value of 22
Segment3 has a final value of 122
I would display Segment3 as value for the calculated column
Using only "IF" would lead me to a complicated IF structure so I'm more looking for something that looks more like a script.
Is there a way to achieve this with Spotfire?
Thanks
Laurent
To cycle through the data rows and calculate a running score, you can use an IronPython script. The script below is reading the numeric data from Col1 and Col2 of a data table named "Data Table". It calculates a score value for each row and writes it to a tab delimited text string. When done, it adds it to the Spotfire table using the Add Columns function. Note, the existing data needs to have a unique identifier. If not, the RowId() function can be used to create a calculated column for a unique row id.
from Spotfire.Dxp.Data import *
from System.IO import StringReader, StreamReader, StreamWriter, MemoryStream, SeekOrigin
from Spotfire.Dxp.Data.Import import *
from System import Array
def add_column(table, text, col_name):
# read the text data into memory
mem_stream = MemoryStream()
writer = StreamWriter(mem_stream)
writer.Write(text)
writer.Flush()
mem_stream.Seek(0, SeekOrigin.Begin)
# define the structure of the text data
settings = TextDataReaderSettings()
settings.Separator = "\t"
settings.SetDataType(0, DataType.Integer)
settings.SetColumnName(0, 'ID')
settings.SetDataType(1, DataType.Real)
settings.SetColumnName(1, col_name)
# create a data source from the in memory text data
data = TextFileDataSource(mem_stream, settings)
# define the relationship between the existing table (left) and the new data (right)
leftColumnSignature = DataColumnSignature("Store ID", DataType.Integer)
rightColumnSignature = DataColumnSignature("ID", DataType.Integer)
columnMap = {leftColumnSignature:rightColumnSignature}
ignoredColumns = []
columnSettings = AddColumnsSettings(columnMap, JoinType.LeftOuterJoin, ignoredColumns)
# now add the column(s)
table.AddColumns(data, columnSettings)
#get the data table
table=Document.Data.Tables["Data Table"]
#place data cursor on a specific column
cursorCol1 = DataValueCursor.CreateFormatted(table.Columns["Col1"])
cursorCol2 = DataValueCursor.CreateFormatted(table.Columns["Col2"])
cursorColId = DataValueCursor.CreateFormatted(table.Columns["ID"])
cursorsList = Array[DataValueCursor]([cursorCol1, cursorCol2, cursorColId])
text = ""
rowsToInclude = IndexSet(table.RowCount,True)
#iterate through table column rows to retrieve the values
for row in table.GetRows(rowsToInclude, cursorsList):
score = 0
# get the current values from the cursors
col1Val = cursorCol1.CurrentDataValue.ValidValue
col2Val = cursorCol2.CurrentDataValue.ValidValue
id = cursorColId.CurrentDataValue.ValidValue
# now apply rules for scoring
if col1Val <= 3:
score -= 3
elif col1Val > 3 and col2Val > 50:
score += 10
else:
score += 5
text += "%d\t%f\r\n" % (id, score)
add_column(table, text, 'Score_Result')
For an approach with no scripting, but also no accumulation, you can use calculated columns.
To get the scores, you can use a calculated column with case statements. For Segment 1, you might have:
case
when [Col1] > 100 then 10
when [Col1] < 100 and [Col2] > 600 then 20
end
The, once you have the scores, you can create a calculated column, say [MaxSegment]. The expression for this will be Max([Segment1],[Segment2],[Segment3]...). Then display the value of [MaxSegment].
The max function in this case is acting as a row expression and is calculating the max value across the row of the columns given.

Python 3 + Flask application that uses routes, views and GET parameters

I have the following problem for part of my python class homework:
Using the functions you created earlier, make a flask application that takes arguments and displays the results of the calculations using routes/views.
For example, you will have three routes and they can be called square, triangle, and cost. You will pass GET query string parameters to these routes and the view will display the appropriate results.
I did some research and could not figure out what to do with Flask. My teacher gave a very short overview in class on Flask, and I'm a beginner with Python, so hoping someone can help me.
I just have no idea what to do. Any help I can get would be appreciated. Thanks!
Here is the code for the functions (this code works)
functions.py file:
# Using the input function ask the user for the base of a triangle and store in a variable
print()
b = int(input(str(user_name)+ ", please enter the base length of your triangle: "))
print()
#Using the input function ask the user for the height of a triangle and store the value in a variable
#Where b = length of base and h = length of height
h = int(input("Now please enter the height length of your triangle: "))
print()
#Call your function passing the two variables that contain the values for base and height
print("The area of your triangle", user_name, "is", str(area_tr(b,h)) +".")
print()
#Part 3: Total Cost
#Assume you work for an outdoor clothing company. Your job is to find out the total cost of buying raw materials for a winter jacket.
#Create a function that takes two arguments and returns the total cost using the formula:
#Total cost = Number of units X price per unit
def tc_wjacket(u,p):
"""
total cost of buying raw materials for a winter jacket.
Total cost = Number of units X price per unit.
"""
return u * p
#Using the input function ask the user for the numbers of units and store it in a variable.
print()
u = int(input(str(user_name)+ ", please enter the number of winter jackets you want for your store: "))
print()
#Using the input function ask the user for the price per unit
p = int(input("Now please enter the cost of the raw materials per jacket: "))
print()
#Call your function passing the two variables that contain the values for number of units and price per unit
print(str(user_name)+ ", according to my calculations, the cost to buy the raw materials for", b ,"jackets with at", p ,"dollars per jacket is", tc_wjacket(u,p) ,"dollars.")
print()
print("I hope this information was helpful " + str(user_name)+ ".")
print()
#importing Flask
from flask import Flask
#creating an app instance in the current namespace
app = Flask(__name__)
#decorator
#app.route("/")
#app.route("/square/<int:side1>/<int:side2>/<int:side3>/<int:side4>")
def add(side1,side2,side3,side4):
"""
perimeter of a square
"""
perim = (side1 + side2 + side3 + side4)
return "<h2>Your square's parimeter is {}</h2>".format(perim)
#app.route("/triangle/<int:b>/<int:h>")
def area_tr(b,h):
"""
Function calculates the area of a triangle
formula = (base * height)/2
"""
area_tr = b * h / 2
return "<h2>Your triangle's area is {}</h2>".format(area_tr)
#app.route("/cost/<int:u>/<int:p>")
def tc_wjacket(u,p):
"""
total cost of buying raw materials for a winter jacket.
Total cost = Number of units X price per unit.
"""
total_cost = u * p
return "<h2>Your triangle's area is {}</h2>".format(total_cost)
#debug=True allows us to make changes to our code and see them in the browser without having to re-run our app
app.run(debug=True, port=8000, host='0.0.0.0')

Resources