Odoo statusbar widget for project.project - odoo

i'm trying to add a field to define statuses of project.project like:
# -*- coding: utf-8 -*-
from odoo import api, fields, models
class Project(models.Model):
_inherit = 'project.project'
_name = 'project.project'
state = fields.Selection(
[('open', 'Open'), ('closed', 'Closed'), ('sleep', 'Sleep')],
string='Status',
default='open'
)
Add added to the view in a heritage:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="edit_project" model="ir.ui.view">
<field name="name">project.project.form</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project"/>
<field name="arch" type="xml">
<xpath expr="//header" position="inside">
<field name="state" widget="statusbar" statusbar_visible="open,closed,sleep" />
</xpath>
</field>
</record>
</odoo>
But the field is displayed like a span in the header.
I tried everything described in the documentation and in base of other usages but with this in particular is not working and i don't know why. Please help!

Well, after trying everything for some ultra strange reason it work with no change.

Related

Why does my simple odoo extension crash my server on upgrade?

I am currently in the process of learning odoo. For this, I attempted to create a small extension module that adds a few fields to the product module. From the material I have, this is what my respective model looks like:
# -*- coding: utf-8 -*-
from odoo import fields, models
class product(models.Model):
_inherit = 'product.product'
testBool = fields.Boolean('This is a test', default=False)
ean = fields.Char('EAN')
and this is the respective view:
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="product_testbool_form_view" model="ir.ui.view">
<field name="name">product.template.common.form.testbool</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<form position="inside">
<sheet position="inside">
<div class="oe_title" position="inside">
<field name="purchase_ok" position="after">
<div>
<field name="testBool"/>
<label for="testBool"/>
</div>
</field>
</div>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="product_ean_form_view">
<field name="name">product.ean</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<field name="barcode" position="after">
<field name="ean"/>
</field>
</field>
</record>
</odoo>
(Obviously the respective init.py and manifest.py files got the needed imports.)
Now, while this installs without errors, it also doesn't work (no additional fields are shown in the product view), so there's definitely something I'm doing wrong here (although I don't know what, because I'm following the tutorials, but oh well).
However, the real problem happens when I stop and then restart the odoo service to see if this changes anything: The server won't start back up and the log contains the following (pastebin for length):
Pastebin error log
Can anyone help me figure out what's going wrong here?
I'm fairly certain it's something trivial that I'm getting wrong that the tutorials and odoo development cookbooks don't mention (they seem to be rather spotty anyway). But I've been trying to solve this for days now and I'm at a loss.

Display a field in the homepage odoo

I have created a module in odoo with a model called "product" and a string field called "formelab" , I want to display this "formelab" field just under the price on the product sheet.
I want to display "ABCCCC" on the PROD sheet under "$1.00"
that's the product_template.xml in the views folder
``
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="formelab_ref_id_form" model="ir.ui.view">
<field name="name">access.product.view.form</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="//field[#name='type']" position="after">
<field name="formelab_ref"/>
</xpath>
</field>
</record>
</odoo>
and that's the product.py in the models folder
# -*- coding: utf-8 -*-
from odoo import api, fields, models
class product(models.Model):
_inherit = 'product.template'
formelab_ref = fields.Char("Formelab")
``
You need to alter the products_item template.
The following code add the formelab_ref value after the priceCurrency span:
<template inherit_id="website_sale.products_item" id="daz">
<xpath expr="//span[#itemprop='priceCurrency']" position="after">
<span t-field="product.formelab_ref"/>
</xpath>
</template>

Odoo 10: Add extra fields to the product form

I want to add a couple of extra fields to the product form, right after 'standard_price'.
I created a view that inherits from "product.product_template_form_view" and added my fields there:
<field name="standard_price" position="after">
<field name="my_field" />
</field>
I then restart odoo updating the module, but I don't see my new fields when I call the product form.
The fields appear on the database model (created inherited models also), but not on the user interface.
What I'm missing here?
Check these things:
Inherited from correct base form product.template.common.form
Make sure you are looking at correct form for product.template (Product), not product.product (Product Variant).
Do you see the input field without caption in edit mode? If this is the case, you can have broken structure in the html level. Next bullet will solve this.
Standard_price field has unique html structure because it can have unit of measure (uom) connected to it. Try connecting to simple field or use the container div standard_price_uom for connection, see template code below.
Template code for working view with a new field after standard_price_uom div:
<div name='standard_price_uom' position="after">
<field name="my_field" />
</div>
If these does not help, please provide whole view definition.
Make sure you use the correct model. Use product.template instead of product.product.
<record id="product_template_form" model ="ir.ui.view">
<field name="name">product.template.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<field name="standard_price" position="after">
<field name="my_field"/>
</field>
</field>
</record>
...
class ProductTemplate(models.Model):
_inherit = "product.template"
my_field = fields.Char()
Make sure you have added your XML file into your module’s __manifest__.py file. Odoo only pulls in XML from files that you tell it to.
You can see examples of this on any core modules. See sale/__manifest__.py for an example.
On your module, it would be something like this:
{
...
‘data’: [
‘views/form/form_product.xml’,
]
...
}
I have tested it in Odoo 12.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_product_template_common_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="//div[#name='standard_price_uom']" position="after">
<label for="my_field" string="My Field"/>
<div>
<field name="my_field"/>
</div>
</xpath>
</field>
</record>
</odoo>

how to make display like sales order lines in odoo

I am a newbie in odoo development, can someone tell me how to make display like in picture sales order line in odoo, Thank you before
This is One2many field in Odoo
to made one like this you have to add some things like this:
In python code
from openerp import fields,models
class sale_order(models.Model):
_inherit='sale.order'
field_One2many=field.One2many('sale.order.line','order_id','Order')
sale_order()
class sale_order_line(models.model):
_inherit='sale.order.line'
order_id=fields.Many2one('sale.order','Order')
sale_order_line()
and you have some code for the view in your Xml file like:
<record model="ir.ui.view" id="view_test">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale_order.form_view_id"/>
<field name="arch" type="xml">
<data>
<xpath expr="pass of position" position="the postion">
<field name='field_One2many'>
<tree>
<!-- Your Fields in the view -->
</tree>
</field>
</xpath>
</data>
</field>
</record>
and done

Inherit form of res.partner

I create a new class fleet_agent that inherits from res.partner without problems
class fleet_agent(osv.Model):
_name = 'fleet.agent'
_inherit = ['res.partner']
_columns = {
'test': fields.char('Test', help='Test'),
}
then fleet_agent_form inherits base.view_partner_form also no problem
<record id="fleet_agent_form" model="ir.ui.view">
<field name="name">fleet.agent.form</field>
<field name="model">fleet.agent</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<field name="state_id" position="before">
<field name="x" />
</field>
</field>
</record>
My problem is that this form does not appear as the formatting of view_partner_form and with all fields without any order ?
You have created a new model 'fleet.agent' by extending the base 'res.partner'. In order to show all the fields, you need to specify the fields in xml or use the classical inheritance by removing 'fleet.agent' and add your field to the base 'res.partner'.
class fleet_agent(osv.Model):
_inherit = 'res.partner'
_columns = {
'field': fields.char('Name', help='help'),
}
In xml file:
<field name="model">fleet.agent</field>
class Partner(model.Model):
_inherit = 'res.partner'
test = fields.Char(string='Test', help='Test'),
}
<record id="fleet_agent_form" model="ir.ui.view">
<field name="name">partner.test</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<field name="test" />
</field>
</record>
Try following,
class fleet_agent(osv.Model):
_inherit = ['res.partner']
_columns = {
'test': fields.char('Test', help='Test'),
}
<record id="fleet_agent_form" model="ir.ui.view">
<field name="name">fleet.agent.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<field name="state_id" position="before">
<field name="x" />
</field>
</field>
</record>
Remove _name = 'fleet.agent' from your python code, it's create new model, and in xml when you extend any parent model you must write parent model name into the view
<field name="model">res.partner</field>
So you will get extended functionality with your base class's functionality.
To copy table to your moule you should use inherits keyword instead of inherit. Also you have to copy view definition of partner form of base module and change it, extending wouldn't help you in creating new table.
Source
Update: additional information on ways os inheritance:
Update2: looks like you're on right way: there is a third way of inheritance: with inherit keyword and by specifying new _name for new model.
Use:
class res_partner(models.Model):
_inherit = 'res.partner'
test = fields.Char(string='test')`
Upgrade module from console:
./odoo-bin -u [module_name] -c [configuration_file