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>
Related
First time dealing with xpath and XML data. I have below xpath query that I got through some Stack Overflow answers. Below, I want to extract all the column names
with t(x) as (
values
('<?xml version="1.0" encoding="UTF-8"?>
<mapping>
<package name="mypackage">
<class name="mytable">
<jdbc-class-map type="base" pk-column="id" table="public.mytable" />
<jdbc-version-ind type="version-number" column="version" />
<jdbc-class-ind type="myclass" column="jdoclass" />
<field name="majorVersion">
<jdbc-field-map type="value" column="majorversion" />
</field>
<field name="minorVersion">
<jdbc-field-map type="value" column="minorversion" />
</field>
<field name="patchVersion">
<jdbc-field-map type="value" column="patchversion" />
</field>
<field name="version">
<jdbc-field-map type="value" column="version0" />
</field>
<field name="webAddress">
<jdbc-field-map type="value" column="webaddress" />
</field>
</class>
</package>
</mapping>'::xml)
)
select
unnest(xpath('./package/class/field/text()', x)) as "fieldname",
unnest(xpath('./package/class/field/jdbc-field-map/text()', x)) as "columns"
from t
The above query returns fieldname empty and coluns as null. I understand there is some problem with the XML path.
I expect to see field name and column lists
fieldName columns
--------------------------
majorversion majorversion
minorversion minorversion
...
If you want to turn XML into a "table", this is typically done much easier using xmltable()
select info.*
from t
cross join xmltable('/mapping/package/class/field' passing x
columns fieldname text path '#name',
"column" text path './jdbc-field-map/#column') as info
Online example
I was able to achieve the result by
with myTempTable(myXmlColumn) as (
values ('<?xml version="1.0" encoding="UTF-8"?>
<mapping>
<package name="mypackage">
<class name="mytable">
<jdbc-class-map type="base" pk-column="id" table="public.mytable" />
<jdbc-version-ind type="version-number" column="version" />
<jdbc-class-ind type="myclass" column="jdoclass" />
<field name="majorVersion">
<jdbc-field-map type="value" column="majorversion" />
</field>
<field name="minorVersion">
<jdbc-field-map type="value" column="minorversion" />
</field>
<field name="patchVersion">
<jdbc-field-map type="value" column="patchversion" />
</field>
<field name="version">
<jdbc-field-map type="value" column="version0" />
</field>
<field name="webAddress">
<jdbc-field-map type="value" column="webaddress" />
</field>
</class>
</package>
</mapping>'::xml))
SELECT
unnest(xpath('//package/class/field/jdbc-field-map/#column', myTempTable.myXmlColumn))::text AS columns,
unnest(xpath('//package/class/field//#name', myTempTable.myXmlColumn))::text AS fieldName
FROM myTempTable
result
fieldName columns
--------------------------
"majorversion" "majorVersion"
"minorversion" "minorVersion"
"patchversion" "patchVersion"
"version0" "version"
"webaddress" "webAddress"
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>
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
i am following the odoo 10 workflow documentation tutorial and i was unable to get any response form clicking on the workflow buttons, no error is showing.
*please note that in my code the name of the module i am developing is "testModule" which is written as "test_module" inside python instead of "openacademy" that is used in the docs tutorial. and the view file is views.xml instead of openacademy.xml , could any of that have an impact?
views.xml
...
<!-- this is the sessions views -->
<!-- session form view -->
<record model="ir.ui.view" id="session_form_view">
<field name="name">session.form</field>
<field name="model">test_module.session</field>
<field name="arch" type="xml">
<form string="Session Form">
<header>
<button name="draft" type="workflow"
string="Reset to draft"
states="confirmed,done"/>
<button name="confirm" type="workflow"
string="Confirm" states="draft"
class="oe_highlight"/>
<button name="done" type="workflow"
string="Mark as done" states="confirmed"
class="oe_highlight"/>
<field name="state" widget="statusbar"/>
</header>
...
session_workflow.xml
<odoo>
<data>
<record model="workflow" id="wkf_session">
<field name="name">OpenAcademy sessions workflow</field>
<field name="osv">test_module.session</field>
<field name="on_create">True</field>
</record>
<record model="ir.actions.server" id="set_session_to_draft">
<field name="name">Set session to Draft</field>
<field name="model_id" ref="model_test_module_session"/>
<field name="code">
model.search([('id', 'in', context['active_ids'])]).action_draft()
</field>
</record>
<record model="workflow.activity" id="draft">
<field name="name">Draft</field>
<field name="wkf_id" ref="wkf_session"/>
<field name="flow_start" eval="True"/>
<field name="kind">dummy</field>
<field name="action"></field>
<field name="action_id" ref="set_session_to_draft"/>
</record>
<record model="ir.actions.server" id="set_session_to_confirmed">
<field name="name">Set session to Confirmed</field>
<field name="model_id" ref="model_test_module_session"/>
<field name="code">
model.search([('id', 'in', context['active_ids'])]).action_confirm()
</field>
</record>
<record model="workflow.activity" id="confirmed">
<field name="name">Confirmed</field>
<field name="wkf_id" ref="wkf_session"/>
<field name="kind">dummy</field>
<field name="action"></field>
<field name="action_id" ref="set_session_to_confirmed"/>
</record>
<record model="ir.actions.server" id="set_session_to_done">
<field name="name">Set session to Done</field>
<field name="model_id" ref="model_test_module_session"/>
<field name="code">
model.search([('id', 'in', context['active_ids'])]).action_done()
</field>
</record>
<record model="workflow.activity" id="done">
<field name="name">Done</field>
<field name="wkf_id" ref="wkf_session"/>
<field name="kind">dummy</field>
<field name="action"></field>
<field name="action_id" ref="set_session_to_done"/>
</record>
<record model="workflow.transition" id="session_draft_to_confirmed">
<field name="act_from" ref="draft"/>
<field name="act_to" ref="confirmed"/>
<field name="signal">confirm</field>
</record>
<record model="workflow.transition" id="session_confirmed_to_draft">
<field name="act_from" ref="confirmed"/>
<field name="act_to" ref="draft"/>
<field name="signal">draft</field>
</record>
<record model="workflow.transition" id="session_done_to_draft">
<field name="act_from" ref="done"/>
<field name="act_to" ref="draft"/>
<field name="signal">draft</field>
</record>
<record model="workflow.transition" id="session_confirmed_to_done">
<field name="act_from" ref="confirmed"/>
<field name="act_to" ref="done"/>
<field name="signal">done</field>
</record>
<record model="workflow.transition" id="session_auto_confirm_half_filled">
<field name="act_from" ref="draft"/>
<field name="act_to" ref="confirmed"/>
<field name="condition">taken_seats > 50</field>
</record>
</data>
inculded the call in manafest.py
'data': [
# 'security/ir.model.access.csv',
'views/views.xml',
'views/templates.xml',
'views/partner.xml',
'views/session_workflow.xml',
],
created the fields and functions in my sessions model in models.py
state = fields.Selection([
('draft', "Draft"),
('confirmed', "Confirmed"),
('done', "Done"),
])
#api.multi
def action_draft(self):
self.state = 'draft'
#api.multi
def action_confirm(self):
self.state = 'confirmed'
#api.multi
def action_done(self):
self.state = 'done'
and at the end i upgraded the module
This happens with Sessions you created before implementing the session_workflow.xml
It should work fine for sessions you create after implementing the session_workflow.xml. They placed a warning for it somewhere in the middle of the example.
Warning
A workflow associated with a model is only created when the model's
records are created. Thus there is no workflow instance associated
with session instances created before the workflow's definition
I have a scenario to map user information to Map of Objects (Map or List).
I have say user info as follows
CommonHeader(CX) block followed by 0 or more ID blocks followed by 0 or more Address blocks
Below are valid formats for user records
CX|19981222|19981222|ID|DriversLicence|111111111|ID|Passport|ABC12345|AD|123 Main Street|Atlanta|GA|30316|AD|100 PeachTree RD|Atlanta|Ga|3007|
CX|19981222|19981222|ID|DriversLicence|111111111|ID|Passport|ABC12345|
CX|19981222|19981222|AD|123 Main Street|Atlanta|GA|30316|AD|100 PeachTree RD|Atlanta|Ga|3007|
Is it possible to map such scenarios using beanio ?
Whats the best solution to handle these cases ?
I am using Beanio-2.1
My beanio mapping file is as follows
<stream name="userrRecord" format="delimited">
<parser>
<property name="delimiter" value="|"/>
</parser>
<record name="urecord" class="map" minOccurs="0" maxOccurs="unbounded" >
<segment name="CX" class="map">
<field name="CX"/>
<field name="DateFirstReported" type="date" format="yyyyMMdd"/>
<field name="DateLastReported" type="date" format="yyyyMMdd"/>
</segment>
<segment name="ID" class="map" minOccurs="0" maxOccurs="unbounded" collection="list">
<field name="ID"/>
<field name="IDType"/>
<field name="DocumentID"/>
</segment>
< segment name="AD" class="map" minOccurs="0" maxOccurs="unbounded" collection="list">
<field name="AD"/>
<field name="Street"/>
<field name="City"/>
<field name="State"/>
<field name="Zipcode"/>
</segment>
</record>
</stream>
When I try to unmarshall a record with 2 ID segmenst and 0 AD segments running into InvalidRecord exception.
Any help is highly appreciated.
I think this is not possible, as stated in the BeanIO Reference Guide:
Flat file formats (CSV, delimited and fixed length) may only contain one
field or segment of indeterminate length (i.e. where maxOccurs is greater
than minOccurs). The position of components that follow are assumed to be
relative to the end of the record.
You should change each of your segments to a separate record, and wrap it in a group. Then your sample input will look like this:
CX|19981222|19981222|
ID|DriversLicence|111111111|
ID|Passport|ABC12345|
AD|123 Main Street|Atlanta|GA|30316|
AD|100 PeachTree RD|Atlanta|Ga|3007|
CX|19981222|19981222|
ID|DriversLicence|111111111|
ID|Passport|ABC12345|
CX|19981222|19981222|
AD|123 Main Street|Atlanta|GA|30316|
AD|100 PeachTree RD|Atlanta|Ga|3007|
And your mapping like this:
<stream name="userrRecord" format="delimited">
<parser>
<property name="delimiter" value="|"/>
</parser>
<group name="urecord" class="map" minOccurs="0" maxOccurs="unbounded">
<record name="CX" class="map">
<field name="CX"/>
<field name="DateFirstReported" type="date" format="yyyyMMdd"/>
<field name="DateLastReported" type="date" format="yyyyMMdd"/>
</record>
<record name="ID" class="map" minOccurs="0" maxOccurs="unbounded" collection="list">
<field name="ID"/>
<field name="IDType"/>
<field name="DocumentID"/>
</record>
<record name="AD" class="map" minOccurs="0" maxOccurs="unbounded" collection="list">
<field name="AD"/>
<field name="Street"/>
<field name="City"/>
<field name="State"/>
<field name="Zipcode"/>
</record>
</group>
</stream>