Sunday, 10 August 2014

OpenERP: Calculate difference between two dates

from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta

date_format = '%Y-%m-%d'

joining_date = '2013-08-23'
current_date = (datetime.today()).strftime(date_format)

d1 = datetime.strptime(joining_date, date_format).date()
d2 = datetime.strptime(current_date, date_format).date()
r = relativedelta(d2,d1)

print r.years
print r.months
print r.days


Thanks!!!!!!!!! Enjoy Programming :)

Saturday, 2 August 2014

File upload not working on PHP Server

Few days back, our team faced a new issue in file upload on server. It was restricting user to upload file size over 8KB while the following parameters were already set :

php_value file_uploads  On
php_value upload_max_filesize 200M
php_value memory_limit  512M
php_value post_max_size 200M
php_value max_execution_time 1000
php_value max_input_time 300

but still file uploading was not working.

Searched over internet and found that above problem was due to LimitRequestBody Directive of Apache. This parameter Restricts the total size of the HTTP request body sent from the client.

"The LimitRequestBody directive allows the user to set a limit on the allowed size of an HTTP request message body within the context in which the directive is given (server, per-directory, per-file or per-location). If the client request exceeds that limit, the server will return an error response instead of servicing the request. The size of a normal request message body will vary greatly depending on the nature of the resource and the methods allowed on that resource."

If, for example, you are permitting file upload to a particular location, and wish to limit the size of the uploaded file to 100K, you might use the following directive:

LimitRequestBody 102400

Please chekc the following link for full description :

http://httpd.apache.org/docs/2.0/mod/core.html#limitrequestbody


Thanks!!!!!!!! Enjoy Programming :)

Friday, 18 July 2014

OpenERP Common Errors

From last one month started working on OpenERP. While customizing code daily facing one or the other issue. So thought of keeping all of them at one place with solutions for future use and may be can help someone else as well :

1) AttributeError: 'NoneType' object has no attribute '_columns'

Solution : Problem is with your __openerp__.py file. Check depends attribute.

Reference Links :
http://stackoverflow.com/questions/10565288/attributeerror-nonetype-object-has-no-attribute-columns
http://forum.openerp.com/forum/topic24199.html

2) Openerp : new module is not showing into module list?

Solution : If you have developed a new module and it's in the addons folder but still not showing in the module list than follow following steps :

a) Restart OpenERP server by using command :

./openerp-server --addons-path=XXXX/XXXXXXX/addons/ (path of addons directory)

b) Go to the browser and open

localhost:8069 or 127.0.0.1:8069

c) Login into OpenERP; Go to Settings menu; Users; Select your user, edit it and check the check-box of 'Technical Features', save it and reload the web page.

d) Again Go to Settings, you will find two more options under Modules section

  • Update Modules List
  • Apply Scheduled Upgrades

Click on 'Update Modules list' option. Update modules.

e) Now search your module using 'Installed Modules' option.

That's it.

Reference Links :

3) Model XXX is declared but cannot be added/loaded

Solution : Problem is with xxx model entry in ir_model table.

a) Login to PostgeSQL database using psql or pgAdmin III

b) Run following commands :

Delete from ir_model_constraint where model=(Select id from ir_model where name='xxx');

Delete from ir_model where name='xxx';

Hopefully this will fix your problem.

Reference Links :
Many more to come.....

Saturday, 5 July 2014

OpenERP: Customize one2many relational field

I was working on one2many relational field to integration one functionality. Worked on python code and then wrote an xml file for the same. Restarted my server. It showed me the row with headers and 'Add an item' button. When clicked on that it opened a pop-up to provide inputs. It shows all the fields with in sequence of it's own.


Q1. I need input fields in other sequence or don't need all fields.

A.   In xml you would have wrote code like this :

<field name="dirtyhandsphp" widget="one2many_list" colspan="4" nolabel="1">
<tree string="Details">
             <field name="field1" />
             <field name="field2" />
                     ---------------------------------------------
             <field name="designation" />
        </tree>                                                    
</field>

Add form section inside and mention all the fields you needed, as follow :

<field name="dirtyhandsphp" widget="one2many_list" colspan="4" nolabel="1">
<tree string="Details">
             <field name="field1" />
             <field name="field2" />
                     ---------------------------------------------
             <field name="designation" />
        </tree>
        <form string="Details" editable="bottom">
             <field name="field1" />
             <field name="field2" />
                     ---------------------------------------------
             <field name="designation" />
        </form>                                            
</field>

Q2. Fields are few so want to edit at the same place. No separate pop-up.

A. Add editable attribute to tree tag as follow

<tree string="Details" editable="bottom">

or

<tree string="Details" editable="top">


Thanks!!!!!!!! Enjoy Programming:)


Friday, 4 July 2014

OpenERP: Custom unique name constraint with ignore case

#custom unique name constraint with ignore case

def _check_unique_insesitive(self, cr, uid, ids, context=None):

        list_ids = self.search(cr, uid , [], context=context)

        lst = [list_id.name.lower() for list_id in self.browse(cr, uid, list_ids, context=context) if list_id.name and list_id.id not in ids]

        for self_obj in self.browse(cr, uid, ids, context=context):
            if self_obj.name and self_obj.name.lower() in lst:
                return False
            return True


Use as following in your class :

_constraints = [(_check_unique_insesitive, <error_message>, ['<field_name>'])] 

e.g : _constraints = [(_check_unique_insesitive, 'Name already exists', ['name'])] 


Thanks!!!!!!!!!! Enjoy Programming :)


Reference Link : http://stackoverflow.com/questions/13263507/openerp-unique-constraint