I created a hierarchy view (parent-childs) for asset, now when I click an item in the list I'd like to open a form view of this item. Following code only opens a NEW form view, any ideas?
<record model="ir.actions.act_window" id="action_assets_hierachy">
<field name="name">Assets</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">asset.asset</field>
<field name="view_type">tree</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('parent_id','=',False)]</field>
</record>
<record id="assets_tree_view_inherit" model="ir.ui.view">
<field name="name">asset.asset.tree</field>
<field name="model">asset.asset</field>
<field name="inherit_id" ref="asset.assets_tree_view"/>
<field name="field_parent">child_ids</field>
<field name="arch" type="xml">
<xpath expr="//tree" position="replace">
<tree toolbar="1">
<field icon="icon" name="asset_number"/>
<field name="display_name"/>
<field name="name"/>
<field name="user_id"/>
</tree>
</xpath>
</field>
</record>
<record id="asset_form" model="ir.actions.act_window">
<field name="name">Assets</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">asset.asset</field>
<field name="view_type">form</field>
<field name="view_mode">form,kanban</field>
</record>
<record id="ir_asset_form_open" model="ir.values">
<field eval="'tree_but_open'" name="key2"/>
<field eval="'asset.asset'" name="model"/>
<field name="name">Assets</field>
<field eval="'ir.actions.act_window,%d'%asset_form" name="value"/>
</record>
<menuitem name="Asset Hierarchy" id="asset_hierarchy" parent="asset.menu_maintenance_assets" action="action_assets_hierachy"/>
You need some sort of JavaScript modification to achieve this. There is a function called "activate" in web/treeview.js which handle the event when an item clicked. You need to extend it like this:
odoo.define('web.ListViewClickable', function (require) {
"use strict";
var TreeView = require('web.TreeView');
TreeView.include({
activate: function(id){
var self = this;
var result = self._super(id);
if (self.model == 'your_model'){ //Only if you want to apply this to specific model
self.do_action({
type: 'ir.actions.act_window',
res_model: self.model,
view_type: 'form',
view_mode: 'form',
res_id: id,
views: [[false, 'form']],
});
}
return result;
},
});
});
Remove the:
<record id="asset_form" model="ir.actions.act_window">
<field name="name">Assets</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">asset.asset</field>
<field name="view_type">form</field>
<field name="view_mode">form,kanban</field>
</record>
Why do you need this action?
Also, change the:
<record model="ir.actions.act_window" id="action_assets_hierachy">
<field name="name">Assets</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">asset.asset</field>
<field name="view_type">tree</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('parent_id','=',False)]</field>
</record>
to:
<record model="ir.actions.act_window" id="action_assets_hierachy">
<field name="name">Assets</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">asset.asset</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('parent_id','=',False)]</field>
</record>
Related
I´m trying to create a new tree view for the invoices in Odoo 13
my code looks like this:
<odoo>
<record model="ir.ui.view" id="new_invoice_tree">
<field name="name">New Tree</field>
<field name="model">account.move</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree>
<field name="custom_field_1"/>
<field name="custom_field_2"/>
</tree>
</field>
</record>
<record id="my_module.new_tree_action_window" model="ir.actions.act_window">
<field name="name">New tree</field>
<field name="res_model">account.move</field>
<field name="view_mode">tree</field>
<field name="view_id" ref="new_invoice_tree"/>
<field name="type">ir.actions.act_window</field>
<field name="domain">[('type','=','out_invoice')]</field>
</record>
<menuitem name="Libro de ventas"
id="my_module.new_tree_menu"
parent="my_parent_menu"
action="my_module.new_tree_action_window"
sequence="1"/>
</odoo>
But when I try to open the menu appears this error:
Rastreo de error:
Error: Unknown field state in domain
at Class.compute (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:322:55)
at evalModifier (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:1197:91)
at Class._evalModifiers (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:1200:44)
at Class._registerModifiers (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:1401:101)
at Class._renderBodyCell (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:2076:70)
at http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:2100:117
at Array.map (<anonymous>)
at Class._renderRow [as _super] (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:2100:80)
at Class._renderRow (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:2010:69)
at Class._renderRow (http://192.168.1.7:8070/web/content/312-75a923f/web.assets_common.js:3863:371)
I´m not sure how my domain should look like, what´s what I´m doing wrong?
The way to avoid this kind of error is by adding the "state" field with the attribute invisible as True, like this:
<odoo>
<record model="ir.ui.view" id="new_invoice_tree">
<field name="name">New Tree</field>
<field name="model">account.move</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree>
<field name="state" invisible="True"/>
<field name="custom_field_1"/>
<field name="custom_field_2"/>
</tree>
</field>
</record>
This error appears on databases that are working with the Enterprise version of Odoo.
I'm trying to add multi field to timesheet module to work as a tasks manage app i did inheritance to account.analytic.line the problem is in the view i got that error "AssertionError: Element odoo has extra content: record, line 4"
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="todo_timesheet_line_tree" model="ir.ui.view">
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree"/>
<field name="model">account.analytic.line</field>
<field name="arch" type="xml"/>
<field name="task_id" position="after">
<field name="priority"/>
</field>
<field name="company_id" groups="base.group_multi_company" position="before">
<field name="gov_department"/>
<field name="priority"/>
<field name="date_deadline"/>
</field>
</record>
</odoo>
from odoo import models, fields, api
class TodoTask(models.Model):
_inherit = 'account.analytic.line'
startdate=fields.Date('start Date', required=True, index=True, default=fields.Date.context_today)
date_deadline=fields.Date('Deadline', required=True, index=True, default=fields.Date.context_today)
priority = fields.Selection(selection=[('1', 'فوري'), ('2','هام جدا' ),('3','اقل اهمية')])
is_done = fields.Boolean ('Done?')
gov_department = fields.Many2one('govauthority','الجهة الحكومية')
class govauthority(models.Model):
govname = fields.Char('GOV_Department', size=25, required=True)
The error is in this line
<field name="arch" type="xml" />
You closed the tag while you really should not. Within this tag the actual XML body should be.
<record id="todo_timesheet_line_tree" model="ir.ui.view">
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree" />
<field name="model">account.analytic.line</field>
<field name="arch" type="xml">
<field name="task_id" position="after">
<field name="priority" />
</field>
<field name="company_id" groups="base.group_multi_company" position="before">
<field name="gov_department" />
<field name="priority" />
<field name="date_deadline" />
</field>
</field>
</record>
Get an error: Odoo Warning - Insufficient fields for Calendar View! and the calendar, of course,never shows up.
I'm missing something but don't know what;
I have this view fragment:
<record model="ir.actions.act_window" id="action_soft_apps_event">
<field name="name">Applications</field>
<field name="res_model">soft.app</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,graph</field>
<field name="arch" type="xml">
<calendar string="App Releases" color="dev_id" date_start="release" date_delay="1">
<field name="name"/>
<field name="desc"/>
<field name="downloads"/>
<field name="valid"/>
</calendar>
</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Register a new App</p>
</field>
</record>
And the model is the following:
class soft_app(osv.osv):
"""Apps"""
_name = 'soft.app'
_columns = {
'name': fields.char('Name', size=32, required=True, help='This is the name of the application'),
'desc': fields.text('Description', help='A brief description of the application'),
'dev_id': fields.many2one('soft.dev','Developer',required=True, help='The app\'s developer'),
'release': fields.datetime('Release Date', help='The date that the app was released'),
'downloads': fields.integer('Download Count', help='Total amount of downloads'),
'user_ids': fields.many2many('soft.user','soft_user_app_rel','app_id','user_id','Users Downloaded', help='Users that have downloaded the app'),
'os_ids': fields.many2many('soft.os','soft_os_app_rel','app_id','os_id','Operating Systems', help='Operating systems survey data'),
'valid': fields.boolean('Is Valid', help='Checks if the app is validated')
}
soft_app()
I think you have to create separate calendar view and action
Like:
Calendar view
<record id="view_invoice_line_calendar" model="ir.ui.view">
<field name="name">account.invoice.calendar</field>
<field name="model">account.invoice</field>
<field name="arch" type="xml">
<calendar string="Invoices" color="journal_id" date_start="date_invoice">
<field name="partner_id"/>
<field name="amount_total"/>
</calendar>
</field>
</record>
Action
<record id="action_invoice_tree" model="ir.actions.act_window">
<field name="name">Invoices</field>
<field name="res_model">account.invoice</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,graph</field>
<field name="view_id" ref="invoice_tree"/>
<field name="context">{'type':'out_invoice'}</field>
<field name="search_view_id" ref="view_account_invoice_filter"/>
</record>
I want to add one field call validator to customer invoice (account_invoice).
openerp.py:
'depends': ['base','account'],
my model:
class account_invoice_validator(models.Model):
_inherit = "account.invoice"
validator = fields.Char()
my view:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<!-- Model: account.invoice -->
<record id="view_account_invoice_customer_validator" model="ir.ui.view">
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='user_id']" position="after">
<field name="validator"/>
</xpath>
</field>
</record>
</data>
</openerp>
the validator column was added to database but i couldn't show it on the tree view (list). What do i miss?
Can you try like this?
<record id="view_account_invoice_customer_validator" model="ir.ui.view">
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_tree"/>
<field name="arch" type="xml">
<xpath expr="//tree/field[#name='user_id']" position="after">
<field name="validator"/>
</xpath>
</field>
</record>
Try this:
<record id="view_account_invoice_customer_validator" model="ir.ui.view">
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_tree"/>
<field name="arch" type="xml">
<xpath expr="/tree/field[#name='user_id']" position="after">
<field name="validator"/>
</xpath>
</field>
</record>
I'm trying to replace a field in a tree view. Help me please.
This is script on base odoo enteprice
<record model="ir.ui.view" id="view_task_form2_inherited">
<field name="name">project.task.form.inherited</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2" />
<field name="arch" type="xml">
<field name="project_id" position="attributes">
<attribute name="on_change">onchange_project(project_id)</attribute>
</field>
<field name="tag_ids" position="after">
<field name="analytic_account_id" invisible="1"/>
<field name="progress" widget="progressbar"
groups="project.group_time_work_estimation_tasks"/>
</field>
<xpath expr="//notebook/page[#name='description_page']" position="after">
<page string="Timesheets" groups="project.group_tasks_work_on_tasks,project.group_time_work_estimation_tasks">
<field name="timesheet_ids" groups="project.group_tasks_work_on_tasks" context="{'default_account_id' : analytic_account_id, 'default_is_timesheet' : 1}">
<tree editable="top" string="Timesheet Activities">
<field name="date"/>
<field name="user_id" required="1"/>
<field name="name"/>
<field name="account_id"/>
<field name="unit_amount" string="Duration" sum="Total time" widget="float_time"/>
<field name="is_timesheet" invisible="1"/>
</tree>
</field>
<group>
<group class="oe_subtotal_footer oe_right" name="project_hours" groups="project.group_time_work_estimation_tasks">
<field name="effective_hours" widget="float_time" groups="project.group_time_work_estimation_tasks"/>
<field name="remaining_hours" widget="float_time" class="oe_subtotal_footer_separator" groups="project.group_time_work_estimation_tasks"/>
</group>
</group>
</page>
</xpath>
</field>
</record>
This is my custom script on _view.xml:
<record id="project_task_view_form" model="ir.ui.view">
<field name="name">project.task.view.form</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2"/>
<field name="arch" type="xml">
<xpath expr="/notebook/page[#name='description_page']" position="replace">
<page string="Timesheets" groups="project.group_tasks_work_on_tasks,project.group_time_work_estimation_tasks">
<field name="timesheet_ids" groups="project.group_tasks_work_on_tasks" context="{'default_account_id' : analytic_account_id, 'default_is_timesheet' : 1}">
<tree editable="top" string="Timesheet Activities">
<field name="date"/>
<field name="user_id" required="1"/>
<field name="name"/>
<field name="unit_amount" string="Duration" sum="Total time" widget="float_time"/>
<field name="is_timesheet" invisible="1"/>
<field name="invoiceable_analytic_line"/>
</tree>
</field>
</page>
</xpath>
</field>
</record>
I want add new field "invoiceable_analytic_line" inside "timesheet_ids", but it doesn't work.
anybody help me?
Thanks.
View
The procedure is correct but just that there is an error with the expr attribute inside xpath.
Instead:
<xpath expr="/notebook/page[#name='description_page']" position="replace">,you have to write:
<xpath expr="//sheet/notebook/page[1]" position="replace"> when on odoo 10<xpath expr="/sheet/notebook/page[#string='Description']" position="replace">Because description_page doesn't existSo copy whole <page string="Description">..</page> tag from /project/project_view.xml and paste it inside your xpath tag by modify the string. After that insert your field where you want
Model
class Add_in_timesheet(models.Model)
_inherit = 'project.task
invoiceable_analytic_line = fields.Char(string=u"Invoiceable")