BeanIo/xsd not throwing exceptions with blank file / no records present - xsd

I want Bean.Io mapping to through exception when records are not present in file(Blank File). But it's not happening.Though it has validation occurs="0+" in place . Also tried minOccurs=1 maxOccurs=unbounded
My mapping file
<?xml version="1.0" encoding="UTF-8"?>
<beanio xmlns="http://www.beanio.org/2012/03">
<stream name="Records" format="fixedlength" strict="true">
<record name="SampleRecord" class="com.test.SampleRecord" **occurs="0+"**>
<field name="mobileNumber" type="string" position="0" length="10" regex="[0-9]*" required="true"/>
<field name="alternateMobileNumber" type="string" position="10" length="20" regex="[0-9]*" required="false"/>
</record>
</stream>
</beanio>

You can try this mapping.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<beanio xmlns="http://www.beanio.org/2012/03"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org/2012/03/mapping.xsd">
<stream name="Records" format="fixedlength" strict="true" minOccurs="1">
<record name="SampleRecord" class="com.test.SampleRecord" occurs="0+">
<field name="mobileNumber" type="string" position="0" length="10" regex="[0-9]*" required="true"/>
<field name="alternateMobileNumber" type="string" position="10" length="20" regex="[0-9]*" required="false"/>
</record>
</stream>
</beanio>
Note the attribute minOccurs="1" on the stream element. The documentation states this:
minOccurs - The minimum number of times the record layout must be read
from an input stream. Defaults to 0.
Thus, changing minOccurs to 1 causes BeanIO to throw an exception with an empty string as input.

Related

odoo: Wrong value for ir.ui.menu.action

I am totally new to odoo, now I am learning about building modules and I am working with odoo 13, When I tried installing the school module it gives me the following error:
File "/home/user/odoo/odoo13/odoo/fields.py", line 2338, in convert_to_cache
raise ValueError("Wrong value for %s: %r" % (self, value))
odoo.tools.convert.ParseError: "Wrong value for ir.ui.menu.action: 'form,189'" while parsing /home/user/odoo/odoo13/custom_addons/school/views/student_view.xml:2, near
<odoo>
<data>
<record id="student_menu_action" model="ir.actions.act_window">
<field name="name">Students</field>
<field name="res_model">student.student</field>
<field name="type">form</field>
<field name="view_mode">tree,form</field>
<field name="domain">[]</field>
<field name="help" type="html
<p class="oe_view_nocontent_create">Create The First Student
</p>
</field>
</record>
<menuitem id="school_menu" name="School"/>
<menuitem id="school_student_menu" parent="school_menu" name="Student" action="student_menu_action"/>
</data>
</odoo>
I would appreciate any help, feel free to ask for more informations if necessary in the comment section.
You forgot to close your double quote and tag near type attribute:
<field name="help" type="html
<p class="oe_view_nocontent_create">Create The First Student</p>
</field>
It should be type="html">

how to run the cron job in odoo

Created the cron job for fetching weather information on every 1 minute but it not work. Here, I attach the code (.py function).
#api.model
def weather_cron(self):
weather_location_ids =self.env['weather_location.weather_location'].search([])
for weather_location_id in weather_location_ids:
url_cron = weather_location_id.api_address + weather_location_id.name
json_data = requests.get(url_cron).json()
formatted_data = json_data['weather'][0]['main']
formatted_data1 = json_data['main']['temp']
formatted_data2 = json_data['main']['temp_min']
formatted_data3 = json_data['main']['temp_max']
formatted_data4 = json_data['main']['humidity']
self.env['current_weather.current_weather'].create({
'weather_id':weather_location_id.id,
'main':formatted_data,
'temp':formatted_data1,
'temp_min':formatted_data2,
'temp_max':formatted_data3,
'humidity':formatted_data4,
})
Cron Job (.xml file):
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data noupdate="1">
<record forcecreate="True" id="create_weather_info_cron" model="ir.cron">
<field name="name">Weather Information</field>
<field name="user_id" ref="base.user_root"/>
<field name="active" eval="False" />
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model" eval="'weather_location.weather_location'"/>
<field name="function" eval="'weather_cron'"/>
</record>
</data>
</odoo>
You made the cron job inactive. Since it is not active this will not trigger the function you wrote. Please change the value to active as True
<field name="active" eval="True"/>
All your field are correct add this two:
<field name="args" eval="'()'"/>
<!-- delay the call 2 minutes just to make sure but it's optional -->
<field name="nextcall" eval="(DateTime.now() + timedelta(minutes=2)).strftime('%Y-%m-%d 00:00:00')" />
Now if the code sill not working you need to make sure of it.
#1- check that your file is in the __openerp__.py or __manifest__.py
#2- if you don't know how to use debug mode in your IDE just use logging to see if Odoo calls your methodname
Hope this Helps you
One thing if you used noupdate="1" in your xml file odoo will not update the record that it's inserted in first time no matter what you change in the code this will not effect the recrod in database.
just change the id and delete the ir.cron record manually from setting menu
EDITS:
every model with "model.name" have an xml_id like this model_model_name
when you see mode_id remember to prefix the name with _model
<field name="model_id" ref="weather_location.model_weather_location"/>
and they are in the same module just put ref="model_weather_location"
But for ir.cron just give the name of the model because it's a Char field not many2one:
<field name="model" eval="'weathe.location'"/>

odoo[v8] rules for groups

I have a boolean field 'classified' on sale order and my idea was that only users who are in the group that I created 'Classified quotations' can see records on tree view in which classified is true . I created two rules and I have no idea why it doesn't work. Here is the code:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="sale_order_rule_group_classified_quotations" model="ir.rule">
<field name="name">sale_order_rule_group_classified_quotations</field>
<field name="model_id" search="[('model','=','sale.order')]" model="ir.model"/>
<field name="groups" eval="[(4,ref('group_classified_quotations'))]"/>
<field name="domain_force">['|',('classified','=',True),('classified','=',False)]</field>
</record>
<record id="sale_order_rule_no_group" model="ir.rule">
<field name="name">sale_order_rule_no_group</field>
<field name="model_id" search="[('model','=','sale.order')]" model="ir.model"/>
<field name="groups" eval="[(4,ref('base.group_user'))]"/>
<field name="domain_force">[('classified','=',False)]</field>
</record>
</data>
</openerp>
What am I doing wrong?
You didn't tell how it does not work (or how it behaves now). Also If you want to allow to see all records on rule, you should use this instead on domain_force: [(1,'=',1)], this means all records and you don't need to make True or False checking. Try if that works.
I've recently done something similar but done so in the .py file.
You can do something like this:
def write(self, cr, user, ids, vals, context=None):
if vals.get('classified'):
group_id = self.pool.get('ir.model.data').get_object_reference(cr, 1, 'your_model', 'your_group')
user = self.pool.get('res.users').browse(cr, user, user)
if group_id not in user.groups_id:
raise osv.except_osv(_('Error'), _("Only x user can adjust this field"))
return super(your_model, self).write(cr, user, ids, vals, context=context)

Raise warning in cron method

I have created a cron which executes a method. Now in that method i want to raise a warning if some value is missing.
Right now my method raise warning(tried Warning and except_orm) but it will log warning to terminal only no warning message appear on GUI.
Am i missing something?
Here is sample code:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="ir_cron_test_warning" model="ir.cron">
<field name="name">Test Warning</field>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">1</field>
<field name="active" eval="True"/>
<field name="model">test.warning</field>
<field name="function">test_warning_exception</field>
<field name="args">()</field>
</record>
</data>
</openerp>
Method:
class test_warning(models.Model):
_name = 'test.warning'
#api.model
def test_warning_exception(self):
aurl = self.env['ir.config_parameter'].get_param('my_path')
if not aurl:
raise Warning(_('Please add mypath to System Parameters1111'))
Regards,
errors and warnings from the cron job will be bypassed by the orm. so you should either make sure only the correct data is taken in the cron function or it should be avoided.

Pentaho Data Integration Mapping

I am using Pentaho Data Integration, I created a new transformation and I have 2 steps in it....1 is a CSV file of my data, the second is an Excel file with two columns one is are the state names and the other the sort form of that state name, Example ("New York" "NY")
In my CSV file I have a state columns with the state names "New York" I want to use my excel file to map "New York" with "NY"
I have googled this all day with no clear answer...can anyone help?
You can use Merge Join. Using this you can merge both the files and select the desired columns. Before merging, you have to sort those files according to fields which use are using for mapping. In your case, it will be state name.
I would recommend you to use stream lookup to do this task. Check the test transformation attached. It will do your task.
<?xml version="1.0" encoding="UTF-8"?>
<transformation-steps>
<steps>
<step>
<name>EXCEL</name>
<type>DataGrid</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<fields>
<field>
<name>State</name>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<length>-1</length>
<precision>-1</precision>
<set_empty_string>N</set_empty_string>
</field>
<field>
<name>Short_state</name>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<length>-1</length>
<precision>-1</precision>
<set_empty_string>N</set_empty_string>
</field>
</fields>
<data>
<line> <item>New York</item><item>TX</item> </line>
<line> <item>Texas</item><item>TX</item> </line>
</data>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>392</xloc>
<yloc>80</yloc>
<draw>Y</draw>
</GUI>
</step>
<step>
<name>CSV</name>
<type>DataGrid</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<fields>
<field>
<name>Full_state_name</name>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<length>-1</length>
<precision>-1</precision>
<set_empty_string>N</set_empty_string>
</field>
</fields>
<data>
<line> <item>New York</item> </line>
<line> <item>Texas</item> </line>
</data>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>511</xloc>
<yloc>169</yloc>
<draw>Y</draw>
</GUI>
</step>
<step>
<name>Stream lookup</name>
<type>StreamLookup</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<from>EXCEL</from>
<input_sorted>N</input_sorted>
<preserve_memory>Y</preserve_memory>
<sorted_list>N</sorted_list>
<integer_pair>N</integer_pair>
<lookup>
<key>
<name>Full_state_name</name>
<field>State</field>
</key>
<value>
<name>State</name>
<rename>State</rename>
<default/>
<type>String</type>
</value>
<value>
<name>Short_state</name>
<rename>Short_state</rename>
<default/>
<type>String</type>
</value>
</lookup>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>510</xloc>
<yloc>79</yloc>
<draw>Y</draw>
</GUI>
</step>
</steps>
<order>
<hop> <from>EXCEL</from><to>Stream lookup</to><enabled>Y</enabled> </hop>
<hop> <from>CSV</from><to>Stream lookup</to><enabled>Y</enabled> </hop>
</order>
<notepads>
</notepads>
<step_error_handling>
</step_error_handling>
</transformation-steps>

Resources