I select field in database using sql command
partner_obj = self.pool.get('res.partner'). browse (cr, uid, ids, *args)
partner_name = partner_obj.ids
customer = (partner_name)
cr.execute("select b.city from res_partner a, res_partner_address b where b.partner_id = a.id AND a.id = %s",(customer))
ads = cr.fetchone()
city = ads and ads[0] or None
but, I just know we must convert into string. I already try to make like this (the code above), but still doesn't work.
I made like this, because you want to know SO is in a message in which the city
may you help me, please
thank you
I don't think you need to run raw SQL, you should be able to use the browse records to get the information you want. I wasn't sure exactly what you wanted from your question, but I'll assume that you are passing in a list of partner ids, and you want back a list of all the city names that they have addresses in. I have not tested this code, it's just a suggestion.
def find_cities(self, cr, uid, partner_ids, context=None):
cities = set()
partner_obj = self.pool.get('res.partner')
for partner in partner_obj.browse(cr, uid, partner_ids, context):
for address in partner.address:
if address.city:
cities.add(address.city)
return list(cities)
First point in OpenERP city is not relation field so when you will trigger sql to fetch the city you will get the name but if you have any customization which stores the city code then you need one more SQL injection to fine out the matching city from city code.
If like if you have city as relation fields with res_partner_address so in that case city field will store only id of the relation record table so when you use sql injection what you will get is id of the city which is linked to your address.
Let me know if I am missing something, Thank You.
Related
I am working on a system where users can block other users. On the user class, there is a relation called "blockedUsers" which points back to the user table.
If I have a user, and I want to find all the users he has blocked, I do this:
ParseUser user = ParseUser.getCurrentUser();
ParseRelation<ParseUser> relation = user.getRelation("blockedUsers");
ParseQuery query = relation.getQuery();
List<ParseUser> blockedUsers = query.find();
In SQL, this would be something like:
select block.blockee
from block
where block.blocker = 'SomeObjectId'
This would give me the object_ids of all the users who were blocked by user 'SomeObjectId'.
In SQL, I could also reverse this, and say:
select block.blocker
from block
where block.blockee = 'SomeObjectId'
This would give me the object_ids of every user who had blocked user 'SomeObjectId'.
The question is, is there a way to do a query in parse that is similar to the second query? I have looked at ParseRelation.java, and there is nothing in there which is obvious. mongodb uses join tables, but I see no way to join backwards.
Any help?
Yes. It is possible. Something like this should do what you need:
ParseQuery<ParseUser> userQuery = ParseUser.getQuery();
userQuery.equalTo('blockedUsers', blockeeUserObject);
List<ParseUser> blockers = query.find();
I have a working query that goes something like this:
Base table ACCT, link to others (listagg/subqueries) and ensure matching year("rollyear") field. Then the final step is to say which year ACCT table is in.
SELECT
FROM table ACCT
FULL OUTER JOIN table TABLE2 on ACCT.id = TABLE2.id and ACCT.rollyear= TABLE2.rollyear
...
FULL JOIN table TABLE7 on ACCT.id = TABLE7.id and ACCT.rollyear= TABLE7.rollyear
where ACCT.rollyear = extract (year from sysdate) +1
I typically use the calendar year plus one. I've been playing with using ACCT.rollyear = &rollyear to get user input... The limitation/issue I have is getting that running using the "User Defined Reports" feature.
Am I using this feature correctly? Does that only work for SQL Queries and not reports? Ive seen videos/comments about Stored Procedures and using "Accept...." but my attempts to mimic give errors and I'm not sure I'm on the right track. Thanks for any advice.
Change your query to use a bind variable:
where ACCT.rollyear = :rollyear
Then in the 'Binds' section you will see a variable with that name:
When you run your query you'll then be prompted to supply the value:
For example, I have employee managing particular country and particular company. I want to query only accounts which are in countries AND companies managed by the given employee. Ideas? Performance issues to be aware of?
Gremlin query is acceptable, also!
This seems to work:
select from Account where
#rId in
(select expand(out('managingCountry').in('inCountry')).#rId
from Employee where userId = 3)
AND
#rId in
(select expand(out('managingCompany').in('inCompany')).#rId
from Employee where userId = 3)
Remains if someone has the better solution
I've tried searching on here for my answer but have had no luck. I've tried many things to get this to work but haven't been successful so I thought I would post my question. I may repeat myself several times but I'm trying to be as specific/detailed as I can.
I have a form which has an append query to transfer all fields on the form into a table. On this form, I have an invisible control (textbox) which pulls the users Windows login ID and uses that as its default value. I have another field (textbox) for the user's full name.
I have ran a query to pull employee data from my tables to have the employee ID (same as their Window's login ID, first name, and last name. I have also ran an expression to concatenate the two name fields into one to show their full name.
What I've been trying to do is have it so that when someone opens up the form, their full name is already pre-loaded. As I stated above, this is pre-loaded based on a comparison of their Window's login ID with their employee ID that we have on record as they're the same. It's essentially Excel's version of vlookup() that I'm trying to do. I've tried dlookup() but was unsuccessful.
Does anyone know how to make the default value of the employee name control on the form to be determined by employee ID control which has its default value based on the user's Window login ID?
Example: Let's say that I have an employee called Fred Flintstone. In the database there's a table with fields for his first name and last name. There's also a field for his employee ID which is A111111.
When opening up the form, there's an invisible textbox control which has its default value derived from the Windows login ID that the employee used to sign onto the computer with. This Windows login ID happens to be A111111 which is the same as the employee's employee ID.
A query was created that has fields for the employee ID, First Name, Last Name, and an expression to concatenate the two name fields. So the first row would be: | A111111 | Fred | Flintstone | Fred Flintstone |. I don't know how to make tables on here yet so bear with me.
Going back to the form, there's a field for Employee Name. How would I get it to show Fred Flintstone as the default value upon opening the form?
Note: The employee name field will eventually be locked so that it cannot be changed by the employee. I don't know if that would have any impact but I thought that I would mention it.
In the onload event of your form (really rough code, will require some tweaking..):
dim db as dao.database
Dim rs as dao.recordset
Dim username as string
dim SQL as string
username = Environ("USERNAME") 'There are better ways to get username, but this is just a quick example.
SQL = "SELECT * FROM Your_Query WHERE username = '" & username & "'"
set db = currentdb
set rs = db.openrecordset(SQL,dbopensnapshot)
if rs.recordcount > 0
rs.movefirst
me.UserNameField = rs!username
else
msg "User Not Found"
End If
set rs = nothing
set db = nothing
I hope yo can point me in the right direction.
I have a SSRS report organized by Continent/Country/Customer and I need to change (force?) some of the customers to appear in a different region/country from the DB. ie:
I have a local NZ customer in the right Region/Country (australasia/New Zealand) but I want this one to show up in a different Region/Country namely (Asia/China) as this customer buys locally but exports all to China.
There are some others customers that needs to be manually organized, following the same criteria, of course.
any idea on how can I do this?
and will be the best option to do it through SQL-Server or SSRS?
Thanks in advance.
Eric
I would create a new table called something like AreaOverride with the following columns:
CustomerId
Continent
Country
Then link to this in your query using a left outer join and replace the Continent and Country with the overridden values if they exist:
Select CustomerId,
Case when AreaOverride.Continent is not null then AreaOverride.Continent else Customer.Continent end as Continent,
Case when AreaOverride.Country is not null then AreaOverride.Country else Customer.Country end as Country
From Customer
Left outer join AreaOverride On AreaOverride.CustomerId = Customer.CustomerId
You might want to make this a view if you are going to use it in several reports or other places.
Then whenever you need to override a customer's details you simply add a row for them in this table and the values will be overridden in your reports.
Note that if you are dealing with a vendor database rather than your own you don't want to be messing with their database structure but you can still do this by creating a new database and put the AreaOverride table in it. Then you add the database name to your join. For example if your database was called MyStuff then your join looks like this:
Left outer join MyStuff.dbo.AreaOveride On ...