Showing posts with label openerp. Show all posts
Showing posts with label openerp. Show all posts

Wednesday, June 28, 2017

Tree view header inside add the dropdown menu in odoo 8 using js and python

Leave a Comment

Tree view header inside add the dropdown menu in odoo 8 using js and python


I am use odoo-8. My question is how to add the dropdown menu above side on tree view in odoo8 using JS and python.

And I want to dynamically show the all the category of products in this drop-down menu.

And when i click on the particular category so, tree view inside sort particular clickable types of products.

i.e

Suppose click on the Mobile category from drop-down menu so tree view inside show only Mobile types of products.

Like I give the example in below image, enter image description here

I want to full solution of this question.
Note: If any query so comment please.

1 Answers

Answers 1

You have to use t-extend in your template.xml code.

ControlPanel is template name of the controlpanel that placed above tree view.

Add this code inside of your template.xml code.

<t t-name="your_template_name" t-extend="ControlPanel">     <t t-jquery=".o_cp_right" t-operation="after">         <-- Add your Drop down list here -->     </t> </t> 

o_cp_right is class after that you can add your dropdown field. You can set t-operation as append, inner, after, replace as per your requirment.

Read More

Tuesday, June 27, 2017

Wrong Leave deduction in Payslip odoo

Leave a Comment

I tried to generate payslip for an employee. An Employee has taken half day leave(0.5) but while calculating payslip its auto filled as 1.

From the code that is already in the module hr_payroll.py, It looks like the following

 def get_worked_day_lines(self, cr, uid, contract_ids, date_from, date_to, context=None):         """         @param contract_ids: list of contract id         @return: returns a list of dict containing the input that should be applied for the given contract between date_from and date_to         """         def was_on_leave(employee_id, datetime_day, context=None):             res = False             day = datetime_day.strftime("%Y-%m-%d")             holiday_ids = self.pool.get('hr.holidays').search(cr, uid, [('state','=','validate'),('employee_id','=',employee_id),('type','=','remove'),('date_from','<=',day),('date_to','>=',day)])             if holiday_ids:                 res = self.pool.get('hr.holidays').browse(cr, uid, holiday_ids, context=context)[0].holiday_status_id.name             return res          res = []         for contract in self.pool.get('hr.contract').browse(cr, uid, contract_ids, context=context):             if not contract.working_hours:                 #fill only if the contract as a working schedule linked                 continue             attendances = {                  'name': _("Normal Working Days paid at 100%"),                  'sequence': 1,                  'code': 'WORK100',                  'number_of_days': 0.0,                  'number_of_hours': 0.0,                  'contract_id': contract.id,             }             leaves = {}             day_from = datetime.strptime(date_from,"%Y-%m-%d")             day_to = datetime.strptime(date_to,"%Y-%m-%d")             nb_of_days = (day_to - day_from).days + 1             for day in range(0, nb_of_days):                 working_hours_on_day = self.pool.get('resource.calendar').working_hours_on_day(cr, uid, contract.working_hours, day_from + timedelta(days=day), context)                 if working_hours_on_day:                     #the employee had to work                     leave_type = was_on_leave(contract.employee_id.id, day_from + timedelta(days=day), context=context)                     if leave_type:                         #if he was on leave, fill the leaves dict                         if leave_type in leaves:                             leaves[leave_type]['number_of_days'] += 1.0                             leaves[leave_type]['number_of_hours'] += working_hours_on_day                         else:                             leaves[leave_type] = {                                 'name': leave_type,                                 'sequence': 5,                                 'code': leave_type,                                 'number_of_days': 1.0,                                 'number_of_hours': working_hours_on_day,                                 'contract_id': contract.id,                             }                     else:                         #add the input vals to tmp (increment if existing)                         attendances['number_of_days'] += 1.0                         attendances['number_of_hours'] += working_hours_on_day             leaves = [value for key,value in leaves.items()]             res += [attendances] + leaves         return res 

I am not sure whether this is where the issue is. Any one with any suggestion on this?

1 Answers

Answers 1

Let me preface: I haven't used odoo and I don't have the rest of your code to test against so I haven't verified this.

You definitely have a problem here:

if leave_type in leaves:     leaves[leave_type]['number_of_days'] += 1.0     leaves[leave_type]['number_of_hours'] += working_hours_on_day else:     leaves[leave_type] = {         'name': leave_type,         'sequence': 5,         'code': leave_type,         'number_of_days': 1.0,         'number_of_hours': working_hours_on_day,         'contract_id': contract.id,     } else:     #add the input vals to tmp (increment if existing)     attendances['number_of_days'] += 1.0     attendances['number_of_hours'] += working_hours_on_day 

see where you reference leaves and attendances, while those are floats they are only incremented in full days, not calculated based on what fraction of a day you pass. You need to change this to something like:

leaves[leave_type]['number_of_days'] += time_off / hours_per_workday # the 1.0 might make sense here depending on if you count time off as an attendance leaves[leave_type]['number_of_hours'] += time_off 

and

attendances['number_of_days'] += 1.0 - time_off / hours_per_workday attendances['number_of_hours'] += working_hours_on_day - time_off 

Obviously the dummy variables I inserted would need to be defined and calculated somewhere.

Additionally, as Anthony Rossi noted in the comments, you generally work in days, not hours. Examples:

day_from = datetime.strptime(date_from,"%Y-%m-%d") day_to = datetime.strptime(date_to,"%Y-%m-%d") 

notice how you only have YY/MM/DD and no hours.

Read More

Monday, April 18, 2016

Is possible to use SSL in Odoo with NginX avoiding the standard ports (80 and 443)?

Leave a Comment

Following this tutorial I configured my Nginx like this:

upstream odoo8 {     server 127.0.0.1:8069 weight=1 fail_timeout=0; }  upstream odoo8-im {     server 127.0.0.1:8072 weight=1 fail_timeout=0; }  server {     # server port and name (instead of 443 port)     listen 22443;     server_name _;      # Specifies the maximum accepted body size of a client request,     # as indicated by the request header Content-Length.     client_max_body_size 2000m;      # add ssl specific settings     keepalive_timeout 60;     ssl on;     ssl_certificate        /etc/ssl/nginx/server.crt;     ssl_certificate_key    /etc/ssl/nginx/server.key;      error_page 497 https://$host:22443$request_uri;      # limit ciphers     ssl_ciphers HIGH:!ADH:!MD5;     ssl_protocols SSLv3 TLSv1;     ssl_prefer_server_ciphers on;      # increase proxy buffer to handle some Odoo web requests     proxy_buffers 16 64k;     proxy_buffer_size 128k;      # general proxy settings     # force timeouts if the backend dies     proxy_connect_timeout 3600s;     proxy_send_timeout 3600s;     proxy_read_timeout 3600s;     proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;      # set headers     proxy_set_header Host $host;     proxy_set_header X-Real-IP $remote_addr;     proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;      # Let the Odoo web service know that we’re using HTTPS, otherwise     # it will generate URL using http:// and not https://     proxy_set_header X-Forwarded-Proto https;      # by default, do not forward anything     proxy_redirect off;     proxy_buffering off;      location / {         proxy_pass http://odoo8;     }      location /longpolling {         proxy_pass http://odoo8-im;     }      # cache some static data in memory for 60mins.     # under heavy load this should relieve stress on the Odoo web interface a bit.     location /web/static/ {         proxy_cache_valid 200 60m;         proxy_buffering on;         expires 864000;         proxy_pass http://odoo8;     } } 

And I have this ports in my Odoo configuration

longpolling_port = 8072 xmlrpc_port = 8069 xmlrpcs_port = 22443 proxy_mode = True 

When I load https://my_domain:22443/web/database/selector in the browser it loads well. But when I choose a database or I make any action, the address loses the https and the port, so it's loaded through the port 80. Then I would need to add this to the NginX configuration and the port 80 should be open

## http redirects to https ## server {     listen 80;     server_name _;      # Strict Transport Security     add_header Strict-Transport-Security max-age=2592000;     rewrite ^/.*$ https://$host:22443$request_uri? permanent; } 

Is there a way to avoid this redirection? Like that I could keep the port 80 closed in order to avoid spoofing

Update

I can open the login screen with the address https://my_domain:22443/web/login?db=dabatase_name and I can work well inside, but if I log out in order to choose another database in the droplist, it loses again the port and the ssl

1 Answers

Answers 1

Please, try to use this construction:

`## http redirects to https ## server { listen 80; server_name _; if ($http_x_forwarded_proto = 'http')     {     return 301 https://my_domain.com$request_uri;     } }` 
Read More

Tuesday, March 15, 2016

OPENERP:validating the field(s) arch: Invalid XML for View Architecture

Leave a Comment

I'm new to programming for OpenERP 7.0, When you import this module to OpenERP gives me an error:ValidateError Error occurred while validating the field(s) arch: Invalid XML for View Architecture!. I`m not locate the error. I would be very grateful if you help me. thanks.

_init_.py

import new_test 

_openerp_.py

{     'name': 'New Test demo',     'version': '1.0',     'author': 'nasr2ldin',     'category': 'Human Resources',     'summary': 'Document  registration',     'website': '',     'description': """ This is a New Test demo Module by nasr2ldin """,     'images': [],     'depends': ['base','hr', 'base_calendar'],     'init_xml': [],     'update_xml': ['new_test_view.xml'],     'installable': True,     'application': True,     'auto_install': False,  } 

new_test.py

import datetime import time from itertools import groupby from operator import itemgetter  import math from openerp.osv import fields, osv from openerp.tools.translate import _  def _employee_get(obj, cr, uid, context=None):     if context is None:         context = {}     ids = obj.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context)     if ids:         return ids[0]     return False   class new_test(osv.osv):     _name = "new_test.register"     _description = "New Test Demo"     _columns = {         'new_test_name': fields.char('User Name',size=256),         'new_test_desc': fields.selection([('18-20','18-20'),('20-30','20-30')],'User Age.'),         'new_test_about': fields.char('About'),         'new_test_date': fields.date('Date')    }  new_test() 

new_test_view.xml

<?xml version="1.0" encoding="utf-8"?>     <openerp>         <data>             <record id="new_test_form" model="ir.ui.view">                 <field name="name">new_test.line.form</field>                 <field name="model">new_test.register.</field>                 <field name="type">form</field>                 <field name="arch" type="xml">                     <form string="New Test" version="7.0">                         <field name="sequence" invisible="1"/>                         <field name="new_test_employee"/>                         <field name="new_test_name"/>                         <field name="new_test_desc"/>                         <field name="new_test_about"/>                         <field name="new_test_date"/>                     </form>                 </field>             </record>              <record  id="new_test_tree" model="ir.ui.view">                 <field name="name">new_test.tree</field>                 <field name="model">new_test.register</field> <!--                <field name="type">tree</field>  -->                <field name="arch" type="xml">                     <tree string="New_test" colors="blue:state=='draft'">                         <field name="employee_id"/>                         <field name="department_id" invisible="1"/>                         <field name="user_id" invisible="1"/>                         <field name="new_test_name"/>                         <field name="new_test_desc"/>                         <field name="new_test_about"/>                         <field name="new_test_date"/>                     </tree>                 </field>             </record>              <record model="ir.actions.act_window" id="action_penalty">                 <field name="name">new_test</field>                 <field name="res_model">new_test.register</field>                 <field name="view_type">form</field>                 <field name="view_mode">tree,form</field>              </record>              <menuitem id="new_test_register" name="New Test Register" parent="hr.menu_hr_root" sequence="25"/>             <menuitem id="new_test_register_main" name="New Test register" parent="new_test_register" action="action_new_test" sequence="20"/>          </data>     </openerp> 

3 Answers

Answers 1

The problems:

  1. Your form and tree views have fields in them which are not on your model. As in Quentin's answer, add those fields to your model. If your model contains the employee id and you want to display your employee's department on the tree view (for example), add a related field to your model and put that on the view.

  2. You are colouring your tree on state. This is fine but you need to add a state field to your model and it must be in the tree view although it can be invisible (e.g. <field name="status" invisible="1"/>).

  3. In your new_test_form record, in the model field, you have new_test.register.; remove the trailing . .

Some helpful hints:

  1. Use of update_xml in the __openerp.py__ file is deprecated in 7, use data instead.

  2. your model should inherit osv.Model (or osv.TransientModel). The old osv and memory are deprecated.

  3. column new_test_about is a char so should have a size. There may be a default but I can't remember and if there is it will be big so you should put one in.

  4. From OpenERP 6.1+ you no longer need to instantiate your models so you can drop the new_test() line.

  5. As a general style rule, it isn't a good idea to mix ORM classes and module level as you will have inconsistent code. Move _employee_get inside the class and access it as self.pool.get('new_test.register')._employee_get

  6. In 7 the <field name="type"... in your views is deprecated.

Answers 2

You should define these fields in "_columns" of "new_test" class:

  • sequence
  • new_test_employee
  • employee_id
  • department_id
  • user_id

And then, update this module.

Answers 3

you have wrongly used object model defined in form view.<field name="model">new_test.register.</field> This is Wrong , it should be <field name="model">new_test.register</field>

  • Another mistake you have done is you have used fields which are not defined in the new_test.register class, so You have to add all those fields in _coulmns and then use it in view.

  • As you are new to OpenERP, Make sure that After improving these things, restart the server to update python changes(i.e. to register new fields to respective tables) and update the module to apply xml changes of view.

  • sequence, new_test_employee, employee_id, department_id are fields defined in form view and tree view, does not exist in object. so add in object.

  • and you have wrongly written the method also. Check this link for more information.

Hope this will help you.

Read More