Load custom models & fields in odoo POS


models.load_models({
    model:  'product.category',
    fields: ['name'],
    loaded: function(self,categories){
        self.categories = categories;
        console.log(self.categories);
    },
});
Advertisements

get one2many parent.id odoo


<notebook colspan="4">
    <page string="Cash Inflow Planning">
        <field name="cash_inflow_ids" context="{'project_id': parent.id}">
            <tree editable="bottom">
                <field name="period_date"/>
                <field name="deliverables_ids" widget="many2many_checkboxes" domain="[('project_id','=',context.get('project_id'))]"/>
                <field name="name"/>
            </tree>
        </field>
    </page>
</notebook>

Odoo-12 installation step on Ubuntu-18.04


Step-1:

Before we get into the installation process, you should definitely update and upgrade Ubuntu.

Open a terminal window and issue the commands:

sudo apt-get update
sudo apt-get -y upgrade

Step-2:

Install Python 3 and dependencies for Odoo.

sudo apt-get install python3-pip
pip3 install Babel decorator docutils ebaysdk feedparser gevent greenlet html2text Jinja2 lxml Mako MarkupSafe mock num2words ofxparse passlib Pillow psutil psycopg2 pydot pyparsing PyPDF2 pyserial python-dateutil python-openid pytz pyusb PyYAML qrcode reportlab requests six suds-jurko vatnumber vobject Werkzeug XlsxWriter xlwt xlrd

Step-3:

Odoo Web Dependencies

sudo apt-get install -y npm
sudo ln -s /usr/bin/nodejs /usr/bin/node
sudo npm install -g less less-plugin-clean-css
sudo apt-get install node-less

Step-4:

sudo apt-get install python-software-properties OR sudo apt-get install software-properties-common

Install Postgresql Latest Version

sudo gedit /etc/apt/sources.list/dgpg.list

Add a line for the repository:

deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main
wget –quiet -O – https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add –

sudo apt-get update

sudo apt-get install postgresql-9.6

If the Above command not worked or not installing the Postgresql 9.6 Then you can use below code to install the Postgresql.

sudo add-apt-repository “deb https://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main”
sudo apt-get update
sudo apt-get install postgresql-9.4

To set Postgres Password:

ubuntu@:~$ sudo passwd postgres

Enter new UNIX password:****

Retype new UNIX password:****

passwd: password updated successfully

Step-5:

Create Database User For Odoo:

sudo su postgres
createuser -s odoo
createuser -s ubuntu_user_name
exit(Ctrl + d)

Step-6:

Create Odoo User and Group:

sudo adduser –system –home=/opt/ –group odoo

Step-7:

install Gdata

cd /opt/
sudo wget https://pypi.python.org/packages/a8/70/bd554151443fe9e89d9a934a7891aaffc63b9cb5c7d608972919a002c03c/gdata-2.0.18.tar.gz
sudo tar zxvf gdata-2.0.18.tar.gz
sudo chown -R odoo: gdata-2.0.18
sudo -s
cd gdata-2.0.18/
python setup.py install
exit

Step-8:
Odoo-12 Download from GITHUB

cd /opt
sudo apt-get install git
sudo chown -R odoo: /opt
sudo su – odoo -s /bin/bash
git clone https://www.github.com/odoo/odoo –depth 1 –branch 12.0 –single-branch
exit

Step-9:

Install the necessary Python packages for the Odoo-12

cd opt/odoo
sudo pip3 install -r requirements.txt

Notes:-if any of the Python Packages is not installing then find and remove from the requirements.txt files. And again run the same above command for further installation. Once done with the installation then those which are installed, install them forcefully from the terminal.

Install pypdf2 python Library for odoo
apt-get install python3-pypdf2

Step-10:

Create Odoo-log Folder and Files:

sudo mkdir /var/log/odoo
cd var/log/odoo
sudo touch odoo-server.log
sudo chown -R odoo:root /var/log/odoo

Step-11:

Edit odoo configuration Files:

sudo gedit /etc/odoo.conf

#Copy This lines and Paste into File and then change user and password if any

[options]
; This is the password that allows database operations:
; admin_passwd = admin
db_host = False
db_port = False
db_user = odoo
db_password = False
logfile = /var/log/odoo/odoo-server.log
addons_path = /opt/odoo/addons,/opt/odoo/odoo/addons

sudo chown odoo: /etc/odoo.conf

Step-12:

Install WKHTMLTOPDF

sudo wget https://builds.wkhtmltopdf.org/0.12.1.3/wkhtmltox_0.12.1.3-1~bionic_amd64.deb
sudo dpkg -i wkhtmltox_0.12.1.3-1~bionic_amd64.deb
sudo apt-get install -f
sudo ln -s /usr/local/bin/wkhtmltopdf /usr/bin
sudo ln -s /usr/local/bin/wkhtmltoimage /usr/bin

Step-13:

Create odoo server file run odoo service

vim /etc/init.d/odoo12

COPY PASTE THE BEOLWE CONTENT IN odoo12 file on terminal.
Makes the necessary changes for the Files like, DAEMON=(ODOO-BIN PATH); CONFIGFILE=(ODOO CONFIG FILE PATH) ETC.

#!/bin/sh

### BEGIN INIT INFO

# Provides: odoo-server

# Required-Start: $remote_fs $syslog

# Required-Stop: $remote_fs $syslog

# Should-Start: $network

# Should-Stop: $network

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Short-Description: Complete Business Application software

# Description: Odoo is a complete suite of business tools.

### END INIT INFO

PATH=/bin:/sbin:/usr/bin

DAEMON=/opt/odoo/odoo-bin

NAME=odoo-bin

DESC=odoo-bin

# Specify the user name (Default: odoo).

USER=odoo

# Specify an alternate config file (Default: /etc/odoo.conf).

CONFIGFILE=”/etc/odoo.conf”

# pidfile

PIDFILE=/var/run/$NAME.pid

Additional options that are passed to the Daemon.

DAEMON_OPTS=”-c $CONFIGFILE”

[ -x $DAEMON ] || exit 0

[ -f $CONFIGFILE ] || exit 0

checkpid() {

[ -f $PIDFILE ] || return 1

pid=`cat $PIDFILE`

[ -d /proc/$pid ] && return 0

return 1

}

case “${1}” in

start)

echo -n “Starting ${DESC}: ”

start-stop-daemon –start –quiet –pidfile ${PIDFILE} \

–chuid ${USER} –background –make-pidfile \

–exec ${DAEMON} — ${DAEMON_OPTS}

echo “${NAME}.”

;;

stop)

echo -n “Stopping ${DESC}: ”

start-stop-daemon –stop –quiet –pidfile ${PIDFILE} \

echo “${NAME}.”

;;

restart|force-reload)

echo -n “Restarting ${DESC}: ”

start-stop-daemon –stop –quiet –pidfile ${PIDFILE} \

–oknodo

sleep 1

start-stop-daemon –start –quiet –pidfile ${PIDFILE} \

–chuid ${USER} –background –make-pidfile \

–exec ${DAEMON} — ${DAEMON_OPTS}

echo “${NAME}.”

;;

*)

N=/etc/init.d/${NAME}

echo “Usage: ${NAME} {start|stop|restart|force-reload}”>&2

exit 1

;;

esac

exit 0

STEP-14:

Now Run Odoo Server from the opt/odoo folder by odoo-bin

cd opt/odoo./odoo-bin

if You want to Run on another port then

./odoo-bin –xmlrpc-port=5069

How to run automated actions at a specific time everyday


<record id="ir_cron_module_get_active_sr" model="ir.cron">
        <field name="name">Get Active Srs</field>
        <field eval="True" name="get_active_srs" />
        <!--<field name="user_id" ref="base.user_root" />-->
        <field name="interval_number">1</field>
        <field name="nextcall" eval="(DateTime.now() + timedelta(days=1)).strftime('%Y-%m-%d 12:00:00')" />        
        <!--<field name="nextcall" eval="(DateTime.now().date() + timedelta(days=1)).strftime('%Y-%m-%d 21:00:00')"/>-->
        <field name="interval_type">days</field>
        <field name="numbercall">-1</field>
        <field eval="False" name="doall" />
        <field eval="'hr.attendance'" name="model" />
        <field eval="'get_active_srs'" name="function" />
        <field eval="'(None,)'" name="args" />
        <field name="priority">1000</field>
</record>

How to call python function from QWeb


.xml code

<t t-foreach="o._get_purchase_mrn_details(o.origin,pack_operation.product_id)" t-as="purchase_line">
   <td class="text-right"><span t-esc="purchase_line['price_unit']"/></td>                            
   <td class="text-right"><span t-esc="purchase_line['taxes_id']"/></td>   
</t>
<span t-if ="o.get_issuenote_title() == 'Issue'">ISSUE NOTE</span> 

.py code

@api.multi
    def _get_purchase_mrn_details(self,origin,product_id):
        if origin and product_id:
            self.ensure_one()
            purchase_data = []
            purchase_order_obj = self.env['purchase.order'].search([('name','=',origin)])
            order_line_ids = purchase_order_obj.order_line.mapped('product_id')
            for line in purchase_order_obj.order_line:
                if line.product_id.id == product_id.id:
                    purchase_data.append ({
                        'price_unit': line.price_unit,
                        'taxes_value': line.taxes_id.amount,
                        'taxes_id': line.taxes_id.name,
                    })
            return purchase_data
@api.multi
    def get_issuenote_title(self):
        
        if  self.location_id.usage == 'supplier' and self.location_dest_id.is_central_stock:
            return "Issue"

        if  self.location_id.is_central_stock and not self.location_dest_id.is_central_stock:
            return "Issue"

        if not self.location_id.is_central_stock  and not self.location_dest_id.is_central_stock:
            return "Site Issue"