Skip to Content
Menu
This question has been flagged
1 Reply
10825 Views

Hello All, 

I am new to Odoo and learning it. I have developed a simple module to create Student details and show these using different view like as Form view and tree view. Now suppose that when user is creating new student record, I want to apply some validation on click of Submit button like as student name should not contain any number and show warning message in case it fails. then how can I do that . 


File : /my_module/__openerp__.py

{
    'name' : 'My Module',

 .....
    # Other Code
    'depends': ['base','web'],
    'data': [
           'views/assets.xml',
          ....
    ],
    # Code XYZ 
    .....
}


I already inherited the CSS and JS code like this :-

File : /my_module/views/assets.xml

<template id="assets_backend" name="my_module assets" inherit_id="web.assets_backend">
   <xpath expr="." position="inside">
    <link rel="stylesheet" href="/my_module/static/src/css/main.css"/>
    <script type="text/javascript" src="/my_module/static/src/js/main.js"></script>
   </xpath>
</template>

 

File : /my_module/static/src/js/main.js

console.log("Welcome to my_module");
openerp.my_module = function(instance, local)
{
console.log("Another Message ");
};

Problem :-
  • I want to execute JS code when user is working on my_module only and if possible then it should be for specified view only

  • I want to apply CSS for my module view only

  • How to identify the module name using JS code. For example On which module user is currently working on .


Whats Happening:-

  • JS code is being executed once Odoo loads my_module 

  • CSS is applied on every page , even on Odoo defined pages like as Settings also 

Extra Information :-

I am using Odoo based view only like as Form View , Tree View so I don't know that how to insert HTML based tags and create ID , Classes on that. 


It will be very helpful if you will suggest some way on it and about the control flow of Odoo module .

Avatar
Discard
Best Answer

Hi Deepak

Use constraint to check student name

@api.one
@api.constrains('name')
def _check_student_name(self):
    if self.name.isalpha() :
        raise ValidationError("Student name should not contain number !!!")
Learn More >>

Call python function from Js to get the context.

print self._context

{u'lang': u'en_US', u'params': {u'action': 256}, u'tz': False, u'uid': 1}

Try to find view using action id. Then pass to Js and  give css using JQuery 


Avatar
Discard
Related Posts Replies Views Activity
2
Sep 21
6625
3
Oct 18
2547
0
Sep 17
3545
1
Mar 15
3086
2
Mar 15
4245