I am creating a service to query Tasks collection from the MongoDB. It have a custom id field called uId, and a task store other uId of other taks in its field named subtask. I want to populate the field subtask, the task model is this task model
I expect to populate the field subtask with uId
Related
I've made a model with a field name Car where users can write a car model, so I want to count the number of each model.
I was looking
self.env['car.model'].search_count(['car_model', '=', 'name_of_model'])
So I want to count every data that user write but dynamically.
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
How to create a dynamic attribute in lov at runtime?
Suppose I have a employee lov, where only two attributes are currently present like employee id and employee name.
It user want to add a few more column at run time like employee age and employee salary.
Without changing the LOV logic. The user has one master table where IT user can handle how many attribute should be displayed to business user. They can add a new parameter in table which can be displayed.
Can anybody suggest me some approach to handle this type of scenario?
If I got you right, I'd use backingBean with method that returns List, that implemented as ArrayList<SelectItem>. Then populate from any source(like VO, or whatever mixed) label and value according to your current user request.
I am having the following case:
There is entity 'Master_Entity'. This entity has properties as name, type, duration etc. There are other two type of entities 'Entity' and 'Sub-Entity'. There are identical as the 'Master_Entity' (They have absolutely the same properties).
At the end the 'Master_Entity' should hold a collection of 'Entity' and 'Entity' should hold a collection of 'Sub-Entity'. The tricky part is that records of type 'Entity' can be part of different 'Master_Entity' (same for 'Sub-Entity'), but they can have different values for duration for example. How can achieve such modularity?
Here I came up with, but it's not quite do the work. May you guys help me with this.
Edit: Imagine this as some sort of a work tracker. For example you have a 'Create PHP App' (Master entity). This entity contains duration of how long it will take to finish this job. In addition it contains a entity 'Writing Code' (Entity) and this one can be divided to 'Writing Http Client' (Sub-Entity) which has duration property which is specific for this job.
On other side you might have other job: 'Create an Java App' (Master Entity) which will contain the same 'Writing Code' entity, but with duration which will have different value, because of the context of the Application you are building.
I want to have a single record 'Writing Code', but the duration value that it have should be different for every job it's assigned to. How can achieve that with creating a minimum duplicating records of type 'Entity'?
It sounds like something like these 3 tables will work for you:
Entity
* Id
* Name
* Type
EntityGroup
* Id
* Name
* ParentEntityGroupId
* ParentEntityId
EntityRelationship
* Id
* EntityId
* ParentEntityId
* EntityGroupId
With this structure, you can have an Entity be a member of a Group, or a solo Child of another Entity. You can also have a Group be a Child of an Entity, or even a Child of another Group. Without knowing specifics of your data, it's hard to know what you might need, but this should get you started.
From what you have said, it seems that you don't need EAV at all because you don't have different properties for each item just different values. And thus you should not be using it.
What you need is a combination of lookup tables and then tables that address the actual tracking history of the work. This is because this is time sensitive data. The tasks at the time the projects was created may be substantially different than the tasks associated with that task group two years from now, but you need to record the tasks at the the time of creation). Note that this is not denormalizing, it is creating a picture of data in time. The real duration always goes to teh project not ever to the Task. In the task, you can have a suggested duration to use as a starting point. I used a similar design (with far more fields of course) to design a database for building sales proposals for technical-hardware related projects. The real key here is to recognize what data needs to be stored as a point time time and what is lookup data used to build the final project data. If someone adds a new task to the "Create a Java App" group, you don't want to change details about projects already completed or in work, only new projects.
So you need:
Task group
Task Group ID
Task Group Name
Task
TaskID
Task Name
SuggestedDuration (can be null if you have tasks that are always different
but filled in for tasks that usually have a similar duration)
Task_Taskgroup
TaskID
TaskGroupID
Project
ProjectID
ProjectName
TaskGroupID
ProjectTask (should be filled in automatically when the task group is
chosen for the project)
ProjectID
Task ID
EstimatedDuration (fills in the default value, but can be changed
by the person creating the work project)
ActualDuration (Field in after the task is done, can be used by an
analyst to create more reflective task default duration values)
Of course each of these tables may have other fields depending on the need.
SCENARIO:
I've got my application which needs to do data synchronization with OpenERP. I am planning to achieve that by:
Creating a date-time field on the OpenERP models I need to get data synced.
Every time the OpenERP model gets updated, that date-time field value changes to the current date-time.
From my Application stand point, I will do a cron job in a given interval. I wont actually use cron jobs, for the sake of simplicity lets stick with cron jobs.
My Application will request a search for all entries that has the date-time field value greater than the last checking time.
QUESTIONS
Is there some kind of event that let me call my custom function upon a form submission?
From my function scope, when a model's entry is being edited, is it possible to find out if any of the form field values had been changed?
The OpenERP ORM has a create and write method. You will need to override both as they both act as on_submit type methods but are called for new or existing records.
All you do is override one or both methods and call super to make sure the record is actually written then do whatever you want. You can also intercept the write and make changes. For a create the code would be:
def create (self, cr, uid, values, context = None):
new_id = super(MyObject, self).create(cr, uid, values, context = context)
# Do stuff here. Can look in values dict to see what has changed
return new_id
The write method is much the same except you also get the ids to be written.
OpenERP already has create and write dates but those are there for OpenERP auditing and locking and you should probably implement your own date/time marker. The easiest would be to make it a functional field and set store=True so it is recalculated and stored everytime the record is written