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/hostname.com.err to see how it creates new ib* files.
  8. Restore databases from the dump:mysql < dump.sql
Advertisements

Get users ids from the group – odoo


@api.model
    def create(self, vals):
        result = super(HrExpenseAdvances,self).create(vals)        
        group_hr_expense_manager_id = self.env['ir.model.data'].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:
            result.message_subscribe_users(user_ids=hr_expense_managers)
        return result
    
    #passing group id using self.env['ir.model.data'].xmlid_to_res_id('hr_expense.group_hr_expense_manager')
    @api.multi
    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,)
        self.env.cr.execute(sql_query, params)
        results = self.env.cr.fetchall()
        for users_id in results:
            users_ids.append(users_id[0])
        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',

    @api.multi
    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"/>
</div>

Create journal entry using code – odoo


   #Posting journal entries
    @api.multi
    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'
            rec.name = self.env['ir.sequence'].with_context(ir_sequence_date=rec.payment_date).next_by_code(sequence_code)
            
            move = {
                'name': '/',
                'journal_id': rec.journal_id.id,
                'date': rec.payment_date,

                'line_ids': [(0, 0, {
                        'name': rec.name or '/',
                        'debit': debit,
                        'account_id': rec.advance_account.id,
                        'partner_id': rec.employee_id.user_id.partner_id.id,
                    }), (0, 0, {
                        'name': rec.name or '/',
                        'credit': credit,
                        'account_id': rec.journal_id.default_credit_account_id.id,
                        'partner_id': rec.employee_id.user_id.partner_id.id,
                    })]
            }
            move_id = self.env['account.move'].create(move)
            move_id.post()    
            return rec.write({'state': 'paid', 'move_id': move_id.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
    @api.model
    def _default_so_tc(self):
        terms_obj = self.env['so.terms.config']
        terms = []
        termsids = terms_obj.search([])
        for rec in termsids:
            values = {}
            values['name'] = rec.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 module.py file

local_context = self.env.context.copy()
local_context.update({
'email_to': 'ananthu@epillars.com',
'email_from': 'admin@epillars.com',
'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(self.id, 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.