Xpath Extract data from Parent element and not its child elements where parent name is same as child - postgresql-9.5

Parent and child tags have same name. I am trying to extract everything from parent except for the child elements.
We have several rows in parent that we want to extract. There are several Parent and child which are nested as below.
Have tried //Record/preceding-sibling::* which does not give me parent element start and end tag.
[not(descendant::Record)] and many other alternatives but no luck.
<Record contentId="1">
<Metrics_Library_Name>Text1</Metrics_Library_Name>
<Metrics_Library_ID>1</Metrics_Library_ID>
<Record contentId="1a">
<Questionnaire_ID>1a</Questionnaire_ID>
<Year>2018</Year>
<Quarter/>
<Month>02-Feb</Month>
</Record>
<Record contentId="1b">
<Questionnaire_ID>1a</Questionnaire_ID>
<Year>2018</Year>
<Quarter/>
<Month>02-Feb</Month>
</Record>
</Record>
Expected output:
<Record contentId="1">
<Metrics_Library_Name>Text1</Metrics_Library_Name>
<Metrics_Library_ID>1</Metrics_Library_ID>
</Record>

Related

Change the name of a parent menu in odoo 16

Change the name of a parent menu in odoo 16
I put this code here because it doesn't work for me. I wanted to clarify that what I want is to change the name of a menu but through code, not through the odoo interface
<record id="hr_payroll.menu_hr_payroll_payslips" model="ir.ui.menu">
<field name="name">New name</field>
</record>
What I'm trying to do is to be able to change the name of a parent menu in odoo 16, but so far the only thing I've managed to do is change the name of a sub-menu. How can I change the name of a parent menu in odoo 16? Could you help me on that part please.
your text`
<record id="menu_hr_payroll_payslips_new" model="ir.ui.menu">
<field name="name">NĂ³mina</field>
<field name="sequence">70</field>
<field name="parent_id"
ref="hr_payroll.menu_hr_payroll_employee_payslips_to_pay"/>
<field name="action" ref="hr_payroll.hr_payslip_action_view_to_pay"/>
</record>
I tried this code and it worked for me but only to change the name of a sub-menu, but what I want is to change the name of a parent menu in odoo16`

How to reference a planning type in a plan

I have a custom odoo module, which extends some existing modules like hr. I want to create an onboarding plan with several predefined tasks in it.
This is my plan acitivity type xml which works at it should. If I update the applikation with this file, I get the desired tasks in the planning types overview.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="hr_plan_activity_type_create_work_contract" model="hr.plan.activity.type">
<field name="activity_type_id" ref="mail.mail_activity_data_todo"/>
<field name="responsible">manager</field>
<field name="summary">Create work contract</field>
<field name="note">Create the work contract for the employee.</field>
</record>
<record id="hr_plan_activity_type_employee_model_in_erp" model="hr.plan.activity.type">
<field name="activity_type_id" ref="mail.mail_activity_data_todo"/>
<field name="responsible">manager</field>
<field name="summary">Employee model in ERP</field>
<field name="note">Complete the employee model in ERP (AHV, Banking, etc.)</field>
</record>
</odoo>
This is my plan.xml which should create a plan with the activity types. The creation of the plan works, but if I reference the activity types, I'll get an error message.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Onboarding -->
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids"
eval="[(6,0,[ref('mycompany.hr_plan_activity_type_employee_model_in_erp')])]"/>
<field name="plan_activity_type_ids"
eval="[(4,0,[ref('mycompany.hr_plan_activity_type_create_work_contract')])]"/>
</record>
</odoo>
In the manifest.py file I first load the plan.activity.type.xml and then the plan.xml so this shouldn't be a problem.
This is the error message I get when I try to upgrade my customized module mycompany:
File "C:\Program Files (x86)\Odoo 13.0e\server\odoo\addons\base\models\ir_model.py", line 1670, in xmlid_lookup
raise ValueError('External ID not found in the system: %s' % xmlid)
odoo.tools.convert.ParseError: "External ID not found in the system: hr.plan.activity.type.hr_plan_activity_type_create_work_contract" while parsing file:/c:/users/myuser/appdata/local/openerp%20s.a/odoo/addons/13.0/mycompany/data/hr/plan.xml:2, near
<odoo>
<!-- Onboarding -->
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids" ref="hr.plan.activity.type.hr_plan_activity_type_create_work_contract"/>
</record>
Does anyone have any ideas?
String identifier stored in ir.model.data, can be used to refer to a record regardless of its database identifier during data imports or export/import roundtrips.
External identifiers are in the form module.id (e.g. account.invoice_graph). From within a module, the module. prefix can be left out.
Sometimes referred to as xml id or xml_id as XML-based Data Files make extensive use of them.
In your example you used model_name.id which probably does not exist in the database, to reference hr_plan_activity_type_create_work_contract record you just need to replace the model name with the module name.
I can see from the log message that the module name is mycompany, try to replace the model name with mycompany:
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids" ref="mycompany.hr_plan_activity_type_create_work_contract"/>
</record>
Update:plan_activity_type_ids is an x2many field
Use the special commands format to set the x2many field values:
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids" eval="[(6,0,[ref('mycompany.hr_plan_activity_type_create_work_contract')])]"/>
</record>
Edit: Only the first one shows up in the GUI
To replaces all existing records in the set by the ids list (using '(6, 0, ids)') you can provide a list of ids inside the triplet. You can find an example in res_partner_demo.xml inside the base module.
Example:
<field name="plan_activity_type_ids" eval="[(6,0,[ref('mycompany.hr_plan_activity_type_employee_model_in_erp'), ref('mycompany.hr_plan_activity_type_create_work_contract')])]"/>
To add an existing record of id id to the set (using (4, id)) you need to provide one id for each triplet. You can find an example in base_groups.xml inside the base module.
Example:
<field name="plan_activity_type_ids" eval="[(4,ref('mycompany.hr_plan_activity_type_employee_model_in_erp')), (4,ref('mycompany.hr_plan_activity_type_create_work_contract'))]"/>
Your ref ids are wrong. hr.plan.activity.type.hr_plan_activity_type_create_work_contract is wrong. You get only one . in a reference. its [<module_name>.]ext_id_of_object.
If you reference the object from the same module you don't have to use module name.part
If you can see the database tables. then things you are referencing are in table ir_model_data
So if the thing you are referencing is in your own model then you cant use just hr_plan_activity_type_create_work_contract as a reference or your_model_name.hr_plan_activity_type_create_work_contract

How to make a many2many field sortable in odoo 9?

I have a many2many field , but I'm unable to sort it . Can anyone help?
I don't think there is any way to sort a many2many field if it is many2many_tags or any display widget other than the default many2many widget.
With that default many2many widget, it should display like a list in the form. You may be able to define the tree view and set a default_order attribute. Something like this:
<field name="your_m2m_field">
<tree default_order="sub_field1, sub_field2 desc">
<field name="sub_field1/>
<field name="sub_field2/>
<field name="sub_field3/>
</tree>
</field>

Disable one2many popup odoo 8

Good Day! is it possible to disable pop of tree view in the form. I tried no_open="True" readonly="1" edit="False" both on field and tree view but didn't worked.
<field name="payment_line">
<tree editable="top" create="false">
<field name="product"/>
<field name="description"/>
<field name="account"/>
<field name="unit"/>
<field name="qty"/>
<field name="amount"/>
<field name="total"/>
</tree>
</field>
I've coped with the same issue in odoo 10, my one2many treeview always make a popup on click. No matter editable='bottom' option was set.
Suddenly I've found web_tree_no_open module from codingforfun, that adds a new option:
< tree open="false" >
It's for version 8 but it can be used in 10 just renaming openerp.py to manifest.py
It can be downloaded from here:
https://github.com/initOS/web/tree/8.0-tree-view-no-select/web_tree_no_open
Worked for me, I hope it helps
Use this style to disable click in read as well as edit mode:
<field name="your_o2m" style="pointer-events:none;" />
Use editable='bottom' in this case, like:
<field name='line_ids'>
<tree create='false' editable='bottom'>
<field name='so_line_id' readonly='1'/>
<tree>
</field>
Odoo Version 10.0
web_tree_no_open module adds a new option: <tree open="false">
Lists
The root element of list views is <tree> 3. The list view's root can have the following attributes:
editable
by default, selecting a list view's row opens the corresponding form view. The editable attributes makes the list view itself editable in-place.
Valid values are top and bottom, making new records appear respectively at the top or bottom of the list.
The architecture for the inline form view is derived from the list view. Most attributes valid on a form view's fields and buttons are thus accepted by list views although they may not have any meaning if the list view is non-editable
default_order
overrides the ordering of the view, replacing the model's default order. The value is a comma-separated list of fields, postfixed by desc to sort in reverse order:
<tree default_order="sequence,name desc">
create, edit, delete
allows disabling the corresponding action in the view by setting the corresponding attribute to false
on_write
only makes sense on an editable list. Should be the name of a method on the list's model. The method will be called with the id of a record after having created or edited that record (in database).
The method should return a list of ids of other records to load or update.
string
alternative translatable label for the view
Deprecated since version 8.0: not displayed anymore
Note
if the list view is editable, any field attribute from the form view is also valid and will be used when setting up the inline form
view
in the form and tree view you can add create='false' to disable the create button and edit='false' to disable the edit button.Also use editable="top" or editable="bottom" if you dont want the form view to popup. for example
<tree string="Sale Order" create="false" edit="false" editable="bottom">
...
...
...
</tree>

How to change the base fields label in openerp 6.1

researchorial but indeed i have done all the google around what i want o achieve in openerp that how to change those fields label ,i don't wanna play with fields and i know how to create new fields but what about base fields i am not able to edit them they throw some error that you cannot change the base fields from here so objective is clear that those label like Company, SSNID in hr module i want them changed according to them nothing else!!
please do not post links of already same question cause they had not been answered !!
Thank You
You can change the label of a field in two ways.
1. Python code
Inherit the model where that field is defined, then inside _columns add the same field name with new label.
For example, if you want to change SSNID to Employee ID, assume that in the base module the field is defined as 'ssnid' and the field is in hr.employee model.
from osv import osv, fields
class hr_employee(osv.osv):
_inherit = 'hr.employee'
_columns = {'ssnid': fields.integer('Employee ID')
}
hr_employee()
2. XML code(change the view)
Inherit your view and add the attribute for the field 'ssnid'. For example in base module the field view is like <field name="ssnid"/> .To change it inherit its corresponding form and tree view and you can change the field by using position="attribute" and also position="replace". Add the attribute string="Employee ID".
<field name="ssnid" position="replace">
<field name="ssnid" string="Employee ID"/>
</field>
Create New Hr employee Inherited view By this way.
<record model="ir.ui.view" id="updated_hr_form_view">
<field name="name">updated.hr.form</field>
<field name="model">hr.employee</field>
<field name="type">form</field>
<field name="inherit_id" ref="hr.view_employee_form" />
<xpath expr="//form/notebook/page[#string='Personal Information'/group/field[#name='ssnid']]" position="replace">
<field name="ssnid" string="Your New Label"/>
</xpath>
</field>
</record>