I want to add new attributes in product tree view but an error happened when I started my server and updated my addons look like :
ParseError: "Erreur lors de la validation de la contrainte
Mod\xe8le non trouv\xe9 : product.template
Contexte de l'erreur :
Vue `productTree`
[view_id: 752, xml_id: n/a, model: product.template, parent_id: 308]
None" while parsing /opt/odoo/odoo-10.0/addons/test_tuto/views/views.xml:3, near
<record id="view_product_tree_inherit" model="ir.ui.view">
<field name="inherit_id" ref="product.product_template_tree_view"/>
<field name="name">productTree</field>
<field name="model">product.template</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<xpath expr="/tree/field[#name='categ_id']" position="after">
<field name="calories"/>
<field name="servingsize"/>
<field name="lastupdated"/>
</xpath>
</field>
</record>
Here is my view source code,
<record id="view_product_tree_inherit" model="ir.ui.view">
<field name="inherit_id" ref="product.product_template_tree_view"/>
<field name="name">productTree</field>
<field name="model">product.template</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<xpath expr="/tree/field[#name='categ_id']" position="after">
<field name="calories"/>
<field name="servingsize"/>
<field name="lastupdated"/>
</xpath>
</field>
</record>
And here is the python code I added 3 fields in my class inherit from product template class.
from odoo import models, fields, api
class test_tuto(models.Model):
_inhirit = 'product.template'
calories = fields.Integer("Calories")
servingsize = fields.Float("Serving size")
lastupdated = fields.Datetime('Last Updated')
as you request here you are my manifest.py file
I write my xml code in views.xml file
# -*- coding: utf-8 -*-
{
'name': "Test_tuto",
'summary': """
Short (1 phrase/line) summary of the module's purpose, used as
subtitle on modules listing or apps.openerp.com""",
'description': """
Long description of module's purpose
""",
'author': "My Company",
'website': "http://www.yourcompany.com",
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/10.0/odoo/addons/base/module/module_data.xml
# for the full list
'category': 'Uncategorized',
'version': '0.1',
# any module necessary for this one to work correctly
'depends': ['base'],
# always loaded
'data': [
# 'security/ir.model.access.csv',
'views/views.xml',
'views/templates.xml',
],
# only loaded in demonstration mode
'demo': [
'demo/demo.xml',
],
}
Please try changing your "xpath" like this
add 'product' in depends
'depends': ['base','product'],
<xpath expr="//tree/field[#name='categ_id']" position="after">
<field name="calories"/>
<field name="servingsize"/>
<field name="lastupdated"/>
</xpath>
Related
I have one field was the M2o and that opposite O2m. I try to display the O2m field in the M2o class just like that and display all the O2m field in the tree view. But I need to hide the one column is based on the ir.config_parameter
from odoo import models, fields, api
class AbcXyz(models.Model):
_name='abc.xyz'
b_ids=fields.One2many('xyz.abc','a_id',string="Xyz")
#api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(AbcXyz, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
if view_type=='form' and self.b_ids:
for line in self.b_ids:
is_applying_view = eval(self.env['ir.config_parameter'].sudo().get_param('test_module.is_applying_k_qty'))
doc = etree.XML(res['arch'])
if is_applying_view:
for node in doc.xpath("//field[#name='line.k_qty']"):
node.set('invisible', '0')
else:
for node in doc.xpath("//field[#name='line.cartoon_qty']"):
node.set('invisible', '1')
return res
class XyzAbc(models.Model)
_name='xyz.abc'
#api.multi
def get_default_k_qty_visible(self):
return eval(self.env['ir.config_parameter'].sudo().get_param('test_module.is_applying_k_qty'))
a_id=fields.Many2one('abc.xyz',string="ABC")
<!---other fields--->
k_qty=fields.Integer(string="Cartoon Qty", default=0)
is_k_qty_visible = fields.Boolean(string="Is K Qty Visible", compute=get_default_cartoon_qty_visible, store=True)
based is_k_qty_visible I try to hide the k_qty column.
<record id="abc_form_view" model="ir.ui.view">
<field name="name">abc.form.view</field>
<field name="model">abc.xyz</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="ABC Process">
<notebook>
<page string="K Qty">
<field name="b_ids" nolabel='1' mode="tree">
<tree>
<field name="k_qty" attrs="{'invisible':[('is_k_qty_visible','!=',True)]}" />
</tree>
</field>
</page>
</notebook>
</form>
</field>
<record>
But it not working for me.
This is not the answer of this question. I have share some information.
This code is used to hide fields in one2many(tree) in odoo11
<
field name="my_field" attrs="{'column_invisible': [('parent.field_name','=',False)]}" />
this type of code only works gives 'parent' in condition
I think this will type of code will work in odoo12 too.
class InvoiceWizard(models.TransientModel):
_name = "pos.order.invoice.wizard"
date_order = fields.Datetime(string='Date Order', readonly=True)
partner_id = fields.Many2one('res.partner', string='Partner')
#api.multi
def to_invoice(self):
pos_order = self.env['pos.order'].search([('id','=',self._context.get('active_id'))])
pos_order.create_invoice()
<record id="pos_order_invoice_done" model="ir.ui.view">
<field name="name">pos.order.wizard.invoice</field>
<field name="model">pos.order.invoice.wizard</field>
<field name="arch" type="xml">
<form string="To Invoice">
<group>
<field name="partner_id"/>
<field name="date_order"/>
</group>
<footer>
<button name="to_invoice"
string="Finished" type="object"
class="btn-primary"/>
<button string="Cancel"
class="btn-default"
special="cancel" />
</footer>
</form>
</field>
</record>
My goal is to create invoice from pos order with this 2 fields that manuale i will select in wizard. what do i'm missing here? i need to transfer data from those fields to create_invoice() method.
partner_id is required in invoice object, so you must fill the fields in create method like:
#api.multi
def to_invoice(self):
invoice_obj =self.env['account.invoice']
values = {'partner_id' : self.partner_id,
'date_invoice' : self.date_order
}
invoice_obj.create(values)
note : make sure all fields required is filled.
I have these 2 buttons in form view:
<button name="%(action_view_task_make_situation)d" string="Create work situation" type="action" states="open" context="{'type': 'situation'}"/>
<button name="%(action_make_general_final_count)d" string="Create Final General Count" type="action" states="done" context="{'type': 'final_count'}"/>
with these actions:
<record id="action_view_task_make_situation" model="ir.actions.act_window">
<field name="name">Make Situation</field>
<field name="res_model">task.make.situation</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">{'type':True}</field>
</record>
<record id="action_make_general_final_count" model="ir.actions.act_window">
<field name="name">Make General Final Count</field>
<field name="res_model">task.make.situation</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">{'type':False}</field>
</record>
now I have task.make.situation model:
class TaskMakeSituation(models.TransientModel):
_name = "task.make.situation"
type = fields.Char(compute = "compute_type", string="Type", readonly= True)
#api.multi
def compute_type(self):
if self._context.get('type', True):
return "situation"
else:
return "final_count"
But when I click one of the buttons the wizard appears with an empty type field.
Compute method have to "write" their values directly into the records:
#api.multi
def compute_type(self):
context_type = self._context.get('type', True)
for record in self:
if context_type:
record.type = "situation"
else:
record.type = "final_count"
Aside from this, your solution should simply use default values for field type. First change your field to a normal char field:
type = fields.Char(string="Type", readonly=True)
Little hint: the parameter string isn't necessary in this example, because newer Odoo versions will use the field name to generate the labels (string becomes the field label) for example: name will get Name or partner_id will get Partner (_id will be dropped).
Now change the button context, use default_type:
<button name="%(action_view_task_make_situation)d"
string="Create work situation" type="action" states="open"
context="{'default_type': 'situation'}"/>
<button name="%(action_make_general_final_count)d"
string="Create Final General Count" type="action" states="done"
context="{'default_type': 'final_count'}"/>
The prefix default_ in combination with a field name, will be used in later default extraction for the creation of a record.
Just try adding "default_" before type in the context, like this:
context="{'default_type': False}"
and only use boolean because you validate boolean in compute_type, make this in the views too.
I have a one2many field like:
pricelist_details = fields.One2many('price.list.details', 'price_list_id', string='Price List Details', copy=True)
and xml like:
<notebook>
<page>
<field name="pricelist_details" nolabel="1" widget="one2many_list">
<tree string="Price List Details" editable="bottom" create="false">
<field name="state" invisible="1"></field>
<field name="date_time" attrs="{'required': True, 'readonly': True}"></field>
<field name="company_id" attrs="{'required': True, 'readonly': True}"></field>
<field name="category_id" attrs="{'required': True, 'readonly': True}"></field>
<field name="grade" attrs="{'required': True, 'readonly': True}"></field>
<field name="ex_mill" attrs="{'required': True, 'readonly': True}"></field>
<field name="sale_price_per_lb" attrs="{'required': True, 'readonly': [('state', '!=', 'draft')]}"></field>
<field name="price_per_bag" attrs="{'required': True, 'readonly': True}"></field>
</tree>
</field>
</page>
</notebook>
On a button click all the records are created and show up on GUI for this field.
Now i have added some filter fields beside this field like:
minor = fields.Many2one('product.minor',string='Minor')
sub_category = fields.Many2one('product.subcategory', string='Sub Category')
What i want is to filter my one2many field records on the basis of these filters. I dont want any records to be deleted. Just have
to filter the records.
Please help me regarding this.
Write the onchange method of the field "sub_category" and populate the response as you want it to be. return statement should looks like below:
return {'values': {'pricelist_details': [record_set]}}
record_set contains the objects that are filtered as per the field sub_category
record_set will be populated as below:
records_set = self.env['product.category'].search([('sub_category', '=', ID)])
NOTE: ID is the id of the changed field whose onchange method you are writing.
<record model="ir.actions.act_window" id="open_gtd_all_tasks_pci">
<field name="name">Tasks (GTD)</field>
<field name="res_model">project.task</field>
<field name="search_view_id" ref="project_gtd.view_task_gtd_search"/>
<field name="context">{'set_visible': True, 'gtd': True, 'search_default_timebox_id': 1, 'search_default_open': 1, 'search_default_open_project': 1, 'hide_stage': 0}</field>
<field name="view_type">form</field>
<field name="view_mode">kanban,tree,form,calendar,gantt,graph</field>
</record>
<record id="planningtask_calendar_view_inherit" model="ir.ui.view">
<field name="name">ic.team.planning.task.calendar.inherit</field>
<field name="model">ic.team.planning.task</field>
<field name="inherit_id" ref="ic_project_issue.ic_team_planning_task_calendar_view"/>
<field name="arch" type="xml">
<xpath expr="//calendar[#string='Team Planning']" position="attributes">
<attribute name="mode">week</attribute>
</xpath>
</field>
</record>
what different res_model with model,what the effect , when use model or res_model? i need explained :-)
Here we have major different between res_model and model,
For Odoo Action of View:
model :
In model action is important for base record for the database table hear which is used to store the particular action of that record id.
In your example :
model="ir.actions.act_window" As a ir_actions_act_window database table
id="open_gtd_all_tasks_pci" As a unique id for that action table record
which is used to create a new record with the id,res_model,search_view_id,context,view_type,view_mode with ir_actions_act_window database table
res_model :
Action of the particular model
For Odoo Design of View:
for model="ir.ui.view" for the record as ir_ui_view database table to store a new record as planningtask_calendar_view_inherit unique id
and same as for name,model,inherit_id fields for storing the record.
hear model field is for desgin the view for that particular model (database table).
In generally Odoo(OpenERP) understand . (dot) with particular model name and make it as _(underscore) and store that record it as the database table.
like res.partner module Odoo (formally OpenERP) treat as res_partner database table.