How to hide column in odoo 12? - odoo-12

Please i need to hide column "Description" in table "Order Lines" in form view external_id="sale.view_order_form", hide this column if details==True
Here is python code:
class ClassSaleOrder(models.Model):
_inherit = 'sale.order'
details = fields.Boolean()
Here is xml file :
<record id="module_sale_order_line_form" model="ir.ui.view">
<field name="name">module.sale.order.line.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='partner_id']" position="after">
<field name="details"/>
</xpath>
</field>
</record>

You need to use position='attributes' and define the value for invisible attribute.
<xpath expr="//field[#name='order_line']/form/group/field[#name='name']" position="attributes">
<attribute name="invisible">[('details', '=', True)]</attribute>
</xpath>

Use the below code for making description field invisible when details is true
<xpath expr="//field[#name='order_line']/tree/field[#name='name']" position="attributes">
<attribute name="attrs">{'invisible':[('details', '=', True)]}</attribute>
</xpath>

Related

how to add field to product.template in odoo 12

I would like to display a field in Form View of the product module, here is the python file (i use odoo 12.):
class ClassProductInherited:
_inherit = 'product.template'
file = fields.Char(string="Choose File")
Here is xml code (i use odoo 12.):
<record id="view_product_form_inherit" model="ir.ui.view">
<field name="name">product.template.common.form.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//page[#name='inventory']/group" position="before">
<group col="2" colspan="2">
<field name="file"/>
</group>
</xpath>
</field>
</record>
When I restart the server, problem is that I have the following error:
File "/home/odoo/models.py", line 1112, in _validate_fields
raise ValidationError("%s\n\n%s" % (_("Error while validating constraint"), tools.ustr(e)))
odoo.tools.convert.ParseError: "Error while validating constraint
Field `file` does not exist
Error context:
View `product.template.common.form.inherit`
[view_id: 2095, xml_id: module.view_product_form_inherit, model: product.template, parent_id: 402]
None" while parsing /home/omar/odoo/custom-addons/addons12/module/views/views.xml:403, near
<record id="view_product_form_inherit" model="ir.ui.view">
<field name="name">product.template.common.form.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//page[#name='inventory']/group" position="before">
<group col="2" colspan="2">
<field name="file"/>
</group>
</xpath>
</field>
</record>
1- First, check if the manifest.py file contains:
"depends": [
'product'
],
2- check if the name of your file that contains the class ClassProductInherited: exists in the init.py file like this for example:
from . import my_file
<record id="view_product_form_inherit" model="ir.ui.view">
<field name="name">product.template.common.form.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='weight']" position="before">
<group>
<field name="file"/>
</group>
</xpath>
</field>
</record>
Try this piece of code and let me know if it works.
check in your .py file that you have to inherit only single module in one ... if you declare more than one module in single record so remove it. and make another record for another module. then after check it you declare or note the field file in your .py file

Editable tree view inside a form view is not saving

I have an editable tree view inside my form view.
See this picture:
I can edit the values inside the tree, but every time I hit the Save button at the top, it doesn't save the updated values inside my tree. It goes back to default (in this case 0).
Below is the code for my form view:
<record model="ir.ui.view" id="score_card_form_view">
<field name="name">Score Card</field>
<field name="model">golf_online_ph.score_card</field>
<field name="arch" type="xml">
<form>
<sheet>
<group string="Score Card">
<field name="round_id" />
<field name="player_id" />
<field name="round_holes">
<tree editable="top" >
<field name="hole_number" readonly="1"/>
<field name="score_value"/>
</tree>
</field>
</group>
</sheet>
</form>
</field>
</record>
What should be my workaround here?
Hello #Adrian Steven Quevada,
Your solved? Else update more info about fields. Because your view seems right.

Is possible treeView inside treeView in odoo

i want to display treeview inside line_ids.
look picture.
group by is sale.order field /line sale.order.line/
How to decision?
Old fashoned tree view:
To get this view you have to define action with view_type="tree" f. e.
<record id="res_partner_action_form" model="ir.actions.act_window">
<field name="name">Partners</field>
<field name="res_model">res.partner</field>
<field name="view_type">tree</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
</p>
<p>
</p>
</field>
</record>
Tree view definition looks the same as normal one. The diffrence is that here you can use parent_id.
<tree string="Account Reports Hierarchy">
<field name="name"/>
<field name="type"/>
<field name="parent_id" invisible="1"/>
<field name="account_report_id"/>
</tree>

odoo 10: extending form view tree of related records (inventory.stock.line)

I need to extend a form (stock.view_inventory_form) in Odoo 10. The form has a sub-tree populated with related records from another model. Here's the part of the original form that I want to change:
<field name="line_ids" string="Inventory Details" context="{'default_location_id': location_id, 'default_product_id': product_id, 'default_prod_lot_id': lot_id, 'default_package_id': package_id, 'default_partner_id': partner_id}" mode="tree,kanban">
<tree string="Inventory Details" editable="bottom" 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', parent.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="True"/>
</tree>
</field>
Where line_ids is a field from a related model (stock.inventory.line). So I extended the model with the following:
class stock_inventory_line(models.Model):
_inherit = 'stock.inventory.line'
x_container_details = fields.Char('Container details')
x_wagon_no = fields.Char('Wagon No')
x_seal_no = fields.Char('Seal No')
x_invoice_no = fields.Integer('Invoice No')
x_net_weight = fields.Integer('Net weight')
x_gross_weight = fields.Integer('Gross Weight')
Then I tried to extend the form with the following code:
<record id="view_form_todo_task_inherited" model="ir.ui.view">
<field name="name">Test</field>
<field name="model">stock.inventory</field>
<field name="inherit_id" ref="stock.view_inventory_form"/>
<field name="arch" type="xml">
<field name="line_ids">
<field name="x_container_details"/>
<field name="x_wagon_no"/>
</field>
</field>
</record>
Odoo is not returning any error, but my fields are not showed in the (sub) tree of the form.. what am I doing wrong?
Thanks to anyone that can help with this!
This is not the right way to extend a view, you should take a look documentation.
You need to specify the position were you want to add or replace fields, this is an example to insert fields at the end of the list:
<record id="view_form_todo_task_inherited" model="ir.ui.view">
<field name="name">Test</field>
<field name="model">stock.inventory</field>
<field name="inherit_id" ref="stock.view_inventory_form"/>
<field name="arch" type="xml">
<!-- to insert your fields at the end of the list -->
<xpath expr="//tree/field[#name='state']" position="after" >
<field name="x_container_details"/>
<field name="x_wagon_no"/>
</xpath>
</field>
I hope this can be helpfull for you.

How to make many2one field auto-complete in Odoo(formerly openerp)?

We have partner_id field in sale order form, I want to make that field auto-complete when user going to input the value, any suggestions will be welcome.
my code is :
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="air_odoo_sale_order_view" model="ir.ui.view">
<field name="name">air.odoo.sale.order.view</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<field name="partner_id" position="attributes">
<attribute name="group">base.group_manager,base.group_sale_salesman</attribute>
</field>
</field>
</record>
</data>
</openerp>