Extract certain attribute names and its values from xml using XSLT - xslt-1.0

I am not an expert in XSLT and require help. We are pulling AWB status from ecomm express logistics. The xml structure they are providing the data is in django serialized xml format. We want to select only the required data from this xml. Tried to extract the attribute name and its value but it's not giving the desired output.
Below is the input structure
<ecomexpress-objects version="1.0">
<object pk="1" model="awb">
<field type="BigIntegerField" name="awb_number">700054480</field>
<field type="CharField" name="orderid">5012</field>
<field type="FloatField" name="actual_weight">0.5</field>
<field type="CharField" name="origin">DELHI-DSW</field>
<field type="CharField" name="destination">DELHI-DLN</field>
<field type="CharField" name="customer">Ecom Express Private Limited - 32012</field>
<field type="CharField" name="consignee">MUKESH KUMAR GUPTA</field>
<field type="CharField" name="pickupdate">11-Feb-2013</field>
<field type="CharField" name="status">Delivered / Closed</field>
<field type="CharField" name="reason_code"/>
<field type="CharField" name="reason_code_description"/>
<field type="CharField" name="reason_code_number">999</field>
<field type="CharField" name="receiver">mukesh 9999488339</field>
<field type="CharField" name="expected_date">12-Feb-2013</field>
<field type="CharField" name="last_update_date">05-Apr-2013</field>
<field type="CharField" name="delivery_date">2013-02-17 11:26:00</field>
<field type="CharField" name="ref_awb">None</field>
<field type="CharField" name="rts_shipment"/>
<field type="CharField" name="system_delivery_update">2013-02-17 11:26:00</field>
<field type="CharField" name="rts_system_delivery_status"/>
</object>
<object pk="2" model="awb">
<field type="BigIntegerField" name="awb_number">700054482</field>
<field type="CharField" name="orderid">5014</field>
<field type="FloatField" name="actual_weight">0.5</field>
<field type="CharField" name="origin">DELHI-DSW</field>
<field type="CharField" name="destination">DELHI-DLN</field>
<field type="CharField" name="customer">Ecom Express Private Limited - 32012</field>
<field type="CharField" name="consignee">MUKESH KUMAR GUPTA</field>
<field type="CharField" name="pickupdate">11-Feb-2013</field>
<field type="CharField" name="status">Delivered / Closed</field>
<field type="CharField" name="reason_code"/>
<field type="CharField" name="reason_code_description"/>
<field type="CharField" name="reason_code_number">999</field>
<field type="CharField" name="receiver">mukesh 9999488339</field>
<field type="CharField" name="expected_date">12-Feb-2013</field>
<field type="CharField" name="last_update_date">05-Apr-2013</field>
<field type="CharField" name="delivery_date">2013-02-17 11:26:00</field>
<field type="CharField" name="ref_awb">None</field>
<field type="CharField" name="rts_shipment"/>
<field type="CharField" name="system_delivery_update">2013-02-17 11:26:00</field>
<field type="CharField" name="rts_system_delivery_status"/>
</object>
</ecomexpress-objects>
Expected output structure is
<ecommexpress>
<awb>
<awb_number>700054480</awb_number>
<orderid>5012</orderid>
.
.
.
.
.
</awb>
<awb>
<awb_number>700054482</awb_number>
<orderid>5014</orderid>
.
.
.
.
.
</awb>
</ecommexpress>
Multiple times AWB Number could come. So nested structure is expected.
Only XSLT 1.0 is accepted in my system. Please help.
Regards,
Siji Anup

Use below code
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="1.0">
<xsl:template match="ecomexpress-objects">
<ecommexpress><xsl:apply-templates/></ecommexpress>
</xsl:template>
<xsl:template match="object[#model = 'awb']">
<awb><xsl:apply-templates/></awb>
</xsl:template>
<xsl:template match="field[#name]">
<xsl:element name="{#name}"><xsl:apply-templates/></xsl:element>
</xsl:template>
</xsl:stylesheet>
see transformation at https://xsltfiddle.liberty-development.net/jxDjina

Related

Odoo14 | No record found for unique ID base.user_admin

Accidently the user with id=2 which is (admin) deleted.How we can recover/fix this?
Create xml record again with that xml ID.
<record id="base.user_admin" model="res.users">
<field name="login">admin</field>
<field name="password">admin</field>
<field name="partner_id" ref="base.partner_admin"/>
<field name="company_id" ref="main_company"/>
<field name="company_ids" eval="[(4, ref('main_company'))]"/>
<field name="groups_id" eval="[(6,0,[])]"/>
<field name="signature"><![CDATA[<span>-- <br/>Administrator</span>]]></field>
</record>

Odoo - How to update non updateable records by XML

I have created a few companies under res.company
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="True">
<record id="partner_my_company_hk" model="res.partner" context="{'default_is_company': True}">
<field name="name">My company HK</field>
<field name="company_id" eval="None"/>
<field name="customer" eval="False"/>
<field name="is_company" eval="True"/>
<field name="street"></field>
<field name="city"></field>
<field name="zip"></field>
<field name="phone"></field>
<field name="email">info#my_company.com</field>
<field name="website">www.my_company.com</field>
<field name="image" type="base64" file="base/static/img/res_company_logo.png"/>
</record>
<record id="partner_my_company_us" model="res.partner">
<field name="name">My company US</field>
<field name="company_id" eval="None"/>
<field name="customer" eval="False"/>
<field name="is_company" eval="True"/>
<field name="street"></field>
<field name="city"></field>
<field name="zip"></field>
<field name="phone"></field>
<field name="email">info#my_company.com</field>
<field name="website">www.my_company.com</field>
<field name="image" type="base64" file="base/static/img/res_company_logo.png"/>
</record>
<record id="company_my_company_hk" model="res.company">
<field name="name">My company HK</field>
<field name="partner_id" ref="partner_my_company_hk"/>
<field name="currency_id" ref="base.USD"/>
</record>
<record id="partner_my_company_hk" model="res.partner">
<field name="company_id" ref="company_my_company_hk"/>
</record>
<record id="company_my_company_us" model="res.company">
<field name="name">My company US</field>
<field name="partner_id" ref="partner_my_company_us"/>
<field name="currency_id" ref="base.USD"/>
</record>
<record id="partner_my_company_us" model="res.partner">
<field name="company_id" ref="company_my_company_us"/>
</record>
</data>
</odoo>
This is my original res_users.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="0">
<record id="base.user_admin" model="res.users">
<field name="groups_id" eval="[(4, ref('account.group_account_user'))]"/>
</record>
</data>
</odoo>
So I want to set those 2 newly created 2 companies into base.user_admin
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="0">
<record id="base.user_admin" model="res.users">
<field name="groups_id" eval="[(4, ref('account.group_account_user'))]"/>
<field name="company_id" ref="company_my_company_hk" />
<field name="company_ids" eval="[(4, ref('company_my_company_hk')),(4, ref('company_my_company_us'))]" />
</record>
</data>
</odoo>
And it is not working. But when I uninstall the module and reinstall it works.
Why? I cannot uninstall the module just to make it work in the future. What are the limitations and how to bypass the limits?
You can change the noupdate value on XML, change the desired fields and should take the change on noupdate back.
<!-- Allow updating on noupdate=True records -->
<function name="write" model="ir.model.data">
<function name="search" model="ir.model.data">
<value
eval="[('module', '=', 'base'), ('name', '=', 'user_admin')]" />
</function>
<value eval="{'noupdate': False}" />
</function>
<record id="base.user_admin" model="res.users">
<!-- change fields here -->
</record>
<!-- Revoke noupdate change -->
<function name="write" model="ir.model.data">
<function name="search" model="ir.model.data">
<value
eval="[('module', '=', 'base'), ('name', '=', 'user_admin')]" />
</function>
<value eval="{'noupdate': True}" />
</function>
External ID user_admin in base has been marked as noupdate.
And noupdate cannot be overridden.
Unless I run
UPDATE ir_model_data SET noupdate=False WHERE name = 'user_admin' and module='base';
Otherwise I won't be able to update it when I upgrade the module
More refined solution to #CZoellner 's solution is:
<function name="toggle_noupdate" model="ir.model.data" eval="['res.users', ref('base.user_admin')]"/>

Group by field name

I want to do Group by by City but this possibility doesn't shows up. where is my mistake? there is field city in python file and it's showing up in tree view but not really in Group by
<openerp>
<data>
<record id="vpicktree" model="ir.ui.view">
<field name="name">Picking tree city</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.vpicktree"/>
<field name="arch" type="xml">
<field name="location_dest_id" position="after">
<field name="city"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="stock_picking_filter_city_search">
<field name="name">stock.picking.tree.filter_search</field>
<field name="model">stock.picking</field>
<field name="arch" type="xml">
<search string="City">
<filter name="city" string="City" context="{'group_by':'city'}"/>
</search>
</field>
</record>
<record id="action_picking_tree_city" model="ir.actions.act_window">
<field name="name">City</field>
<field name="res_model">stock.picking</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,kanban,calendar</field>
<field name="domain"></field>
<field name="context">{ 'group_by':'city' }</field>
<field name="search_view_id" ref="stock.view_picking_internal_search"/>
</record>
</data>
</openerp>
The group by must be in search view not on the action setion as you did, so you have to edit your search view:
<record model="ir.ui.view" id="stock_picking_filter_city_search">
<field name="name">stock.picking.tree.filter_search</field>
<field name="model">stock.picking</field>
<field name="arch" type="xml">
<search string="City">
<filter name="city" string="City" context="{'group_by':'city'}"/>
<group expand="0" string="Grouper par">
<filter string="City" icon="terp-personal" domain="[]" context="{'group_by':'city'}"/>
</group>
</search>
</field>
</record>

Openerp make scheduled action

In openerp there's a standard module named account_followup_print, in here there's a method called do_process which sends out all the payment followup emails.
I want it to automatically do this every day without having to click the button. So I have made the following:
<openerp>
<data>
<record forcecreate="True" id="ir_cron_project_task" model="ir.cron">
<field name="name">Run Payment Follow-up scheduler</field>
<field eval="True" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'account_followup.print'" name="model"/>
<field eval="'do_process'" name="function"/>
</record>
</data>
Yet this does not work, what am I doing wrong here? Thanks in advance!
Try following,
<record id = "ir_cron_project_task" model = "ir.cron">
<field name="name">Run Payment Follow-up scheduler</field>
<field eval="True" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'account_followup.print'" name="model"/>
<field eval="'do_process'" name="function"/>
<field eval="'()'" name="args"/>
</record>

Customize dashboard in Odoo/Open ERP

Odoo/openerp 8 supports creating dashboard in which we can add multiple reports into it.
My question is: How can we inherit this dashboard to customize it?
For example, I want to add a button which helps clone the dashboard to another user.
It seems that this dashboard is not a usual FormView.
You can't inherit dashboards in Odoo 8.because dashboards is work like views container not usual view if you want to customize one .. just copy it's code and paste it in your module over again and customize what you need.
Try to make formview for yourself :-)
This is a good example:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.actions.act_window" id="act_centiro_stocks_tree_pendientes">
<field name="name">Centiro stock</field>
<field name="res_model">stock.picking</field>
<field name="view_type">tree</field> <!-- form -->
<field name="view_mode">tree</field>
<field name="domain">[('state', 'not in', ('assigned','done'))]</field>
</record>
<record model="ir.actions.act_window" id="act_centiro_stocks_tree_procesados">
<field name="name">Centiro stock</field>
<field name="res_model">stock.picking</field>
<field name="view_type">tree</field> <!-- form -->
<field name="view_mode">tree</field>
<field name="domain">[('state', 'in', ('assigned','done'))]</field>
</record>
<record model="ir.actions.act_window" id="act_centiro_stocks_graph">
<field name="name">Operaciones Centiro</field>
<field name="res_model">gc.operaciones.centiro</field>
<field name="view_type">form</field>
<field name="auto_refresh" eval="1" />
<field name="view_mode">kanban,form</field>
</record>
<record model="ir.ui.view" id="board_view_stock_centiro_form">
<field name="name">Stock Centiro</field>
<field name="model">board.board</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Centiro Stock Dashboard">
<hpaned>
<child1>
<action string="Estado almacén Centiro" name="%(act_centiro_stocks_graph)d" colspan="2" />
</child1>
<child2>
<action string="Pedidos pendientes" name="%(act_centiro_stocks_tree_pendientes)d" colspan="2" />
<action string="Pedidos sin ubicar" name="%(act_centiro_stocks_tree_procesados)d" colspan="2" />
</child2>
</hpaned>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="open_stock_centiro_board">
<field name="name">Stock Centiro Dashboard</field>
<field name="res_model">board.board</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="usage">menu</field>
<field name="view_id" ref="board_view_stock_centiro_form" />
</record>
<menuitem id="dashboard_menu" name="Dasboard custom module"
parent="cabecera_dashboard_custom_module" action="open_stock_centiro_board" />
</data>
Good luck