Calling a python method (server action) directly from menuitem or button

Tags


Here is an example:

Server Action

<record id=”action_make_testing” model=”ir.actions.server”>

<field name=”name”>Make Testing</field>

<field name=”condition”>True</field>

<field name=”type”>ir.actions.server</field>

<field name=”model_id” ref=”model_res_partner” />

<field name=”state”>code</field>

<field name=”code”>self.test_act(cr, uid, context.get(‘active_ids’, []), context=context)</field>

</record>

Menu:

<menuitem id=’menu_testing’ name=’Testing’ sequence=”100″ parent=”base.menu_base_config” action=”action_make_testing”/>

or

<button name=”%(action_make_testing)d” string=”Send by Email” type=”action” confirm=”Are you sure you want to do this?”/>

Python code to run : Method name = test_act

class res_partner(osv.osv):

_inherit = ‘res.partner’

def test_act(self,cr,uid,ids,context={}):

return True

How to send email with existing template -odoo

Tags


def send_by_email(self, cr, uid,ids, context=None):
mail_mail = self.pool.get('mail.mail')
email_template_obj = self.pool.get('email.template')
template_ids = email_template_obj.search(cr, uid, [('model_id.model', '=','account.invoice')], context=context)
ir_attachment = self.pool.get('ir.attachment')
if template_ids:

values = email_template_obj.generate_email(cr, uid, template_ids[0], 2, context=context)
if not values.get('email_from'):
raise osv.except_osv(_('Warning!'), _("Sender email is missing or empty after template rendering. Specify one to deliver your message"))
values['recipient_ids'] = [(4, pid) for pid in values.get('partner_ids', list())]
attachment_ids = values.pop('attachment_ids', [])
attachments = values.pop('attachments', [])
msg_id = mail_mail.create(cr, uid, values, context=context)
mail = mail_mail.browse(cr, uid, msg_id, context=context)

for attachment in attachments:
attachment_data = {
'name': attachment[0],
'datas_fname': attachment[0],
'datas': attachment[1],
'res_model': 'mail.message',
'res_id': mail.mail_message_id.id,
}
context = dict(context)
context.pop('default_type', None)
attachment_ids.append(ir_attachment.create(cr, uid, attachment_data, context=context))
if attachment_ids:
values['attachment_ids'] = [(6, 0, attachment_ids)]
mail_mail.write(cr, uid, msg_id, {'attachment_ids': [(6, 0, attachment_ids)]}, context=context)

#if msg_id:
#mail_mail.send(cr, uid, [msg_id], context=context)

return True

Customize odoo notification mail from Name

Tags

,


class mail_message(osv.Model):
    _inherit="mail.message"
    
    def _get_default_from(self, cr, uid, context=None):
        this = self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context)
        if this.alias_name and this.alias_domain:
            return formataddr(('odoo - '+this.name, '%s@%s' % (this.alias_name, this.alias_domain)))
        elif this.email:
            return formataddr(('odoo - '+this.name, this.email))
        raise osv.except_osv(_('Invalid Action!'), _("Unable to send email, please configure the sender's email address or alias."))

How to Create a Network Share Via Samba – odoo

Tags

,


1). sudo apt-get install samba
2). vim /etc/samba/smb.conf
add below line to bottom
[odoo10-share]
  comment = odoo share
  path = /opt/odoo
  browsable = yes
  guest ok = yes
  read only = no
  create mask = 0777
  force user = odoo
  directory mask = 0777
3) sudo systemctl restart smbd.service nmbd.service
4) Access through \\192.168.56.11\odoo10-share

Install ODOO 10 on UBUNTU 16.04 LTS

Tags


STEP 1

Update apt source list

sudo apt-get update

STEP 2

Install Updates

sudo apt-get upgrade

STEP 3

Install Python Dependencies for Odoo

sudo apt-get install python-dateutil python-docutils python-feedparser python-jinja2 python-ldap python-libxslt1 python-lxml python-mako python-mock python-openid python-psycopg2 python-psutil python-pybabel python-pychart python-pydot python-pyparsing python-reportlab python-simplejson python-tz python-unittest2 python-vatnumber python-vobject python-webdav python-werkzeug python-xlwt python-yaml python-zsi poppler-utils python-pip python-pypdf python-passlib python-decorator gcc python-dev mc bzr python-setuptools python-markupsafe python-reportlab-accel python-zsi python-yaml python-argparse python-openssl python-egenix-mxdatetime python-usb python-serial lptools make python-pydot python-psutil python-paramiko poppler-utils python-pdftools antiword python-requests python-xlsxwriter python-suds python-psycogreen python-ofxparse python-gevent

STEP 4

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

STEP 5

Install PostgreSQL

sudo apt-get install python-software-properties
sudo vim /etc/apt/sources.list.d/pgdg.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

STEP 6

Create Database user for Odoo

sudo su postgres
cd
createuser -s odoo
createuser -s ubuntu_user_name
exit

STEP 7

Create Odoo user and group

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

STEP 8

Install Gdatacd /opt/odoo

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 9

Odoo 10 Download from GitHub

cd /opt/odoo
sudo wget https://github.com/odoo/odoo/archive/10.0.zip
sudo unzip 10.0.zip
sudo chown -R odoo: odoo-10.0

sudo mv odoo/ odoo-10.0/
sudo chown -R odoo: odoo-10.0

STEP 10

Create Odoo Log File

sudo mkdir /var/log/odoo
sudo chown -R odoo:root /var/log/odoo

STEP 11

Edit Odoo configuration file

sudo cp /opt/odoo/odoo-10.0/debian/odoo.conf /etc/odoo.conf
sudo chown odoo: /etc/odoo.conf
sudo vim /etc/odoo.conf

#Copy and paste below content in config file
[options]
; This is the password that allows database operations:
; admin_passwd = PASSWORD
db_host = False
db_port = False
db_user = odoo
db_password = False
addons_path = /opt/odoo/odoo-10.0/addons
;Log Settings
logfile = /var/log/odoo/odoo.log
log_level = error

STEP 12

sudo wget  https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.1/wkhtmltox-0.12.1_linux-trusty-i386.deb

Install the package using command

sudo dpkg -i wkhtmltox-0.12.1_linux-trusty-amd64.deb

Copy wkhtmltoimage to /usr/bin location from /usr/local/bin by using below command

sudo cp /usr/local/bin/wkhtmltoimage /usr/bin/wkhtmltoimage

Copy wkhtmltopdf to /usr/bin location from /usr/local/bin by using below command

sudo cp /usr/local/bin/wkhtmltopdf /usr/bin/wkhtmltopdf

STEP 13

Now Start Odoo Server

cd /opt/odoo/odoo-10.0
./odoo-bin

STEP 14 (Automated Start)

sudo vim /etc/systemd/system/odoo10.service

[Unit]
Description=Odoo
Documentation=http://www.odoo.com/
[Service]
# Ubuntu/Debian convention:
Type=simple
User=odoo
ExecStart=/opt/odoo/odoo-10.0/odoo-bin -c /etc/odoo.conf
[Install]
WantedBy=default.target

sudo mkdir /var/lib/odoo
sudo chown odoo:root /var/lib/odoo -R

sudo systemctl start odoo10.service (starts service)
sudo systemctl stop odoo10.service (stops service)
sudo systemctl restart odoo10.service (restarts Service)
sudo systemctl status odoo10.service (status of service)
sudo systemctl enable odoo10.service (starts service at boot)
sudo systemctl disable odoo10.service (disables service at boot)

STEP 15

Go to web browser to access Odoo 10

http://localhost:8069

Odoo PyCharm Templates

Tags


Templates for Odoo in PyCharm

This Templates can help you to develop Odoo Modules Faster and with no Typing Errors

Download odoo.xml file and place in pycharm template folder

https://github.com/ananthukrishna/odoo-pycharm-templates/blob/master/Odoo.xml

Configuration:

Windows

C:\Users\user\.PyCharmCE2016.3\config\templates

If You are using a linux distribution you can save the XML file in PyCharm files, Just find the path:

~/.PyCharm*/config/templates

MacOs X users, look for the templates folder here:

~/Library/Preferences/PyCharm*/templates

and save the XML file there. Enjoy your time developing great Odoo Modules 🙂

How to open wizard from odoo more option

Tags

,


In xml file

<!– Define the form view –>

<record model=”ir.ui.view” id=”view_id”>
<field name=”name”>view.name</field>
<field name=”model”>wizard model name</field>
<field name=”arch” type=”xml”>
<form string=”any string” version=”7.0″>
<group>
<!– Define fields–>
</group>
<footer>
<button string=”Any String” name=”your_method_name” type=”object” class=”oe_highlight”/>
or
<button string=”Cancel” class=”oe_link” special=”cancel”/>
</footer>
</form>
</field>
</record>

<!– Define the act window –>

<act_window id =”your_action_id”
name=”Any String”
res_model=”wizard model name”
src_model=”model name where you want to see from more option”  # I want See wizard inside sale order more option so here I will write “sale.order”
view_type=”form”
view_mode=”form”
key2=”client_action_multi”
target=”new”
/>