Carry page values to another model page, Odoo - 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.

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

Odoo many2one field related to one2many

I'm confused by something in the Odoo source code. On the stock.picking model, there is a product_id field. It's defined as a related field via move_lines.product_id.
move_lines is a one2many field. I don't understand how a many2one field can use a one2many field as its relation.
Here's a link to the source code I'm referring to:
https://github.com/odoo/odoo/blob/316ffc80147de076b28c6156ac679dd90da0935e/addons/stock/models/stock_picking.py#L288
You can see that product_id is defined as:
product_id = fields.Many2one('product.product', 'Product', related='move_lines.product_id')
And move_lines is defined as:
move_lines = fields.One2many('stock.move', 'picking_id', string="Stock Moves", copy=True)
What is the purpose of this definition? How is it even allowed?
If I look at the value of the product_id field for a picking, it returns the product for the first move line in the picking, not all of products.
However, if I search the picking tree view with a custom filter on the Product field, for example, Product contains 'Product Name', the results seem to account for all products in the picking. If I search for any product in the picking the picking appears in the view, it's not just limited to the first product.
Can someone explain this behavior? There is even a note in the source code that the product_id field is specifically for searching, so I'm thinking there is some magic functionality I never knew about.
It's not related to the One2many field, it's related to the move_lines object (which is stock.move model), and takes from that model product_id field, which has a type of Many2one. So, everything is correct. Here's the code.

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.

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