How to create just a view in odoo9 that does not save data in a model? - odoo

I am working in odoo9. Now I needed a view that permits the user to select partner and get his sale history.
Now I created a model "sale.history" but it saves the selected data as a record in db. I really don't need this.
How can I create a view for this.
Please also see this image.

You have two options for such views/reports.
Use TransientModel instead of Model for the model inheritance. Transient model records in database will be deleted by a frequently running cron job. The email message PopUp/Wizard is a nice example for that.
Write your own report (database view) for sales order. Actually there already is one report for that: Reporting/Sales/Sales Analysis. The model for that report is sale.report if you want to know, how it's done.

Aside from using a TransientModel (old api) or AbstractModel (new api)...you can simply set the store property of field to false, that way your field will never be persisted to the database, it will simply be a 'view field'.
class sale_history(model.Model):
_name='sale.history'
partner = fields.Many2one('res.partner', store=False)
The partner field will never get saved to the database

You can use store=False on the field in the model (as danidee suggested).
You can also overwrite the create method on the model.
Question - what is the purpose of the "sale.history" model? If it does not store any data at all then you may be better off creating a new view against "res.partner" rather than creating a new model.

Related

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

How to order rows when custom model is made from GUI in Odoo v 10?

I have made a custom model using GUI. This model contains a field named sequence.
I want to order my rows by this field.
This same this has been done for res.company model and i want the same.
So, for companies
_order = 'sequence, name' is written in model.
and widget='handle' is used in tree view that orders various companies just by drag and drop.
So, i added this widget attribute in my tree view, but i don't know where to use _order='sequence'(the field I created in my model) because i don't have code for that model.
Is there a way that i can do i from GUI itself or I need to create that model from code??

concept of create method odoo8

I'm new at using odoo, so i faced an override of create method but still don't quite understand the concept.
This is the create method I used :
#api.model
def create(self, vals):
vals['task_idd'] = self.env['crane.task'].create({'equipment_id': vals['equipment_id'], 'type': vals['type']}).id
vals['task_ids'] = [(4, vals['task_idd'])]
return super(crane_workorder, self).create(vals)
this code works perfectly
i had a one2many relation that has been converted into one2one(logically), so i override the create method till i can create two records from two different classes...
PS1: equipment_id & type are required fields, but i don't understand how does it work ...
If what you mean is how does the list containing a single tuple [(4, vals['task_idd'])] give the desired result here is my understanding.
When Odoo is either creating or writing to a record which is a relation field Odoo uses a command syntax which is the structure you used in your code. Basically when writing or creating a related field from the perspective of any particular record Odoo tries to take away the ambiguity by creating a specific series of commands to use in these circumstances.
For instance if you need to write to a One2many field how is Odoo supposed to know if your are adding a new record to the list of many other records or are you saying that the list of related records is this new record you have referenced in your code.
So imagine you have a tree with a One2many relation with its Apples. If you were writing to a database recording another apple for the tree are you saying that this apple is to be added to the list of existing apples or is it replacing the existing list and should be considered the only apple that belongs to the tree.
So Odoo uses this tuple structure and has a process for parsing the tuple and determining how to handle its values and what to write to the database.
Here is a screen shot of the documentation Odoo provides on the matter. Here is the link to the page

Adding lookups to given view

I'm just getting into Yii. I have a simple relational db. I have a "client" table related to "orders" table (client:id to orders:client_id). If I build my CRUD for orders i naturally see client_id, however I'd rather add a lookup for client name somehow
I have found how to do this on new and update _forms by adding a dropDownList. The list based views seem a little more complex. I can see that actionIndex() in the controller is gathering data and passing it to index.php, finally through to _view, but I can't find any help on where and how I should break into this with my lookup returning the client name
I'd appreciate any help
thanks
Check the Yii documentation about relations. You will need to create a relation in your orders table, lets call it client, Then in your list view where it generates client_id you can put client.name instead. Now you will need to make sure that you have the appropriate label because in the generated model it will only have a label for client_id, and you need a label for client.name. Yii will guess, or you can add it, or you can modify the label for client_id, and instead of using client.name in the view you can use
array(
'name'=>'client_id',
'value'=>$model->client->name,
)
I tend to gravitate towards more explicit definitions rather than shortcuts, but to each his own.

Accommodating Dynamic Hierarchies in a Data Warehouse Model

I am building a data warehouse for the company's (which I am working for) core ERP application, for a particular client.
Most of the data in the source database, which is related to hierarchies in the data warehouse are in columns as shown below:
But traditionally the model to store dimension data according to my knowledge is as:
I could pivot the data and fit them in the model shown above. But the issue comes when a user introduces a new hierarchy value. Say for instance the user in the future decides to define a new level called Product Sub Category. Then my entire data warehouse model will collapse without a way to accommodate the new hierarchy level defined.
Do let me know a way to overcome this situation.
I hope my answer is clear enough. Just let me know if further details are needed.
Well, nothing should collapse -- the ETL should extract and load the data as always.
Here are a few options to consider:
Simply add one more column for the new hierarchy to the dimProduct.
Try using hierarchy helper table.
Consider adding path string attribute to the dimProduct.