How to show many2many field of another model in form Odoo13? - odoo

I need to display many to many field in form view, depending on the related user
modelo que contiene many2many fields:
many2one field where I want to show the many2many of the other model but filtered by user_id(Column: Asesor de servicio) only show records(column:bodegas) by column: Asesor de servicio

Related

Exist any way to create a new country state without popup a form in Odoo

I have a Many2one field of the res.country.state model and when I try to create a new record it always shows me a popup with the form view, Is there any way to prevent this and just create the new record
Code in the view
<field name="state_id" context="{'default_country_id': country_id}"
options="{'no_open': True}"/>
Code in the model
state_id = fields.Many2one('res.country.state', 'Issued Place', domain="[('country_id', '=?', country_id)]")

How to add fields to a tree view with default values on button click?

I add a button that open a new wizard, this last is contain only one field is number , that's number is the number of fields that i want to creat on my tree notebook tree view with default value
for example if i type 20 , thene whene i submit should i get 20 entries in the tree view
Here is a capture of the model :
Look to my code :
#api.multi
def creat_fields(self):
numbers = self.w_qtt
for values in numbers:
# self.env['sale.order.line'].create(lignes_vales)
self.env['sale.order.line'].create({
'contrat_name_id': self.w_contrat_name,
'contrat_lignes_id' : self.w_contrat_line,
'product_id' : self.w_product_name,
'bons_po' : self.w_po_number,
'product_uom_qty' : 1,
'price_unit' : self.w_prix,
})
and on the xml :
<footer>
<button string="Cancel" class="oe_link" special="cancel"/>
<button
name="creat_fields"
string="Enregistrer"
class="oe_highlight"
context="{'default_source_record_id': active_id}"/>
</footer>
I'm assuming that this is a one2many field. One2many fields are linked to your model by specifying the record id number in a field that you specify when you define the many2one field.
For example:
child_ids = fields.One2many('child.model.name', 'parent_id', 'Child Records')
So when you create a new line using the one2many field, a new record is created of model "child.model.name" and the parent_id field is set to the id of the current record.
So to create a number of empty lines in your form, all you have to do is create records with the "parent_id" field set to the originating records id.
Firstly, you will need to pass the originating record's id to the wizard, which you would do in the button definition:
<button name="%(wizard_action)d"
string="Wizard Button"
type="action"
context="{'default_source_record_id': active_id}" />
You will need a field called "source_record_id" in your wizard, which will be a many2one field with the same model that you are calling it from, and you will need to have that field in your wizard view, but you can make it invisible if you want.
In the code you're calling from the wizard, you will create a loop to call the create method on the "child.model.name" model to create that number of empty records. It would look something like this:
iterations = self.nombre
for i in range(iterations):
self.env['child.model.name'].create({
'parent_id': self.source_record_id.id
})
That will create the empty records and they will be displayed in your one2many field.

odoo 9 how to inherit many2one field value from parent view

I have hospital appointment registration model that is relates to lab test model :
'lab_test_ids': fields.one2many('oeh.medical.lab.test','apoointment','Lab Tests', readonly=False,states={'Completed': [('readonly', True)]}),
in the view I have a TAB (page) under appointment form :
page string="Lab Tests"> <field name="lab_test_ids" context="{'default_appointment': active_id}" domain="[('appointment', '=', active_id)">
My challenge is that I have patient and physician in both views (selection fields) that relate to two other models. I was wondering if I could SET value for a patient field in the parent view and inherit that value to the child view (Lab test). how can I do that?
NOW i use domain to filter through the patient. and the candidate patient is Only one . how can I set this value to the field automatically.
> <field name="patient" domain="[('id', '=', parent.patient)]"
I appreciate your help.
I'm not sure I 100% fully understand the question but you only have a few options to handle the scenario of copying field data between views.
1.
Onchange Field. Create an onchange if they are on the same view. (Don't believe this will work for you.)
lab_test = fields.One2many(...)
#api.onchange('lab_test')
def _onchange_set_lab_test(self):
self.other_field = self.lab_test
2.
Related Field. Setup the child as a related field if it's of the same type:
child = fields.One2many(related='lab_test')
3.
Computed Field. Setup the child as a computed field with pulls whatever information you need.
child = fields.One2many(compute='_compute_child_field')

Domain Filter is not working on many2many field in OpenERP 7.0

I have added new many2many fields into the wizard view and also put invoice filed of many2many fields
Field on py file :
'sup_inv_entries':fields.many2many('account.invoice', 'sup_inv_rel', 'sup_inv_id1', 'sup_new_inv_id', 'Invoice Entries'),
Field on XML view file:
<field name="sup_inv_entries" nolabel="1" domain="['|',('period_id','in',period_ids),('&',('date_invoice','>',date_from),('date_invoice','<',date_to)),'&',('type','=','in_invoice'),('state','=','open')]">
I want to make the filter invoice ids based on periods or date_invoice (from date and to date ) based on user selected scenario from the wizard.

Odoo show values of selected Many2one record

In my custom view, there is a field Many2one, next to it I would like to show values of that item as information in view after a serial_number is selected.
# model.py (newApi)
serial_number = fields.Many2one(comodel_name="stock.production.lot", string="Serial Number", required=True)
# view.xml
<field name="serial_number" options="{'no_open': True, 'no_create': 1, 'no_create_edit': 1}"/>
<div>
<span>serial_number.product_id.name</span>
<span>serial_number.product_id.description</span>
</div>
How I have to do correctly?
As per your requirement you need to use widget='selection' This will make many2one field as a selection field.
try with this:
<field name="serial_number" widget='selection'/>
USE related to do this :
Create a related fild in the model that have many2one relation
like this
field_name = fields.Char(string="Selected value", related="Field_name_in_co_model")
than put it in your form with readOnly :
<field name="field_name" readonly="1" />
when the user select an item the information of the selected record will show automaticly in the fields sorry for my english if you didn't undertand tell me i will give an exemple
you can even put it in tree form it's greate thing