Showing posts with label odoo. Show all posts
Showing posts with label odoo. Show all posts

Tuesday, 7 September 2021

How to create an Odoo custom module in one command?

While creating a new Odoo custom module, it is a nightmare to do copy & paste, edit & delete files, folders, icons, readme, manifest file etc.

By default Odoo provides a super cool command called scaffold to help you in this situation.

What is Odoo Scaffolding?

Scaffolding is the automated creation of a skeleton structure to simplify bootstrapping (of new modules, in the case of Odoo). While not necessary it avoids the tedium of setting up basic structures and looking up what all starting requirements are.

Scaffolding is available via the odoo-bin scaffold subcommand.

-t <template>

a template directory, files are passed through jinja2 then copied to the destination directory

name

the name of the module to create, may munged in various manners to generate programmatic names (e.g. module directory name, model names, …)

destination

directory in which to create the new module, defaults to the current directory

 

I have built a few custom module templates as per different categories to manage it.

For example, 

  1. If I want to create a new web related custom module, then I manage it under the web_custom_addons_template module.  
  2. If I want to create a new non-web related custom module, then I manage it under standard_custom_addons_template. 
  3. If I want to create a new customer (project related) custom module, then I manage it under project-code_custom_addons_template
  4. If I want to create a new company (generic) related custom module, then I manage it under company-prefix-custom_addons_template
  5. If I want to create a new OCA related custom module, then I manage it under oca_custom_addons_template


In these template modules, I maintain different manifest files and folders (web/non-web controllers/generic/customer/company). This will save a lot of time to modify/delete files & folders, icons compared to Odoo standard generic custom module template.

Here is command to generate Odoo custom module: 

./odoo-bin scaffold -t source_custom_module_name new_custom_module_name destination_path

where

source_custom_module_name is one of my 4 options. It can vary in your module management.

new_custom_module_name is unique module name based on what I extend workflow

destination_path in which create the new module


I hope you like this article. Share your views. Happy Learning !!!

 

Reference link: https://docs.huihoo.com/odoo/developer/12.0/reference/cmdline.html#scaffolding

Monday, 29 March 2021

Difference between Invoice Lines and Journal Items in Odoo 14

In account.move has type selection field. If it has value entry then Odoo treats as a Journal entry. And if it has value other then entry, Odoo treats as a Invoice / Bill / Credit Note / Refund.

In account.move.line has type_name computed field, which set value according account.move type value.

Monday, 27 February 2017

ValueError Expected singleton in Odoo


Expected Singleton:

Class methods required single invoking object (Single Browsable Record) to invoke the method and suppose it will call by multiple invoking objects (Browsable Recordsets) then method is not able to identify for which object it should process, therefore it will raise an error Expected Singleton.

New API decorator is used to define method calling pattern whether methods allows only single object or multiple objects to invoke this method.


For Example:


if self.location_id:     #face ValueError Expected singleton because self contains multiple recordset.
 
    ########

Need to change with following:

for warehouse in self:

    if warehouse.location_id:

        ########


@api.one

This decorator loops automatically on Records of RecordSet for you. Self is redefined as current record

Note:

Caution: the returned value is put in a list. This is not always supported by the web client, e.g. on button action
methods. In that case, you should use @api.multi to decorate your method, and probably call self.ensure_one() in
the method definition.

@api.multi

Self will be the current RecordSet without iteration. It is the default behavior (multiple browsable objects). Methods which returns non premitive type data(list, dictionary, function) must be decorated with @api.multi 

@api.model

This decorator will convert old API calls to decorated function to new API signature. It allows to be polite when
migrating code. Self does not contain any record/recordset in methods which are decorated by this decorator.

So simply call like this

self.env['model_name'].method_name(arguments)

Monday, 28 November 2016

Unable to git clone , Failed to connect to github.com port 443: Network is unreachable

Recently, I have encountered following problem. Might be useful for others who face same error.

I have two different Internet service provider. With one ISP, it works fine but with others it fails.

For example:

git clone https://github.com/odoo/odoo.git

It throws me following error:

fatal: unable to access 'https://github.com/odoo/odoo.git': Failed to connect to github.com port 443: Network is unreachable

I have solved with following trick.

ping github.com
PING github.com (192.30.253.112) 56(84) bytes of data.


Add  192.30.253.112 github.com in /etc/hosts file.


Saturday, 12 November 2016

How to create server actions in Odoo 10?

Below is example of server actions in Odoo 8.

<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <data>
        <record id="action" model="ir.actions.server">
            <field name="name">My Action</field>
            <field name="model_id" ref="model_module_model"/>
            <field name="code">self.action(cr, uid, context=context)</field>
       </record>
    </data>
</odoo>

Following is example for Server actions in Odoo 10.

<?xml version="1.0" encoding="utf-8" ?>
<odoo>

    <data>
        <record id="action" model="ir.actions.server">
            <field name="name">My Action</field>
            <field name="model_id" ref="model_module_model"/>
            <field name="code">
           
            if context.get('active_model') == 'your.module.model' and context.get('active_ids'):
                    action = env['module.model'].browse(context['active_ids']).action()
          
            </field>
       </record>
    </data>
</odoo>


There is no need of self variable to declare server action in Odoo 10.

Thursday, 7 July 2016

Error when override orm write method in Odoo 8 or 9

If you try override write method with following new API:

         @api.model
         def write(self, vals):
            ....
            return super(MyClass, self).write(vals)

You will see the following error:

        Traceback (most recent call last):
          File "/opt/odoo/odoo-server/openerp/http.py", line 530, in _handle_exception
            return super(JsonRequest, self)._handle_exception(exception)
          File "/opt/odoo/odoo-server/openerp/http.py", line 567, in dispatch
            result = self._call_function(**self.params)
          File "/opt/odoo/odoo-server/openerp/http.py", line 303, in _call_function
            return checked_call(self.db, *args, **kwargs)
          File "/opt/odoo/odoo-server/openerp/service/model.py", line 113, in wrapper
            return f(dbname, *args, **kwargs)
          File "/opt/odoo/odoo-server/openerp/http.py", line 300, in checked_call
            return self.endpoint(*a, **kw)
          File "/opt/odoo/odoo-server/openerp/http.py", line 796, in __call__
            return self.method(*args, **kw)
          File "/opt/odoo/odoo-server/openerp/http.py", line 396, in response_wrap
            response = f(*args, **kw)
          File "/opt/odoo/odoo-server/addons/web/controllers/main.py", line 939, in call_button
            action = self._call_kw(model, method, args, {})
          File "/opt/odoo/odoo-server/addons/web/controllers/main.py", line 927, in _call_kw
            return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
          File "/opt/odoo/odoo-server/openerp/api.py", line 241, in wrapper
            return old_api(self, *args, **kwargs)
          File "/opt/odoo/odoo-server/openerp/api.py", line 239, in wrapper
            return new_api(self, *args, **kwargs)
        TypeError: write() got an unexpected keyword argument 'context'

Question: How to resolved mentioned error ?

Solution:

The method write should be decorated with decorator @api.multi. The mapping new API → old API defined by @api.model is inadequate (argument ids is missing).

Try with following code:

         @api.multi
         def write(self, vals):
            ....
            return super(MyClass, self).write(vals)

For more details Odoo documentation 

Friday, 18 December 2015

Login in Odoo with Google Acoount

This article will help us to login In Odoo with Google account.

If you have Google Apps then you probably want to allow your Odoo users to login with their Google account. The good news is Odoo supports OAuth authentication which means it plays nicely with Google Apps.

However setting this up can be quite tricky. In this guide I’m going to step you through the process so you can get it working first time.


Note that Google Apps is different to standalone GMail. You must follow each of the steps below in sequence otherwise your authentication process will fail.

There are six main steps:
  1. Enable OAuth authentication support in Odoo
  2. Enable the Google App Engine Admin Console in your Google Apps domain
  3. Create Google Apps OAuth2 access for Odoo
  4. Add Google OAuth2 credentials to Odoo
  5. Create a new Odoo user with Google Apps authentication
  6. Activating Google Apps authentication for new user
Important: Make sure Odoo is correctly configured to send email before starting this. Odoo will need to email an activation link when you enable OAUTH.

So, let’s get started.

Please follow steps for more details

Tuesday, 29 September 2015

Domain in Odoo

In this article, we will see some theory of domain.

A domain is a list of criteria, each criteria being a triple (either a list or a tuple) of (field_name, operator, value).

Where,

 - field_name:

         It's string type and must be from the current model or any relational traversal field through the Many2one field using membership (.) dot operator.

 - operator:

         It's for comparing field's value with passed value.
Valid operator list (>, >=, <, <=, =, !=, =?, ilike, like =like, =ilike, not like, not ilike, childs_of, in, not in)

 - value:

         It's for comparing with field's value.

Multiple criteria can be joined with three logical operators. Logical AND, logical OR, logical NOT.

Let's take a real inputs example:

Suppose we have 10 records like:

Record 1: Openerp

Record 2: openerp

Record 3: Opensource

Record 4: opensource

Record 5: Open

Record 6: open

Record 7: Odoo

Record 8: odoo

Record 9: Odooopenerp

Record 10: OdooOpenerp

OUTPUT:

'like':

[('input', 'like', 'open')] -  Returns case sensitive (wildcards - '%open%') search.

O/p: open, opensource, openerp, Odooopenerp

'not like':

[('input', 'not like', 'open')] -  Returns results not matched with case sensitive (wildcards - '%open%') search.

O/p: Openerp, Opensource, Open, Odoo, odoo, OdooOpenerp

'=like':

[('name', '=like', 'open')] - Returns exact (=  'open') case sensitive search.

O/p: open

'ilike':


[('name', 'ilike', 'open')] - Returns exact case insensitive (wildcards - '%open%') search.

O/p: Openerp, openerp, Opensource, opensource, Open, open, Odooopenerp, OdooOpenerp

'not ilike': [('name', 'not ilike', 'open')] - Returns results not matched with exact case insensitive (wildcards - '%open%') search.

O/p: Odoo, odoo

'=ilike':

[('name', '=ilike', 'open')] - Returns exact (=  'open' or 'Open') case insensitive search.

O/p: Open, open

'=?': 

name = 'odoo'
parent_id = False
[('name', 'like', name), ('parent_id', '=?', parent_id)] - Returns name domain result & True

name = 'odoo'
parent_id = 'openerp'
[('name', 'like', name), ('parent_id', '=?', parent_id)] - Returns name domain result & parent_id domain result

'=?' is a short-circuit that makes the term TRUE if right is None or False, '=?' behaves like '=' in other cases

'in':

[('value1', 'in', ['value1', 'value2'])] - in operator will check the value1 is present or not in list of right term

'not in':

[('value1', 'not in', ['value2'])] - not in operator will check the value1 is not present in list of right term
While these 'in' and 'not in' works with list/tuple of values, the latter
'=' and '!=' works with string

'=':

value = 10
[('value','=',value)] - term left side has 10 in db and term right our value 10 will match

'!=':


value = 15
[('value','!=',value)] - term left side has 10 in db and term right our value 10 will not match

'child_of':


parent_id = '1' #Agrolait
'child_of':
[('partner_id', 'child_of', parent_id)]
- return left and right list of partner_id for given parent_id

'<=', '<', '>', '>=':

These operators are largely used in openerp for comparing dates - [('date', '>=', date_begin), ('date', '<=', date_end)]. You can use these operators to compare int or float also.



For details/reference visit domains in Odoo

I hope you like this article. Share your views to improve content. Happy Learning !!!

Sunday, 27 September 2015

Email validation in Odoo

This article will help us to validate Email field on Partner form.

First of all, we need to understand argument of _constraints.

    _constraint has list of arguments in which

          1. Method is name,

          2. Warning/Error message and

          3. List of field name.

Method will be fire based on, change of field value given as third argument in _constraint.

Now we need to set constraint for Email field.

Here is code for constraint.
  
    _constraints = [
        (_validate_email, 'Please enter a valid email address.', ['email']),
    ]

Here is code for method.

    @api.multi
    def _validate_email(self):
        for partner in self:
            if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", partner.email) == None:
                return False
        return True

NOTE:

         Warning/Error message will be populate, only when method will return False.

I hope you like this article. Share your views to improve content. Happy Learning !!!

Monday, 17 August 2015

one2many, many2many, many2one field in openerp


In OpenERP/Odoo, we have one2many and many2many datatype field. For add, update, delete we have some trick to link with record, which are listed below.

1. (0, 0,  { values })    link to a new record that needs to be created with the given values dictionary

2. (1, ID, { values })    update the linked record with id = ID (write *values* on it)

3. (2, ID)                     remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)

4. (3, ID)                     cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)

5. (4, ID)                     link to existing record with id = ID (adds a relationship)

6. (5)                          unlink all (like using (3,ID) for all linked records)

7. (6, 0, [IDs])             replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)


one2mnay we will use 1,2,3 points and for many2many we will use all the points.

For many2one field we only need to set record ID.


For more details, Please visit Odoo documentation

Youtube Video 

Friday, 31 July 2015

Odoo 8 release notes


Here is reference link for more details.

Key improvements of version 8 include, by order of priority:
  • Usability & productivity improvements: Odoo 8 is faster, easier to use and configure 
  • Improvement of existing apps: 732 tasks covering most applications
  • New website builder and CMS 
  • New apps: Point of sales with full hardware support, marketing apps, a new WMS and a CMS,
  • The frontend to every app: online jobs offers, booking of events, quotation builder and electronic signature, etc.
  • Technical improvements: refactoring of the framework (new API)
  • Removed modules / features

Sunday, 21 June 2015

ImportError: No module named phonenumbers

Sometime we install community module in our system and facing error like No module ****. This blog is for what I face the same error. Might be helpful to you guys.

Module name => base_phone

Server Traceback:

Traceback (most recent call last):
  File "/home/openerp/workspace/openerp/server/openerp/service/__init__.py", line 60, in load_server_wide_modules
    openerp.modules.module.load_openerp_module(m)
  File "/home/openerp/workspace/openerp/server/openerp/modules/module.py", line 415, in load_openerp_module
    getattr(sys.modules['openerp.addons.' + module_name], info['post_load'])()
  File "/home/openerp/workspace/openerp/web/addons/web/http.py", line 628, in wsgi_postload
    openerp.wsgi.register_wsgi_handler(Root())
  File "/home/openerp/workspace/openerp/web/addons/web/http.py", line 517, in __init__
    self.load_addons()
  File "/home/openerp/workspace/openerp/web/addons/web/http.py", line 580, in load_addons
    m = __import__('openerp.addons.' + module)
  File "/home/openerp/workspace/openerp/server/openerp/modules/module.py", line 133, in load_module
    mod = imp.load_module('openerp.addons.' + module_part, f, path, descr)
  File "/home/openerp/workspace/openerp/fpg/base_phone/__init__.py", line 22, in <module>
    from . import base_phone
  File "/home/openerp/workspace/openerp/custom_addons/base_phone/base_phone.py", line 26, in <module>
    import phonenumbers
ImportError: No module named phonenumbers


Here is command for resolving issue on Linux.

sudo apt-get update
sudo apt-get upgrade
pip install phonenumbers

For other OS you may advice to visit Here

Once you completed download the compressed file , decompress the file and then inside you will see a python file named setup.py. This is the install file of the package, you need to run a command prompt in the folder and execute following line :

python setup.py install


I hope you like this article. Share your views to improve content. Happy Learning !!!

Youtube Video 

Thursday, 28 May 2015

How to set default value in Odoo ?

When User open a form view at that time default value display and than after save record it will display value based on our requirement.

Here is char type field example which will display a string before save record default and than it will show different string.

We will use function filed for that. This field will not take input from the user click that will only used for information purpose.

Here is code example:

def _default_get(self, cr, uid, context=None):
    print " This function called before new record create "
    res = 'bhavesh'
    return res     

def _set_value(self, cr, uid, ids, name, args, context=None):
    print " This function called at time of saving record and form view load "
    res = {}
    for i in self.browse(cr, uid, ids, context=context):
        res[i.id] = 'odedra'
    return res

_columns = {
    'value': fields.function(_set_value, type='char', string='Value'),
}

_defaults = {
    'value': _default_get,
}

I hope you like this article. Share your views to improve content. Happy Learning !!! 

Monday, 20 April 2015

How to start Libreoffice Server and Telnet Server in Ubuntu?

In Odoo/OpenERP, when we are generating a Aeroo report, we must start these below two server.
  1. Libreoffice Server and
  2. Telnet Server
If Libreoffice is not install in Ubuntu than first install with these command.

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install libreoffice

Start Libreoffice with these command.

cd /usr/lib/libreoffice/program/ #to move to the libreoffice:

./soffice -nologo -nofirststartwizard -headless -norestore -invisible "-accept=socket,host=localhost,port=8100,tcpNoDelay=1;urp;" #Open Libreoffice server

If Telnet Server is not install in Ubuntu than visit Telnet installation guidance

Don't stop Libreoffice server and open another terminal for test localhost with Telnet Server
 
    telnet localhost 8100

And than Go to Settings/ Modules / Update module list : Search for 'ooo' , you will find 'report_aeroo_ooo'. Install that module.

And Finally, Configure OpenOffice.org connection from Setting/Technical/Configure OpenOffice.org co. and press connect.


I hope you like this article. Share your views to improve content. Happy Learning !!!

Monday, 9 February 2015

How related field work in Odoo 8, 9, and 10?


Let's take an example of Sale Order Line. Scenario is like when we add Product in sale order line at time, the Product Category name should be fill up. For that we need to do two  things.

  1. add related field in 'sale.order.line' and give it in view at proper place
  2. need to override onchange of product, if we don't want to override the onchange than at the time of record save it will also save the product category name.

Here is .py code:

Old API:

class sale_order_line(osv.Model):
    _inherit = 'sale.order.line'

    _columns = {
        'product_categ_name': fields.related('product_id', 'categ_id', 'name', type='char', string='Product Category', store=True, readonly=True),
}

New API:

from openerp import api, fields, models, _

class SaleOrderLine(models.Model)
    _inherit = 'sale.order.line'

    product_categ_name = fields.Char(related='product_id.categ_id.name', string='Product Category', store=True, readonly=True)

Here is .xml file

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
   
        <record id="view_product_category_related_sale_line" model="ir.ui.view">
            <field name="name">view.product.category.related.sale.line</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form" />
            <field name="arch" type="xml">
                <xpath expr="//field[@name='order_line']/form/group/group/field[@name='product_id']" position="after">
                    <field name="product_categ_name"/>
                </xpath>
            </field>
        </record>

    </data>
</openerp>


Here is screen shot of it


More about on related field, take a look here

I hope you like this article. Share your views to improve content. Happy Learning !!!

Youtubde Video 

Friday, 23 January 2015

How to replace kanban image using XPATH in Odoo?

We take an example for Partner Object like either partner has checked with Is a Company than we will show the different image or already uploaded image will show.

In Customer Form has field  " " based on it, we will show image in kanban view.

For that we only need to put .xml code.

Here is code:

<record model="ir.ui.view" id="res_partner_kanban_view_extened">
    <field name="name">res.partner.kanban.view.extened</field>
    <field name="inherit_id" ref="base.res_partner_kanban_view"/>
    <field name="model">res.partner</field>
    <field name="arch" type="xml">
        <xpath expr='//kanban/templates/t/div/a/t/t[@t-if="record.is_company.raw_value === true"]' position="replace">
        <!-- check condition weather IS A COMPANY is checked or not -->
            <t t-if="record.is_company.raw_value === true">
                <img  src="custom_patht_of_image" class="oe_kanban_image"/>
            </t>
        </xpath>
    </field>
</record>

I hope you like this article. Share your views to improve content. Happy Learning !!!

Youtube Video 

Monday, 5 January 2015

How to change "Powered by Odoo" footer in Odoo?



First go to your Odoo web module and open below file.

    addons => web => views => webclient_templates.xml

Now find this tag <div class="oe_footer">

<div class="oe_footer">
   Powered by <a href="http://www.openerp.com" target="_blank"><span>Odoo</span></a>
</div>

We can change anything like your company name or else. Now I change with "Odedra" save it and restart your server and upgrade your web module form GUI and you will got your changes.

<div class="oe_footer">
   Powered by <a href="http://www.openerp.com" target="_blank"><span>Odedra</span></a>
</div>
 


I hope you like this article. Share your views to improve content. Happy Learning !!!

Youtube Video



Thursday, 1 January 2015

Linkedin Integration with Odoo

How to integrate Linkedin with Odoo?

First of all we required following modules installed in Odoo.
  • web_linkedin
  • auth_oauth
After install above module in Odoo, We need API key of Linkedin to integrate with Odoo. For that purpose we need to create application in Linkedin, use this link https://www.linkedin.com/secure/developer

Click on Add New Application and follow below steps.

 
Here is an example of an Application. You may need to use your website URL.


 
Now agree with condition and it will generate a API key and Secret Key. Note API key because we need to use in Odoo.

Give API key to Odoo under Settings => Configuration => Sales => Social Network Integration


Apply and now go Sales => Sales => Customers and click on create button it will open below form.


Now Click on Blue button "in" it will open a pop-up below which will give you a company name and people name. And also we can find a people from the Linkedin form the right side of pop-up window.



I hope you like this article. Share your views to improve content. Happy Learning !!! 


Youtube Video

Saturday, 20 December 2014

How to display custom header and footer in all page in RML report in OpenERP 7?

Here is page template tag that may used it for display custom header and footer in all pages.

According to the report view, we need to change x and y co-ordinates. 

<pageTemplate id="first">
  <frame id="first" x1="30.0" y1="27.0" width="508" height="815"/>
    <pageGraphics>
        <image x="1.3cm" y="26.0cm" height="90.0">
              [[company.logo or removeParentNode('image')]]</image>
        <place x="16.6cm" y="25.3cm" height="1.8cm" width="15.0cm">
        <para fontSize="7.0" fontName="Helvetica" >
              [[ display_address(company.partner_id) or  '' ]]</para>
        </place>
        <lines>1.3cm 24.9cm 19.9cm 24.9cm</lines>
    </pageGraphics>
</pageTemplate>

I hope you like this article. Share your views to improve content. Happy Learning !!!  

Youtube Video 

Saturday, 13 December 2014

How to hide small edit button beside many2one field in Odoo?


Here is Purchase order form view.


For that we need to Active debug mode from the right hand side and click to the Admin and than About Odoo.


Click to the Active the Active Developer mode.


Now select Edit Formview from the Debugview.


Edit this attribute to partner_id field => options='{"no_open": True}'


Save it and Refresh the browse or press F5. We may see it now navigate menu is hide from there.



I hope you like this article. Share your views to improve content. Happy Learning !!!

Youtube Video 

ModuleNotFoundError: No module named 'psycopg2'

  Odoo 18:  Traceback (most recent call last): File "/home/bodedra/odoo18/demo/src/odoo/./odoo-bin", line 5, in ...