Mysql crashed and won’t start up

  1. Stop mysqld.
  2. Backup /var/lib/mysql/ib*
  3. Add the following line into /etc/my.cnf

innodb_force_recovery = 1 (they suggest 4, but its best to start with 1 and increment if it won’t start)

  1. Restart mysqld.
  2. Dump all tables:# mysqldump -A > dump.sql
  3. Drop all databases which need recovery.
  4. Stop mysqld.
  5. Remove /var/lib/mysql/ib*
  6. Comment out innodb_force_recovery in /etc/my.cnf
  7. Restart mysqld. Look at mysql error log. By default it should be /var/lib/mysql/server/ to see how it creates new ib* files.
  8. Restore databases from the dump:mysql < dump.sql

Get users ids from the group – odoo

    def create(self, vals):
        result = super(HrExpenseAdvances,self).create(vals)        
        group_hr_expense_manager_id = self.env[''].xmlid_to_res_id('hr_expense.group_hr_expense_manager')
        hr_expense_managers = self.get_users_from_group(group_hr_expense_manager_id)
        if hr_expense_managers:
        return result
    #passing group id using self.env[''].xmlid_to_res_id('hr_expense.group_hr_expense_manager')
    def get_users_from_group(self,group_id):
        users_ids = []
        sql_query = """select uid from res_groups_users_rel where gid = %s"""                
        params = (group_id,), params)
        results =
        for users_id in results:
        return users_ids

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:

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.message_post(body=body, subject=subject,message_type="notification", subtype="mail.mt_comment",)

.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.