I am using Odoo 10-e. I came from .net what i want to do is that i need to create my custom setting configuration file in Odoo like we have AppSettings file in asp.net where we set some static key values to use them in project. How to create that kind of file and how can i access that file in python code or xml files ?
Create a class that inherits from res.config.settings (so you can edit the record):
class farmacia_pedido_config_settings(models.TransientModel):
_inherit = 'res.config.settings'
_name = 'farmacia.config.settings'
lista_precios_defecto = fields.Many2one(
'product.pricelist',
string='Lista de precios por defecto')
Associate with the view:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_farmacia_configuration" model="ir.ui.view">
<field name="name">farmacia config settings</field>
<field name="model">farmacia.config.settings</field>
<field name="arch" type="xml">
<form string="Farmacia" class="oe_form_configuration">
<header>
<button string="Aplicar" type="object" name="execute" class="oe_highlight"/>
<button string="Cancelar" type="object" name="cancel" class="oe_link"/>
</header>
<field name="lista_precios_defecto" class="oe_inline"/>
</group>
</form>
</field>
</record>
<record id="action_farmacia_configuration" model="ir.actions.act_window">
<field name="name">Farmacia</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">farmacia.config.settings</field>
<field name="view_mode">form</field>
<field name="target">inline</field>
</record>
<menuitem id="menu_farmacia_config" name="Farmacia" parent="base.menu_config"
sequence="3" action="action_farmacia_configuration"/>
</data>
</openerp>
Save in a file accessing via python (this is uglier)
config = ConfigParser()
your_file = os.getenv("HOME")+os.path.sep+"your_file.conf"
if os.path.isfile(your_file):
config.read(your_file)
else:
raise models.except_orm(
'Error',
"File not found " + os.getcwd())
Related
When you define a field in odoo, by default, it displays the string for that value and next to it, the value.
If you don't put the field between group tags, the string value, doesn't appear.
The problem is that I am defining a tree view which doesn't contain group tags:
<record model="ir.ui.view" id="field_partida_fertilizer_tree">
<field name="name">field.diary.partida.fertilizer.tree.view</field>
<field name="model">field.diary.partida.fertilizer</field>
<field name="priority" eval="17"/>
<field name="arch" type="xml">
<tree string="Fertilizante">
<field string= 'Nombre' name="fertilizer"/>
<field string='N' name="nitrato" options='{"show_string": False}' widget="percentpie"/>
<field string='P' name="fosforo" options='{"fg_color": "white"}' widget="percentpie"/>
<field string='K' name="potasio" options='{"fg_color": "white"}' widget="percentpie"/>
<field string='Cantidad (kg)' name="quantity"/>
</tree>
</field>
</record>
By using widget percentpie, I can display this:
I want to hide the letter N next to the graph but not the column and I can't find any property of the widget to do that. The only way I could trick this is by giving the color white to the text so it disappears with the background, but the column cant be centered.
I have tried with the option show_string I found on GitHub but it doesn't work.
Any help would be awesome...
Thank you!
Odoo defines a condition in the PercentPie template to show the string attribute vaue:
<span t-if="widget.string"><t t-esc="widget.string"/></span>
You can alter the template and define a new condition base on a value (show_string ) passed through the options attribute:
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="FieldPercentPie">
<t t-jquery="span" t-operation="attributes">
<attribute name="t-if">widget.string and (widget.attrs.options.show_string === undefined or widget.attrs.options.show_string)</attribute>
</t>
</t>
</templates>
Create a new XML file with the above content and add it under the qweb section of the manifest file.
Example:
<record model="ir.ui.view" id="field_partida_fertilizer_tree">
<field name="name">field.diary.partida.fertilizer.tree.view</field>
<field name="model">field.diary.partida.fertilizer</field>
<field name="priority" eval="17"/>
<field name="arch" type="xml">
<tree string="Fertilizante">
<field string='Nombre' name="fertilizer"/>
<field name="nitrato" options='{"show_string": False}' widget="percentpie"/>
<field name="fosforo" options='{"show_string": False}' widget="percentpie"/>
<field name="potasio" options='{"show_string": False}' widget="percentpie"/>
<field string='Cantidad (kg)' name="quantity"/>
</tree>
</field>
How Can I extract the characteristics values for the following XML code using XPATH?
Example: Extract displayName, firsName, lastName, etc.
This is my XML data:
<directory>
<fieldset>
<field id="displayName">Display name</field>
<field id="firstName">First name</field>
<field id="lastName">Last name</field>
<field id="preferredName">Preferred name</field>
<field id="jobTitle">Job title</field>
<field id="workPhone">Work Phone</field>
<field id="canUploadPhoto">Can Upload Photo</field>
</fieldset>
<employees>
<employee id="229">
<field id="displayName">Susan</field>
<field id="firstName">TestName</field>
<field id="canUploadPhoto">no</field>
</employee>
</employees>
</directory>
You can get actual values along the following XPath expression:
/directory/employees/employee/field[#id="displayName"]/text()
I am trying to import data from files like CSV, XML and Json to solr core, I am new to solr so this might be a straightforward to some but for me I have tried many online suggestions but not getting the desired result.
So I have a json file and I have enabled dataimport by adding the following requestHandler to solrconfig.xml:
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">solr-data-config.xml</str>
</lst>
</requestHandler>
And in the solr-data-config.xml:
<dataConfig>
<dataSource name="dfs" type="FileDataSource"/>
<document>
<entity name="sourcefile" processor="FileListEntityProcessor" fileName=".*" rootEntity="false" baseDir="${solr.install.dir}/example/exampledocs">
<entity name="entryline" processor="LineEntityProcessor" url="${sourcefile.fileAbsolutePath}" rootEntity="true" dataSource="fds" separator=","/>
</entity>
</document>
The updated version:
<dataConfig>
<script><![CDATA[
function CategoryPieces(row) {
var pieces = row.get('manu_id_s').split('/');
var arr = new Array();
for (var i=0; i < pieces.length; i++) {
row.put('manu_id_s' + i, pieces[i].trim());
arr[i] = pieces[i].trim();
}
row.put('manu_id_s', (pieces.length - 1).toFixed());
row.put('manu_id_s', arr.join('/'));
row.put('manu_id_s', arr.join('/'));
return row;
}
]]></script>
<dataSource type="FileDataSource" />
<document>
<entity
name="document"
processor="FileListEntityProcessor"
baseDir="${solr.install.dir}/example/exampledocs/khaled"
fileName=".*.xml$"
recursive="false"
rootEntity="false"
dataSource="null">
<entity
name="test"
processor="XPathEntityProcessor"
transformer="script:CategoryPieces"
url="${document.fileAbsolutePath}"
useSolrAddSchema="true"
stream="true">
</entity>
</entity>
</document>
</dataConfig>
And I have added a json, csv and xml files to the path, in the ui of solr when I use the dataimport it says that e.g. Requests: 0 , Fetched: 26 , Skipped: 0 , Processed: 0 and nothing in the logs, can someone advice how to add the data in the file to solr?
Here is my sample data in the xml file:
<add>
<doc>
<field name="id">USD</field>
<field name="name">One Dollar</field>
<field name="manu">Bank of America</field>
<field name="manu_id_s">boa</field>
<field name="cat">currency</field>
<field name="features">Coins and notes</field>
<field name="price_c">1,USD</field>
<field name="inStock">true</field>
</doc>
<doc>
<field name="id">EUR</field>
<field name="name">One Euro</field>
<field name="manu">European Union</field>
<field name="manu_id_s">eu</field>
<field name="cat">currency</field>
<field name="features">Coins and notes</field>
<field name="price_c">1,EUR</field>
<field name="inStock">true</field>
</doc>
<doc>
<field name="id">GBP</field>
<field name="name">One British Pound</field>
<field name="manu">U.K.</field>
<field name="manu_id_s">uk</field>
<field name="cat">currency</field>
<field name="features">Coins and notes</field>
<field name="price_c">1,GBP</field>
<field name="inStock">true</field>
</doc>
<doc>
<field name="id">NOK</field>
<field name="name">One Krone</field>
<field name="manu">Bank of Norway</field>
<field name="manu_id_s">nor</field>
<field name="cat">currency</field>
<field name="features">Coins and notes</field>
<field name="price_c">1,NOK</field>
<field name="inStock">true</field>
</doc>
</add>
Now the data returned from the query looks like:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"*:*",
"_":"1547556805546"}},
"response":{"numFound":4,"start":0,"docs":[
{
"manu_id_s":"boa",
"id":"USD",
"_version_":1622731088078045184},
{
"manu_id_s":"eu",
"id":"EUR",
"_version_":1622731088081190912},
{
"manu_id_s":"uk",
"id":"GBP",
"_version_":1622731088081190913},
{
"manu_id_s":"nor",
"id":"NOK",
"_version_":1622731088082239488}]
}}
I am new to solr so I might have wrongly written the dih.I have data already in my solr db and I need to extend my dih file such that it can index csv file which contain more information and csv and solr db data are mapped by common id.What I have done is -find in the code below
This is my csv file-->
Node_IP probe_name Global_ID
10.53.3.87 ILRNAPSUD03 4b44aaff1e09f3d793fe9
10.224.47.26 ILRNAPSUD03 47eebea2c2d485b59
Here is a dih snippet-->
<entity name="tmin"
processor="XPathEntityProcessor"
dataSource="FileDataSource"
stream="true"
url="${pickupdir.fileAbsolutePath}"
onError="skip"
forEach="/execution/"
transformer="script:makePair,script:makeLogPair, TemplateTransformer,
RegexTransformer, HTMLStripTransformer"
>
<field column="jobid_t" xpath="/execution/#jobId" />
<field column="destinationid_t" xpath="/execution/#destinationid" />
<field column="id" template="${tmin.destinationid_t}" />
<field column="log_param" xpath="/execution/log/#severity" />
<field column="log" xpath="/execution/log" />
<entity name="importcsv"
processor="LineEntityProcessor"
url="C:\Users\arpiagar\Desktop\IP Probe name_ILRNAPSUD01.csv"
rootEntity="false"
dataSource="FileDataSource"
header="true"
separator=","
transformer="TemplateTransformer, RegexTransformer,script:mapcsv"
>
<field column="rawLine" groupNames="Node_IP,probe_name,Global_ID"/>
<field column="id" name="Global_ID" />
<field column="probe_name" name="probe_name" />
</entity>
</entity>
I need to map id in the tmin entity with the id which we will get after indexing csv data and index probe_name and node_ip at that particular id.
SSIS Bulk Import data transformation Row/Column delimiter definition. Trying to import from a csv file to sql table. After doing the import data/values come as follows
Col1 col2 col3
"XXX" "BBN" "BBB"
"XXX" "BBN" "BBB"
"XXX" "BBN" "BBB"
data/values are wrapped around double quotes.
How can i fix this.
Connection manager for csv file has text qualifer: " ,
header row delimiter has {CR}{LR}
unforunately bulk import doesn't have text qualifier
Here's a way to setup an XML format file to handle CSV with double quotes:
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="0" xsi:type="CharFixed" LENGTH="1"/>
<FIELD ID="1" xsi:type="CharTerm" TERMINATOR="","" MAX_LENGTH="12"/>
<FIELD ID="2" xsi:type="CharTerm" TERMINATOR="","" MAX_LENGTH="38"/>
<FIELD ID="3" xsi:type="CharTerm" TERMINATOR="","" MAX_LENGTH="50" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="4" xsi:type="CharTerm" TERMINATOR="","" MAX_LENGTH="11" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="SequenceID" xsi:type="SQLINT"/>
<COLUMN SOURCE="2" NAME="TransactionID" xsi:type="SQLUNIQUEID"/>
<COLUMN SOURCE="3" NAME="Product_Name" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="4" NAME="Product_Code" xsi:type="SQLVARYCHAR"/>
</ROW>
</BCPFORMAT>
If you want to handle pipe-delimited instead, change "","" to ""|""