Show values of one2many in tree - odoo

I have a tree table inside of another tree table. When I'm editing, the nested table is properly shown inside of the cell. But when I just view the values, there are just comma separated ids in the cell (instead of the nested table). How can I display the table in the cell or at least formatted values in the view mode?
Nested table:
<record id="view_mrp_repair_line_item_tree" model="ir.ui.view">
<field name="name">mrp.repair.line.item.tree</field>
<field name="model">mrp.repair.line.item</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Repair line items" editable="bottom">
<field name="description" />
<field name="price" />
</tree>
</field>
</record>
The parent table:
<field colspan="4" mode="tree" name="operations" nolabel="1" widget="one2many_list">
<tree string="Operations" editable="bottom">
...
<field name="items" context="{'default_repair_line_id':active_id}" widget="one2many_list" />
</tree>
</field>
Model from nested table:
class mrp_repair_line_item(osv.osv):
_name = 'mrp.repair.line.item'
_columns = {
'repair_line_id': fields.many2one('mrp.repair.line', 'Repair Line', required=True),
'description': fields.char('Description', required=False, size=160),
'price': fields.float('Price', required=False)
}
mrp_repair_line_item()

You can create a functional field that returns a single string that represents the values and display that field instead. For example: [description1: Price1], [description2: Price2], ...

Related

Odoo Inheriting fields and functionality

I am have made two different classes(model.Models). I have 10 fields in one class and I need to inherit only two fields in other class from the former one. Like I update two fields in one class , It automatically must be updated in next class. So please help me out. How should I need to inherit these two fields and their functionality?
This is the Odoo Framework.
You can use related fields to get values from another model. You can do this by defining a Many2one to the model and access field in that model using related fields.
example:
class ModelA(models.Model):
_name = 'model.a'
field1 = fields.Char()
.....
field10 = fields.Char()
class ModelB(models.Model):
_name = 'model.b'
model_a_id = fields.Many2one('model.a', string='Related Model')
field1 = fields.Char(related='model_a_id.field1', string='field1')
field2 = fields.Char(related='model_a_id.field2', string='field2')
You can access any field in model.a from model.b using related fields. If you change values of field1 or field2 from any of these models, the change will be reflected in both models. So if you don't want the user to change values of these model from model.b, you can make them readonly in that model.
<record id="ping_tree_view_id" model="ir.ui.view">
<field name="name">Ping tree view</field>
<field name="model">ping.ping</field>
<field name="arch" type="xml">
<tree string="Ping">
<field name="model_a_id"/>
<field name="Last_update"/>
<field name="Last_attempt"/>
</tree>
</field>
</record>
<record id="ping_form_view_id" model="ir.ui.view">
<field name="name">Ping form view</field>
<field name="model">ping.ping</field>
<field name="arch" type="xml">
<form string="Ping">
<sheet>
<group>
<field name="model_a_id"/>
<field name="Last_update"/>
<field name="Last_attempt"/>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="ping_actions_win">
<field name="name">Ping</field>
<field name="res_model">ping.ping</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>

Show list of available product fields for Inventory Adjustments (to find the barcode field)

I would like to add the barcode of my products to the product list in the inventory list in the inventory adjustments. The view list is:
<?xml version="1.0"?>
<tree editable="top" string="Inventory Details" decoration-info="product_qty != theoretical_qty" decoration-danger="theoretical_qty < 0">
<field name="product_id" domain="[('type','=','product')]"/>
<field name="product_uom_id" string="UoM" groups="product.group_uom"/>
<field name="location_id" domain="[('id', 'child_of', inventory_location_id)]" groups="stock.group_stock_multi_locations"/>
<field name="prod_lot_id" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}" groups="stock.group_production_lot"/>
<field name="package_id" domain="['|', ('location_id','=', False), ('location_id', '=', location_id)]" groups="stock.group_tracking_lot"/>
<field name="partner_id" groups="stock.group_tracking_owner"/>
<field name="theoretical_qty" readonly="1"/>
<field name="product_qty" string="Real Quantity"/>
<field name="state" invisible="1"/>
<field name="inventory_id" invisible="1"/>
<field name="inventory_location_id" invisible="1"/>
</tree>
If I try to add the field <field name="product_id.barcode" /> I am told that:
Field product_id.barcode does not exist
How to see all the fields that are possible to add in this list?
Seems like you can't go throughout models in XML views.
You can add a related field to the model you're displaying in this view basically like that : barcode = fields.Char(related='product_id.barcode') then you can show it in your view like this : <field name="barcode"/>.

Odoo: Display a field in tree view depending on value of another field in the model

I have a tree view in which I want to display a column depending on the value of another field. To be specific, in the Inventory app, I want to add a column in the tree view when the picking type is 'Internal Transfers'. I do not want to show the same column in any other picking type.
Please note, I am customizing this in Odoo Enterprise Edition.
I did attrs="{'invisible': [('x_picking_type_name','=', 'Internal Transfers')]}", where x_picking_type_name is a custom field in the model. I am able to hide values in the records but the column remains in other picking types.
I suppose, there is a way around with context but I could not make it work. I will appreciate any help on this.
The XML I am using. I am trying it in original view without inheriting.
<?xml version="1.0"?>
<tree decoration-info="state == 'draft'" decoration-muted="state == 'cancel'" decoration-danger="state not in ('cancel', 'done') and min_date < current_date" string="Picking list">
<field name="name"/>
<field name="location_dest_id"/>
<field name="partner_id"/>
<field name="date" invisible="1"/>
<field name="min_date"/>
<field name="origin"/>
<field name="x_picking_type_name"/>
<field name="check_todo" attrs="{'invisible': [('x_picking_type_name','!=', 'Internal Transfers')]}"/>
<field name="group_id" invisible="1"/>
<field name="backorder_id"/>
<field name="state"/>
<field name="priority" invisible="1"/>
<field name="picking_type_id" invisible="1"/>
<field name="product_id"/>
</tree>
According to this post
https://www.odoo.com/es_ES/forum/ayuda-1/how-to-add-a-field-conditional-to-tree-view-of-customer-14707#answer_198626
`attrs="{'invisible':[('customer','!=',True)]}"`

how to make an odoo field invisible if a many2many field value is "rice"

I am trying to make a duration character field visible 'only if' parent field called category_ids Many2Many field value "Non-Permanent" is selected. I have tried so many things but seems not working. Below is my code snippet
Model:
class hr_employee(models.Model):
_inherit = 'hr.employee'
identification_id = fields.Char(string="Employee No")
duration = fields.Char(string="Duration")
View:
<!-- Employee Form View -->
<record model="ir.ui.view" id="hr_custom_form_view">
<field name="name">hr.custom</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="groups_id" eval="[(4, ref('base.group_hr_user'))]"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='user_id']" position="after">
<field name="duration"/>
</xpath>
</field>
</record>

ODOO 8 on_change

Please I am facing somes problems with the new odoo 8 api, I have the following classes
class TypeProcessus(models.Model):
_name = 'atom.promaintenance.type.processus'
name = fields.Char()
id_phases = fields.One2many('atom.promaintenance.phases','id_processus','Liste des Phases')
class Phases(models.Model):
_name = 'atom.promaintenance.phases'
name = fields.Char()
autoriserCommentaire = fields.Boolean()
autoriserPiecesJointes = fields.Boolean()
id_processus = fields.Many2one('atom.promaintenance.type.processus')
parent_id = fields.Many2one('atom.promaintenance.phases','Phase Parent', select=True, ondelete='cascade')
commentaire = fields.Text()
#api.one
#api.onchange('name')
def phases_write(self):
print 'test'
<record model="ir.ui.view" id="atom_promaintenance_type_processus">
<field name="name">atom.promaintenance.type.processus.form</field>
<field name="model">atom.promaintenance.type.processus</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Type Processus" >
<sheet>
<h1>UPDATED</h1>
<field name="name" />
<tree string="note_evaluation_tree" editable="bottom">
<field name="id_phases" />
</tree>
</sheet>
</form>
</field>
</record>
First of all my problem is when Creating a new Processus, and adding phases, there is a relation parent child between phases and the drop down list for parent stay empty unless u save the processus to make them available.
i managed to add onChange event to the phases to persist them to database but i can't figure out how to save those records with the new api system, thank you
If you mean what I understand, you need to use the widget one2many_list in the XML code, which by the way, I think is wrong. It should be something like this:
<record model="ir.ui.view" id="atom_promaintenance_type_processus">
<field name="name">atom.promaintenance.type.processus.form</field>
<field name="model">atom.promaintenance.type.processus</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Type Processus" >
<sheet>
<h1>UPDATED</h1>
<field name="name" />
<field name="id_phases" widget="one2many_list">
<tree string="note_evaluation_tree" editable="bottom">
<field name="name"/>
<field name="autoriserCommentaire"/>
<field name="autoriserPiecesJointes"/>
<field name="parent_id"/>
<field name="commentaire"/>
</tree>
</field>
</sheet>
</form>
</field>
</record>
The widget will allow you to add phases for a processus and then save it.
The new API uses self for all the record modifications. So in your case, if you want to change the name, write like this:
#api.one
#api.onchange('name')
def onchange_name(self):
self.name = 'what you want to save'