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

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??

Related

Carry page values to another model page, Odoo

I want to carry notebook page One2many field to another model page.
These field from my main model. I want to carry page field with this operation.
T
How can fill these page fields after creating method.
Brother, Please state your question clearly.
I hope that notebook has a one2many relation with the purchase ?
If so, Before that you have to know in which purchase order id you want to add those field values.
Then create a object button in your custom model, use create method in that and in the dictionary pass the same purchase order id in that.

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 create just a view in odoo9 that does not save data in a model?

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.

OpenErp(Odoo) How to add custom analysis on reporting Tab

I need to make summery of raw materials used, the qualty of products ,final products status . . . for each manufactureing process and provide this information on the reporing tab like sales anlysis and purchase analysis . . . How can I do this? and insights about my requirment?
Create a module for your custom analysis report. I will explain how the Sales Analysis report is created. Using that you could create your own analysis report.
Steps
Create a module for your report in the addons folder. You can use the following link for details about creating a module How to create an ODOO module
Create a python file in the module and import it in the __init__.py file. In that file create a model based on a PostgreSQL view. Add a method init(self, cr) that creates a PostgreSQL View matching the fields declared in _columns. You can check this in the file sale_report.py in report folder of sale module. Create the fields you needed in the _columns and write the query in the init method for getting values to these fields.
Specify the parameter _auto=False to the OpenERP object, so no table corresponding to the _columns dictionary is created automatically.
For the model sale.report data is taken from a view defined in the init method of the model. The value for each field is calculated dynamically, that is at the time we click on the menuitem for the Sales Analysis report in Reporting tab. The aliases in the select query of the view creation are the field names of the model sale_report. For example in select query you can find uom_id as product_uom where product_uom is column in the model sale_report.
Define the views. Create an XML file in the report folder of the module. You can use the sale_report_view.xml file in the sale module as reference. Create an XML view for the model, including tree view, search view and graph view. In the tree view, there is an attribute in the <tree> tag that is create="false". This is used for hiding the create button in the tree view. Create an action and a menuitem for the view as in the sales analysis report.
Restart the server and upgrade the module.
Compare your report with sales analysis reportto solve any issues.

How to add a many2one relation to a custom model

I try to add to an order a new attribute that relates to a custom many2one relation. The goal is to choose for each order one specific contract condition. I would like to manage those contract conditions in the database, so that I can easily manage them.
I sort of got far. I can edit those conditions, assign them and get them properly printed. However, on the sale-order form they get displayed in a weird way. Instead of the descirption-text of the condition, I see sort of a description of the associated record. So my question is, how to show the proper description attribute. See here:
Below I added a few screenshots that explain the type of changes that I did.
custom data structure:
many2one relation from sale.order to custom structure:
views for custom structure:
reference from order form, which is displayed oddly
Define _rec_name into your class.
_rec_name = 'x_condition'
It's because it will looking for name field into your custom model when you add many2one field for that model, when you define _rec_name it will take that field value.
Try to use x_name instead of x_condition for field name