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.
Related
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">
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.
I want to view 'working_hours' field only for employee, his manager and 'hr.group_hr_user' group.
how to hide this field automatically without edit form or trigger a button
class InheritHrEmployee(models.Model):
_inherit = 'hr.employee'
def hide_working_hours(self):
if self.env.uid == self.user_id.id or self.env.uid == self.parent_id.user_id.id or self.env.user.has_group(
'hr.group_hr_user'):
self.working_hours_view = True
else:
self.working_hours_view = False
working_hours_view = fields.Boolean(computed=hide_working_hours)
XML:
<record id="hide_working_hours_for_employees" model="ir.ui.view">
<field name="name">Hide Working Hours Employees Form</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='resource_calendar_id']" position="before">
<field name="working_hours_view" invisible="1"/>
</xpath>
<xpath expr="//field[#name='resource_calendar_id']" position="attributes">
<attribute name="attrs">{'invisible': [('working_hours_view' ,'=', False)]}</attribute>
</xpath>
</field>
</record>
Try below code for display working hours field only hr.group_hr_user group users.
XML:
<record id="hide_working_hours_for_employees" model="ir.ui.view">
<field name="name">Hide Working Hours Employees Form</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='resource_calendar_id']" position="before">
<field name="working_hours_view" invisible="1"/>
</xpath>
<xpath expr="//field[#name='resource_calendar_id']" position="attributes">
<attribute name="groups">hr.group_hr_user</attribute>
</xpath>
</field>
</record>
You can add multiple attributes in the XML file like above code.
i added the field before the function and it works now automatically
class InheritHrEmployee(models.Model):
_inherit = 'hr.employee'
inv = fields.Boolean(string="Invisible", compute="c_inv", store=False)
#api.one
def c_inv(self):
if self.env.uid == self.user_id.id or self.env.uid == self.parent_id.user_id.id or self.env.user.has_group(
'hr.group_hr_user'):
self.inv = False
else:
self.inv = True
.. like this example
make fields visible to user and invisible to other
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'"/>
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)