Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
11719 Lượt xem

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 .

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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 


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 9 21
7526
3
thg 10 18
3173
0
thg 9 17
4531
1
thg 3 15
4006
2
thg 3 15
5252