I have a XML FIle which is shown below--
<ROOT>
<account name="ABC" code="XX">
<row>
<field name="ID">7650987</field>
<field name="Length">00:02:37</field>
<field name="Verif">6064625</field>
</row>
<row>
<field name="ID">7651474</field>
<field name="Length">00:01:08</field>
<field name="Verif">6065064</field>
</row>
<row>
<field name="ID">7651105</field>
<field name="Length">00:00:42</field>
<field name="Verif">6064737</field>
</row>
</account>
I need to extract the "code="XX"" based on the Verif value.
I am able to grab the Verif value using Xpath & then I tried reaching root using Parent syntax like,
/ROOT/account/row/field[#name='ID' and text()="7650987"]/parent::*
Above expression is returning blank.
How do I change the same?
First, your XML ROOT tag is not closed. Your XML should finish with
</ROOT>. No xpath would work till you fix the malformed xml. When you close it, your attempted solution would not be blank anymore, although it won't be correct: /ROOT/account/row/field[#name='ID' and text()="7650987"]/parent::*:
This means return "The parent of a 'field' that has name of 'ID' and text of '7450978'", which would be a whole block of XML:
<row>
<field name="ID">7650987</field>
<field name="Length">00:02:37</field>
<field name="Verif">6064625</field>
</row>
Now, what you need is: "The code value of an 'account' that has a child 'row/field' with name of 'ID' and text of '7450978'"
This can be translated as:
//account[row/field/#name="ID" and row/field/text()="7650987"]/#code
I tested it in online XPATH tester and works.
Try ending your xml ROOT
<ROOT>
<account name="ABC" code="XX">
<row>
<field name="ID">7650987</field>
<field name="Length">00:02:37</field>
<field name="Verif">6064625</field>
</row>
<row>
<field name="ID">7651474</field>
<field name="Length">00:01:08</field>
<field name="Verif">6065064</field>
</row>
<row>
<field name="ID">7651105</field>
<field name="Length">00:00:42</field>
<field name="Verif">6064737</field>
</row>
</account>
</ROOT>
This XPath,
/ROOT/account[row/field[#name="ID"]="7650987"]/#code
will return the #code attribute of the account element which has a row/field element with an #name attribute value of "ID" and string value of "7650987", as requested.
Related
[![enter image description here][1]][1]I have a problem with adding a new field to the sale order view of odoo12. I have created a new module. I hope that you can help me.
Below the code of my view form
<odoo>
<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml"></field>
<field name="payment_term_id" position="after">
<field name="additional_note"/>
</field>
</record>
</odoo>```
when i try to install the new module i have the following error:
File "src\lxml\etree.pyx", line 3557, in lxml.etree._Validator.assert_
AssertionError: Element odoo has extra content: record, line 3
[1]: https://i.stack.imgur.com/e1DOw.png
The problem is in the <field name="arch" type="xml"></field> line: the <field> tag is closed, and your additional_note field is declared outside of it.
Try this code instead:
<odoo>
<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<!-- Leave the 'arch' field open -->
<field name="arch" type="xml">
<!-- Put your custom field and its position inside the 'arch' field.
Use 'xpath' tag to create a more precise positioning -->
<xpath expr="//group/group/field[#name='payment_term_id']" position="after">
<field name="additional_note"/>
</xpath>
<!-- Now, close the 'arch' field -->
</field>
</record>
</odoo>
The view is not correctly defined, you can refer to account_analytic_view.
The view definition should be (according to the provided link):
<odoo>
<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<data>
<field name="payment_term_id" position="after">
<field name="additional_note"/>
</field>
</data>
</field>
</record>
</odoo>
I'm new to Odoo. While trying to call a server action from a menuitem it can't find the model_id.
My view code:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.actions.server" id="open_calculator">
<field name="name">Open Calculator</field>
<field name="model_id" ref="calculator"/>
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="code">
<!--code-->
</field>
</record>
<!-- Top menu item -->
<menuitem name="Calculator" id="calculator.menu_root"
action="open_calculator"/>
</data>
</openerp>
The error:
raise ValueError('External ID not found in the system: %s' % (xmlid))
ParseError: "External ID not found in the system: calculator.calculator" while parsing /home/administrador/Escritorio/calculator-test-project/calculator/views/views.xml:4, near
<record model="ir.actions.server" id="open_calculator">
<field name="name">Open Calculator</field>
<field name="model_id" ref="calculator"/>
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="code">
<!--code-->
</field>
</record>
Model:
# -*- coding: utf-8 -*-
from openerp import models, fields, api, http
class Calculator(models.Model):
_name = 'calculator'
What am I missing?
It appears that there is a convention you have to follow in model_id's ref attr. You have to add '_model' before your model name:
<field name="model_id" ref="model_calculator"/>
instead of:
<field name="model_id" ref="calculator"/>
or it won't work.
Just as in this question
i have candidat model inherit the hr.emplyee model
i want to display the form view of hr.employee and add fields of my child model candidat
class hr_candidat(models.Model):
_name='hr_recrutement.candidat'
_inherit='hr.employee'
_description="Informations du Candidats"
situation=fields.Selection(string="Situation",selection=[('Nouveau','Nouveau'),('RDV Thechnique','RDV Technique'),('Annulation','Annulationn')])
.
.
.
<record id="hr_recrutement_candidat_form" model="ir.ui.view">
<field name="name">Candidat</field>
<field name="model">hr_recrutement.candidat</field>
<field name="arch" type="xml">
<form string="Candidat">
<sheet>
<group>
<field name="situation" />
.
.
</group>
</sheet>
</form>
</field>
</record>
I dont know how to display fields of hr.employee + my fields of candidat in view
Just we should set the below code from the view xml file and also
add the depended module as hr in your openerp.py and set the view xml file path as well.
Add below code in your .py file
class hr_employee(models.Model):
_inherit='hr.employee'
_description="Informations du Candidats"
situation=fields.Selection(string="Situation",selection=[('Nouveau','Nouveau'),('RDV Thechnique','RDV Technique'),('Annulation','Annulationn')])
Add below code in your .xml file
<record id="hr_recrutement_caindidat_form" model="ir.ui.view">
<field name="name">Candidat</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form" />
<field name="arch" type="xml">
<xpath expr="field[#name='work_location']" position="after">
<field name="situation" />
</xpath>
</field>
</record>
Hear We have to set the position of your element based on xpath using before,after,inside,replace Attributes of xpath tag.
I hope my answer may helpful for you :)
how do i can search multiple index content in spring data solr showcase?
just now i only can search "name".
for example how do i can search "companyNo"?.
thanks in advance
sample xml of indexed in solr:
<?xml version="1.0" encoding="UTF-8"?>
<add>
<doc>
<field name="id">1051879H_15082014_00003457</field>
<field name="name">BEST MEGALINK SDN. BHD.</field>
<field name="entityName"></field>
<field name="companyNo">1051879-H</field>
<field name="noticeType">RMAT_N_C</field>
<field name="noticeDate">15/08/2014</field>
<field name="repNames"></field>
<field name="repNames"></field>
<field name="repNames"></field>
<field name="repICs"></field>
<field name="repICs"></field>
<field name="repICs"></field>
<field name="format">PDF</field>
<field name="folder">15082014</field>
<field name="pages">2</field>
</doc>
</add>
Other fields which need to be searched, needs to be added as part of schema.xml.
For example, the fields like the following needs to be added as part schema.xml:
<field name="entityName" type="text_string" indexed="true" stored="true"/>
<field name="companyNo" type="text_string" indexed="true" stored="true"/>
<field name="noticeType" type="text_string" indexed="true" stored="true"/>
I created a module to show related Purchase Orders from projects:
After clicking the Compras (Purchases) button a custom tree view is shown with the currency_id field:
Is there a way to show the symbol of the currency instead of the name? Something like you would do for example using Django: currency_id.symbol. Even better, I want to drop the currency_id field and prepend the currency symbol in the total amount, is that possible? Something like S/. 336.30 in the amount_total field.
Here's my tree view:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
....
....
<record id="purchase_order_project_tree" model="ir.ui.view">
<field name="name">purchase.order.tree</field>
<field name="model">purchase.order</field>
<field name="arch" type="xml">
<tree string="Compras"
colors="grey:state=='cancel';blue:state in ('wait','confirmed');red:state in ('except_invoice','except_picking')">
<field name="name" string="Reference"/>
<field name="date_order" />
<field name="partner_id"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
<field name="currency_id" />
<field name="amount_total" />
<field name="state"/>
</tree>
</field>
</record>
....
....
</data>
</openerp>
You can add a field called currency_symbol in your module (py) that gets the currency symbol when the currency changues with an on_changue to the currency. So you bring that field to the view, you cant directly do it from the XML.
When you click on the that button to get the tree get listed, you can override the "name_get" method of "Currency" and fetch the "currency symbol" instead of name. For this you can pass a flag in the context to limit this modification specific to your module only.
Hope this helps!!.