Import data to qweb report odoo - report

I'm creating a simple odoo qweb report to display some records in the database. Up to now I can create a report with some static content(hardcoded).But I want to connect my template with the table in my database. My table is Faculty. Here is my template file
`<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="ums_faculty_report">
<div class="page">
<h2>Report title</h2>
<p>This is the description</p>
<!--
In here i want to display the list of data-
<t t-foreach="dbrecords" t-as="o">
<p><t t-esc="i"/></p>
</t>
->
</div>
</template>
</data>
</openerp>`
And this is my report.xml file
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<report
id="ums.faculty_report"
model="ums.faculty"
string="All Faculties"
report_type="qweb-pdf"
name="ums.ums_faculty_report"
attachment_use="False"
/>
</data>
Simply I will repeat my problem again, I want to know how to bind a model to dbrecords in figure 1.Thanks in advance

Related

odoo, qweb: I like to replace attribute's value in odoo report

In odoo, qweb report. I have created an inherited report whith objective to change t-call attribute value from internal_layout to external layout. i have used the next code:
<template id="!!!!!!!!!!!!" inherit_id="!!!!!!!!!!!!!">
<xpath expr="//t[#t-call='web.internal_layout']" position="attributes">
<attribute name="attrs">{'t-call':'web.external_layout'}</attribute>
</xpath>
</template>
This code did not work, I wonder if there is a way to insert sub part of the same report.
<template id="!!!!!!!!!!!!!!!!!!" inherit_id="!!!!!!!!!!!">
<xpath expr="//t[#t-call='web.internal_layout']" position="replace">
<t t-call='web.external_layout'>
insert here original sub report
</t>
</xpath>
</template>
Operation doable by this small changment !
<data>
<template id="!!!!!!!!!!" inherit_id="!!!!!!!!!!!!!!!!!">
<xpath expr="//t[#t-call='web.internal_layout']" position="attributes">
<attribute name="t-call">web.external_layout</attribute>
</xpath>
</template>
</data>
If your views is for multiple object, like contains:
<t t-set="o" t-value="o.with_context({'lang':o.customer_id.lang})" />
you must add others attributes modification:
<xpath expr="//t[#t-call='web.internal_layout']" position="attributes">
<attribute name="t-call">web.external_layout</attribute>
<attribute name="t-foreach">docs</attribute>
<attribute name="t-as">o</attribute>
</xpath>

Odoo 10 : Removing a button from customer form view

I want to remove 'Unpublished on Website' button from customer form view.
This button is not part of form view so when i tried below code ,i got an error that element doesn't exist in parent view:
<xpath expr='//div[#class="oe_button_box"]//button[#name="website_publish_button"]' position='replace'>
<button type="object" name="callSurvey" icon="contacts_custom/static/description/survey.png" class="oe_stat_button">
<field string="Surveys" name="survey_count" widget="statinfo" modifiers="{'readonly': true}"/>
</button>
</xpath>
Then i tried to remove it using css. My css.css file :
button[name=website_publish_button]
{
display:none !important;
}
and template :
<openerp>
<data>
<!-- Adds all assets in Odoo -->
<template id="assets_backend" name="contacts_custom assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<!--These links will be called when loading your Odoo -->
<link rel="stylesheet" href="/contacts_custom/static/css/css.css"/>
</xpath>
</template>
</data>
</openerp>
But still button appears.Am i doing something wrong or Is there any other method to remove this button?
You could do it extending the view like this:
<record id="view_partners_form_website" model="ir.ui.view">
<field name="name">view.res.partner.form.website</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="website_partner.view_partners_form_website"/>
<field eval="18" name="priority"/>
<field name="arch" type="xml">
<data>
<button name="website_publish_button" position="replace">
<button type="object" name="callSurvey" icon="contacts_custom/static/description/survey.png" class="oe_stat_button">
<field string="Surveys" name="survey_count" widget="statinfo" modifiers="{'readonly': true}"/>
</button>
</button>
</data>
</field>
</record>
Add a depends entry to the module website_partner to be able to inherit the view that add the button like the snippet above

ODOO my header doesn't appears in my custom report

I have some trouble with my report header in odoo.
I can't make it appears correctly.
I've made a custom report here's the code:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="report_timesheet">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="doc">
<div class="page">
<t t-call="report.external_layout">
#SOMESTUFF
</t>
</div>
</t>
</t>
</template>
</data>
</odoo>
The thing is my header appears twice when I run this code, I've seen from standard module example that the line
<t t-call="report.external_layout">
should be before
<div class="page">
but when I do that the header doesn't appear at all. Does anyone have any idea about what's going wrong with this?
You can create your report as following:
<template id="report_invoice_document">
<t t-call="report.external_layout">
....
</t>
</template>
<template id="report_invoice">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="account.report_invoice_document" t-lang="o.partner_id.lang"/>
</t>
</t>
</template>

How to use XQuery to Update an Attribute in BaseX XML Database?

I am using BaseX to store XML data with multiple item nodes in the following format:
<root>
<item id="Root" parent_id="0" type="folder">
<content>
<name>Root</name>
</content>
</item>
<item id="One" parent_id="Root" type="file">
<content>
<name>First File in the Tree</name>
</content>
</item>
<item id="Two" parent_id="Root" type="file">
<content>
<name>Second File in the Tree</name>
</content>
</item>
</root>
I am trying to update the parent_id on one of the 'item' nodes to another item node's id attribute.
The tree before running the XQuery expression:
Root
∟ First File in the Tree
∟ Second File in the Tree
I am trying to figure out the correct XQuery expression to change the parent of one of the items from root to "one" item, so that my tree now looks like this:
Expected result tree:
Root
∟ First File in the Tree
    ∟ Second File in the Tree
Since the attribute parent_id controls this, I am looking to update exactly that.
If all you want to do is to update the #parent_id attribute, use a simple updating query like
replace value of node //item[#id='Two']/#parent_id with 'One'
But: this wouldn't actually change the XML tree, but only the one you're representing in XML (although I believe that this is what your question was about). A more XML-like approach to store the tree would be directly mapping the tree you want to have to XML:
<root>
<item id="Root" type="folder">
<content>
<name>Root</name>
</content>
<item id="One" type="file">
<content>
<name>First File in the Tree</name>
</content>
<item id="Two" type="file">
<content>
<name>Second File in the Tree</name>
</content>
</item>
</item>
</item>
</root>
Or even more concise, holding the same information:
<folder id="Root" name="Root">
<file id="One" name="First File in the Tree">
<file id="Two" name="Second File in the Tree" />
</file>
</folder>

Create web form from xml in asp.net mvc

I am assigned to web part of some project.There are two parts in this project,
window and web.In window part,User can create their own customized template
like visual studio IDE,you can addform and other controls.And then,we save this template
with data in xml file.My duty isto read from this xml file and create webform.
For web part,just showing information that createdfrom window part.
our xml file format is like below.For web part,we developed in c#.net with asp.net mvc.
<Object type="System.Windows.Forms.Form">
<Object type="System.Windows.Forms.Label">
<Property name="Name">lblCity</Property>
<Property name="Text">City</Property>
</Object>
<Object type="System.Windows.Forms.TextBox">
<Property name="Name">txtCity</Property>
<Property name="Text">England</Property>
</Object>
<Object type="System.Windows.Forms.Label">
<Property name="Name">lblNRIC</Property>
<Property name="Text">NRIC</Property>
</Object>
<Object type="System.Windows.Forms.TextBox">
<Property name="Name">txtNRIC</Property>
<Property name="Text">ABC01234</Property>
</Object>
<Object type="System.Windows.Forms.RadioButton">
<Property name="Name">RadioButton1</Property>
<Property name="Text">OptionA</Property>
</Object>
<Object type="System.Windows.Forms.CheckBox">
<Property name="Name">CheckBox1</Property>
<Property name="Text">Yes</Property>
</Object>
<Object type="System.Windows.Forms.CheckBox">
<Property name="Name">CheckBox2</Property>
<Property name="Text">No</Property>
</Object>
<SampleDataSet>
<SampleTable>
<TableName>Sample1</TableName>
<ProductName>ABC</ProductName>
<Price>100</Price>
<Qty>10</Qty>
<Amount>1000</Amount>
</SampleTable>
<SampleTable>
<TableName>Sample2</TableName>
<ProductName>DEF</ProductName>
<Price>200</Price>
<Qty>20</Qty>
<Amount>4000</Amount>
</SampleTable>
<SampleTable>
<TableName>Sample3</TableName>
<ProductName>GHK</ProductName>
<Price>300</Price>
<Qty>30</Qty>
<Amount>9000</Amount>
</SampleTable>
</SampleDataSet>
</Object>
We know it should not be create web form like window part,but,we really need it.
So,how i solve my problem?can i use xml serilization?
please give me right ways with some examples.
Regards
Han
You could use XSLT to transform this XML to XHTML. Also, you could inherit your own XMLBasedFormResult from MVC ActionResult class and generate form HTML at ExecuteResult method using C# (e.g. with LinqToXML).
Well, don't you think you will really end up duplicating what visual studio does..?
I would suggest you use something like WPF, which can be shown in the browser as well as in the Windows app. I am telling from experience this idea of parsing xml and generating UI is not very good..it is almost like writing a jsp/asp engine.
Also i noticed that the xml you have there has no formatting information, location on screen, color, style, font etc..
How do you intend on populating text boxes, dropdown lists, menus etc..?
As mace said XSLT is a good solution.
This is the xls stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Template for <Object type="System.Windows.Forms.Form -->
<xsl:template match="*[#type = 'System.Windows.Forms.Form']">
<!-- Here's the html's form tag -->
<form>
<fieldset>
<xsl:apply-templates />
</fieldset>
</form>
</xsl:template>
<!-- Template for <Object type="System.Windows.Forms.Label -->
<xsl:template match="*[#type = 'System.Windows.Forms.Label']">
<!-- Here's the html's label tag -->
<label><xsl:value-of select="." /></label>
</xsl:template>
<!-- Template for <Object type="System.Windows.Forms.TextBox -->
<xsl:template match="*[#type = 'System.Windows.Forms.TextBox']">
<!-- Create the html's input tag -->
<xsl:element name="input">
<!-- And set the attributes -->
<xsl:attribute name="name">
<xsl:value-of select="./Property[#name ='Name']" />
</xsl:attribute>
<xsl:attribute name="type">text</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="./Property[#name ='Text']" />
</xsl:attribute>
</xsl:element>
</xsl:template>
<!-- Add here templates for RadioButton, Checkbox ... -->
</xsl:stylesheet>
You can read this Tutorial to get basic skills of xls.
You can run this xsl transformation now in C#:
//load the Xml doc
XPathDocument myXPathDoc = new XPathDocument(sXmlPath) ;
XslTransform myXslTrans = new XslTransform() ;
//load the Xsl
myXslTrans.Load(sXslPath) ;
//create the output stream
XmlTextWriter myWriter = new XmlTextWriter
("result.html", null);
//do the actual transform of Xml
myXslTrans.Transform(myXPathDoc,null, myWriter);
myWriter.Close() ;
You have to modify that for your scenario. Look at the MSDN for information about the XslTransform-class etc.

Resources