I want to the priority widget on my selection field. But priority widget not show the first option. I will start from the second option.
Is this a bug from Odoo source code or I need to write something else to make it work as I expected?
In Odoo Widget priority :
if you want 5 levels you must start from '0' to '5'
if you want 4 levels you must start from '0' to '4'
if you want 3 levels you must start from '0' to '3' and so on
So in your example you should add field as below
priority = fields.selection([('0', 'Very Low'),('1', 'Low'),('2',
'Normal'),('3', 'High'), string = 'Priority']
Do like this
priority = fields.Selection([(0, ''), (1, 'Low X'), (2, 'Normal Y'), (3, 'High Z')]
Related
I am trying to have a parameter that either filters out interns or includes interns and every other job title using a column that holds 'Yes' or 'No' whether that job title is an intern.
The basics of my code are like this:
SELECT
Date
,BillHours
,OrgArea
,Jobtitle
,InternYesNo
FROM(
SELECT
Date
,BillHours
,OrgArea
,Jobtitle
,CASE WHEN LEFT(jobtitle, 6) = 'Intern' THEN 'Yes' ELSE 'No' END AS 'InternYesNo') MainQuery
WHERE InternYesNo IN(#includeinterns)
So I'm thinking I want to specify the available values in the #includeinterns parameter, but I think I would need to have one of the values be an expression so that it includes both 'Yes' and 'No' rows based on the InternYesNo column.
My question is how do I write an expression for specifying values so that one of the available values includes both 'Yes' and 'No' rows? Do I need an additional dataset to hold those values? Or is there better way to accomplish this?
I think I have figured out a solution. I updated my code to this:
SELECT
Date
,BillHours
,OrgArea
,Jobtitle
,InternYesNo
FROM(
SELECT
Date
,BillHours
,OrgArea
,Jobtitle
,CASE WHEN LEFT(jobtitle, 6) = 'Intern' THEN 'Yes' ELSE 'No' END AS 'InternYesNo') MainQuery
WHERE (InternYesNo = #includeinterns OR #includeinterns = 'abc')
Then I specify available values with one labeled as 'No' and the value is 'No' and the other is labeled as 'Yes' with a value of 'abc'.
I have the following table in the DDBB:
On the other side, i have an interface with an start and end filter parameters.
So i want to understand how to query the table to only get the data from the table which period are within the values introduces by the user.
Next I present the 3 scenarios possible. If i need to create one query per each scenario is ok:
Scenario 1:If the users only defines start = 03/01/2021, then the expected output should be rows with id 3,5 and 6.
Scenario 2:if the users only defines end = 03/01/2021, then the expected output shoud be rows with id 1 and 2.
Scenario 3:if the users defines start =03/01/2021 and end=05/01/2021 then the expected output should be rows with id 3 and 5.
Hope that makes sense.
Thanks
I will assume that start_date and end_date here are DateFields [Django-doc], and that you have a dictionary with a 'start' and 'end' as (optional) key, and these map to date object, so a possible dictionary could be:
# scenario 3
from datetime import date
data = {
'start': date(2021, 1, 3),
'end': date(2021, 1, 5)
}
If you do not want to filter on start and/or end, then either the key is not in the dictionary data, or it maps to None.
You can make a filter with:
filtr = {
lu: data[ky]
ky, lu in (('start', 'start_date__gte'), ('end', 'end_date__lte'))
if data.get(ky)
}
result = MyModel.objects.filter(**filtr)
This will then filter the MyModel objects to only retrieve MyModels where the start_date and end_date are within bounds.
I'm trying to modify a report that shows health assessments using SQL. On the report, I would like to add a section for comments that were added to the health assessments. I was able to add the comment section, and with a suggestion provided here, I used SUBSTRING to limit the number of characters displayed on the report to 1000 as opposed to 8000.
The issue I'm experiencing now is with limiting the number of characters displayed for the option 'Other' as shown below. I used SUBSTRING (ex: SUBSTRING(HltNutrition.Comment, 1, 1000)) for all of the assessments and have included the Nutrition assessment as an example (which is working correctly) along with the snippet of code featuring the 'Other' (Chronic) option (which is not working correctly). I replaced 3 with 1 and although this did not produce an error, it did not have the intended effect for 'Other' as SUBSTRING([HealthAssessName].Comment, 1, 1000).
Any assistance is appreciated. Thank you in advance.
-- Nutrition
INSERT INTO #ChronicCondition(IdApplicant, ExamDate, Condition, TreatmentNeeded, TreatmentReceived, Status, Comment)
SELECT #Enroll.IdApplicant,
HltNutrition.ExamDate,
'Nutrition',
HltNutrition.TrtNeed,
HltNutrition.TrtStatus,
HltNutrition.Status,
SUBSTRING (HltNutrition.Comment, 1, 1000)
FROM #Enroll
JOIN HltNutrition ON HltNutrition.IdApplicant = #Enroll.IdApplicant
WHERE HltNutrition.Overweight = 1
-- Chronic
INSERT INTO #ChronicCondition(IdApplicant, ExamDate, Condition, TreatmentNeeded, TreatmentReceived, Status, Comment)
SELECT #Enroll.IdApplicant,
HltChronic.ExamDate,
CASE ChronicCondition.Id
WHEN 3 THEN 'Other' + ISNULL(' - ' + hltChronic.ConditionOther, '')
ELSE ChronicCondition.Condition
END,
HltChronic.TrtNeed,
HltChronic.TrtStatus,
hltChronic.Status,
SUBSTRING (HltChronic.Comment, 1, 1000)
FROM #Enroll
JOIN hltChronic ON hltChronic.idApplicant = #Enroll.idApplicant
JOIN ChronicCondition ON ChronicCondition.Id = hltChronic.Condition
Thank you for the assistance, I walked through the concern with the senior developer and found that the SUBSTRING function was not the cause of the issue. The problem I was encountering was due to data entry that was used for testing the report. The code I added is actually correct and the problem has been resolved.
Thanks again for any assistance that was provided.
My company uses numbers as a system identifier to branches. The problem is my end users do not like seeing 000201 as a branch name. Therefore I am trying to convert these numbers to a string and then roll up the satellite locations into the main branch. The branch format is as follows:
BBBBSS so, as an example, the Nashville main branch will follow 000201 and all satellites would follow sequentially 000202, 000203, 000204.
I want all of our details to roll up into "Nashville". So any instance that ORGID is like 0002** it would roll up everything into a field named "Nashville".
Sorry if I'm not too clear. I've been banging my head against the wall so my thoughts are jumbled.
If I understand your question, there are at least Two ways i can think of accomplishing this ;
The 1st way is straight forward, you'd add a case statement for each Branch, if you have many branches i'd go with the 2nd way.
Select case SUBSTRING(cast(Branch.Id as varchar(10)), 1, 4 )
when '0002' then 'Nashville'
when '0003' then 'Branch 03'
when '0004' then 'Branch 04'
else SUBSTRING(cast(Branch.Id as varchar(10)), 1, 4 ) end OrgName,
COUNT(*)
from Branch group by SUBSTRING(cast(Branch.Id as varchar(10)), 1, 4 )
This 2nd way you would have a separate table to Hold Branch Name, etc. For demonstration i will call this table OrgTable with a OrgId containing your "0002" Ids, and a OrgName containing the "Nashville".
Select OrgTable.OrgName, count(*)
from Branch
inner join OrgTable on ( OrgTable.OrgId = SUBSTRING(cast(Branch.Id as varchar(10)), 1, 4 ))
Group By OrgTable.OrgName
I haven't checked that the SQL above is without syntax errors, but hopefully you get the picture.
HTH,
You can create a simple formula in CR to convert your ORGID to the branch name:
//Convert ORGID to string and save branch code
local stringvar branch := left(totext({Table.ORGID},0,''),4);
//Display city based on branch code
select branch
case "0002" : "Nashville"
case "0003" : "Other City"
<...>
default : "No matching branch!"
MySQL provides a string function named FIELD() which accepts a variable number of arguments. The return value is the location of the first argument in the list of the remaining ones. In other words:
FIELD('d', 'a', 'b', 'c', 'd', 'e', 'f')
would return 4 since 'd' is the fourth argument following the first.
This function provides the capability to sort a query's results based on a very specific ordering. For my current application there are four statuses that I need to manager: active, approved, rejected, and submitted. However, if I simply order by the status column, I feel the usability of the resulting list is lessened since rejected and active status items are more important than submitted and approved ones.
In MySQL I could do this:
SELECT <stuff> FROM <table> WHERE <conditions> ORDER BY FIELD(status, 'rejected', 'active','submitted', 'approved')
and the results would be ordered such that rejected items were first, followed by active ones, and so on. Thus, the results were ordered in decreasing levels of importance to the visitor.
I could create a separate table which enumerates this importance level for the statuses and then order the query by that in descending order, but this has come up for me a few times since switching to MS SQL Server so I thought I'd inquire as to whether or not I could avoid the extra table and the somewhat more complex queries using a built-in function similar to MySQL's FIELD().
Thank you,
David Kees
Use a CASE expression (SQL Server 2005+):
ORDER BY CASE status
WHEN 'active' THEN 1
WHEN 'approved' THEN 2
WHEN 'rejected' THEN 3
WHEN 'submitted' THEN 4
ELSE 5
END
You can use this syntax for more complex evaluation (including combinations, or if you need to use LIKE)
ORDER BY CASE
WHEN status LIKE 'active' THEN 1
WHEN status LIKE 'approved' THEN 2
WHEN status LIKE 'rejected' THEN 3
WHEN status LIKE 'submitted' THEN 4
ELSE 5
END
For your particular example your could:
ORDER BY CHARINDEX(
',' + status + ',',
',rejected,active,submitted,approved,'
)
Note that FIELD is supposed to return 0, 1, 2, 3, 4 where as the above will return 0, 1, 10, 17 and 27 so this trick is only useful inside the order by clause.
A set based approach would be to outer join with a table-valued-constructor:
LEFT JOIN (VALUES
('rejected', 1),
('active', 2),
('submitted', 3),
('approved', 4)
) AS lu(status, sort_order)
...
ORDER BY lu.sort_order
I recommend a CTE (SQL server 2005+).
No need to repeat the status codes or create the separate table.
WITH cte(status, RN) AS ( -- CTE to create ordered list and define where clause
SELECT 'active', 1
UNION SELECT 'approved', 2
UNION SELECT 'rejected', 3
UNION SELECT 'submitted', 4
)
SELECT <field1>, <field2>
FROM <table> tbl
INNER JOIN cte ON cte.status = tbl.status -- do the join
ORDER BY cte.RN -- use the ordering defined in the cte
Good luck,
Jason
ORDER BY CHARINDEX(','+convert(varchar,status)+',' ,
',rejected,active,submitted,approved,')
just put a comma before and after a string in which you are finding the substring index or you can say that second parameter.
and first parameter of charindex is also surrounded by ,