Odoo 10 selection field after save error - field

I have a selection field and this function for list items in field by dynamically.
def get_years(self):
year_list = []
year = date.today().year+1
lastyear = date.today().year - 20
for i in range(int(lastyear),int(year)):
year_list.append((i, str(i)))
return year_list
this is the field,
year = fields.Selection(get_years, string='Yıl', default=get_current_year, restore="True")
and when I save the form, this field becomes unknown. I found what is the problem but I don't know the solution. Problem is compute function, when i write items like [(1997,1997),(2016,2016),(2017,2017)] it is working but i don't want to write hard code. How can i solve this problem? Thank you.

I found the solution, i don't need to create a new method and can use like;
year = fields.Selection([(num, str(num)) for num in range(1900, (datetime.now().year)+1 )],string='Year', default=datetime.now().year)
Thanks.

Related

Currency cells and PHPSpreadsheet: How to read the currency from it?

I have an Excel (XLSX) file with a column containing values in different currencies, e.g. "CAD 4711.00", "NOK 56.78", "CHF 123.45".
Now I try to read data from these cells and I just cannot get the currencies. The best I can do is get the value (4711, 56.78, 123.45) but I also need to figure out which currency the cell is in. How can I do this?
I would be relatively happy if I could just get the formatted value but I do not see a way to do that either.
maybe this helps to get started :
$fileExcel = 'mony.xlsx';
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$spreadsheet = $reader->load($fileExcel);
$sheet = $spreadsheet->getActiveSheet();
$lsValue = $sheet->getCell('A1')->getValue();
$lsFormat = $sheet->getStyle('A1')->getNumberFormat()->getFormatCode();
echo $lsValue .':'. $lsFormat .'<HR>';
the result is something like that:
123:#,##0.00\ "€"
123.12:#,##0.00\ [$EUR]
3123:#,##0.00\ [$₽-444]
split the format and inspect it further for your currency

0 Checking if TextBox.Text contains the string in the table. But it doesn't work? Lua

I am making a script inside TextButton script that will check if the TextBox contains any of the word or string inside the table.
text = script.Parent.Parent:WaitForChild('TextBox')
label = script.Parent.Parent:WaitForChild('TextLabel')
a = {'test1','test2','test3'}
script.Parent.MouseButton1Click:connect(function()
if string.match(text.Text, a) then
label.Text = "The word "..text.Text.." was found in the table."
else
label.Text = "The word "..text.Text.." was not found in the table."
end
end)
But it gives an error string expected, got table. from line 7 which is refering to the line if string.match....
Is there any way to get all text in the table?
What's the right way to do it?
Oh boy, there's a lot to say about this.
The error message
Yes.
No, seriously, the answer is yes. The error message is exactly right. a is a table value; you can clearly see that on the third line of code. string.match needs a string as its second argument, so it obviously crashes.
Simple solution
use a for loop and check for each string in a separately.
found = false
for index, entry in ipairs(a) do
if entry == text.Text then
found = true
end
end
if found then
... -- the rest of your code
The better* solution
In Lua, if we want to know if a single element is in a set, we usually take advantage of the fact that tables are implemented as hashmaps, meaning they are very fast when looking up keys.
For that to work, one first needs to change the way the table looks:
a = {["test1"] = true, ["test2"] = true, ["test3"] = true}
Then we can just index a with a string to find out if it is contained int eh set.
if a[text.Text] then ...
* In practice this is just as good as the first solution as long as you only have a few elements in your table. It only becomes relevant when you have a few hundred entries or your code needs to run absolutely as fast as possible.

How to make text roll over into another textbox? Visual Basic

So, I want to make it so that, when the user pastes something into a textbox, once it pastes the first 24 characters into that textbox, it will send the rest to a richtextbox.
I've tried splitting, joining, with no luck. I don't know what else I can do. Any ideas?
I've tried:
If TextBox1.Text > TextBox1.MaxLength Then
RichTextBox4.Text = TextBox1.Text
End If
And some other weird things that didn't work out. I would appreciate some help.
Thank you.
use Substring....
Dim input = textbox1.text
Dim substring As String = input .Substring(0, 24)
richtextbox4.text = substring
http://www.dotnetperls.com/substring-vbnet

How to use Slickgrid Formatters with MVC

I am working on a first Slickgrid MVC application where the column definition and format is to be stored in a database. I can retrieve the list of columns quite happily and populate them until I ran into the issue with formatting of dates. No problem - for each date (or time) column I can store a formatter name in the database so this can be retrieved as well. I'm using the following code which works ok:
CLOP_ViewColumnsDataContext columnDB = new CLOP_ViewColumnsDataContext();
var results = from u in columnDB.CLOP_VIEW_COLUMNs
select u;
List<dynColumns> newColumns = new List<dynColumns>();
foreach(CLOP_VIEW_COLUMN column in results)
{
newColumns.Add(new dynColumns
{
id = column.COLUMN_NUMBER.ToString(),
name = column.HEADING.Trim(),
field = column.VIEW_FIELD.Trim(),
width = column.WIDTH,
formatter = column.FORMATTER.Trim()
});
}
var gridColumns = new JavaScriptSerializer().Serialize(newColumns);
This is all fine apart from the fomatter. An example of the variable gridColumns is:
[{"id":"1","name":"Date","field":"SCHEDULED_DATE","width":100,"formatter":"Slick.Formatters.Date"},{"id":"2","name":"Carrier","field":"CARRIER","width":50,"formatter":null}]
Which doesn't look too bad however the application the fails with the error Microsoft JScript runtime error: Function expected in the slick.grid.js script
Any help much appreciated - even if there is a better way of doing this!
You are assigning a string to the formatter property, wich is expected to be function.
Try:
window["Slick"]["Formatters"]["Date"];
But i really think you should reconsider doing it this way and instead store your values in the db and define your columns through code.
It will be easier to maintain and is less error prone.
What if you decide to use custom editors and formatters, which you later rename?
Then your code will break or you'll have to rename all entries in the db as well as in code.

split the string to get specific value on ruby on rails?

I want to get two separate value from
/en/faq
the two separate value will be
lang =en
rem =faq
I have used to split which was relatively much easier. Nonetheless, this is my approach which needs tweaking around, hopefully from your help I will be able to accomplish it.
string = "/en/faq"
lang = string.split("/").first
rem = string.split("/en/")
puts "/#{lang}/#{rem[1]}"
The desired output should be "/en/faq/" but the output is
"//faq"
i know i have got '.first' which is why I am getting a null value but could anyone help on getting the right results please?
thanks in advance.
string = "/en/faq"
lang = string.split("/")
rem = string.split("/#{lang[1]}/")
puts "/#{lang[1]}/#{rem[1]}"
this does the trick and thanks to Sebi for his prompt answer!

Resources