Geting user details using foreign key from res.users in Odoo - forms

I have a model Employee and have included a foreign key to store the user object from the res.users table using the following code in my model:
user_id = fields.Many2one('res.users', string='user id', default=lambda self: self.env.user)
In my form, I am already capturing the user object.
Now, I want to display the user object's details (id, name, email) using the foreign key (that is the user object) in my form view.
The <field name="user_id"/> in my form view would display the user name of the stored object. I want to display different fields for id, email.

you can create a related field for user_id,
x = fields.Char(related='user_id.email')
like this you can access the all field values of related record.

Related

Adding data to Postgres database with Entity Framework Core HttpPost failing because of child table constraint

I am trying to add some data to a Postgres database using Entity Framework Core via a Http POST method.
The data to be added is passed in the body of my post request which looks like this:
{"id":42,"name":"Hans Musterman","email":"hans#gpost.com", "gender": {"id": 2, "name": "male"}}
Which is exactly the structure I would get returned using a get request.
Still the insert fails with an error:
Duplicate key value violates unique constraint "PK_Genders"
Of course the gender male already exists in the Genders table. What I want to do is add a user to the users table with a gender but referenced for the new user but not new created. What the system seems to do when using DbContext Add is trying to add User and Gender.
Is there a way to do it with a reference? Adding a User with "gender" = null does work.
I think you should have something like genderId or foreign key that reference the gender table in the user model use that foreign key id (genderId) instead of gender.
eg. in you user object
{ ... "genderId": 2 }
Otherwise Entity Framework is going to create a new gender that is why you are getting that error

When Create in CRUD show other column then Foreign Key

Pretty sure you guys will know that i'm
fairly new in this by looking at my problem.
So when i create From CRUD i get foreign key id values which is understandable here my foreign key is Grade id but i want to show user not id but grade which can be A,B,C which is stored in another Column while still saving foreign key ID when user click on create
enter image description here
Sorry for bad English.
If you want the display of the dropdownlist is the Grade value rather than Grade id , you could try Using ViewBag to transfer the list of items
public IActionResult Create()
{
//using viewbag
ViewBag.Country = new SelectList(_context.Country, "Id", "CountryName");
return View();
}
And in the view
<select asp-for="CountryId" class="form-control" asp-items="ViewBag.Country"></select>
More methods of Select Tag Helper binding value, you could refer to here

customized user id in User table in laravel

Helo I am trying to assign a user id with some prefixes like PS00 and save it in user table while user registration.
I have tried mutators in laravel
public function setProfileIdAttribute($value){
$this->attributes['profile_id'] = "PS00".$this->id;
}
But unable to add profile_id to table, as it says profile_id can not be null.

What's the relationship between res.partner and res.user?

I am new to odoo v8 and i am not able to understand the relationship between res_partner and res_users tables and also with hr_employee table are they all related?
The relationship between res.partner and res.user is that res.user inherits from res.partner using an inheritance type called "Delegation Inheritance" (see documentation).
Because of "Delegation Inheritance" every res.user record has a mandatory internal connection to a corresponding res.partner record using a field partner_id. What is this connection all about is to directly use all the fields of res.partner to store data shared by res.user and res.partner (i.e. name, phone, etc... if for example you refer to phone property of a record of res.user you'll get the value stored in the corresponding res.partner record) so res.user has to define fewer number of fields on it's own, like password, login, etc..
Note also that because of this relation res.user can NOT exist in the system without corresponding res.partner, it's why every res.user has one, but nonetheless res.partner can exist without res.user.
hr.employee have m21 with res.users (user_id)
res.users have m21 with res.partner(partner_id)
Actually only res.users has a "real" relationship to res.partner, because with every user odoo will create a partner (per default no customer and no supplier). this partner will be used e.g. for emails and the followers system in odoo.
But you can have partners without users, too. That will be a normal partner, for defining customers and suppliers.
And finally there is the employee. You can set a user on it. If i recall right, the user will be used for attendances and timesheets.

Extend User authentication object in Azure Mobile Services

Is it possible to add additional properties to the User object on the server in WAMS? I would like to store the Id primary key of my User table for (secure) use in my table scripts. At the moment the only id is the vendor specific authentication Id, but I'd like to be able to allow users to choose an authentication method. Currently my (simplified) table design is as follows:
User table:
id
googleId
twitterId
facebookId
name, etc...
League table
id
userId
name, etc
I'd like to store the user primary key in the userId field on the league table, and then query it to ensure that users only get to see leagues they created. At the moment, the user object in table scripts sends through a User object with the Google/Twitter/Windows authentication token and I have to do a query to get the primary key userID, everytime I want to carry out an operation on a table with a userId column.
Ideal solution would be that when the Insert script on my User table is called on registrations and logins I can do:
// PSEUDO CODE
function insert(item, user, request) {
var appUserId;
Query the user table using the user.userId Google/Twitter/Facebook id
If user exists {
// Set a persisted appUserId to use in all subsequent table scripts.
user.appUserId = results.id;
} else {
Set the GooTwitFace columns on the user table, from user.userId
insert the user then get the inserted record id
// Set a persisted appUserId to use in all subsequent table scripts
user.appUserId = insertUserPK;
}
}
Then, in subsequent table scripts, I'd like to use user.appUserId in queries
If all you are trying to do is authorize users to only have access to their own data, I'm not sure you even need the "user" table. Just use the provider-specific userId on the user object to query your "league" table (making sure the userId column is indexed). The values will be provider-specific, but that shouldn't make any difference.
If you are trying to maintain a notion of a single user identity across the user's Google/Facebook/Twitter logins, that's a more complicated problem where you would need a "user" table and the kind of lookup you are describing. We hope to ship support for this scenario as a feature out of the box. It is possible (but fairly messy) to do this yourself, let me know if that's what you're trying to do.