I would like to bring the field client_order_reffrom sale.order model to mrp.workorder . I did it like this but when I run, It does not show any value. What could be wrong?
class MRPWorkOrder(models.Model):
_inherit = 'mrp.workorder'
nro_viaje_id = fields.Many2one('sale.order', string="Nro de Viaje")
nro_viaje = fields.Char(related='nro_viaje_id.client_order_ref', store=True)
The view extension:
<record id="view_workorder_form_inherit" model="ir.ui.view">
<field name="name">view.workorder.form.inherit</field>
<field name="model">mrp.workorder</field>
<field name="inherit_id" ref="mrp.mrp_production_workorder_tree_editable_view"/>
<field name="arch" type="html">
<xpath expr="//field[#name='workcenter_id']" position="after">
<field name="nro_viaje" string="Viaje" optional="show" readonly="True">
</field>
</xpath>
</field>
</record>
This is the error it shows me when I run it #Tiki
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/odoo/odoo/odoo/http.py", line 639, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/odoo/odoo/odoo/http.py", line 315, in _handle_exception
raise exception.with_traceback(None) from new_cause
odoo.tools.convert.ParseError: while parsing /opt/odoo/odoo/custom_addons/mrp_custom/views/views.xml:37, near
<record id="view_workorder_form_inherit" model="ir.ui.view">
<field name="name">view.workorder.form.inherit</field>
<field name="model">mrp.workorder</field>
<field name="inherit_id" ref="mrp.mrp_production_workcenter_tree_view_inherit"/>
<field name="arch" type="html">
<xpath expr="//field[#name='workcenter_id']" position="after">
<field name="nro_viaje" string="Viaje" optional="show" readonly="True"/>
</xpath>
</field>
</record>
Related
I have a parent model (Plant) which sends the active_id (plant_id) in the context as a default:
class Plant(models.Model):
_name = 'db.plant'
_description = 'db.plant'
name = fields.Char("Name", required=True)
...
Plant view with a many2one relation between them:
<odoo>
<data>
<record id="plant_list_view" model="ir.ui.view">
<field name="name">db.plant.view</field>
<field name="model">db.plant</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
...
</tree>
</field>
</record>
<record id="plant_form_view" model="ir.ui.view">
<field name="name">db.form.view</field>
<field name="model">db.plant</field>
<field name="arch" type="xml">
<form>
<sheet>
<group string="Plant">
<field name="name"/>
...
</group>
<group string="Components">
<notebook>
<page string="Data Sources">
<field name="data_source_ids" context="{'default_plant_id': active_id}">
<tree >
<field name="name"/>
...
<!-- <field name="plant_id"/> -->
</tree>
</field>
</page>
</notebook>
</group>
</sheet>
</form>
</field>
</record>
<record id="plant_action" model="ir.actions.act_window">
<field name="name">plant</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">db.plant</field>
<field name="view_mode">tree,form</field>
</record>
</data>
and his child model (Data_source):
class DataSource(models.Model):
_name = 'db.data_source'
_description = 'db.data_source'
name = fields.Char("Name", required=True)
plant_id = fields.Many2one('db.plant', name="Plant", required=True)
data_source view:
<odoo>
<data>
<record id="data_source_list_view" model="ir.ui.view">
<field name="name">db.data_source.view</field>
<field name="model">db.data_source</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
...
</tree>
</field>
</record>
<record id="data_source_form_view" model="ir.ui.view">
<field name="name">db.form.view</field>
<field name="model">db.data_source</field>
<field name="arch" type="xml">
<form>
<group>
<field name="name"/>
...
</group>
<group>
<field name="plant_id" domain="[('id', '=', context.default_plant_id)]" />
</group>
<group>
</group>
</form>
</field>
</record>
<record id="data_source_action" model="ir.actions.act_window">
<field name="name">Data Source</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">db.data_source</field>
<field name="view_mode">tree,form</field>
</record>
</data>
I know that the default_plant_id is received in the child because the plaint_id domain is filtering just my plant_id but I am not able to set it automatically as a default value. I need to click on the list and select my plant_id (which is the only element in the list).
I also tried adding an #api.on_change("plant_id") in the child (data_source) in two ways:
Option 1:
#api.onchange('plant_id')
def onchange_plant_id(self):
if self.plant_id:
context = dict(self._context or {})
return [(0,0,{'plant_id': context.get('default_plant_id')})]
giving me this exception:
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/albertocrespo/tools/odoo/odoo/http.py", line 640, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/Users/albertocrespo/tools/odoo/odoo/http.py", line 316, in _handle_exception
raise exception.with_traceback(None) from new_cause
AttributeError: 'list' object has no attribute 'get'
Option 2 (I am not sure what to send as a response, but the write statement is also not working):
#api.onchange('plant_id')
def onchange_your_many_to_one_field(self):
context = dict(self._context or {})
self.plant_id.write({'id':context.get('default_plant_id')})})
res = {}
return res
I need to auto-select my plant as an option in the data_source view before saving it.
There is no need of onchange method or anything on xml side - context level. You can simply use field plant_id in a relation one2many field data_source_ids.
Try with this:
data_source_ids = fields.One2many("db.data_source", "plant_id")
I tried this code but nothing happened:
#view.xml
<odoo>
<data>
<record id="view_pos_config_kanban_inherit" model="ir.ui.view">
<field name="name">pos.config.inherit</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.view_pos_config_kanban"/>
<field name="arch" type="xml">
<xpath expr="//kanban/templates/t/div/div[3][contains(#class='o_kanban_manage_button_section')]" position="replace">
</xpath>
</field>
</record>
</data>
</odoo>
What I want To Hide
Odoo will raise odoo.tools.convert.ParseError: "Invalid number of arguments" because of contains function used in div.
You can check in the XPath documentation provided by Odoo that contains is a function to manipulate strings:
contains(s1, s2)
returns true if s1 contains s2
Use XPath to locate the div with o_kanban_manage_button_section class and make it invisible.
Example:
<record id="view_pos_config_kanban" model="ir.ui.view">
<field name="name">pos.config.kanban.view</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.view_pos_config_kanban"/>
<field name="arch" type="xml">
<xpath expr="//t/div/div/div[#class='o_kanban_manage_button_section']" position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
</field>
</record>
My Solution:
<odoo>
<data>
<record id="view_pos_config_kanban" model="ir.ui.view">
<field name="name">pos.config.kanban.view</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.view_pos_config_kanban"/>
<field name="arch" type="xml">
<xpath expr="//kanban/templates/t/div/div[1]/div[2][#class='o_kanban_manage_button_section']" position="replace">
</xpath>
</field>
</record>
</data>
</odoo>
I am using Odoo 11 and get the below error when installing a custom module. This is a module that is working in Odoo 10. I cant figure out where I am going wrong.
Field `custom_discount_product_id2` does not exist
Error context:
View `pos.config.custom.discount.form.view`
[view_id: 1029, xml_id: pos_custom.view_pos_config_form_custom_discount, model: pos.config, parent_id: 730]
None" while parsing /odoo/custom/addons/pos_custom/views/pos_custom_sale_view.xml:22, near
<record model="ir.ui.view" id="view_pos_config_form_custom_discount">
<field name="name">pos.config.custom.discount.form.view</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[#id='title']" position="after">
<group string="Custom Discount">
<field name="custom_discount_product_id2"/>
</group>
</xpath>
</field>
</record>
Here is my sale.py file
from odoo import api, fields, models
class PosConfig(models.Model):
_inherit = 'pos.config'
custom_discount_product_id2 = fields.Many2one('product.product', string='Custom Discount Product')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
And here is the view file.
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_pos_config_form_custom_discount">
<field name="name">pos.config.custom.discount.form.view</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[#id='title']" position="after">
<group string="Custom Discount">
<field name="custom_discount_product_id2" />
</group>
</xpath>
</field>
</record>
</data>
</openerp>
I've checked other modules, restarted server, but for some reason the field is not created.
Make sure <your_module>/__init__.py contains:
from . import models
and that <your_module>/models/__init__.py contains:
from . import sale
I have an error with this record definition
<record id="file_rule_canceled" model="ir.rule">
<filed name="name"> File Canceled=True User Cann't Read</filed>
<field name="model_id" ref="model_muk_dms_file"/>
<field name="perm_read" eval="False"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_unlink" eval="False"/>
<field name="domain_force">[('canceled','=','True')] </field>
<field name="groups" eval="[(4, ref('group_gesion_dms_general_manager')), (4, ref('group_gesion_dms_manager')),(4, ref('group_gesion_dms_designer')),(4,ref('group_gesion_dms_reader'))]"/>
</record>
Odoo Server Error:
File "D:\Odoo10_Dev\odoo10\odoo\tools\convert.py", line 902, in convert_xml_import
relaxng.assert_(doc)
File "src/lxml/lxml.etree.pyx", line 3501, in lxml.etree._Validator.assert_ (src\lxml\lxml.etree.c:194922)
AssertionError: Element odoo has extra content: record, line 4
Could you help to find out what it's wrong?
Try this:
<record id="file_rule_canceled" model="ir.rule">
<field name="name">File Canceled=True User Can't Read</field>
<field name="model_id" ref="model_muk_dms_file"/>
<field name="perm_read" eval="False"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_unlink" eval="False"/>
<field name="domain_force">[('canceled','=','True')]</field>
<field name="groups" eval="[(4, ref('group_gesion_dms_general_manager')), (4, ref('group_gesion_dms_manager')),(4, ref('group_gesion_dms_designer')),(4,ref('group_gesion_dms_reader'))]"/>
</record>
How can I show Category in stock move tree.
This is my coding.
My view file.
<record id="royalfood_stock_move_tree_view" model="ir.ui.view">
<field name="name">stock.move.tree</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_tree" />
<field name="arch" type="xml">
<xpath expr="//field[#name='product_id']" position="before">
<field name="categ_id" groups="base.group_user"/>
</xpath>
</field>
</record>
My .py File
class custom_stock_move_tree(osv.osv_memory):
_columns = {
'categ_id': fields.related('product_id', 'categ_id', type='many2one' ,relation='product.category', store=True),
}
custom_stock_move_tree()
Any Help is Appreciated.
try this files.
your .py file
class custom_stock_move_tree(osv.Model): #their is different b/w osv.Model and osv.osv_memory before to use it read it's usage
_inherit = 'stock.move' # if you want to add data in existing module use inherit
_columns =
{
'categ_id': fields.related('product_id', 'categ_id', type='many2one' ,relation='product.category', store=True, string='Product Category'),
}
Your view.xml file
<record id="royalfood_stock_move_tree_view" model="ir.ui.view">
<field name="name">stock.move.tree</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_tree" />
<field name="arch" type="xml">
<xpath expr="//field[#name='product_id']" position="before">
<field name="categ_id" groups="base.group_user"/>
</xpath>
</field>
After this see your Stock Move Tree view.