'Changes the Standard Price of Product and creates an account move accordingly.'

@api.multi
def do_change_standard_price(self, new_price, account_id):

    AccountMove = self.env['account.move']
    locations = self.env['stock.location'].search([('usage', '=', 'internal'), ('company_id', '=', self.env.user.company_id.id)])
    product_accounts = {product.id: product.product_tmpl_id.get_product_accounts() for product in self}
    for location in locations:
        for product in self.with_context(location=location.id, compute_child=False).filtered((lambda r: (r.valuation == 'real_time'))):
            diff = (product.standard_price - new_price)
            if float_is_zero(diff, precision_rounding=product.currency_id.rounding):
                raise UserError(_('No    difference    between    standard    price    and    new    price!'))
            if (not product_accounts[product.id].get('stock_valuation', False)):
                raise UserError(_("You    don't    have    any    stock    valuation    account    defined    on    your    product    category.    You    must    define    one    before    processing    this    operation."))
            qty_available = product.qty_available
            if qty_available:
                if ((diff * qty_available) > 0):
                    debit_account_id = account_id
                    credit_account_id = product_accounts[product.id]['stock_valuation'].id
                else:
                    debit_account_id = product_accounts[product.id]['stock_valuation'].id
                    credit_account_id = account_id
                move_vals = {'journal_id': product_accounts[product.id]['stock_journal'].id, 'company_id': location.company_id.id, 'line_ids': [(0, 0, {'name': _('Standard    Price    changed'), 'account_id': debit_account_id, 'debit': abs((diff * qty_available)), 'credit': 0}), (0, 0, {'name': _('Standard    Price    changed'), 'account_id': credit_account_id, 'debit': 0, 'credit': abs((diff * qty_available))})]}
                move = AccountMove.create(move_vals)
                move.post()
    self.write({'standard_price': new_price})
    return True
