Avoiding Boxing/Unboxing on unknown input - vb.net

I am creating an application that parses an XML and retrieves some data. Each xml node specifies the data (const), a recordset's column-name to get the data from (var), a subset of possible data values depending on some condition (enum) and others. It may also specify, alongside the data, the format in which the data must be shown to the user.
The thing is that for each node type I need to process the values differently and perform some actinons so, for each node, I need to store the return value in a temp variable in order to later format it... I know I could format it right there and return it but that would mean to repeat myself and I hate doing so.
So, the question: How can I store the value to return, in a temp variable, while avoiding boxing/unboxing when the type is unknown and I can't use generics?
P.S.: I'm designing the parser, the XML Schema and the view that will fill the recordset so changes to all are plausible.
Update
I cannot post the code nor the XML values but this is the XML structure and actual tags.
<?xml version='1.0' encoding='utf-8'?>
<root>
<entity>
<header>
<field type="const">C1</field>
<field type="const">C2</field>
<field type="count" />
<field type="sum" precision="2">some_recordset_field</field>
<field type="const">C3</field>
<field type="const">C4</field>
<field type="const">C5</field>
</header>
<detail>
<field type="enum" fieldName="some_recordset_field">
<match value="0">M1</match>
<match value="1">M2</match>
</field>
<field type="const">C6</field>
<field type="const">C7</field>
<field type="const">C8</field>
<field type="var" format="0000000000">some_recordset_field</field>
<field type="var" format="MMddyyyy">some_recordset_field</field>
<field type="var" format="0000000000" precision="2">some_recordset_field</field>
<field type="var" format="0000000000">some_recordset_field</field>
<field type="enum" fieldName ="some_recordset_field">
<match value="0">M3</match>
<match value="1">M4</match>
</field>
<field type="const">C9</field>
</detail>
</entity>
</root>

Have you tried using the var type? That way you don't need to know the type of each node. Also, some small sample of your scenario would be useful.

Related

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

odoo 9 how to add relational field to pivot view?

I'm customizing Project's pivot view to show timesheet description along with task's name.
here is my code below but when I click pivot view it shows an error
<!-- Insert Project Issue Pivot Field -->
<record id="project_task_custom_pivot" model="ir.ui.view">
<field name="name">project.task.custom.pivot</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_project_task_pivot"/>
<field name="arch" type="xml">
<field name="stage_id" position="after">
<field name="name" type="row"/>
<field name="timesheet_ids" type="row"/>
</field>
</field>
</record>
Error below
assert groupby_def and groupby_def._classic_write, "Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True"
Edit
I re-defined the field "timesheet_ids" as #George Daramouskas mentioned.
timesheet_ids = fields.One2many('account.analytic.line', 'task_id', string="Timesheetss", store=True)
But It didn't work.
So I took a look at the source code in Odoo Source
The function "One2many" has no such a parameter.
I guess the Store=True is for only regular field not related field.
Is there any other solution for this?
Thanks
Create your field with the attribute store=True in the constructor so that the field is stored in the database.

Use Solr to index/search txt file content

I'm making a study to compare different search platforms' performance over Twitter's tweets. For my purpose I have collected a set of tweets (around 50,000) and saved them in a single text (.txt) file in a format similar to the following:
Tweet ID User Tweet Content Tweet Time-stamp
The data would look like this:
31261817690923008 username1 tweet 1 content goes here 1482180069
31132193287839744 username2 tweet 2 content goes here 1274400000
Now, using Solr 6.3.0, is it possible to index each line of content separately? Instead, should I use XML or JSON? or do I have to store each line (tweet) in a different file?
You can use the CSV Update Handler, which will result in a single document for each row.
To adjust the parsing to the structure you've used, you can use separator (TAB? %09) to provide the separator used between fields / columns, encapsulator to set the value used to encapsulate a single field value (it doesn't seem you've used any) and fieldnames to provide a proper field name for each column, unless they're in the first row - in that case set header to true (and don't provide fieldnames).
Assuming two things:
#1 You do not want to do an awful lot of coding for the data entry.
#2 Your text file is TAB or comma separated.
If so, you can easily turn it into an XML that can be added via the Admin interface.
A few things to keep in mind:
Enclose your data in <add> ... </add> blocks of a reasonable size. Ideally not 50K. Experiment a little.
Enclose each entry - line in your case in <doc> ... <doc>
Each column needs to have its own field as in
<field name="id"> ... </field>
<field name="username"> ... </field>
...
All need unique IDs.
For practical purposes, if you can open the textfile in a spreadsheet, add the tag columns in between your data and then concatenate the lines, it is relatively easy even if a little labour intensive for 50K.
A doc set of two would look something like:
<add>
<doc>
<field name="id"> ... </field>
<field name="user"> ... </field>
<field name="content"> ... </field>
<field name="time_stamp"> ... </field>
</doc>
<doc>
<field name="id"> ... </field>
<field name="user"> ... </field>
<field name="content"> ... </field>
<field name="time_stamp"> ... </field>
</doc>
</add>

Extracting XML Data with SQL

I have the following XML data stored in a SQL table
<CustomFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.kaseya.com/vsa/2007/12/ServiceDeskDefinition.xsd">
<Field fieldName="ChangeRequest">No</Field>
<Field fieldName="ProblemRecord">No</Field>
<Field fieldName="Source">Email</Field>
<Field fieldName="KB_Article">No</Field>
<Field fieldName="OptimusRef">264692</Field>
<Field fieldName="TimeSpentOnTicket">0.25</Field>
<Field fieldName="PONumber" />
<Field fieldName="ResourceAssignedEngineer" />
What I would like to do is select the TimeSpentOnTicket Value form a stored procedure.
Any ideas how I can do this?
The problem here is your XML. It's invalid, so there's not really a way do search it until you fix it. A simple way to check this is using an online tool like the one at W3Schools. Another issue that I see is that the namespace (xmlns) that you reference no longer exists. I think this will mess up Postgres as well, but I'm not 100% on that. You might to have to filter that out when ingesting. However, after fixing the XML, it's pretty easy to get things out using XPath within the appropriate XML function.
For example, using the following table:
CREATE TABLE BLA.TEMPTABLE (ID INT, MYXML XML)
Then, insert a valid version of your XML:
INSERT INTO BLA.TEMPTABLE ( ID, MYXML )
SELECT 1 as ID,
'<?xml version="1.0" encoding="UTF-8"?>
<CustomFields>
<Field fieldName="ChangeRequest">No</Field>
<Field fieldName="ProblemRecord">No</Field>
<Field fieldName="Source">Email</Field>
<Field fieldName="KB_Article">No</Field>
<Field fieldName="OptimusRef">264692</Field>
<Field fieldName="TimeSpentOnTicket">0.25</Field>
<Field fieldName="PONumber" />
<Field fieldName="ResourceAssignedEngineer" />
</CustomFields>' as MYXML
Then, to query it back out, you can do something like the following (you can test your XPath with a tool like this, if you need to):
SELECT
tt.ID,
tt.MYXML,
XPATH('/CustomFields//Field[#fieldName=''TimeSpentOnTicket'']/text()', tt.MYXML)
FROM
BLA.TEMPTABLE tt

OpenERP always displays inherited view instead of original

Original views:
<record id='view_1' model='ir.ui.view'>
<field name="name">view.name</field>
<field name="model">my.object</field>
<field name="priority" eval="17"/>
<field name="type">form</field>
<field name="arch" type="xml">
...
</field>
</record>
inherited view from the original:
<record id='view_2' model='ir.ui.view'>
<field name="name">view.name</field>
<field name="model">my.object</field>
<field name="priority" eval="10"/>
<field name="inherit_id" ref="view_1"/>
<field name="type">form</field>
<field name="arch" type="xml">
...
</field>
</record>
So what happens is OpenERP always displays the inherited view ignoring the priority value. Is this expected behaviour, or there's something else I am missing?
If this is the expected behaviour, then please read further :-)
I have my.second.object with many2one field to my.object, and when I want to create my.object from this field, I want to open a bit different form view of my.object. I am trying to create a different view just for that purpose, but as you see it doesn't work so easily (or does it?).
Any help is appreciated.
Yes it is the expected behavior. The priority of a view only serves to select the main view to use when no specific view was requested. Inherited views are "patch views" that act like children of the view they inherit from, and may never be selected as "main views". They always apply on top of their parent view when that view is displayed.
If you want an alternative view for a certain model you should define a new stand-alone view that does not inherit from any other. If that view is meant to be used only in the context of the view of my.second.object, there are two common tricks to make OpenERP use it:
Define it inline in the form view of my.second.object, as a child of the <field> element. This may not work in all OpenERP clients depending on the version, and works best for declaring inline form views for o2m lines, normally.
Declare it as a stand-alone view with a low priority (e.g. 32) and put a magic context key in the many2one field of the my.second.object view that should use it. The magic key is in the form <view_type>_view_ref, and the value must be the XML ID of the desired view. This should work everywhere.
<!-- Example 1: inline form view -->
<form string="My second object">
<field name="my_object_id">
<form string="My object inline view">
<field name="name"/>
</form>
</field>
</form>
<!-- Example 2: explicitly ask for special view using magic key -->
<form string="My second object">
<field name="my_object_id" context="{'form_view_ref': 'module.my_object_form2'}"/>
</form>
For reference, have a look at this page of the OpenERP documentation that explains most of the options for making and using context-specific views.
NOTE: If you have used form_view_ref and from form view if you have
any button which is opening another form view of some other model then
it will give you error . It will try to open the same form view you
have passed in form_view_ref for another model also.
What "position" you defined in <field name="field_from_original_view">?
<record id='view_2' model='ir.ui.view'>
<field name="name">view.name</field>
<field name="model">my.object</field>
<field name="priority" eval="10"/>
<field name="inherit_id" ref="view_1"/>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="field_from_original_view" position="after" (or before)>
<field name="inherit1" />
<field name="inherit2" />
<field name="inherit3" />
</field>
</field>
</record>
There may not be a possibility to make an inherited form the standard form of your model so that it will be presented automatically.
BUT If you look at a specific task --> open an inherited form view for a one2many field e.g.; there is. Set the context variable 'form_view_ref' to 'MODULE.VIEW_ID'.
<field name="myOne2ManyField" context="{'form_view_ref': 'myModule.myInheritedView'}/>
Still works with Odoo 9.0.