Wednesday 12 April 2023

How to update One2many or Many2many field in odoo ?

Below is the possible way to update, remove or add values in the many2many field:


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


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


(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)


(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)


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


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


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

Friday 31 March 2023

How to scan barcode without barcode scanner using python ?

 import time, sys, pyautogui


def barcode_scan(delay, output):

    time.sleep(delay)

    pyautogui.typewrite(output)

    

barcode_scan(4, 'DU0000000084')

Monday 6 March 2023

Log all queries in the official Postgres docker image

 Setting log_destination to stderr did the trick for me without creating a new image:


version: "2.2" services: db: image: postgres:12-alpine command: ["postgres", "-c", "log_statement=all", "-c", "log_destination=stderr"]


And then I was able to trace the statements using docker-compose logs -f db.

Should work with other versions too, but I only tested it with postgres:12-alpine. 

Tuesday 10 January 2023

How to pass data from wizard to sql view report odoo?

 There is 2 way we can pass wizard data to SQL view ODOO. 


1 )  using context we can pass the selected value by user .

        as per below wizard view report method.


 def view_report(self):

        action = self.env["ir.actions.actions"]._for_xml_id("module_name.report_sql_view_action")

        context = {

            'start_date': self.start_date,

            'end_date': self.end_date,

        }

        # to initialise again SQL report with user new value.

        self.env["model.report"].with_context(context).init()

        return action


2 )  using init method of sql class as a passing parameter in the method.


 def view_report(self):

        action = self.env["ir.actions.actions"]._for_xml_id("module_name.report_sql_view_action")

        # to initialise again SQL report with user new value.

        self.env["model.report"].init(self.start_date, self.end_date)

        return action

Wednesday 17 June 2020

Which is the best IDE for developping in Odoo on Ubuntu?

There are best 3 editor you can use for developing odoo applications or any developing purpose.

1) Sublime: This is the light weight editor and provides some theme and shortcuts for ubuntu. It is very useful for low configuration device. It will take very low memory of usage.

2) PyCharm: This is very useful and attractive editor. It will provides lots of addons.

3) Eclipse: This is also good one

Odoo10 - How to inherit t-if tag and extend it template.

<t t-extend="template_name">

    <t t-jquery="[div,span,button,etc].class_name" t-operation="[replace,after,before]">

        <-- your code -->

    </t>

</t>

for example :

<t t-extend="website_sale.products_item">

    <t t-jquery="div.product_price" t-operation="replace">

        <-- your code -->

    </t>

</t>

Sunday 16 June 2019

Get started with Docker for Windows + Odoo

        Docker is a full development platform for creating containerized apps, and Docker Desktop for Windows is the best way to get started with Docker on Windows.
          Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

See Install Docker Desktop for Windows for information on system requirements and stable & edge channels.
Open a terminal window (Command Prompt or PowerShell, but not PowerShell ISE).
  1. Run docker --version to ensure that you have a supported version of Docker:
    > docker --version
    
    Docker version 18.03.0-ce, build 0520e24
    
  2. Pull the hello-world image from Docker Hub and run a container:
    > docker run hello-world
    
    docker : Unable to find image 'hello-world:latest' locally
    ...
    
    latest:
    Pulling from library/hello-world
    ca4f61b1923c:
    Pulling fs layer
    ca4f61b1923c:
    Download complete
    ca4f61b1923c:
    Pull complete
    Digest: sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1
    Status: Downloaded newer image for hello-world:latest
    
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    ...
    
  3. List the hello-world image that was downloaded from Docker Hub:
    > docker image ls
    
  4. List the hello-world container (that exited after displaying “Hello from Docker!”):
    > docker container ls --all
    
  5. Explore the Docker help pages by running some help commands:
    > docker --help
    > docker container --help
    > docker container ls --help
    > docker run --help
Configuring Odoo

For configuring Odoo we have to first setup PostgreSQL image on docker and link that to the Odoo.


// pulls the PostgreSQL image from docker hub docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo --name db postgres:9.4
// pulls the Odoo image from docker hub and linking to PostgreSQL docker run -p 8069:8069 --name odoo --link db:db -t odoo // pulls the Odoo 10 image from docker hub and linking to PostgreSQL
docker run -p 8069:8069 --name odoo --link db:db -t odoo:10
In above code the --name is the name of the docker container. We can use that to start and stop the container. -p is the port no: that docker needed to expose to outside.

For start and stop servers we can use the following commands. After you run docker runcommand once don't run it again, unless you are planning for multiple instance of Odoo. Use below commands instead. Because it will download latest version again and will occupy more space.

docker start odoo // start the odoo
docker stop odoo // stop odoo container

Now you can check the Odoo running on:8069

Also, here is some useful command when we are using docker

For Buid New image:

> docker build -t "New Image Name" "path of docker file"

For Execute command and Connect to image:

> docker exec -it "image name" bash //Enter in the image or
> docker exec -it "image name" pip3 install xlrd // Install Package