Using virtualenv


sudo apt-get install virtualenv

create virtualenv

virtualenv env_name

activate virtualenv

source env_name/bin/activate

switch to normal env



Odoo’s Coding Tips

Proper way to get Today’s Date and Now’s Datetime

  • Now’s Datetime >
  • Today’s Date > fields.Date.context_today(self)

Above command resolve Timezone problem, unlike using python alone, i.e., time.strftime(‘%Y-%m-%d’)

Change how the many2one dropdown is displayed through the use of name_get()


On view

<field name=”calendar_period_id” context=”{‘use_calendar_name’: True}” />

On class

class AccountPeriod(models.Model):
    _inherit = 'account.period'

    calendar_name = fields.Char(
        string='Calendar Name',

    def name_get(self):
        res = super(AccountPeriod, self).name_get()
        if self._context.get('use_calendar_name', False):
            res = []
            for rec in self:
                res.append((, rec.calendar_name))
        return res

Sorting lines with different field on Tree view

<record id="_view_sale_order_line_tree" model="ir.ui.view">
    <field name="name">sale.order.line.tree1</field>
    <field name="model">sale.order.line</field>
    <field name="type">tree</field>
    <field name="priority" eval="1"/>
    <field name="arch" type="xml">
        <tree string="Sales Order Lines" default_order="name">
            <field name="name"/>
            <field name="sequence"/>