How to update external_id for partners/companies and Where is default external_id is generating in odoo? - odoo

I want to update all the external ids of res.partner in system while creating partners using create() method. Also, I am not getting the functionality where the default external id name(res_partner_id) is generating.
Example :
Default generated external_id : res_partner_[id]
External id to be updated : abcd_res_partner_country_id_[id]

An External ID is an identifier for a data record. The mechanism behind this is quite simple: Odoo keeps a table with the mapping between the named External IDs and their corresponding numeric database IDs. That is the ir.model.data model.
To inspect the existing mappings, go to the Technical section of the Settings menu, and select the Sequences & Identifiers | External Identifiers menu item.
Recommended link: https://www.odoo.com/forum/help-1/question/how-to-update-external-id-50395

Related

reactjs: material-table: how to do serverside validation when adding or editing

I am planning to use material-table. Its a simple table with a column name
I have seen some tutorials how to do CRUD operation using material-table.
But i want to check the name is unique from server side, not on client side.
and pass the error if the name is not unique.
Can we do these things with material table

How to create a unique number in Sanity.io?

I have a field of the type number defined on a document in my schema. When the user inputs a number, I want a validation which verifies that no another document of the same type has the same number assigned to this field. How am I able to do this?
There's no out of the box solution to check for uniqueness. Currently the only input that does this is the slug field. However, you can create your own custom validation that uses the client to check for other documents with the same number for the specific field.
You can read more about custom validation in the docs. To import the client, you can add this to the top of your schema import client from 'part:#sanity/base/client'. Then, write a GROQ query to look for the number and validate accordingly.
Hope that helps!

Why related fields use Write function

_name = "my.table"
building_id = fields.Many2one('building', related='floor_id.building_id', readonly=False)
floor_id = fields.Many2one('building.floor')
A user with the read access to 'building' and 'building.floor' tables, tries to create a record in "my.table" If the user chooses building_id and floor_id together an error occurs. The error says that my user has no access to write 'building.floor' table. My question is: why a related field use the write function, what is the difference between the compute and related in this scenario?
Related fields are very simple computed fields. So simple they can be "implemented" with one parameter on field definition. Odoo has generic methods for those fields. For example a lot of developers don't write inverse methods for computed fields, which inverse the compute method, because the simply don't need it. But without it and without storing the computed field, Odoo sets the field readonly.
Related fields have a generic inverse method. In your case changing building_id when there was already a floor_id chosen, Odoo will write the building_id on that floor_id.building_id, because that's how related fields work (i know that's not the best explanation).
The user obviously has no write/update rights on builiding.floor model and that's why there will be the access error message in the end, because Odoo wants to write the new building on the floor.
Seems to me you want to filter the floors by buildings, but you shouldn't use a related field for that. Just put a domain on floor_id which filters by the chosen building_id:
floor_id = fields.Many2one('building.floor', domain="[('building_id', '=?', building_id)]")
You could also use domain operator =, but =? will show all floors when no building was set yet.

Adding a constraint to stop a user from updating some fields when importing the data with its generated external id

I want to add a constraint but I don't have the idea of how to do it. I created a custom export which auto-generates external ids for each record I export. The export contains a list of students which the lecturer has to update their marks.. and re-imports the same excel sheet which also updates the marks of the students.
However much there is some information which I don't want the lecturers to update but I have failed to restrict the lecturer from importing the data in case those field values have been updated.
Any Ideas, Thank you.
If a student is a res.partner and you're a bit technical (eg: you know how to code in Odoo), you can migrate this module partner_changeset to version 12. It's only available for v10 now.
This module allows an administrator to setup rules on some fields of res.partner object. With this rule, you can discard changes made by a user or send the change to validation to an "admin".

Compute many2many field with values from another model using Odoo developer interface

I need a new field inside Contact model that would hold information about Allowed companies of the related user.
Now there is only field about Currently picked company by that user (and it is not enough for me to make a record rule).
The field I want to copy values from is inside model Users and it is called company_ids.
I’m trying to add this field in the developer mode (Settings > Technical > Fields) like this:
But I’m having trouble with code that would fill my field with values from the another model.
for record in self:
record[("x_company_ids")] = env['res.users'].company_ids
I’m guessing that the record is referring to a record inside Contact model and it does not contain fields from another models like Users. So I can’t figure it out how to reference a field from another model.
Something similar to this: env['res.users'].company_ids?
It is even harder for me because it is many2many field and should always update when the source changes.
Maybe better solution would be to use Automatic action to write values to this field?
I saw some threads like this: Computed many2many field dependencies in Odoo 10.
But it seems like in those cases they had clear connection between the fields and I don't have it. I don't know how to get related user while I'm inside Contact model. I know only how to this oposite way (from user to contact): user.partner_id.id
Here in below given code you haven't specified related user from which you will get company_ids, you have directly accessing company_ids
for record in self:
record[("x_company_ids")] = env['res.users'].company_ids
You can write as following :
for record in self:
record["x_company_ids"] = self.env['res.users'].search([('partner_id','=',record.id)]).company_ids