How to track a field in messages in Odoo

.python file
For tracking a field we have to specify it in the field definition with parameter track_visibility set to ‘always’ or ‘onchange’ like the following:

from odoo import models,fields,api,_,SUPERUSER_ID

class SaleOrder(models.Models):
    _name = "sale.order"
    _inherit = ['mail.thread', 'ir.needaction_mixin']
    state = fields.Selection([
        ('draft', 'Draft'),
        ('submitted', 'Submitted'),
        ('paid', 'Paid'),
        ],default='draft',string='Status', copy=False, index=True,         readonly=True, store=True,track_visibility='always',

    def action_submit(self):        
        self.state = 'submitted'
        body =_("Expense Advance Submitted")
        subject = _("Expense Advance")
        self.sudo().message_post(body=body,subject=subject, message_type="notification", subtype="mail.mt_comment",

you can use author_id=SUPERUSER_ID

.xml file after sheet you can place this.

<div class="oe_chatter">
   <field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
   <field name="message_ids" widget="mail_thread"/>

Create journal entry using code – odoo

   #Posting journal entries
    def action_done(self):
        for rec in self:
            debit = credit = rec.currency_id.compute(rec.paid_amount, rec.currency_id)           
            if rec.state == 'draft':
                raise UserError(_("Only a Submitted payment can be posted. Trying to post a payment in state %s.") % rec.state)

            sequence_code = 'hr.advance.sequence'
   = self.env['ir.sequence'].with_context(ir_sequence_date=rec.payment_date).next_by_code(sequence_code)
            move = {
                'name': '/',
                'date': rec.payment_date,

                'line_ids': [(0, 0, {
                        'name': or '/',
                        'debit': debit,
                    }), (0, 0, {
                        'name': or '/',
                        'credit': credit,
            move_id = self.env['account.move'].create(move)
            return rec.write({'state': 'paid', 'move_id':})

Automatically fill One2many in Odoo

#T&C in each SO
class sale_order(models.Model):
    _inherit = "sale.order"
    #By default load the terms and conditions configured in the master T&C configuration
    def _default_so_tc(self):
        terms_obj = self.env['so.terms.config']
        terms = []
        termsids =[])
        for rec in termsids:
            values = {}
            values['name'] =
            values['description'] = rec.description
            terms.append((0, 0, values))
        return terms

    terms = fields.One2many('sale.order.terms.conditions','order_id',string='Terms and Conditions',copy=True,default=_default_so_tc)

Use context in email templates odoo

in file

local_context = self.env.context.copy()
'email_to': '',
'email_from': '',
'name': 'Passport',
'document_number': 'H89746023',
'expiry_date': '12-12-2017',
'description': 'Please Check',
template = self.env.ref('hr_dcoument_manager.email_template_employee_document_reminder_mail',False)
template.with_context(local_context).send_mail(, raise_exception=True)

In email template code you can access context as:

<div>Document Name: <strong>${ctx['name']}</strong><br/></div>
<div>Document ID: <strong>${ctx['document_number']}</strong></div>

file permissions for WordPress

When you setup WP you (the webserver) may need write access to the files. So the access rights may need to be loose.

chown www-data:www-data -R /var/www/html/* # Let Apache be owner
find /var/www/html -type d -exec chmod 755 {} \; # Change directory permissions rwxr-xr-x
find /var/www/html -type f -exec chmod 644 {} \; # Change file permissions rw-r–r–

After the setup you should tighten the access rights, according to Hardening WordPress all files except for wp-content should be writable by your user account only. wp-content must be writable by www-data too.

chown : -R * # Let your useraccount be owner
chown www-data:www-data wp-content # Let apache be owner of wp-content

Maybe you want to change the contents in wp-content later on. In this case you could

temporarily change to the user to www-data with su,
give wp-content group write access 775 and join the group www-data or
give your user the access rights to the folder using ACLs.
Whatever you do, make sure the files have rw permissions for www-data.

Redirect to tree view from button click odoo

.py file

from odoo import api, fields, models, _
from odoo.exceptions import ValidationError
from odoo import tools

class Project(models.Model):
    _inherit = "project.project"

    def action_view_project_cashflow_report(self):
        project_ids =
            'name'          :   ('Project Cashflow Report'),
            'type'          :   'ir.actions.act_window',
            'view_type'     :   'form',
            'view_mode'     :   'pivot',
            'target'        :   'new', 
            'res_model'     :   '',
            'view_id'       :   False,
            'domain'        :   [('project_id','in',[project_ids])]

.xml file

<xpath expr="//button[@name='attachment_tree_view']" position="after">
<button class="oe_stat_button" name="action_view_project_cashflow_report"
        string="Cash Flow" type="object"

get one2many parent id odoo

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